Developer Docs

Payment Intents

Create and manage payment intents via the Public API.

Payment Intents are the core object for accepting payments via BSync. Create one server-side, redirect the customer to checkoutUrl, then track status via API or webhooks.

OpenAPI: PaymentIntent, PaymentIntentCreateRequest schemas — /docs/api-reference

Endpoints

MethodPathSDK MethodDescription
POST/v1/payment-intentspaymentIntents.create()Create a payment
GET/v1/payment-intents/{paymentId}paymentIntents.get()Get full payment
GET/v1/payment-intents/{paymentId}/statuspaymentIntents.getStatus()Lightweight status
POST/v1/payment-intents/{paymentId}/cancelpaymentIntents.cancel()Cancel a pending payment

Create a Payment Intent

Request Fields

FieldRequiredDefaultDescription
amountYesPayment amount (must be > 0)
currencyNoEGPISO currency code
customerPhoneNonullCustomer mobile number
externalOrderIdNoYour order reference
metadataNo{}Arbitrary key-value data
successUrlNonullHTTPS redirect after successful payment
cancelUrlNonullHTTPS redirect after cancellation
redirectDelayNo3Seconds before redirect to successUrl
expiresAtNo30 min from creationFuture ISO 8601 expiry

SDK:

const payment = await bsync.paymentIntents.create({
  amount: 250,
  currency: "EGP",
  customerPhone: "+201012345678",
  externalOrderId: "ORD-42",
  successUrl: "https://merchant.example/success",
  cancelUrl: "https://merchant.example/cancel",
  redirectDelay: 3,
  metadata: { description: "Order 42", sku: "ITEM-001" },
});

curl:

curl -X POST https://api.bsyncapp.com/v1/payment-intents \
  -H "Authorization: Bearer bsync_test_your_key" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-ORD-42" \
  -d '{
    "amount": 250,
    "currency": "EGP",
    "externalOrderId": "ORD-42",
    "redirectDelay": 3
  }'

Response

Returns HTTP 201 with a PaymentIntent object. Key fields:

FieldDescription
paymentIdUnique payment identifier
statusCurrent lifecycle status
checkoutUrlURL to redirect the customer
amount, currencyPayment amount
expiresAtWhen the payment expires
matchStatuswaiting, matched, review_required
verificationStatuspending, verified, manual_review, failed
reference.externalOrderIdYour order reference
metadataYour custom data

Status Lifecycle

pending → paid
pending → expired
pending → cancelled
pending → failed
StatusMeaning
pendingAwaiting customer payment
paidPayment confirmed
expiredPayment window closed
cancelledCancelled by merchant or customer
failedPayment failed (e.g. review rejected)

Poll status:

const status = await bsync.paymentIntents.getStatus("pay_abc123");
console.log(status.status);
console.log(status.matchStatus);
console.log(status.verificationStatus);

Prefer webhooks over polling for production. See Webhooks.

Cancellation

Cancel a pending payment:

const cancelled = await bsync.paymentIntents.cancel("pay_abc123");

Returns the updated PaymentIntent with status: "cancelled".

Cannot cancel payments that are already paid, expired, or under review. See error codes below.

Expiration

Payments expire at expiresAt (default: 30 minutes from creation). Override with a future ISO 8601 timestamp:

await bsync.paymentIntents.create({
  amount: 100,
  currency: "EGP",
  redirectDelay: 3,
  expiresAt: "2026-07-14T20:00:00.000Z",
});

Expired payments return status: "expired" and trigger a PAYMENT_EXPIRED webhook.

Idempotency

POST /v1/payment-intents supports the Idempotency-Key header. The SDK auto-generates one on every create() call. See Idempotency.

Metadata

Attach arbitrary data to a payment:

metadata: {
  description: "Premium subscription",
  planId: "pro-monthly",
  userId: "usr_123",
}

Metadata is returned in the response and included in webhook payloads where applicable. Max practical size: keep under 4 KB.

Customer Phone

Optional. When provided, BSync can use it for payment matching:

customerPhone: "+201012345678",

Redirect URLs

FieldWhen used
successUrlCustomer redirected here after successful payment (after redirectDelay seconds)
cancelUrlCustomer redirected here if they cancel checkout

Both must be HTTPS in production.

Error Codes

HTTPCodeWhen
400VALIDATION_ERRORInvalid amount, missing fields
404RESOURCE_NOT_FOUNDPayment ID not found
409PAYMENT_NOT_CANCELLABLECannot cancel this payment
409PAYMENT_ALREADY_PROCESSEDPayment already completed
409IDEMPOTENCY_CONFLICTSame key, different body
422PAYMENT_CANNOT_BE_CANCELLEDBusiness rule prevents cancellation
422PAYMENT_UNDER_REVIEWPayment is under manual review
422REVIEW_REQUIREDManual review required

Was this page helpful?

payment-intents

Command Palette

Search for a command to run...