Xendit Node SDK

repository·master·Indexed 40 days ago

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

The official Node.js library for interacting with Xendit's REST APIs. Version 7.0.0 provides native TypeScript support and simplified API calls for managing account balances, transactions, and customer profiles. Requires Node.js 18.0 or later.

Tokens
87.2K
Snippets
250
Records
321
Agent score
99%

What's inside Xendit

  1. Use EWallet as a payment method

    master

    When creating a payment request using the EWallet method, you must provide specific properties to identify the wallet provider and the user's account details. The EWallet object consists of three main properties:

    • channelCode: Specifies the specific EWallet provider (e.g., OVO, Dana, LinkAja).
    • channelProperties: Contains provider-specific configuration or metadata.
    • account: Contains the user's wallet account information (e.g., phone number).
  2. Handle Invoice webhooks with `InvoiceCallback`

    master

    Xendit sends webhooks (callbacks) for invoice events, such as successful payments. While you don't instantiate these objects yourself, you can use the InvoiceCallback type from xendit-node/invoice/models to type your webhook handler for better developer experience.

    import { InvoiceCallback } from 'xendit-node/invoice/models'
    
    // Example of how a callback object looks when received
    const invoiceCallback: InvoiceCallback = {
      "amount" : 2000000,
      "paymentDestination" : "TEST815",
      "created" : "2020-01-13T02:32:49.827Z",
      "externalId" : "testing-invoice",
      "description" : "Invoice webhook test",
      "userId" : "5848fdf860053555135587e7",
      "merchantName" : "Xendit",
      "paymentChannel" : "ALFAMART",
      "paymentMethod" : "RETAIL_OUTLET",
      "paidAt" : "2020-01-14T02:32:50.912Z",
      "currency" : "IDR",
      "id" : "593f4ed1c3d3bb7f39733d83",
      "paidAmount" : 2000000,
      "payerEmail" : "test@xendit.co",
      "updated" : "2020-01-13T02:32:50.912Z",
      "status" : "PAID"
    }
    
    // Usage in a handler
    function handleWebhook(invoiceCallback: InvoiceCallback) {
        const { id } = invoiceCallback
        // process the callback
    }
  3. Configure invoice notification preferences

    master

    The NotificationPreference object allows you to specify which notification channels (e.g., email, SMS) are used for different stages of an invoice's lifecycle. You can configure preferences for three specific events:

    • invoiceCreated: Channels used when a new invoice is generated.
    • invoiceReminder: Channels used when an invoice reminder is sent.
    • invoicePaid: Channels used when an invoice has been successfully paid.

    Each property accepts an array of NotificationChannel objects.

  4. Understand the VirtualAccountAlternativeDisplay object

    master
    The VirtualAccountAlternativeDisplay is an alternative display object used within the Xendit API. It provides a mechanism to present different types of data or display formats for Virtual Account payments. It consists of a type identifying the display method and a data payload containing the relevant information for that specific type.
  5. Configure channel-specific properties for Invoices

    master
    When creating or managing Invoices, you can use the ChannelProperties object to provide configuration specific to the payment channel being used. Currently, this object supports the cards property, which allows for fine-grained control over card-related payment settings via the ChannelPropertiesCards interface.
  6. Configure Paylater details for Invoices

    master

    When working with Invoices, you can use the Paylater object to specify how paylater payment options should be presented or filtered.

    Key properties include:

    • paylaterType: A required field of type PaylaterType that defines the specific paylater configuration.
    • shouldExclude: A boolean flag that, when set to true, indicates that this specific paylater option should be excluded from the invoice.
  7. Understand the TransactionsResponse structure

    master

    The TransactionsResponse object is returned when querying transactions. It contains an array of transaction data and metadata for handling pagination. If no transactions match the query, it returns an empty data array.

    Key properties for handling the response:

    • data: An array of TransactionResponse objects containing the actual transaction details.
    • hasMore: A boolean indicating if there are additional results available. If true, you should use the provided links to fetch the next page.
    • links: An array of LinkItem objects used to navigate to the next set of results (pagination).
  8. Handle RefundCallback webhooks

    master

    Xendit sends RefundCallback objects to your webhook endpoint to notify you of refund events (e.g., refund.succeeded).

    While you do not need to instantiate this object yourself, you can use the RefundCallback type to type your webhook handler for better developer experience.

    Example Callback Structure:

    {
      "data" : {
        "reason" : "CANCELLATION",
        "amount" : 10000,
        "id" : "rfd-6f4a377d-a201-437f-9119-f8b00cbbe857",
        "status" : "SUCCEEDED",
        ...
      },
      "event" : "refund.succeeded",
      ...
    }
    import { RefundCallback } from 'xendit-node/refund/models'
    
    function handleWebhook(refundCallback: RefundCallback) {
        const { id } = refundCallback.data;
        // Process the refund event
    }