Server SDKs

Official Server SDKs for Node.js, PHP, .NET, and Java

Qasimha's server SDKs provide a lightweight, consistent way to integrate with the Merchant API from your backend. Official SDKs are available for Node.js, PHP, .NET, and Java, and each follows the same core design principles. Regardless of the language you choose, you'll work with the same resources, methods, request options, and error models, adapted to match the conventions and idioms of that language.

The SDKs are intended to run exclusively on your server. Your secret API key (sktest... or sklive...) should never leave your backend environment and must never be exposed in a browser, mobile application, or any other client-side code.

In a typical integration:

  1. Your backend creates a checkout session using the SDK.
  2. The customer completes payment on the Qasimha-hosted checkout page.
  3. Your server retrieves and verifies the resulting order.
  4. Webhooks notify your application when order events occur.
  5. Your backend responds to those events and updates your business systems accordingly.

Because payment collection happens on the hosted checkout, sensitive payment information never passes through your servers. This reduces integration complexity while helping you maintain a secure architecture.

Use this documentation to select your preferred language and compare SDK functionality across platforms. Although the syntax differs, the underlying capabilities remain consistent, making it straightforward to switch languages or support multiple services within the same organization.

Each language-specific guide includes:

  • Complete API reference documentation
  • Installation and configuration instructions
  • Framework integration examples
  • Authentication and error-handling guidance
  • End-to-end sample applications
  • Webhook verification examples
  • Production-ready server implementations

Whether you're building a new integration or migrating an existing one, the SDKs provide a familiar and predictable developer experience across all supported languages.

Why use an SDK instead of raw HTTP

You can call the API directly. The SDKs save you from rebuilding the parts that are easy to get wrong:

What the SDK doesWhy it matters
Picks the environment from the key prefixsk_test_ goes to UAT (sandbox), sk_live_ to production. A key and environment that disagree are refused at start-up.
Retries safelyRetries connection failures, 429, 502, 503 and 504 with backoff and jitter. Never retries a 500 or other 4xx, because a write may already have gone through.
Sends an Idempotency-Key on every POSTA UUID v4 per call, reused across its retries, so a retried create returns the first result instead of a second order. See Idempotency.
Checks the basket before sendingRefuses amounts with more than two decimals and baskets that do not add up, naming the failing line, with no request sent.
Verifies webhooksChecks X-Qasimha-Signature on the raw body, in constant time, with a 5-minute tolerance and support for secret rotation.
Raises typed errorsOne error class per case (validation, auth, duplicate reference, declined, rate limit, ...), each carrying the API code and requestId.
Normalises statusesOrder statuses always come back as names (Confirmed), even when the API sends a number. Unknown values pass through as strings and never crash your code.
Keeps secrets out of logsKeys, webhook secrets and customer data are never logged or printed. maskedKey() gives sk_live_…AbCd for your own logs.

Packages

LanguagePackageMinimum runtimeInstall
Node.js@qasimha/sdk (npm)Node.js 18 (native fetch); ESM, CommonJS and TypeScript typesnpm install @qasimha/sdk
PHPqasimha/php-sdk (Packagist)PHP 8.1 with ext-curl, ext-json, ext-mbstringcomposer require qasimha/php-sdk
.NETQasimha.Sdk (NuGet).NET 6 or .NET 8dotnet add package Qasimha.Sdk
Javacom.qasimha:qasimha-sdk (Maven Central)Java 11implementation("com.qasimha:qasimha-sdk:0.1.0") or the Maven <dependency>

Install sdk

npm install @qasimha/sdk

Shared behaviour

All four SDKs share these rules:

  • Configuration. Pass the secret key; everything else is optional. Defaults: timeout 30 seconds per attempt, maxRetries 2 (allowed 0–5), language en (ar returns Arabic API messages). A baseUrl override must be https://, except localhost / 127.0.0.1 for test servers.
  • Basket rules, checked to the halala (0.01 SAR) before sending:
    • item.totalAmount = quantity × unitPrice − item.discountAmount
    • totalAmount = Σ item.totalAmount + taxAmount + shippingAmount − discountAmount
  • shippingAddress is required on an online session, even for digital baskets.
  • Hosted checkout outcome. An order that completes the hosted checkout is already Confirmed (first instalment paid). Mark it paid on Confirmed, call fulfill when you ship, and refund after that. capture only applies to New / Approved orders.
  • The return URL is not proof. Always read the order back with orders.get before marking it paid. See Return URLs.
  • Plan quotes (getPlans) use the publishable key (pk_test_...) and never send the secret key.
  • Duplicate references. A 409 DUPLICATE_ORDER_REFERENCE on the first attempt is raised as an error that carries the existing order and payment URL. The same 409 on a retry means the first attempt succeeded, and the SDK returns that session.

Demo merchant backend

Each server SDK ships a demo merchant backend in its examples/ folder (sdks/<lang>/examples/ in the source repository). It is the part every merchant writes: a small server that holds the secret key, prices the basket, creates the session, confirms the order and verifies webhooks.

All four backends expose the same HTTP API on port 4300, so the Angular and React demo stores run unchanged against any of them.

EndpointWhat it does
GET /api/qasimha/configWhat the browser needs: the publishable key, language and return URLs. Never the secret key.
GET /api/productsThe demo catalogue.
POST /api/checkoutPrices the basket from the catalogue (never from the browser), calls checkout.createSession, and returns orderId, orderReferenceId, paymentUrl and merchantUrl.
GET /api/orders/{id}The server-side confirmation through orders.get; paid is true for Confirmed, FullyFulfilled and PartiallyFulfilled.
POST /api/webhooks/qasimhaVerifies the raw body with the SDK's webhook verifier.

The backend reads QASIMHA_API_KEY, QASIMHA_PUBLISHABLE_KEY, QASIMHA_WEBHOOK_SECRET and QASIMHA_BASE_URL from the environment.

Mock mode. With no QASIMHA_API_KEY set, the backend talks to a local mock Qasimha instead of a real environment. The Node backend starts the mock itself. The PHP, .NET and Java backends expect it running on port 4301:

node sdks/node/examples/demo-merchant-server/mock-qasimha.mjs

To run against UAT instead, set QASIMHA_API_KEY=sk_test_... and QASIMHA_PUBLISHABLE_KEY=pk_test_.... The backend listens on 127.0.0.1:4300 by default (HOST and PORT change this).

Errors at a glance

Every error extends one base class (QasimhaError in Node.js, QasimhaException in PHP, .NET and Java) and carries the API code, the HTTP status, field errors and a requestId. Quote the requestId when you contact support.

Node.jsPHP / .NET / JavaWhen
ConfigurationErrorConfigurationExceptionClient misconfigured, or an argument refused before sending
ValidationErrorValidationExceptionAny 400, or a basket refused locally
AuthenticationErrorAuthenticationException401: bad or revoked key (empty body)
PermissionErrorPermissionException403: the key lacks the scope
NotFoundErrorNotFoundException404
DuplicateOrderReferenceErrorDuplicateOrderReferenceException409 DUPLICATE_ORDER_REFERENCE; carries the existing order id and payment URL
ConflictErrorConflictExceptionAny other 409
OrderDeclinedErrorOrderDeclinedException422 ORDER_DECLINED
RateLimitErrorRateLimitException429 after retries
ServerError / ApiErrorServerException / ApiException5xx / anything else unexpected
ConnectionErrorConnectionExceptionDNS, TLS, socket or timeout failure
WebhookSignatureErrorWebhookSignatureExceptionA webhook failed verification

See Errors for the API codes.

Security

  • The secret key belongs in a secrets manager or environment variable on your server. Never send it to a browser or a mobile app.
  • The publishable key (pk_...) only opens the plan quote and is safe to put in a page.
  • The SDKs talk TLS only. Certificate checks cannot be switched off, there is no certificate pinning, and redirects are never followed. If you hand the PHP, .NET or Java SDK your own HTTP client, turn redirects off on that client.
  • Keys, webhook secrets and customer data never appear in SDK logs, error messages or a printed client.
  • No SDK handles card data. Customers pay on the Qasimha hosted checkout, so your integration stays in PCI DSS SAQ-A scope.
Do I need an SDK to integrate?

No. The SDKs call the same public API described in this hub. Without one, you must build the retries, idempotency keys, basket checks and webhook signature checks yourself.

Can I use the SDK in a browser or mobile app?

No. The server SDKs need the secret key, which must stay on your server. Browser and mobile apps call your backend, which calls Qasimha.

Choose your language


Did this page help you?