Skip to content

Latest commit

 

History

History
187 lines (152 loc) · 6.44 KB

Invoice.md

File metadata and controls

187 lines (152 loc) · 6.44 KB

Invoice

You can use the APIs below to interface with Xendit's Invoice API. To start using the API, you need to destruct instantiated Xendit client or directly import the module and set the secret key.

import { Xendit, Invoice as InvoiceClient } from 'xendit-node';

const xenditClient = new Xendit({secretKey: YOUR_SECRET_KEY})
const { Invoice } = xenditClient

const xenditInvoiceClient = new InvoiceClient({secretKey: YOUR_SECRET_KEY})

// At this point, `Invoice` and `xenditInvoiceClient` will have no usage difference, for example:
// Invoice.
// or
// xenditInvoiceClient.

All URIs are relative to https://api.xendit.co, except if the operation defines another base path.

Method HTTP request Description
createInvoice() POST /v2/invoices/ Create an invoice
getInvoiceById() GET /v2/invoices/{invoice_id} Get invoice by invoice id
getInvoices() GET /v2/invoices Get all Invoices
expireInvoice() POST /invoices/{invoice_id}/expire! Manually expire an invoice

createInvoice() Function

Function Signature

Name Value
Function Name createInvoice
Request Parameters CreateInvoiceOperationRequest
Return Type Invoice

Request Parameters - CreateInvoiceOperationRequest

Field Name Type Required Default
data CreateInvoiceRequest ☑️
forUserId string

Usage Example

Create Invoice Request

import { CreateInvoiceRequest, Invoice } from 'xendit-node/invoice/models'

const data: CreateInvoiceRequest = {
  "amount" : 10000,
  "invoiceDuration" : 172800,
  "externalId" : "test1234",
  "description" : "Test Invoice",
  "currency" : "IDR",
  "reminderTime" : 1
}

const response: Invoice = await xenditInvoiceClient.createInvoice({
    data
})

getInvoiceById() Function

Function Signature

Name Value
Function Name getInvoiceById
Request Parameters GetInvoiceByIdRequest
Return Type Invoice

Request Parameters - GetInvoiceByIdRequest

Field Name Type Required Default
invoiceId string ☑️
forUserId string

Usage Example

import { Invoice } from 'xendit-node/invoice/models'

const response: Invoice = await xenditInvoiceClient.getInvoiceById({ 
    invoiceId: "62efe4c33e45294d63f585f2",
)

getInvoices() Function

Function Signature

Name Value
Function Name getInvoices
Request Parameters GetInvoicesRequest
Return Type Invoice[]

Request Parameters - GetInvoicesRequest

Field Name Type Required Default
forUserId string
externalId string
statuses InvoiceStatus[]
limit number
createdAfter Date
createdBefore Date
paidAfter Date
paidBefore Date
expiredAfter Date
expiredBefore Date
lastInvoice string
clientTypes InvoiceClientType[]
paymentChannels string[]
onDemandLink string
recurringPaymentId string

Usage Example

import { Invoice } from 'xendit-node/invoice/models'

const response: Invoice[] = await xenditInvoiceClient.getInvoices({ )

expireInvoice() Function

Function Signature

Name Value
Function Name expireInvoice
Request Parameters ExpireInvoiceRequest
Return Type Invoice

Request Parameters - ExpireInvoiceRequest

Field Name Type Required Default
invoiceId string ☑️
forUserId string

Usage Example

import { Invoice } from 'xendit-node/invoice/models'

const response: Invoice = await xenditInvoiceClient.expireInvoice({ 
    invoiceId: "5f4708b7bd394b0400b96276",
)

Callback Objects

Use the following callback objects provided by Xendit to receive callbacks (also known as webhooks) that Xendit sends you on events, such as successful payments. Note that the example is meant to illustrate the contents of the callback object -- you will not need to instantiate these objects in practice

InvoiceCallback Object

Invoice Callback Object

Model Documentation: InvoiceCallback

Usage Example

Note that the example is meant to illustrate the contents of the callback object -- you will not need to instantiate these objects in practice

import { InvoiceCallback } from 'xendit-node/invoice/models'

const 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"
}

You may then use the callback object in your webhook or callback handler like so,

function SimulateInvoiceCallback(invoiceCallback: InvoiceCallback) {
    const { id } = invoiceCallback
    // do things here with the callback
}

[Back to README]