Create Subscription Order
2 min
This API creates a subscription order to enable users to make payment and start subscriptions. It accepts amount and currency details. On creating an order a dynamic token is returned from this api which is required to be passed to Pay3 SDK
This api requires access token that can be generated using Access TokenAccess Token API.
Create Checkout Order
Create an order with payin details from application's backend
POST
https://your-hostname.pay3.app/v1/client/checkout/create-order
curl --location 'https://api.dev.pay3.app/v1/client/subscription/create-order' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'signature: {{signature}}' \
--header 'access-token: ' \
--data-raw '{
"currencyId": "usd_usa",
"fiatAmount": "1.00",
"paymentMethodId": "all",
"email": "[email protected]",
"userId": "....",
"clientId": "....",
"requestId": "....",
"interval": "MONTHLY",
"requestDescription": "Gold plan",
"mode": "returnUrl"
}'Signature Generation
The request for creating checkout order requires a header signature. This can be generated using following code snippet.
const crypto = require('crypto');
// Required Parameters
const secretKey="Api-Secret-Provided-By-Pay3";
const fiatAmount = "0.02";
const requestId = "Order-Id-Generated-By-Application";
const currencyId = "currency-id";
const interval = "MONTHLY";
const trialPeriodDays = "7";
const clientId = "your-client-id";
const accessToken = "dynamic-access-token";
const getSignature = (secretKey, fiatAmount, requestId) => {
// Prepare the string to sign in same format.
// currencyId, fiatAmount, requestId and interval (if trialPeriodDays then add trialPeriodDays as well)
let stringToSign = 'currencyId=' + currencyId +
'&fiatAmount=' + fiatAmount +
'&requestId=' + requestId +
'&interval=' + interval;
if(trialPeriodDays && trialPeriodDays != "") {
stringToSign = stringToSign + '&trialPeriodDays=' + trialPeriodDays;
}
// Generating signature using SHA256 and provided secret and
// base64 encode the result
const mac = crypto.createHmac('sha256', secretKey);
return mac.update(stringToSign).digest('base64');
}
// Generate Signature
const signature = getSignature(secretKey, fiatAmount, requestId);import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
class Signature {
fun getPay3Signature(secretKey: String, requestId: String, fiatAmount: String, currencyId: String): String {
return try {
val stringToSign = "currencyId=$currencyId&fiatAmount=$fiatAmount&requestId=$requestId"
val mac = Mac.getInstance("HmacSHA256")
val secretKeySpec = SecretKeySpec(secretKey.toByteArray(), "HmacSHA256")
mac.init(secretKeySpec)
val hash = mac.doFinal(stringToSign.toByteArray(Charsets.UTF_8))
Base64.getEncoder().encodeToString(hash)
} catch (e: Exception) {
throw RuntimeException("Error generating signature", e)
}
}
}const crypto = require('crypto');
// Required Parameters
const secretKey="Api-Secret-Provided-By-Pay3";
const fiatAmount = "0.02";
const requestId = "Order-Id-Generated-By-Application";
const clientId = "your-client-id";
const accessToken = "dynamic-access-token";
const getSignature = (secretKey, fiatAmount, requestId) => {
// Prepare the string to sign in same format.
// fiatAmount followed by requestId
const stringToSign = 'fiatAmount=' + fiatAmount + '&requestId=' + requestId;
// Generating signature using SHA256 and provided secret and
// base64 encode the result
const mac = crypto.createHmac('sha256', secretKey);
return mac.update(stringToSign).digest('base64');
}
// Generate Signature
const signature = getSignature(secretKey, fiatAmount, requestId);