AlyaPay Documentation
API Integration

Create Transaction

Create a new BNPL transaction

Create Transaction

Create a new Buy Now, Pay Later transaction. The transaction starts in PENDING status and the customer receives an SMS to confirm.

Endpoint

POST /api/v1/public/partner/transactions

Request

Headers

HeaderRequiredValue
X-Api-KeyYesYour API key
Content-TypeYesapplication/json

Body

FieldTypeRequiredValidationDescription
customerPhonestringYes10-15 digits (no + sign)Customer's phone number
totaldecimalYesMin: 500.00, Max: 15,000.00Total amount in MAD
currencystringYesMust be MADCurrency code
itemsarrayYesAt least 1 itemProducts/services
items[].namestringYesMax 200 charsProduct name
items[].referencestringNoMax 100 charsProduct SKU
items[].quantityintegerYesMin: 1Quantity
items[].unitPricedecimalYesMin: 0.01Unit price in MAD
items[].categoryIdlongNo-Product category ID
vendorReferencestringNoMax 100 charsYour order ID

Example

curl -X POST "https://api.alyapay.com/api/v1/public/partner/transactions" \
  -H "X-Api-Key: sk_live_xxx.yyy" \
  -H "Content-Type: application/json" \
  -d '{
    "customerPhone": "212612345678",
    "total": 500.00,
    "currency": "MAD",
    "items": [
      {
        "name": "iPhone Case",
        "reference": "CASE-001",
        "quantity": 1,
        "unitPrice": 500.00
      }
    ],
    "vendorReference": "ORDER-2024-001"
  }'

Response

Success (201 Created)

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "orderReference": "AB12345",
  "vendorReference": "ORDER-2024-001",
  "status": "PENDING",
  "totalAmount": 500.00,
  "currency": "MAD",
  "customerPhone": "212612345678",
  "merchantName": "My Store",
  "storeName": "Downtown Branch",
  "items": [...],
  "createdAt": "2024-12-08T10:30:00Z",
  "updatedAt": null
}

Transaction Statuses

StatusDescription
PENDINGWaiting for customer confirmation
APPROVEDCustomer confirmed (webhook sent)
CANCELEDTransaction canceled
COMPLETEDAll installments paid

Common Errors

StatusCodeDescription
400INVALID_REQUESTValidation error
401UNAUTHORIZEDInvalid API key
409DUPLICATE_VENDOR_REFERENCEvendorReference already exists
422PURCHASE_AMOUNT_EXCEEDS_LIMITCredit limit exceeded

Best Practices

  1. Always store the transaction id for future reference
  2. Use vendorReference with your order ID for easy lookup
  3. Validate phone format - 10-15 digits without + sign (e.g., 212612345678)
  4. Handle duplicate errors - Check for existing transactions before retrying