Skip to main content

Web Checkout

This documentation details the process of implementing the latest e-Payment Checkout platform released by SwiftPay.

Prerequisites

Before you begin, ensure you have:

  • A SwiftPay merchant account
  • Access to your SwiftPay Dashboard
  • Your API credentials (SwiftPay Token)

How it works?

  • User visits the merchant's website to make some purchase
  • A unique transasction_id is generated at merchant's system
  • Payment request is made to SwiftPay providing the transasction_id as transaction, amount and callback
  • User is redirected to the epayment portal (eg. https://webpayment.raisa.com.np)
  • After payment is made by the user, a successful callback is made to the callback URL
  • The merchant website can optionally confirm the payment received
  • The merchant website then proceeds other steps after payment confirmation

Integration Steps

Base URL

https://pay.raisa.com.np

Initiate Endpoint

URLMethodAuthorizationFormat
api/v1/initiatePOSTRequiredapplication/json

1. Authentication

All API requests must include your SwiftPay token in the headers:

x-swiftpay-token: YOUR_SWIFTPAY_TOKEN
x-swiftpay-environment: production

2. Initiating Payment

To start a payment transaction, make a POST request to our initiation endpoint.

Endpoint:

POST https://pay.raisa.com.np/api/v1/initiate

Headers:

Content-Type: application/json
x-swiftpay-token: YOUR_SWIFTPAY_TOKEN
x-swiftpay-environment: production

JSON Payload Details

ParameterTypeRequiredDescription
callbackstringYesURL where SwiftPay will send payment status notifications
domainstringYesYour website's domain URL
amountnumberYesTransaction amount (in NPR)
transactionstringYesYour unique transaction identifier

Sample Request Payload

{
"callback": "https://yourwebsite.com/payment/callback",
"domain": "https://yourwebsite.com",
"amount": 1200,
"transaction": "00RT89SR2CV"
}

3. Handling the Response

Successful Response

A successful request returns a payment URL and transaction details:

{
"tnx": "SWIFTPAY-A64666C5-1053-416F-9281-74042F58A060-EWP",
"payment_url": "https://webpayment.raisa.com.np?tnx=SWIFTPAY-A64666C5-1053-416F-9281-74042F58A060-EWP",
"expires_at": "2024-11-20T08:03:28.000000Z",
"expires_in": 1800,
"environment": "production"
}
FieldDescription
tnxUnique SwiftPay transaction identifier
payment_urlURL to redirect customers for payment
expires_atPayment link expiration timestamp
expires_inTime until expiration in seconds
environmentCurrent environment (production/sandbox)

Error Response

If the request is invalid, you'll receive an error response:

{
"status": "error",
"code": 422,
"message": "Validation failed",
"errors": {
"callback": [
"Callback URL is required",
"Callback URL must be a valid URL"
],
"domain": [
"Domain URL is required",
"Domain URL must be a valid URL"
],
"amount": [
"Amount is required"
],
"transaction": [
"Transaction ID is required"
]
}
}

4. Implementation Samples

curl --location 'https://pay.raisa.com.np/api/v1/initiate' \
--header 'x-swiftpay-token: SWIFTPAY-QZIGNIE7QMVRLSRSJ8FZONZNPVT' \
--header 'x-swiftpay-environment: production' \
--header 'Content-Type: application/json' \
--data '{
"callback": "https://yourdomain.com/payment/callback",
"domain": "https://yourdomain.com",
"amount": 1200,
"transaction": "00RT89SR2CV"
}'

5. Redirecting to Payment Page

After receiving a successful response:

  1. Store the tnx value in your database (Optional)
  2. Redirect the customer to the payment_url

You may redirect the customer to the payment_url using any appropriate method that aligns with your requirements.

Redirecting Reference

const data = response.json();
if (response.ok) {
// Redirect to payment page
window.location.href = data.payment_url;
} else {
console.error('Payment initiation failed:', data);
}

6. Payment Callback

Once the payment is completed, SwiftPay will send a POST request to your callback URL with the payment status.

Callback Parameters:

ParameterDescription
tnxSwiftPay transaction ID
statusPayment status (success/failed)
amountTransaction amount
transactionYour original transaction ID
messageAdditional information about the transaction (Optional)

Sample Callback Request

https://yourwebsite.com/payment/callback?tnx=SWIFTPAY-A64666C5-1053-416F-9281-74042F58A060-EWP
&status=completed
&amount=1200
&transaction=00RT89SR2CV
Important
  • Please use the lookup API for the final validation of the transaction.
  • SwiftPay payment link expires in 30 minutes in production and sandbox (default).
Configuration
  • The callback url callback URL should support GET method
  • User shall be redirected to the callback URL with following parameters for confirmation

Testing

  1. Use the sandbox environment for testing:
x-swiftpay-environment: sandbox
  1. Test different scenarios:
    • Successful payment
    • Failed payment
    • Expired payment link
    • Invalid parameters

Generic Errors

This document outlines the possible error responses you may encounter when using the SwiftPay API. All error responses follow a consistent format and include appropriate HTTP status codes.

Error Response Format

{
"error": "Error message description",
"code": 4XX
}

Error Types

Environment Errors (400 Bad Request)

{
"error": "Invalid environment. Must be production or sandbox.",
"code": 400
}

Occurs when the x-swiftpay-environment header value is neither 'production' nor 'sandbox'.

Authentication Errors (401 Unauthorized)

Invalid Token

{
"error": "Invalid or missing token.",
"code": 401
}

Occurs when the provided x-swiftpay-token is invalid or missing.

Merchant Verification

{
"error": "Unverified Merchant",
"code": 401
}

Occurs when the merchant's business status is not verified.

Authorization Errors

Private Token Issues

{
"error": "User does not have the required private attribute.",
"code": 403
}
{
"error": "Invalid private token.",
"code": 403
}

Occurs during payment initiation when there are issues with the private token.

Public Token Issues

{
"error": "User does not have the required public attribute.",
"code": 403
}
{
"error": "Invalid public token.",
"code": 403
}

Occurs during payment verification when there are issues with the public token.