Quick Start
Complete AlyaPay integration in 15 minutes
Quick Start
Get AlyaPay up and running in 15 minutes.
This guide covers Online Checkout for websites. For POS/ERP integration, see API Integration.
Prerequisites
Before you begin, you'll need:
- AlyaPay merchant account
- API Key - Provided by our team after account approval
API Base URLs:
- Sandbox:
https://sandbox-api.alyapay.com - Production:
https://api.alyapay.com
Use development URL with test API keys during development, and production URL with live keys when going live.
Step 1: Create Session Token (Backend)
Your backend creates a session token for each checkout.
Endpoint: POST /api/v1/public/sessions
Headers:
X-API-Key: YOUR_API_KEY_HERE
Content-Type: application/jsonRequest:
{
"total": 1799.00,
"currency": "MAD",
"items": [
{
"id": "PRODUCT_123",
"name": "Wireless Headphones",
"price": 1799,
"quantity": 1
}
]
}Response:
{
"token": "session_abc123...",
"expiresAt": "2024-12-08T10:30:00Z"
}Step 2: Frontend Integration (Redirect Flow)
Add the SDK and initialize with a redirect_url:
<script src="https://cdn.alyapay.com/latest/alyapay-sdk.min.js"></script>
<div id="alyapay-button"></div>
<script>
AlyaPay.Payments.init({
session_token: 'session_abc123...',
redirect_url: 'https://yoursite.com/payment-callback',
locale: 'en'
});
AlyaPay.Payments.load({
container: '#alyapay-button'
});
</script>After payment, handle the callback on your redirect_url page:
// On /payment-callback page
const urlParams = new URLSearchParams(window.location.search);
const status = urlParams.get('status');
const transactionId = urlParams.get('transaction_id');
if (status === 'SUCCESS' && transactionId) {
// Verify with backend
verifyPayment(transactionId);
}Note: The popup flow is deprecated. All new integrations should use the redirect flow shown above. Learn more →
Step 3: Verify Payment (Backend)
Verify the transaction on your backend:
Endpoint: GET /api/v1/public/transactions/{transactionId}
Headers:
X-API-Key: YOUR_API_KEY_HEREResponse:
{
"id": "trans_123",
"status": "APPROVED",
"amount": 1799.00,
"currency": "MAD"
}Next Steps
- Redirect Flow Documentation - Complete implementation guide
- Backend Integration - Session creation and verification
- Components - Payment button and widget options
- Error Handling - Handle common errors
Need Help?
Email support@alyapay.com