Skip to main content

Node, PHP and Python libraries

Install an official library, create payments, verify webhooks and handle errors in your own language.

The official libraries wrap the API with typed objects, automatic idempotency and retries, cursor pagination and webhook verification. None of them has a runtime dependency.

Node, PHP and Python libraries
LibraryPackageNeeds
Node.js@bezanbecard/nodeNode 18 or later (the global fetch); ESM and CommonJS; TypeScript types included
PHPbezanbecard/bezanbecard-phpPHP 7.4 or 8.x with ext-curl and ext-json
PythonbezanbecardPython 3.8 or later, standard library only; type hints with py.typed

Install

yarn add @bezanbecard/node

Create a client

The key decides the mode: sk_test_… sees only test data, sk_live_… only live data. Keep it on your server.

import Bezanbecard from '@bezanbecard/node';
// CommonJS: const { Bezanbecard } = require('@bezanbecard/node');

const bezanbecard = new Bezanbecard(process.env.BEZANBECARD_SECRET_KEY);

Methods

The resources and methods are the same in all three. The table names them as Node does: PHP calls the same names with -> ($bezanbecard->payments->attachDeposit(…)) and lists with all and deletes with delete; Python spells every name in snake_case (bezanbecard.payment_links.list(), attach_deposit) and deletes with delete.

Methods
ResourceMethods
paymentscreate, retrieve, update, list, cancel, topup, attachDeposit, detachDeposit, approve, resolveOverpayment
receiptslist, retrieve, create, approve, reject
depositslist, retrieve, create, ignore, restore
paymentLinkscreate, retrieve, update, list
customerscreate, retrieve, update, list, del
eventsretrieve, list
webhookEndpointscreate, retrieve, update, list, del
cards, devicesretrieve, list
accountretrieve
testHelpers.depositscreate

Create and confirm a payment

const payment = await bezanbecard.payments.create({
  amount: 12_500_000,
  reference: 'order-1042',
  customer_details: { name: 'Test Customer', phone: '09900001234' },
  return_url: 'https://shop.example/orders/1042/thanks',
});
// redirect to payment.checkout_url; later:
const current = await bezanbecard.payments.retrieve(payment.id);
if (current.status === 'succeeded') fulfilOrder(current.reference);

Errors

Every library raises one class per error type, carrying type, code, param, message and the request id.

Errors
Node and PythonPHPWhen
InvalidRequestErrorInvalidRequestException400, 402, 404, 409
AuthenticationErrorAuthenticationException401
PermissionErrorPermissionException403
IdempotencyErrorIdempotencyExceptionA reused or busy Idempotency-Key
RateLimitErrorRateLimitException429 after the retries
APIErrorApiErrorException5xx after the retries
ConnectionError (Python: APIConnectionError)ApiConnectionExceptionNo answer: network or timeout
SignatureVerificationErrorSignatureVerificationExceptionA webhook failed verification
import { InvalidRequestError } from '@bezanbecard/node';

try {
  await bezanbecard.payments.create({ amount: 500 });
} catch (error) {
  if (error instanceof InvalidRequestError && error.code === 'amount_too_small') console.log(error.param, error.requestId);
  else throw error;
}

The codes are listed in errors.

Retries, idempotency and webhooks

  • Every POST carries an Idempotency-Key, reused on retries. Network failures, 409 idempotency conflicts, 429 and 5xx are retried twice by default with a growing, jittered wait that respects Retry-After. Pass your own key to stay idempotent across restarts (idempotency).
  • Lists iterate every page for you (pagination).
  • constructEvent / Webhook::constructEvent / Webhook.construct_event verify the signature on the raw body and accept either v1 during a secret roll (webhooks).

Configuration

Configuration
OptionNodePHPPython
API versionapiVersionbezanbecard_versionapi_version
Base URLbaseUrlapi_basebase_url
Timeouttimeout (ms)timeout, connect_timeout (s)timeout (s)
RetriesmaxNetworkRetriesmax_network_retriesmax_network_retries

Per-request options (a different key, an idempotency key, a version) go in the last argument of each method, so one process can act for several accounts.