Create a payment link
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"currency": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"billingIntervalCount": 123,
"pricingName": "<string>",
"successUrl": "<string>"
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link"
payload = {
"currency": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"billingIntervalCount": 123,
"pricingName": "<string>",
"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({
currency: '<string>',
pricing: '<string>',
minAmount: 123,
maxAmount: 123,
billingIntervalCount: 123,
pricingName: '<string>',
successUrl: '<string>'
})
};
fetch('https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link', 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/product/{id}/payment-link",
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([
'currency' => '<string>',
'pricing' => '<string>',
'minAmount' => 123,
'maxAmount' => 123,
'billingIntervalCount' => 123,
'pricingName' => '<string>',
'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/product/{id}/payment-link"
payload := strings.NewReader("{\n \"currency\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"billingIntervalCount\": 123,\n \"pricingName\": \"<string>\",\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/product/{id}/payment-link")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"currency\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"billingIntervalCount\": 123,\n \"pricingName\": \"<string>\",\n \"successUrl\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link")
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 \"currency\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"billingIntervalCount\": 123,\n \"pricingName\": \"<string>\",\n \"successUrl\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"amount": 123,
"createdAt": "<string>",
"currency": "<string>",
"flexibleAmount": true,
"isActive": true,
"name": "<string>",
"paymentLinkUrl": "<string>",
"pricingId": "<string>",
"pricingType": "<string>",
"provider": "<string>",
"title": "<string>",
"description": "<string>",
"minAmount": 123,
"maxAmount": 123,
"successUrl": "<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
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}Merchant API 端点
创建付款链接
为已有产品添加价格和可分享的付款链接。
POST
/
v1
/
product
/
{id}
/
payment-link
Create a payment link
curl --request POST \
--url https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link \
--header 'Content-Type: application/json' \
--header 'Idempotency-Key: <idempotency-key>' \
--header 'X-API-Key: <api-key>' \
--data '
{
"currency": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"billingIntervalCount": 123,
"pricingName": "<string>",
"successUrl": "<string>"
}
'import requests
url = "https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link"
payload = {
"currency": "<string>",
"pricing": "<string>",
"minAmount": 123,
"maxAmount": 123,
"billingIntervalCount": 123,
"pricingName": "<string>",
"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({
currency: '<string>',
pricing: '<string>',
minAmount: 123,
maxAmount: 123,
billingIntervalCount: 123,
pricingName: '<string>',
successUrl: '<string>'
})
};
fetch('https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link', 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/product/{id}/payment-link",
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([
'currency' => '<string>',
'pricing' => '<string>',
'minAmount' => 123,
'maxAmount' => 123,
'billingIntervalCount' => 123,
'pricingName' => '<string>',
'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/product/{id}/payment-link"
payload := strings.NewReader("{\n \"currency\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"billingIntervalCount\": 123,\n \"pricingName\": \"<string>\",\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/product/{id}/payment-link")
.header("Idempotency-Key", "<idempotency-key>")
.header("X-API-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"currency\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"billingIntervalCount\": 123,\n \"pricingName\": \"<string>\",\n \"successUrl\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://merchant-api-prod.anyway.sh/v1/product/{id}/payment-link")
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 \"currency\": \"<string>\",\n \"pricing\": \"<string>\",\n \"minAmount\": 123,\n \"maxAmount\": 123,\n \"billingIntervalCount\": 123,\n \"pricingName\": \"<string>\",\n \"successUrl\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"amount": 123,
"createdAt": "<string>",
"currency": "<string>",
"flexibleAmount": true,
"isActive": true,
"name": "<string>",
"paymentLinkUrl": "<string>",
"pricingId": "<string>",
"pricingType": "<string>",
"provider": "<string>",
"title": "<string>",
"description": "<string>",
"minAmount": 123,
"maxAmount": 123,
"successUrl": "<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
}{
"data": "<unknown>",
"error": {
"code": "<string>",
"message": "<string>"
},
"message": "<string>",
"success": true
}请使用属于该产品所在组织、且为全部权限或勾选了
products:payment_links:write 权限(控制台中“可创建和修改”下的支付链接)的 API 密钥进行认证。只有 Owner 和 Admin 角色可以授予该权限。
id是你组织内的产品 ID,无论该产品是通过 API 还是在控制台创建的。其他组织的产品或不存在的产品返回404。- 每次调用都会为该产品新建一个价格及其付款链接,因此一个产品可以有多个价格。
- 必填请求头
Idempotency-Key(1–255 个 ASCII 字符,范围为0x21至0x7E,不允许空格),规则与结账会话相同。相同的键加相同的请求体,返回第一次创建的链接(201),不会重复创建。相同的键但请求体不同,或用于另一个产品,返回409。如果该键创建的链接之后被删除,重试也会返回409,请换一个新的键。 pricingType为ONE_TIME或SUBSCRIPTION。pricing是以主单位表示的字符串,如"9.99"。不传pricing即为灵活的“自定义金额”,仅限ONE_TIME,此时minAmount和maxAmount可选。SUBSCRIPTION价格必须提供billingInterval(DAY、MONTH或YEAR)。billingIntervalCount可选,默认为1。successUrl是客户付款后跳转的绝对 HTTPS 地址。不传则客户看到 Anyway 的收据页。- 款项通过 Anyway 平台账户收取。通过 API 创建的链接仅支持银行卡付款,不支持加密货币付款链接。
- 未知字段会被拒绝,返回
400。 - 请原样分享返回的
paymentLinkUrl。响应结构与读取产品付款链接中的条目相同。
结账会话无法销售灵活金额。若要让客户自行决定付款金额,请在此创建灵活的一次性付款链接。
| 状态码 | 错误码 | 含义 |
|---|---|---|
400 | 校验失败:货币无效、订阅缺少计费周期、灵活价格的订阅、金额小于或等于 0、successUrl 不是绝对 HTTPS 地址、未知字段,或缺少 Idempotency-Key 或其无效。 | |
401 | API 密钥缺失或无效。 | |
403 | INSUFFICIENT_SCOPE | 密钥缺少 products:payment_links:write。 |
403 | ORG_FROZEN | 组织的收款已被冻结。 |
403 | CARD_USD_VERIFICATION_REQUIRED | 创建美元银行卡付款链接前需先完成企业认证。 |
404 | 产品不存在,或属于其他组织。 | |
409 | PRODUCT_CONFLICT | Idempotency-Key 已用于不同的请求体或另一个产品,或它创建的链接已被删除。 |
413 | PAYLOAD_TOO_LARGE | 请求体超过 64 KB。 |
503 | CARD_USD_CAPABILITY_UNAVAILABLE | 企业认证状态暂时无法获取,请稍后重试。 |
授权
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路径参数
Product ID
请求体
application/json
Price and payment link
可用选项:
SUBSCRIPTION, ONE_TIME Currency code, for example USD
Fixed amount in major units, for example "9.99". Omit for a flexible (pay what you want) amount, which is ONE_TIME only.
Optional minimum for a flexible amount (ONE_TIME only)
Optional maximum for a flexible amount (ONE_TIME only)
可用选项:
DAY, MONTH, YEAR Number of intervals between charges (SUBSCRIPTION). Defaults to 1.
Name of the price
Absolute HTTPS URL to send the customer to after paying. Defaults to the Anyway receipt.