Create a checkout session
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/checkout-sessions \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"cancelUrl": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"expiresIn": 3600,
"merchantReference": "<string>",
"metadata": {},
"pricingData": {
"amount": 123,
"billingIntervalCount": 123,
"currency": "<string>",
"pricingName": "<string>",
"productData": {
"description": "<string>",
"name": "<string>"
},
"productId": "<string>"
},
"pricingId": "<string>",
"quantity": 1,
"successUrl": "<string>"
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/checkout-sessions"
payload = {
"cancelUrl": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"expiresIn": 3600,
"merchantReference": "<string>",
"metadata": {},
"pricingData": {
"amount": 123,
"billingIntervalCount": 123,
"currency": "<string>",
"pricingName": "<string>",
"productData": {
"description": "<string>",
"name": "<string>"
},
"productId": "<string>"
},
"pricingId": "<string>",
"quantity": 1,
"successUrl": "<string>"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'X-API-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
cancelUrl: '<string>',
customerEmail: '<string>',
customerId: '<string>',
expiresIn: 3600,
merchantReference: '<string>',
metadata: {},
pricingData: {
amount: 123,
billingIntervalCount: 123,
currency: '<string>',
pricingName: '<string>',
productData: {description: '<string>', name: '<string>'},
productId: '<string>'
},
pricingId: '<string>',
quantity: 1,
successUrl: '<string>'
})
};
fetch('https://merchant-api-prod.anyway.sh/v1/checkout-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://merchant-api-prod.anyway.sh/v1/checkout-sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cancelUrl' => '<string>',
'customerEmail' => '<string>',
'customerId' => '<string>',
'expiresIn' => 3600,
'merchantReference' => '<string>',
'metadata' => [
],
'pricingData' => [
'amount' => 123,
'billingIntervalCount' => 123,
'currency' => '<string>',
'pricingName' => '<string>',
'productData' => [
'description' => '<string>',
'name' => '<string>'
],
'productId' => '<string>'
],
'pricingId' => '<string>',
'quantity' => 1,
'successUrl' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://merchant-api-prod.anyway.sh/v1/checkout-sessions"
payload := strings.NewReader("{\n \"cancelUrl\": \"<string>\",\n \"customerEmail\": \"<string>\",\n \"customerId\": \"<string>\",\n \"expiresIn\": 3600,\n \"merchantReference\": \"<string>\",\n \"metadata\": {},\n \"pricingData\": {\n \"amount\": 123,\n \"billingIntervalCount\": 123,\n \"currency\": \"<string>\",\n \"pricingName\": \"<string>\",\n \"productData\": {\n \"description\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"productId\": \"<string>\"\n },\n \"pricingId\": \"<string>\",\n \"quantity\": 1,\n \"successUrl\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://merchant-api-prod.anyway.sh/v1/checkout-sessions")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"cancelUrl\": \"<string>\",\n \"customerEmail\": \"<string>\",\n \"customerId\": \"<string>\",\n \"expiresIn\": 3600,\n \"merchantReference\": \"<string>\",\n \"metadata\": {},\n \"pricingData\": {\n \"amount\": 123,\n \"billingIntervalCount\": 123,\n \"currency\": \"<string>\",\n \"pricingName\": \"<string>\",\n \"productData\": {\n \"description\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"productId\": \"<string>\"\n },\n \"pricingId\": \"<string>\",\n \"quantity\": 1,\n \"successUrl\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/checkout-sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cancelUrl\": \"<string>\",\n \"customerEmail\": \"<string>\",\n \"customerId\": \"<string>\",\n \"expiresIn\": 3600,\n \"merchantReference\": \"<string>\",\n \"metadata\": {},\n \"pricingData\": {\n \"amount\": 123,\n \"billingIntervalCount\": 123,\n \"currency\": \"<string>\",\n \"pricingName\": \"<string>\",\n \"productData\": {\n \"description\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"productId\": \"<string>\"\n },\n \"pricingId\": \"<string>\",\n \"quantity\": 1,\n \"successUrl\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"amount": 123,
"createdAt": "<string>",
"currency": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"expiresAt": "<string>",
"id": "<string>",
"lastError": {
"code": "<string>",
"occurredAt": "<string>",
"operation": "<string>",
"requestId": "<string>"
},
"merchantReference": "<string>",
"metadata": {},
"orderId": "<string>",
"orderStatus": "<string>",
"paymentLinkId": "<string>",
"pricing": {
"amount": 123,
"billingInterval": "DAY",
"billingIntervalCount": 123,
"currency": "<string>",
"flexibleAmount": true,
"maxAmount": 123,
"minAmount": 123,
"pricingId": "<string>",
"pricingName": "<string>",
"pricingType": "SUBSCRIPTION"
},
"product": {
"description": "<string>",
"name": "<string>",
"productId": "<string>"
},
"productName": "<string>",
"provider": "<string>",
"quantity": 123,
"status": "CREATED",
"url": "<string>"
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}Merchant API 端点
创建结账会话
创建结账会话,请求限定于密钥所属组织。
POST
/
v1
/
checkout-sessions
Create a checkout session
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/checkout-sessions \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"cancelUrl": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"expiresIn": 3600,
"merchantReference": "<string>",
"metadata": {},
"pricingData": {
"amount": 123,
"billingIntervalCount": 123,
"currency": "<string>",
"pricingName": "<string>",
"productData": {
"description": "<string>",
"name": "<string>"
},
"productId": "<string>"
},
"pricingId": "<string>",
"quantity": 1,
"successUrl": "<string>"
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/checkout-sessions"
payload = {
"cancelUrl": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"expiresIn": 3600,
"merchantReference": "<string>",
"metadata": {},
"pricingData": {
"amount": 123,
"billingIntervalCount": 123,
"currency": "<string>",
"pricingName": "<string>",
"productData": {
"description": "<string>",
"name": "<string>"
},
"productId": "<string>"
},
"pricingId": "<string>",
"quantity": 1,
"successUrl": "<string>"
}
headers = {
"Idempotency-Key": "<idempotency-key>",
"X-API-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'Idempotency-Key': '<idempotency-key>',
'X-API-Key': '<api-key>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
cancelUrl: '<string>',
customerEmail: '<string>',
customerId: '<string>',
expiresIn: 3600,
merchantReference: '<string>',
metadata: {},
pricingData: {
amount: 123,
billingIntervalCount: 123,
currency: '<string>',
pricingName: '<string>',
productData: {description: '<string>', name: '<string>'},
productId: '<string>'
},
pricingId: '<string>',
quantity: 1,
successUrl: '<string>'
})
};
fetch('https://merchant-api-prod.anyway.sh/v1/checkout-sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://merchant-api-prod.anyway.sh/v1/checkout-sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'cancelUrl' => '<string>',
'customerEmail' => '<string>',
'customerId' => '<string>',
'expiresIn' => 3600,
'merchantReference' => '<string>',
'metadata' => [
],
'pricingData' => [
'amount' => 123,
'billingIntervalCount' => 123,
'currency' => '<string>',
'pricingName' => '<string>',
'productData' => [
'description' => '<string>',
'name' => '<string>'
],
'productId' => '<string>'
],
'pricingId' => '<string>',
'quantity' => 1,
'successUrl' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Idempotency-Key: <idempotency-key>",
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://merchant-api-prod.anyway.sh/v1/checkout-sessions"
payload := strings.NewReader("{\n \"cancelUrl\": \"<string>\",\n \"customerEmail\": \"<string>\",\n \"customerId\": \"<string>\",\n \"expiresIn\": 3600,\n \"merchantReference\": \"<string>\",\n \"metadata\": {},\n \"pricingData\": {\n \"amount\": 123,\n \"billingIntervalCount\": 123,\n \"currency\": \"<string>\",\n \"pricingName\": \"<string>\",\n \"productData\": {\n \"description\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"productId\": \"<string>\"\n },\n \"pricingId\": \"<string>\",\n \"quantity\": 1,\n \"successUrl\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Idempotency-Key", "<idempotency-key>")
req.Header.Add("X-API-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://merchant-api-prod.anyway.sh/v1/checkout-sessions")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"cancelUrl\": \"<string>\",\n \"customerEmail\": \"<string>\",\n \"customerId\": \"<string>\",\n \"expiresIn\": 3600,\n \"merchantReference\": \"<string>\",\n \"metadata\": {},\n \"pricingData\": {\n \"amount\": 123,\n \"billingIntervalCount\": 123,\n \"currency\": \"<string>\",\n \"pricingName\": \"<string>\",\n \"productData\": {\n \"description\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"productId\": \"<string>\"\n },\n \"pricingId\": \"<string>\",\n \"quantity\": 1,\n \"successUrl\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/checkout-sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = '<idempotency-key>'
request["X-API-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"cancelUrl\": \"<string>\",\n \"customerEmail\": \"<string>\",\n \"customerId\": \"<string>\",\n \"expiresIn\": 3600,\n \"merchantReference\": \"<string>\",\n \"metadata\": {},\n \"pricingData\": {\n \"amount\": 123,\n \"billingIntervalCount\": 123,\n \"currency\": \"<string>\",\n \"pricingName\": \"<string>\",\n \"productData\": {\n \"description\": \"<string>\",\n \"name\": \"<string>\"\n },\n \"productId\": \"<string>\"\n },\n \"pricingId\": \"<string>\",\n \"quantity\": 1,\n \"successUrl\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"amount": 123,
"createdAt": "<string>",
"currency": "<string>",
"customerEmail": "<string>",
"customerId": "<string>",
"expiresAt": "<string>",
"id": "<string>",
"lastError": {
"code": "<string>",
"occurredAt": "<string>",
"operation": "<string>",
"requestId": "<string>"
},
"merchantReference": "<string>",
"metadata": {},
"orderId": "<string>",
"orderStatus": "<string>",
"paymentLinkId": "<string>",
"pricing": {
"amount": 123,
"billingInterval": "DAY",
"billingIntervalCount": 123,
"currency": "<string>",
"flexibleAmount": true,
"maxAmount": 123,
"minAmount": 123,
"pricingId": "<string>",
"pricingName": "<string>",
"pricingType": "SUBSCRIPTION"
},
"product": {
"description": "<string>",
"name": "<string>",
"productId": "<string>"
},
"productName": "<string>",
"provider": "<string>",
"quantity": 123,
"status": "CREATED",
"url": "<string>"
},
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}购买输入、幂等与付款状态说明见结账会话指南。
授权
Merchant API key (format: ak_BASE64)
请求头
Unique creation request key: 1-255 ASCII characters in the range 0x21-0x7E (no spaces or control characters)
Required string length:
1 - 255请求体
application/json
Purchase and checkout configuration
Optional customer email, at most 255 bytes. Mutually exclusive with customerId.
Optional existing customer ID. Omit both customer fields or provide only one.
Lifetime in seconds: 1800-86400 for card checkout, 60-86400 for cryptocurrency checkout.
Optional business correlation value, at most 255 bytes; not a uniqueness constraint.
At most 50 string pairs. Keys must contain 1-40 characters without [ or ]; values may contain at most 500 characters.
Show child attributes
Show child attributes
Show child attributes
Show child attributes
Omit for card checkout; use CRYPTO for cryptocurrency checkout.
可用选项:
STRIPE, CRYPTO 必填范围:
1 <= x <= 999999