Direct Order API

This guide explains how to create direct order through API call . After calling the API successfully the user will be notified by email and/or SMS (according to API parameters).

REQUEST

testing server:

POST https://staging.xpay.app/api/orders/create-direct-order/

production(Live) server:

POST https://community.xpay.app/api/orders/create-direct-order/

Parameters

Authorization

This method requires authorization, supply the header with a key value pair with that structure

"x-api-key" : string

Required Properties

Property nameValueDescriptionNotes
x-api-keystringAPI key linked to your communitygenerate API key

​

Request body

Required Properties

Property nameValueDescriptionNotes
namestringdirect order's name
community_idstringID that is uniques to your community
amount.amountfloatrepresents the amount you want to charge the userif your community fees is Added in bill then use the value returned from prepare amount endpoint , otherwise use the amount you want to charge the user directly.
amount.currencystringCurrencysupported currencies are "EGP", "USD", "EUR", "SAR", "AED" and "GBP". default is "EGP"
payment_methodsarrayallowed payment methods.see payment available payment methods
customer_namestringuser first and last namemust contain first and last name in english letters with space between them.
customer_emailstringuser email
customer_mobilestringuser phone numbermust contain country code prefixed
danger

Hardcoding the customer data in the production version of your app will raise a risk in the payment processor and the transaction will be declined

Optional Properties

Property nameValueDescriptionNotes
discount_amount.amountfloatwill be subtracted from the amount
discount_amount.currencystringsupported "EGP", "USD", "EUR", "SAR", "AED" and "GBP".default is "EGP"
allow_recurring_paymentsbooleanChange from regular to reccuring paymentNeeded if your payment is recurring
expiry_datestringExpiry Date of the reccuring paymentNeeded if your payment is recurring
minimum_days_between_paymentsintegerNumber of days between each paymentNeeded if your payment is recurring
custom_fieldsarrayCustom Fields
order_descriptionstringOrder description
addressstringbilling address
customer_titlestringCustomer title used when sending notification.e.g. Mr, Mrs, Doctor,... etc.
vat_percentagefloatThe percentage will be calculated and added to the amount.will show in the payment pages as a separate entity titled VAT
send_by_emailbooleanIf true notify customer by email .
cc_emailstringCC email in case of email sent.
send_by_smsbooleanIf true notify customer by mobile.
redirect_urlstringredirect url
callback_urlstringcallback url
paidbooleandefault falseMay be use in case of recurring payment and you want to mark the first payment as paid.
tagsstringpayment tags see the example below

Response

If successful, this method returns a response body with the following structure:

{
    "status": {
        "code": 201,
        "message": "success",
        "errors": []
    },
    "data": {
        "success": true,
        "merchant_id": "xL4rPB7",
        "payment_id": "1BlbR48",
        "payment_link": "https://staging-iframe.xpay.app/i/community/xL4rPB7/direct-order/1BlbR48",
        "message": "Direct order created successfully. SMS and email notifications sent."
    },
    "count": null,
    "next": null,
    "previous": null
}
Property nameValueDescriptionNotes
merchant_idstringMerchant's idSame as the community_id which sent in the request.
payment_idstringDirect order's unique id
payment_linkstringPayment Link

Example

{
    "name": "Monthly rent",
    "address": "123 Main St, City",
    "order_description": "Monthly rent payment", 
    "customer_title": "Mr.", 
    "customer_name": "Mahmoud mmm", 
    "customer_email": "test@example.com", 
    "allow_recurring_payments": false, 
    "customer_mobile": "+201223456789", 
    "cc_email": "cc@example.com", 
    "amount": {
        "amount": 100.0,
        "currency": "EGP"
    },
    "discount_amount": {
        "amount": 10.0,
        "currency": "EGP"
    },
    "community_id": "xL4rPB7", 
    "paid": false, 
    "tags": [ 
        {
            "id": 1,
            "name": "test-checkoutpage"
        }
    ],
    "payment_methods": [ 
        "CARD",
        "FAWRY"
    ],
    "vat_percentage": 5.0, 
    "expiry_date": "2025-05-31", 
    "minimum_days_between_payments": 30, 
 "custom_fields": [
    {
      "field_label": "test label1",
      "field_type": "TEXT"
    },
    {
      "field_label": "check example",
      "field_type": "CHECKBOX"
    },
    {
      "field_label": "number example",
      "field_type": "NUMBER",
      "required": false
    },
    {
      "field_label": "drop down example",
      "field_type": "DROPDOWNLIST",
      "field_choices": "c1,c2,c3",
      "required": true
    }
  ],
    "send_by_email": true, 
    "send_by_sms": true, 
    "redirect_url": "https://webhook.site/90b597de-669b-499a-a595-423054d9d46d",
    "callback_url": "https://webhook.site/90b597de-669b-499a-a595-423054d9d46d"
}
{
    "status": {
        "code": 201,
        "message": "success",
        "errors": []
    },
    "data": {
        "success": true,
        "merchant_id": "xL4rPB7",
        "payment_id": "1BlbR48",
        "payment_link": "https://staging-iframe.xpay.app/i/community/xL4rPB7/direct-order/1BlbR48",
        "message": "Direct order created successfully. SMS and email notifications sent."
    },
    "count": null,
    "next": null,
    "previous": null
}

Recurring Payment

​Just follow the example above and don't forget to include the recurring payment paramaters

Payment Options

There are four payment options available at the moment

  • card
  • kiosk (aman)
  • fawry (both kiosk and fawryPay)
  • mobile wallets
  • valU

Custom Fields

If you wish to request extra data from user during paymner, you can send custom fields array. each field in custom fields array contains:

Property nameValueDescription
field_labelstringlabel that will appears to the customer on payment
field_typestringfield type: TEXT, NUMBER, CHECKBOX or DROPDOWNLIST
requiredbooleanoptional parameter indicates if the field is mandatory
field_choicesstringonly used in case of DROPDOWNLIST (comma separated values of the drop down list)

Example

Request body

{
  ....
  "custom_fields": [
    {
      "field_label": "test label1",
      "field_type": "TEXT"
    },
    {
      "field_label": "check example",
      "field_type": "CHECKBOX"
    },
    {
      "field_label": "number example",
      "field_type": "NUMBER",
      "required": false
    },
    {
      "field_label": "drop down example",
      "field_type": "DROPDOWNLIST",
      "field_choices": "c1,c2,c3",
      "required": true
    }
  ]
  ....
}

Redirect Url

if it is assigned then once the payment is completed a redirect to the url will happen and will contain the following as query paramaters:

Property nameValueDescription
total_amount_piastersfloattransaction amount in piasters
total_amountfloattransaction amount
transaction_uuidstringtransaction UUID in XPay system
transaction_statusstringtransaction status

and if there iscustom fields then it will be included in query parameters

Callback url

If it is assigned, a POST request will be send after the customer pay the direct order with json body that includes:

Property nameValueDescription
total_amount_piastersfloattransaction amount in piasters
total_amountfloattransaction amount
transaction_uuidstringtransaction UUID in XPay system
transaction_statusstringtransaction status

and if there is custom fields then it will be included in the request json body.

The following is an example of the parametes sent to callback url:

{
  "message": "SportingClub Monthly rent callback", // message describes the callback
  "member_id": null,
  "payment_id": "W29gzjQ", // Direct order's unique id
  "merchant_id": "xL4rPB7", // Merchant id
  "test label1": "",//custom field
  "total_amount": 99.99,
  "check example": true,//custom field
  "number example": "",//custom field
  "transaction_id": "0901eddd-f71c-4f31-81a9-f03d08c328b5",
  "drop down example": "c2",//custom field
  "transaction_status": "SUCCESSFUL",
  "total_amount_piasters": 9999
}