Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions packages/sdk/src/clients/invoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ export class InvoiceClient extends BaseContractClient {
return this.writeContract("create", args, signerPublicKey);
}

/**
* Lists an existing invoice for public financing on the marketplace.
* Side effect: the invoice status transitions to `Listed`.
*
* @param invoiceIdHex - The invoice ID as a 32-byte hex string.
* @param discountBps - The discount rate in basis points (e.g. 500 = 5%).
* @param signerPublicKey - The Stellar public key that will sign the transaction. Must be the invoice issuer.
* @returns `true` when the transaction succeeds on-chain.
* @throws If the transaction simulation fails or the on-chain submission errors.
*/
async listForFinancing(
invoiceIdHex: string,
discountBps: number,
Expand All @@ -57,6 +67,16 @@ export class InvoiceClient extends BaseContractClient {
);
}

/**
* Confirms delivery of goods for an invoice on-chain.
* Side effect: updates the confirmation status for the provided `confirmerAddress`.
*
* @param invoiceIdHex - The invoice ID as a 32-byte hex string.
* @param confirmerAddress - The Stellar address whose delivery confirmation is being recorded.
* @param signerPublicKey - The Stellar public key that will sign the transaction. Must be the buyer or issuer.
* @returns `true` when the transaction succeeds on-chain.
* @throws If the transaction simulation fails or the on-chain submission errors.
*/
async confirmDelivery(
invoiceIdHex: string,
confirmerAddress: string,
Expand All @@ -71,6 +91,15 @@ export class InvoiceClient extends BaseContractClient {
);
}

/**
* Repays a financed invoice on-chain, returning funds to the liquidity pool.
* Side effect: the invoice status transitions to `Repaid` and LP yield is distributed.
*
* @param invoiceIdHex - The invoice ID as a 32-byte hex string.
* @param signerPublicKey - The Stellar public key that will sign the transaction. Must be the invoice buyer.
* @returns `true` when the transaction succeeds on-chain.
* @throws If the transaction simulation fails or the on-chain submission errors.
*/
async repay(invoiceIdHex: string, signerPublicKey: string): Promise<boolean> {
const args = [xdr.ScVal.scvBytes(Buffer.from(invoiceIdHex, "hex"))];
return this.writeContract("repay", args, signerPublicKey).then(() => true);
Expand All @@ -86,6 +115,15 @@ export class InvoiceClient extends BaseContractClient {
);
}

/**
* Retrieves a single invoice by its on-chain ID.
* This is a read-only (simulated) call — no on-chain side effects.
*
* @param invoiceIdHex - The invoice ID as a 32-byte hex string.
* @param signerPublicKey - The Stellar public key used to simulate the read call.
* @returns The parsed {@link Invoice} object.
* @throws If the simulation fails or the return value cannot be parsed.
*/
async get(invoiceIdHex: string, signerPublicKey: string): Promise<Invoice> {
const args = [xdr.ScVal.scvBytes(Buffer.from(invoiceIdHex, "hex"))];
return this.readContract("get", args, signerPublicKey, (val) =>
Expand Down
Loading