When to use PayHere
Use PayHere for LKR or USD one-time checkout, a PayHere overlay, or advanced operations such as retrieval, refunds, recurring billing, preapprovals, authorizations, token charges, and captures. Every operation on this page runs from your backend. Your browser must never receive a PayHere Merchant Secret, Merchant API App Secret, access token, customer token, authorization token, or UPGcompletionContext.
Common
availability(), createOrder(), and completePayment() are documented in Quick Setup. This page documents PayHere-specific functions only.Shared data for session-creating functions
Recurring, preapproval, and authorization functions create aPaymentSession. Its public checkout instructions may be sent to the browser. Its completionContext is server-only and must be saved with your pending order.
PaymentSession: $session->gateway, $session->mode, $session->status, $session->checkout, $session->requestId, $session->flow, $session->binding, $session->verification, and $session->completionContext.
Retrieve payments by order ID
Use retrieval when your backend needs a privacy-safe projection of payments associated with one of your own order IDs. It is read-only and does not replacecompletePayment() for a newly received callback.
- PHP SDK
- Laravel SDK
- Node.js SDK
Create a full or partial refund
Use this backend-only command to refund a settled PayHere payment or to release an authorization. Provide exactly one ofpaymentId or authorizationToken, a clear description, a durable idempotency key, and confirmRefund: true.
- Omit
amountfor a full refund. - Set
amountto a positive decimal string, such as'100.50', for a partial refund. - Reuse the same idempotency key if your application timed out and the outcome is unknown. A different key is a new financial command.
- PHP SDK
- Laravel SDK
- Node.js SDK
provider_status reflects PayHere’s status value. PayHere documents 1 as success, 0 as an initiation error, and -1 as a failed refund; inspect your controlled error handling for rejected requests.Create a recurring checkout session
Use a recurring session to obtain the buyer’s approval for scheduled PayHere subscription payments.recurrence accepts values such as '1 Month'; duration accepts 'Forever' or a value such as '1 Year'.
- PHP SDK
- Laravel SDK
- Node.js SDK
PaymentSession. See the shared session response above. Save $session->completionContext; send only $session->checkout to the buyer.Create a preapproval session
Use preapproval to obtain a PayHere customer token for a later backend-only automated charge. The token is returned in the verified provider callback; your application is responsible for storing it securely. AvraAPI does not retain it.- PHP SDK
- Laravel SDK
- Node.js SDK
PaymentSession with flow: 'preapproval'. The authorization result and customer token are received later through the verified callback; they are not part of the checkout-session response.Create an authorization hold session
Use authorization when you need to hold a customer’s funds and capture the full or lower approved amount later. PayHere sends the authorization token through its verifiednotify_url callback; use that token only from your backend.
- PHP SDK
- Laravel SDK
- Node.js SDK
PaymentSession with flow: 'authorization'. A verified authorization callback can later contain the merchant-owned authorization token. Browser return data does not prove the hold was authorised.List subscriptions
Use this read-only function to list the safe subscription projections available to the configured PayHere profile.- PHP SDK
- Laravel SDK
- Node.js SDK
SubscriptionSummary objects:Get one subscription
Use this read-only function for one known PayHere numeric subscription ID.- PHP SDK
- Laravel SDK
- Node.js SDK
SubscriptionSummary object:List payments for a subscription
Use this read-only function to inspect privacy-safe payment projections for one known PayHere subscription.- PHP SDK
- Laravel SDK
- Node.js SDK
Retry a subscription payment
This is a state-changing command. It requires a durable idempotency key andconfirmRetry: true.
- PHP SDK
- Laravel SDK
- Node.js SDK
SubscriptionCommandResult:Cancel a subscription
This is a state-changing command. It requires a durable idempotency key andconfirmCancel: true.
- PHP SDK
- Laravel SDK
- Node.js SDK
SubscriptionCommandResult:Create an automated token charge
Use this backend-only command after your application has safely stored a PayHere customer token received from a verified preapproval callback. It requires an enabled Automated Charging permission, a durable idempotency key, andconfirmCharge: true.
- PHP SDK
- Laravel SDK
- Node.js SDK
Capture an authorization
Use this backend-only command to capture an existing PayHere authorization. The requested capture amount cannot exceedexpectedAuthorizedAmount. Bind the command to the expected order, currency, and authorisation details to prevent a mismatched capture.
- PHP SDK
- Laravel SDK
- Node.js SDK
Payment Elements
Payment Elements can render PayHere as a redirect method or provider overlay. It does not expose PayHere advanced Merchant API commands to browser code.Gateway-specific options
For one-time PayHere checkout,providerOptions can include delivery_address, delivery_city, delivery_country, custom_1, custom_2, and payment_method. These are non-secret, server-validated provider fields. Do not use them for merchant secrets, App Secrets, access tokens, customer tokens, authorization tokens, callback URLs, or payment status.
Completion, webhooks, and safety
PayHere’snotify_url is the authoritative payment signal for checkout, recurring sessions, preapprovals, and authorization holds. Preserve callback fields and call common completePayment() using the pending order’s stored completion context. A browser return or Payment Elements event can update the UI but cannot mark an order paid.
For provider API background and provider response codes, see PayHere’s official Refund API, Retrieval API, Recurring API, Preapproval API, Authorize API, Subscription Manager API, Charging API, and Capture API documentation.