Skip to main content

createOrder Method

Overview

The createOrder method initializes a payment order at the processor before collecting payment details. This enables improved fraud detection, session tokens for wallet payments, and better authorization rates.

Business Use Case: Set up the payment infrastructure before the customer reaches checkout, or when integrating wallet payments that require a session token.

Purpose

ScenarioBenefit
Wallet paymentsGenerate session token for Apple/Google Pay
Pre-checkoutPrepare payment context early
Risk assessmentAllow processor fraud checks
Session continuityMaintain context across pages

Request Fields

FieldTypeRequiredDescription
merchantOrderIdstringYesYour unique order reference
amountMoneyYesExpected payment amount
webhookUrlstringNoURL for notifications
metadataobjectNoAdditional data (max 20 keys)
testModebooleanNoProcess as test transaction

Response Fields

FieldTypeDescription
merchantOrderIdstringYour reference (echoed back)
connectorOrderIdstringConnector's order ID
statusPaymentStatusSTARTED, FAILED
sessionTokenobjectSession data for wallets
errorErrorInfoError details if failed
statusCodenumberHTTP status code

Example

SDK Setup

const { PaymentClient } = require('hyperswitch-prism');

const paymentClient = new PaymentClient({
connector: 'stripe',
apiKey: 'YOUR_API_KEY',
environment: 'SANDBOX'
});

Request

const request = {
merchantOrderId: "order_001",
amount: {
minorAmount: 1000,
currency: "USD"
},
webhookUrl: "https://your-app.com/webhooks/stripe",
testMode: true
};

const response = await paymentClient.createOrder(request);

Response

{
merchantOrderId: "order_001",
connectorOrderId: "pi_3Oxxx...",
status: "STARTED",
sessionToken: {
clientSecret: "pi_3Oxxx..._secret_xxx"
},
statusCode: 200
}

Next Steps