Download the PHP package paymentsnp/paymentsnp-php without Composer

On this page you can find all versions of the php package paymentsnp/paymentsnp-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package paymentsnp-php

Paymentsnp PHP SDK

Official PHP client for the Paymentsnp API: hosted checkout for eSewa, Khalti and Fonepay, verified payments, invoices, settlement reconciliation and webhook verification.

Install

Without Composer (WHMCS modules and similar), copy this folder and:

Quick start

The key's prefix sets the environment: np_test_ keys only see test data, np_live_ keys only live data ($paymentsnp->environment). A return to success_url is not proof of payment. Confirm with the payment.succeeded webhook or by retrieving the session.

Options

Resources

Each method names the API key scope it needs.

Method API Scope
checkout->sessions->create($params, ['idempotency_key' => ...]) POST /checkout/sessions checkout:create
checkout->sessions->retrieve($id) GET /checkout/sessions/:id checkout:read
checkout->sessions->expire($id) POST /checkout/sessions/:id/expire checkout:create
payments->list($params) GET /payments (limit, offset, provider, search, from/to) payments:read
payments->retrieve($id) GET /payments/:id payments:read
payments->summary() GET /payments/summary (verified totals, never a balance) payments:read
invoices->list($params) GET /invoices (status, search, limit, offset) invoices:read
invoices->retrieve($id) GET /invoices/:id invoices:read
invoices->pdf($id) GET /invoices/:id/pdf, returns the PDF bytes invoices:read
invoices->create($params) POST /invoices (a draft) invoices:write
invoices->update($id, $params) PATCH /invoices/:id (drafts) invoices:write
invoices->finalize($id) POST /invoices/:id/finalize invoices:write
invoices->send($id, ['channels' => ['email']]) POST /invoices/:id/send invoices:write
invoices->markPaid($id, ['note' => ...]) POST /invoices/:id/mark-paid invoices:write
invoices->void($id) POST /invoices/:id/void invoices:write
invoices->markUncollectible($id) POST /invoices/:id/uncollectible invoices:write
invoices->duplicate($id) POST /invoices/:id/duplicate invoices:write
reconciliation->list($params) GET /reconciliation reconciliation:read
reconciliation->report(['period' => '30']) GET /reconciliation/report (7, 30, 90) reconciliation:read
reconciliation->importSettlement($record) POST /reconciliation/import reconciliation:write
reconciliation->importBulk(['records' => [...]]) POST /reconciliation/import/bulk (up to 500, per-row results) reconciliation:write

Refunds and payouts are not part of the API.

Idempotency and retries

checkout->sessions->create always sends an Idempotency-Key. If you pass none, the SDK generates one per call and reuses it on that call's retries. Pass your own (for example checkout-<order id>) so a retry from a new request or process returns the same session; the same key with a different body raises InvalidRequestError (409 idempotency_conflict).

The SDK retries connection errors, 429 and 5xx up to max_retries times with exponential backoff and jitter, honouring Retry-After (capped at 60 seconds). It retries only GET requests and POSTs that carry an idempotency key, so invoice and reconciliation writes are never sent twice.

Errors

All errors extend Paymentsnp\PaymentsnpError with getStatus(), getErrorCode() (the API's snake_case code), getMessage(), getRequestId() and getRetryAfter().

Class When Typical codes
AuthenticationError 401 unauthorized, api_key_expired
PermissionError 403 insufficient_scope, api_key_ip_denied, environment_mismatch
InvalidRequestError 400, 404, 409, 422 invalid_request, not_found, idempotency_conflict, duplicate_settlement
RateLimitError 429 rate_limited (see getRetryAfter())
ApiError 5xx internal_error
ConnectionError no response network, DNS, TLS or timeout
SignatureVerificationError webhook check failed

Webhooks

Paymentsnp signs each delivery with Paymentnp-Signature: t=<unix>,v1=<hex> (HMAC-SHA256 of "<t>.<raw body>" with your whsec_ secret) and sends Paymentnp-Event-Id. Events: payment.succeeded, payment.failed, checkout.expired, webhook.test. The body is {id, type, api_version, environment, created_at, data}.

It compares signatures in constant time, rejects timestamps older than the tolerance and throws SignatureVerificationError. Deliveries are retried, so de-duplicate on the event id. Reply 2xx quickly; redirects count as failures. For tests, Webhook::generateTestHeader($body, $secret, $timestamp = null) builds a valid header.

Money helpers

Examples

Tests

The unit tests use a stub HttpClient. The live tests in tests/e2e.php run only when PAYMENTSNP_E2E_BASE_URL (e.g. http://localhost:4000/v1) and PAYMENTSNP_E2E_API_KEY (a test key with all scopes, Sandbox gateway enabled, backend started with ENABLE_SANDBOX_PROVIDER=true) are set.


All versions of paymentsnp-php with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package paymentsnp/paymentsnp-php contains the following files

Loading the files please wait ...