Skip to main content

create order

to start the divit journey for your customer, you need to create an order with divit so we know what the customer is expected to pay and what type of product the customer is buying.

caution

all monetary values are in integer format. So, $987.65 = 98765

order creation API

airlines have a unique experience with divit. as always, we try to keep the purchase flow seamless, and as such, we want to keep ticket details with the user even during the payment process.

so for that, we require some special details to be passed on so we can show these to the user. parts of the structure follow amadeus API so it should be familiar formats for most airlines.

  • departure Departure details for the user
  • arrival Time and location of arrival
sample request
var data = JSON.stringify({
"totalAmount": {
"amount": 400253,
"currency": "HKD"
},
"nonrefundableAmount": {
"amount": 300253,
"currency": "HKD"
},
"refundableAmount": {
"amount": 100000,
"currency": "HKD"
},
"webhook_success": "http://sucess.com",
"webhook_failure": "http://failure.com",
"webhook_events": "http://events.coms",
"partnerRef": "INTERNAL-REF-12121",
"OrderItems": [
{
"OrderType": "flight",
"OrderData": {
"departure": {
"iataCode": "MAD",
"terminal": "2",
"at": "2021-05-12T20:25:00"
},
"arrival": {
"iataCode": "AMS",
"at": "2021-05-12T23:00:00"
},
"carrierCode": "KL",
"number": "1706",
"aircraft": {
"code": "73J"
},
"operating": {
"carrierCode": "KL"
},
"duration": "PT2H35M",
"id": "81",
"numberOfStops": 0
}
}
]
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});

xhr.open("POST", "https://sandbox-api.divit.dev/orders");
xhr.setRequestHeader("Authorization", "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJQYXJ0bmVySUQiOiJVMmQyN0tia0poTG9GdkpZZTJKeCIsImV4cCI6MTU4NTkx");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.send(data);

create order response

when order was created on the divit platform a redirect-uri is generated and sent back. this should be used to redirect the user to divit so they can complete the purchase after which an event is sent to your backend system.

success response
{
"redirect-uri": "https://sandbox-consumer.divit.dev/order/8a6638b2-b5e6-4d11-9cbe-272e8010875e",
"orderid": "8a6638b2-b5e6-4d11-9cbe-272e8010875e"
}

redirect user

almost done! Just redirect your user to the supplied URL and we will take it from there. now you can sit back and wait for our webhook_events call.

sample request
function pageRedirect() {
window.location.replace("https://sandbox-consumer.divit.dev/order/8a6638b2-b5e6-4d11-9cbe-272e8010875e");
}