Transactions
Understanding the lifecycle of a transaction
Overview
A transaction in PayOS represents the complete lifecycle of a payment event. It encompasses all payment attempts, refunds, and adjustments associated with a specific payment flow. Understanding how PayOS handles transactions helps merchants track payments, retries, and outcomes.
Transaction Lifecycle
A transaction in PayOS can include multiple states as part of its journey. The following flow outlines the typical stages of a transaction when it makes use of the Hosted Checkout:
-
Initiation:
- The transaction starts when a merchant sends an API call to PayOS to initiate a payment.
- The initiation includes details like the amount, currency, payment methods, and customer information.
- Use the
/payment/initiate
endpoint to start a transaction, ensuring you have a valid OAuth 2.0 access token for authentication.
Example Request:
Example Response:
-
Payment Attempt:
- After the transaction initiation, the merchant renders the hosted checkout to the payer.
- The payer interacts with the hosted checkout, selecting one of the available payment methods. These methods are displayed based on configurable rules in the Rules Engine.
- This stage involves the payer engaging with the checkout interface, selecting their preferred payment method, and entering any necessary details specific to that method.
- In cases where the merchant is choosing to make use of direct integration, they will need to make use of the
/payment/initiate
endpoint with theintegrationType
set todirect
and supply thepaymentMethods
array with the relevant payment method details.
-
Authorization:
- The payment is authorized, and funds are reserved on the customer’s payment method. In some cases additional interaction may be required from the payer, and in these cases the Hosted Checkout will handle all interactions. In cases where a merchant is making use of direct integration, they might need to surface the userInteractionRequired URL to the payer.
- Use the
/payment/payments/{paymentId}
endpoint to check the status of a payment.
Example Request:
Example Response:
-
Settlement:
- Once authorized, the payment may move into a settled state, and funds are transferred to the merchant’s account.
- The status can be checked using the same endpoint as for authorization.
Example Response:
-
Refunds and Adjustments:
- If necessary, refunds or adjustments can be processed using the
/payment/payments/{paymentId}/refund
endpoint. - Adjustments to the authorized amount can be made using the
/payments/{id}/adjust-authorization
endpoint.
Example Refund Request:
Example Refund Response:
- If necessary, refunds or adjustments can be processed using the
-
Completion:
- The transaction is completed once all payment attempts are successful or the payment is cancelled, and any necessary refunds or adjustments are processed.
Example Transaction Response
Here’s an example of a transaction response from the PayOS API:
Monitoring and Reporting
PayOS provides detailed logs and dashboards to monitor transaction statuses and identify any issues in the payment flow. Merchants can use these tools to track retries, cancellations, and refunds within a transaction.
Authentication and Security
All transaction-related API calls require OAuth 2.0 authentication. Ensure that your access token is valid and included in the Authorization
header of your requests. Refer to the Authentication Guide for more details on setting up and managing your OAuth 2.0 credentials.