Start a payment for an order
const url = 'https://apibase.ecomweb.app/api/v1/public/stores/example/payments/initiate';const options = { method: 'POST', headers: { 'x-storefront-api-key': '<x-storefront-api-key>', 'Content-Type': 'application/json' }, body: '{"order_code":"example","provider_code":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://apibase.ecomweb.app/api/v1/public/stores/example/payments/initiate \ --header 'Content-Type: application/json' \ --header 'x-storefront-api-key: <x-storefront-api-key>' \ --data '{ "order_code": "example", "provider_code": "example" }'Starts a payment attempt for an order that is awaiting payment, through one of the store’s enabled gateways, and returns the page to send the shopper to. Every gateway answers with the same shape: redirect the shopper to redirect_url, then poll the payment state until the status changes. The attempt expires after a while; start a new one to retry. Fails with 404 when the order is not found, and with 400 when it is not awaiting payment, the gateway is not enabled or not configured for the store, or the order’s currency is not supported.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The store’s ref, as returned by GET /stores.
Request Bodyrequired
Section titled “Request Bodyrequired”object
Orders.order_code of the order to charge
Gateway provider code, e.g. “onepay”, “momo”
Example generated
{ "order_code": "example", "provider_code": "example"}Responses
Section titled “Responses”object
ID of the payment attempt that was created.
The gateway’s payment page. Redirect the shopper to it exactly as returned: the URL is opaque and, for some gateways, carries signed parameters and the return address, so do not parse or modify it. The shopper returns to the store’s order page afterwards.
Example generated
{ "payment_id": 1, "redirect_url": "example"}The request is malformed or failed validation.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key is missing, invalid, revoked or expired.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The key may not do this: a missing scope, a readonly key, a publishable key on a Store API route, or a disallowed origin.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}The resource does not exist in this store.
object
The HTTP status code.
What went wrong; validation failures list one message per problem.
The HTTP status text, such as Bad Request.
object
A stable, machine-readable error code.
A human-readable explanation.
Extra context about the error, when there is any.
object
When the error happened, as an ISO 8601 timestamp.
Example generated
{ "statusCode": 1, "message": [ "example" ], "error": "example"}