Skip to main content

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 UPG completionContext.
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 a PaymentSession. Its public checkout instructions may be sent to the browser. Its completionContext is server-only and must be saved with your pending order.
The SDK maps this response to 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 replace completePayment() for a newly received callback.
SDK response — a list of safe payment projections:

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 of paymentId or authorizationToken, a clear description, a durable idempotency key, and confirmRefund: true.
  • Omit amount for a full refund.
  • Set amount to 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.
SDK response — AvraAPI returns a safe command projection, not PayHere’s raw OAuth response:
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.
Do not generate a refund idempotency key from a timestamp alone, and never make this call from browser code.

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'.
SDK response — 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.
SDK response — 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 verified notify_url callback; use that token only from your backend.
SDK response — 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.
SDK response — a list of SubscriptionSummary objects:

Get one subscription

Use this read-only function for one known PayHere numeric subscription ID.
SDK response — one SubscriptionSummary object:

List payments for a subscription

Use this read-only function to inspect privacy-safe payment projections for one known PayHere subscription.
SDK response:

Retry a subscription payment

This is a state-changing command. It requires a durable idempotency key and confirmRetry: true.
SDK response — SubscriptionCommandResult:

Cancel a subscription

This is a state-changing command. It requires a durable idempotency key and confirmCancel: true.
SDK response — 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, and confirmCharge: true.
SDK response:

Capture an authorization

Use this backend-only command to capture an existing PayHere authorization. The requested capture amount cannot exceed expectedAuthorizedAmount. Bind the command to the expected order, currency, and authorisation details to prevent a mismatched capture.
SDK response:

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.
For rendering, events, visual customization, and checkout lifecycle details, see More Payment Elements features.

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’s notify_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.
Last modified on October 1, 2026