JS API Reference

Class: InvoiceProcessor

payment/InvoiceProcessor.InvoiceProcessor

A class that provides methods for working with invoices. It interacts with the Yagna API directly.

Table of contents

Constructors

Methods

Constructors

constructor

new InvoiceProcessor(api): InvoiceProcessor

Use InvoiceProcessor.create() to create an instance of this class.

Parameters

NameType
apiYagnaApi

Returns

InvoiceProcessor

Defined in

src/payment/InvoiceProcessor.ts:29

Methods

collectInvoices

collectInvoices(options?): Promise<{}[]>

Collects invoices from the Yagna API until the limit is reached or there are no more invoices.

Parameters

NameTypeDefault valueDescription
optionsObject{}The parameters for collecting invoices.
options.after?DateundefinedOnly collect invoices that were created after this date.
options.limit?number50Maximum number of invoices to collect.
options.statuses?string[]undefinedOnly collect invoices with these statuses.
options.providerIds?string[]undefinedOnly collect invoices from these providers.
options.minAmount?NumericundefinedOnly collect invoices with an amount greater than or equal to this.
options.maxAmount?NumericundefinedOnly collect invoices with an amount less than or equal to this.
options.providerWallets?string[]undefinedOnly collect invoices from these provider wallets.
options.paymentPlatforms?string[]undefinedOnly collect invoices from these payment platforms.

Returns

Promise<{}[]>

Example

const invoices = await invoiceProcessor.collectInvoices({
 after: new Date(Date.now() - 24 * 60 * 60 * 1000), // only collect invoices that were created in the last 24 hours
 limit: 100, // only collect 100 invoices max
 statuses: ["RECEIVED"], // only collect unpaid invoices
 providerIds: ["0x1234"], // only collect invoices from this provider
 minAmount: "0.1", // only collect invoices with an amount greater than or equal to 0.1 GLM
 maxAmount: "1", // only collect invoices with an amount less than or equal to 1 GLM
 providerWallets: ["0x1234"], // only collect invoices from this provider wallet
 paymentPlatforms: ["erc20-polygon-glm"], // only collect invoices from this payment platform
});

Defined in

src/payment/InvoiceProcessor.ts:57


fetchSingleInvoice

fetchSingleInvoice(invoiceId): Promise<Invoice>

Fetches a single invoice from the Yagna API.

Parameters

NameType
invoiceIdstring

Returns

Promise<Invoice>

Defined in

src/payment/InvoiceProcessor.ts:109


acceptInvoice

acceptInvoice(«destructured»): Promise<InvoiceAcceptResult>

Creates an allocation for the exact amount of the invoice and accepts the invoice. If dryRun is true, no allocation will be created and the invoice will not be accepted.

Parameters

NameTypeDefault value
«destructured»Objectundefined
› invoiceInvoiceundefined
› dryRun?booleanfalse

Returns

Promise<InvoiceAcceptResult>

Defined in

src/payment/InvoiceProcessor.ts:117


acceptManyInvoices

acceptManyInvoices(«destructured»): Promise<InvoiceAcceptResult[]>

Creates an allocation for the exact amount of the invoices and accepts the invoices. Since the invoices can be from different payment platforms and payer addresses, multiple allocations might be created. If dryRun is true, no allocation will be created and the invoices will not be accepted. Please keep in mind that this method is not atomic, so if one of the invoices fails to be accepted, the others will still be accepted. This is a limitation of the Yagna API. Use the returned InvoiceAcceptResult to check which invoices were accepted successfully.

Parameters

NameTypeDefault value
«destructured»Objectundefined
› invoicesInvoice[]undefined
› dryRun?booleanfalse

Returns

Promise<InvoiceAcceptResult[]>

Defined in

src/payment/InvoiceProcessor.ts:182

Was this helpful?