Skip to main content

Payment Links

Use the Payment Link resource to build hosted checkout URLs you can share with customers. Create fixed-price or custom-amount links, attach line items (catalog products or user-priced rows), and manage links over their lifecycle (enable, disable, list, and detail).

All Payment Link operations are available via the client.paymentLink property on your GStableClient instance.

Error handling​

Failures surface as GStableError or a subclass. When a line item uses itemType: 'product', invalid or blocked catalog state may be reported as GStableProductError (business codes 100301–100306).

import { GStableClient, GStableProductError } from 'gstable-js';

const client = new GStableClient({ apiKey: process.env.GSTABLE_API_KEY! });

try {
const link = await client.paymentLink.create({
linkType: 'fixed',
linkName: 'Starter checkout',
accountId: 'acc_xxx',
settlementToken: 'polygon::usdc',
feeModel: 1,
lineItems: [
{ itemType: 'product', productId: 'prod_xxx', quantity: 1, unitPrice: 10_000_000 },
],
});
} catch (error) {
if (error instanceof GStableProductError) {
console.error(`Product Error [${error.code}]: ${error.message}`);
}
}

TypeScript support​

We provide TypeScript definitions for Payment Link payloads, line items, and list responses. Import them from the package root.

Core types

  • PaymentLink — The link object returned by create/detail (ids, URL, status, amounts, line items, and related fields per API).
  • PaymentLinkType — 'fixed' vs 'custom' flow discriminator.
  • PaymentLinkFeeModel — Who absorbs fees (1 merchant, 2 payer).
  • SettlementTokenInfo — Optional settlement metadata on link payloads when the API includes it.

Request bodies

  • CreatePaymentLinkBody — Payload for create (account, settlement token, fee model, line items, optional URLs and copy).
  • UpdatePaymentLinkBody — Full replacement: all CreatePaymentLinkBody fields plus linkId.
  • PaymentLinkLineItemInput — Discriminated union for product vs user_priced rows.

Response wrappers

  • PaymentLinkListData — Paginated list container (links, total, page, size).
  • OperationSuccess — Returned for update, enable, disable, and similar success envelopes.
import type {
PaymentLink,
PaymentLinkType,
PaymentLinkFeeModel,
PaymentLinkLineItemInput,
CreatePaymentLinkBody,
UpdatePaymentLinkBody,
PaymentLinkListData,
OperationSuccess,
SettlementTokenInfo,
} from 'gstable-js';

create​

Creates a Payment Link (fixed or custom amount flow per linkType).

client.paymentLink.create(body)

Parameters​

NameTypeRequiredDescription
bodyCreatePaymentLinkBodyYesSee table below.

CreatePaymentLinkBody:

FieldTypeRequiredDescription
linkTypePaymentLinkType ('fixed' | 'custom')YesFixed vs payer-chosen amount flows.
linkNamestringYesLabel for operators / reports.
accountIdstringYesReceiving account id.
settlementTokenstringYesSettlement token id (e.g. network::symbol).
feeModelPaymentLinkFeeModel (1 | 2)Yes1 = merchant pays fee, 2 = payer pays fee.
lineItemsPaymentLinkLineItemInput[]YesLine items (product or user-priced).
payerEmailRequirednumberNo1 require email, 0 optional (per API).
successUrlstringNoRedirect after success.
customSuccessTextstringNoCustom copy.
customDisabledTextstringNoWhen link disabled.

PaymentLinkLineItemInput (discriminated union):

  • { itemType: 'product', productId, quantity, unitPrice } — unitPrice micro units, > 0.
  • { itemType: 'user_priced', productId, quantity, unitPrice? } — unitPrice optional / 0 for donor-style flows.

Returns​

Promise<PaymentLink> — Includes linkId, linkUrl, lineItems, amount, status, optional settlementTokenInfo, etc.

Example​

import { GStableClient } from 'gstable-js';

const client = new GStableClient({ apiKey: process.env.GSTABLE_API_KEY! });

const link = await client.paymentLink.create({
linkType: 'fixed',
linkName: 'Starter checkout',
accountId: 'acc_xxx',
settlementToken: 'polygon::usdc',
feeModel: 1,
lineItems: [
{
itemType: 'product',
productId: 'prod_xxx',
quantity: 1,
unitPrice: 10_000_000, // micro-units per API
},
],
payerEmailRequired: 0,
});

console.log(link.linkId, link.linkUrl);

update​

Full replacement update for an existing link.

client.paymentLink.update(body)

Parameters​

NameTypeRequiredDescription
bodyUpdatePaymentLinkBodyYesExtends CreatePaymentLinkBody with linkId.

UpdatePaymentLinkBody: all CreatePaymentLinkBody fields plus linkId: string.

Returns​

Promise<OperationSuccess>

Example​

await client.paymentLink.update({
linkId: 'link_xxx',
linkType: 'fixed',
linkName: 'Starter checkout v2',
accountId: 'acc_xxx',
settlementToken: 'polygon::usdc',
feeModel: 1,
lineItems: [
{ itemType: 'product', productId: 'prod_xxx', quantity: 1, unitPrice: 12_000_000 },
],
});

disable​

client.paymentLink.disable(linkId)

Parameters​

NameTypeRequiredDescription
linkIdstringYesPayment link id.

Returns​

Promise<OperationSuccess>

Example​

await client.paymentLink.disable('link_xxx');

enable​

client.paymentLink.enable(linkId)

Parameters​

NameTypeRequiredDescription
linkIdstringYesPayment link id.

Returns​

Promise<OperationSuccess>

Example​

await client.paymentLink.enable('link_xxx');

detail​

client.paymentLink.detail(linkId)

Parameters​

NameTypeRequiredDescription
linkIdstringYesPayment link id.

Returns​

Promise<PaymentLink>

Example​

const link = await client.paymentLink.detail('link_xxx');
console.log(link.status, link.amount);

list​

client.paymentLink.list(page, size)

Parameters​

NameTypeRequiredDescription
pagenumberYes1-based page.
sizenumberYesPage size.

Returns​

Promise<PaymentLinkListData> — { links, total, page, size }.

Example​

const { links, total } = await client.paymentLink.list(1, 20);
console.log(total, links[0]?.linkId);