JS & STC Pay

Use this library to integrate Paylink payments into your app and grow your business with Paylink APIs to proceed with easy payment and generate customer invoices.

Step 1: SDK Initialization

Please ensure the SDK Initialization steps are completed before proceeding with the following steps. This is crucial for the proper functioning of the payment process.

Step 2: Send OTP to STCPay Client Phone

The method sendStcPayOtp uses a Promise from the "payment" object, passing it "token," "order," "mobileCountryCode," and "mobile" as arguments and returning a Promise that will resolve with the response.

 let stcpayOtpResponse = await payment.sendStcPayOtp(token, order, mobileCountryCode, mobile);

Developers are advised to use "async" and "await" when using this method to simplify the handling of the Promise and the response data, as "await" allows the Promise to resolve.

The response is to be stored in "stcpayOtpResponse" before proceeding to the next step of passing the same object to the "processStcPayPayment" method, along with an "otp" value, to initiate and complete a payment transaction via the STC Pay payment gateway.

Step 3: Process the STCPay Payment

The "processStcPayPayment" method is often used to process a payment transaction and confirm the receipt of a one-time password (OTP). The OTP is typically required as an additional security measure to verify the identity of the user making the payment, and the method will not proceed without a valid OTP.



Developer need to pass the same response object received from "sendStcPayOtp" with the OTP received by the buyer.

await payment.processStcPayPayment(otp, stcpayOtpResponse);

The provided code uses the "await" keyword to call the "processStcPayPayment" method from the "payment" object, passing it "otp" and "stcpayOtpResponse" as arguments and storing the response in "stcpayPaymentResponse."

If the transaction is successful, the buyer will be redirected to the callback URL of the merchant. However, suppose an error occurs during the transaction. In that case, an error object will be returned instead, containing information about the cause of the error and any relevant details that may be useful in diagnosing and resolving the issue.

Step 4: Handling Payment Process Response

Finally, from the server side, programmatically process the payment response sent by Paylink after the payment process finishes. This step is crucial for security reasons; carefully follow Get Invoice to handle the payment result from Paylink.



  • Merchant's application must call GetInvoice (here) endpoint immediately after the payment from the server side. First, check the integrity of the price by checking the payment status "orderStatus" and the amount paid "amount".
  • Then proceed with the order processing of the client as paid or not. Otherwise, avoid using the endpoint GetInvoice and checking the amount and status will jeopardize the security of the payment.

Sample code

You can download a sample of the code written in PHP from here.