checkout
Step 3: Redirect Users to Checkout​
After receiving the response, extract the checkoutUrl from data.checkoutUrl and redirect your users to this URL.
Implementation Examples​
HTML Link:
<a href="https://checkout.wepay.com.sa?token=...">Pay with WePay</a>
JavaScript Redirect:
// After receiving the API response
const checkoutUrl = response.data.checkoutUrl;
window.location.href = checkoutUrl;
React/Next.js:
// After receiving the API response
const checkoutUrl = response.data.checkoutUrl;
<Link href={checkoutUrl}>Pay with WePay</Link>
// Or redirect programmatically
router.push(checkoutUrl);
PHP:
// After receiving the API response
$checkoutUrl = $response['data']['checkoutUrl'];
header("Location: " . $checkoutUrl);
exit;
Python (Flask/Django):
# Flask
from flask import redirect
checkout_url = response['data']['checkoutUrl']
return redirect(checkout_url)
# Django
from django.shortcuts import redirect
checkout_url = response['data']['checkoutUrl']
return redirect(checkout_url)
Step 4: Request a New Checkout Token (If Expired)​
If the original checkout token has expired, you must request a new checkout token before proceeding with the payment.
POST apps/api/contracts/checkout
Headers:
- Authorization:
Bearer {access_token}— Replace{access_token}with the token obtained from Step 1. - Content-Type: application/json
{
"buyerPhoneNumber": "966583944460",
"externalContractId": "CNT-2604-00100000"
}
Field Descriptions​
| Field Name | Type | Description | Required / Notes / Example |
|---|---|---|---|
| phoneNumber | string | User phone number | Required |
| externalContractId | string | Contract id | Required |
Example Request (cURL)​
curl --location 'https://api.wepay.com.sa/apps/api/contracts/checkout' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--data '{
"buyerPhoneNumber": "966583944460",
"externalContractId": "CNT-2604-00100000"
}'
Example Response​
{
"data": {
"checkoutUrl": "https://integration.wepay-sa.com/checkout?token=encodedToken"
},
"message": "ContractCheckoutStartedSuccessfully",
"status": 200,
"validationErrors": []
}