Skip to main content

GET Order Details

For Credify to create a payment flow for your orders, we will need basic info about the order, this guide will provide the details on how to get this API setup from your side.

caution

This is only required for custom e-commerce stores, if you are using WooCommerce or Shopify follow the instructions in merchant dashboard.

API Specifications

Endpoint:

GET <Your order details API URL>?orderID={orderID}&timestamp={timestamp}&hmac={hashString}
ParameterDescription
Base URLYou can pick any base URL on your website and inform Credify with the URL during the setup process
orderIDA unique order identifier that was initially sent by iframe/your website
timestampA timestamp that was taken upon receiving the request. Can be used by your side for better security controls
hashStringHMAC hash of the URL without hmac parameter ('<Your order details API URL>?orderID={orderID}&timestamp={timestamp}' for example: 'https://my-store.com/api/order?orderID=12333&timestamp=1732742969'), this hash can be used to validate the authenticity of the request.

Expected Response

{
"lineItems": ["2 X Large White T-Shirt", "Black Hat"],
"shippingAddress": "Giza \nEgypt",
"total": 500.5,
"customer": {
"name": "John Doe",
"phone": "+201009993343"
},
"orderSerial": "#11"
}
FieldDescription
lineItemsAn array of items included in the order, with quantity and description.
shippingAddressThe address where the order will be shipped.
totalThe total cost of the order.
customerAn object containing customer name and phone number.
orderSerialA unique serial number for the order.

Validating the HMAC

To ensure the integrity and authenticity of the URL with HMAC, you can validate the HMAC provided with the URL. Here is a step-by-step guide on how to validate the HMAC:

  1. Extract Parameters: Extract the orderID, timestamp, and hmac from the URL.
  2. Recreate the URL with Parameters: Recreate the URL using the extracted orderID and timestamp.
  3. Generate HMAC: Use the same HMAC secret to generate a hash from the recreated URL.
  4. Compare HMACs: Compare the generated HMAC with the provided hmac. If they match, the URL is valid.
const crypto = require('crypto')

function validateHMAC(baseURL, HMACSecret, orderID, timestamp, providedHMAC) {
const urlWithParams = `${baseURL}?orderID=${orderID}&timestamp=${timestamp}`
const hmac = crypto.createHmac('sha256', HMACSecret)
const hash = hmac.update(urlWithParams).digest('hex')
return hash === providedHMAC
}

// Example usage
const baseURL = 'https://example.com/api/order'
const HMACSecret = 'your_hmac_secret'
const orderID = '12345'
const timestamp = '1617181723'
const providedHMAC = 'your_provided_hmac_string_here'

const isValid = validateHMAC(
baseURL,
HMACSecret,
orderID,
timestamp,
providedHMAC,
)
console.log(`Is the URL valid? ${isValid}`)