Class: InvoiceProcessor
payment/InvoiceProcessor.InvoiceProcessor
A class that provides methods for working with invoices. It interacts with the Yagna API directly.
Table of contents
Methods
Methods
create
▸ create(options?
): Promise
<InvoiceProcessor
>
Creates an instance of InvoiceProcessor
and connects to the Yagna API.
Parameters
Name | Type | Description |
---|---|---|
options? | YagnaOptions | Options for the Yagna API. |
Returns
Promise
<InvoiceProcessor
>
Defined in
src/payment/InvoiceProcessor.ts:36
collectInvoices
▸ collectInvoices(«destructured»?
): Promise
<Invoice
[]>
Collects invoices from the Yagna API until the limit is reached or there are no more invoices.
Parameters
Name | Type | Default value |
---|---|---|
«destructured» | Object | {} |
› after? | Date | undefined |
› limit? | number | 50 |
› statuses? | string [] | undefined |
› providerIds? | string [] | undefined |
› minAmount? | Numeric | undefined |
› maxAmount? | Numeric | undefined |
› providerWallets? | string [] | undefined |
› paymentPlatforms? | string [] | undefined |
Returns
Promise
<Invoice
[]>
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:68
fetchSingleInvoice
▸ fetchSingleInvoice(invoiceId
): Promise
<Invoice
>
Fetches a single invoice from the Yagna API.
Parameters
Name | Type |
---|---|
invoiceId | string |
Returns
Promise
<Invoice
>
Defined in
src/payment/InvoiceProcessor.ts:120
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
Name | Type | Default value |
---|---|---|
«destructured» | Object | undefined |
› invoice | Invoice | undefined |
› dryRun? | boolean | false |
Returns
Promise
<InvoiceAcceptResult
>
Defined in
src/payment/InvoiceProcessor.ts:128
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
Name | Type | Default value |
---|---|---|
«destructured» | Object | undefined |
› invoices | Invoice [] | undefined |
› dryRun? | boolean | false |
Returns
Promise
<InvoiceAcceptResult
[]>