Xendit Go SDK

repository·master·Indexed 41 days ago

https://github.com/xendit/xendit-go

The official client library for interacting with Xendit's REST APIs within Go applications. Version v7 provides an APIClient to manage services including InvoiceApi, PaymentRequestApi, PaymentMethodApi, RefundApi, BalanceApi, TransactionApi, CustomerApi, and PayoutApi.

Tokens
196.7K
Snippets
443
Records
719
Agent score
99%

What's inside Xendit

  1. Access and set Capture properties

    master

    The Capture object provides getter and setter methods for all its fields.

    Getter Patterns

    For most fields, there are two types of getters:

    1. Get<FieldName>(): Returns the field value if non-nil, or the zero value otherwise.
    2. Get<FieldName>Ok(): Returns a tuple containing a pointer to the field value and a boolean indicating if the value was actually set.

    Setter Patterns

    • Set<FieldName>(v): Sets the field to the provided value.
    • For NullableString or map types, you can also use:
      • Set<FieldName>Nil(bool): Sets the value to an explicit nil.
      • Unset<FieldName>(): Ensures no value is present, not even an explicit nil.
  2. Use DateRangeFilter to filter transactions by time

    master

    The DateRangeFilter is used to constrain balance or transaction queries to a specific time window. It uses two primary properties:

    • Gte: The start time (Greater Than or Equal to). If not specified, the API lists all dates.
    • Lte: The end time (Less Than or Equal to). If not specified, the API lists all dates.

    You can instantiate this filter using NewDateRangeFilter() (which ensures required API properties are set) or NewDateRangeFilterWithDefaults() (which only applies default values).

  3. Manage Card properties

    master

    The Card object contains several properties used for payment method details. Because many fields are pointers or nullable, the SDK provides specific getter and setter methods to safely manage them.

    Properties

    NameTypeRequiredDescription
    ChannelCode*CardChannelCode
    Currency*NullableString
    ChannelPropertiesNullableCardChannelProperties☑️
    CardInformation*TokenizedCardInformation
    CardVerificationResults*NullableCardVerificationResults

    Accessing Values

    To avoid nil pointer dereferences, use the Get...Ok pattern which returns the value and a boolean indicating if the field was set:

    • GetChannelCodeOk() (*CardChannelCode, bool)
    • GetCurrencyOk() (*string, bool)
    • GetChannelPropertiesOk() (*CardChannelProperties, bool)
    • GetCardInformationOk() (*TokenizedCardInformation, bool)
    • GetCardVerificationResultsOk() (*NullableCardVerificationResults, bool)
  4. Understand the ServerError structure

    master

    The ServerError type represents an error response from the Xendit API. It contains three primary properties:

    NameTypeRequiredDescription
    StatusCodefloat32YesThe HTTP status code returned by the server
    ErrorstringYesThe error code or identifier
    MessagestringYesA human-readable error message

    Use the provided getter and setter methods to safely interact with these fields, especially when handling nil pointers.

  5. Manage nullable fields in VirtualAccountParameters

    master

    Since many fields in VirtualAccountParameters are pointers to nullable types, the SDK provides a consistent pattern of getter and setter methods to manage presence and nullability:

    Setting Values

    • Set[FieldName](value): Sets the field to the provided value.
    • Set[FieldName]Nil(bool): Sets the field to an explicit nil if true.
    • Unset[FieldName](): Ensures no value is present for the field (removes even an explicit nil).

    Getting Values

    • Get[FieldName](): Returns the field value if non-nil, otherwise returns the zero value.
    • Get[FieldName]Ok() (*Type, bool): Returns a tuple containing the field value (if non-nil) and a boolean indicating if the field was actually set.
    • Has[FieldName]() bool: Returns true if the field has been set.
  6. Manage PaymentMethodParameters fields

    master

    The PaymentMethodParameters struct provides getter and setter methods for its various fields. Most fields follow a consistent pattern for handling optionality and nil values:

    Getters

    • Get<FieldName>(): Returns the field value if non-nil, otherwise returns the zero value.
    • Get<FieldName>Ok(): Returns a tuple (*Type, bool). The boolean indicates if the value has been explicitly set.

    Setters

    • Set<FieldName>(v Type): Sets the field to the provided value.
    • Set<FieldName>Nil(b bool): Sets the field to an explicit nil.
    • Unset<FieldName>(): Ensures no value is present for the field, not even an explicit nil.

    Presence Checks

    • Has<FieldName>(): Returns a boolean indicating if the field has been set.
  7. Manage PatchCustomer fields (Set, Get, and Presence)

    master

    The PatchCustomer object uses a specific pattern for managing fields to support partial updates (patching). For every field (e.g., ClientName, Email, Status), the following methods are available:

    Setting Values

    • Set<FieldName>(v): Sets the field to the provided value.
    • Set<FieldName>Nil(b bool): Sets the field to an explicit nil (useful for clearing values in the API).
    • Unset<FieldName>(): Ensures no value is present for the field, not even an explicit nil (the field will be omitted from the request).

    Getting Values

    • Get<FieldName>(): Returns the field value if non-nil, otherwise returns the zero value.
    • Get<FieldName>Ok(): Returns a tuple (*Type, bool). The boolean is true if the field has been explicitly set, and false otherwise.

    Checking Presence

    • Has<FieldName>(): Returns true if the field has been set.

    Supported Fields

    Commonly used fields include:

    • ClientName (string)
    • ReferenceId (string)
    • Email (string)
    • MobileNumber (string)
    • PhoneNumber (string)
    • Description (string)
    • Status (EndCustomerStatus)
    • Metadata (map[string]interface{})
    • Addresses ([]AddressRequest)
    • IndividualDetail (IndividualDetail)
    • BusinessDetail (BusinessDetail)
  8. Manage CardVerificationResultsThreeDSecure fields

    master

    The SDK provides a consistent pattern for interacting with the nullable fields in CardVerificationResultsThreeDSecure. For each field (e.g., ThreeDSecureFlow, EciCode, ThreeDSecureResult, ThreeDSecureResultReason, ThreeDSecureVersion), you can use the following methods:

    Getting Values

    • Get<FieldName>() string: Returns the field value if non-nil; otherwise, returns the zero value.
    • Get<FieldName>Ok() (*string, bool): Returns a tuple containing the field value (if non-nil) and a boolean indicating if the value was actually set.
    • Has<FieldName>() bool: Returns true if the field has been set.

    Setting Values

    • Set<FieldName>(v string): Sets the field to the provided string value.
    • Set<FieldName>Nil(b bool): Sets the field to an explicit nil if b is true.
    • Unset<FieldName>(): Ensures no value is present for the field (removes even explicit nil).
  9. Configure ReceiptNotification for Payouts

    master
    The ReceiptNotification object is used to provide additional notification settings for completed payouts. You can specify email addresses for the primary recipient (EmailTo), carbon copy (EmailCc), and blind carbon copy (EmailBcc). All these fields accept a slice of strings ([]string).
  10. Use RefundCallback for Payments API notifications

    master

    The RefundCallback object is used to handle callbacks for successful or failed Refunds made via the Xendit Payments API. It contains metadata about the event, the business ID, and the creation timestamp, along with a Data field containing specific refund details.

    Properties

    NameTypeRequiredDescription
    EventstringYesIdentifies the event that triggered the notification
    BusinessIdstringYesThe business_id
    CreatedstringYesThe creation timestamp
    DataPointer to RefundCallbackDataNoDetailed refund information (see RefundCallbackData)
  11. Use DirectDebitAllOf for payment requests

    master

    The DirectDebitAllOf struct is used to represent the polymorphic nature of direct debit payment methods. It allows you to specify the type of direct debit and provide the corresponding details, such as a BankAccount or a DebitCard.

    Properties

    NameTypeRequiredDescription
    TypeDirectDebitType☑️The type of direct debit
    BankAccount*NullableDirectDebitBankAccountDetails for bank account direct debit
    DebitCard*NullableDirectDebitDebitCardDetails for debit card direct debit
  12. Manage CustomerObject properties

    master

    The CustomerObject uses a pattern of getter and setter methods to manage its fields. Most fields are handled via NullableString pointers to allow for explicit null values or unset states.

    Common Property Patterns

    For most string fields (like Id, PhoneNumber, Email, etc.), the following methods are available:

    • Getters:
      • Get<FieldName>() string: Returns the value if non-nil, otherwise returns the zero value.
      • Get<FieldName>Ok() (*string, bool): Returns a tuple containing the field value and a boolean indicating if the value was actually set.
    • Setters:
      • Set<FieldName>(v string): Sets the field to the provided value.
      • Set<FieldName>Nil(b bool): Sets the value to an explicit nil if b is true.
      • Unset<FieldName>(): Ensures no value is present for the field (removes even explicit nil).
    • Presence Checks:
      • Has<FieldName>() bool: Returns true if the field has been set.