创建 Payment Intent
创建 Payment Intent 后,附加支付方式并确认,即可完成付款。
创建时设置 confirm=true,等同于在一次调用中创建并确认 Payment Intent。它同样接受 Confirm a PaymentIntent 端点的任意参数。
POST https://api.stripe.com/v1/payment_intents
备注
从服务器通过 HTTPS 发送此请求。不要在客户端代码中存放密钥。
示例
运行以下 cURL 命令发送请求。
cURL
curl -X POST https://api.stripe.com/v1/payment_intents \
-u "<YOUR_SECRET_KEY>:" \
-d "amount=212" \
-d "currency=usd" \
-d "automatic_payment_methods[enabled]=true"
参数
正文参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
amount | 整数 | 必需 | 要扣款的总金额。输入以货币最小单位表示的正整数,因此 100 美分收取 $1.00。 |
automatic_payment_methods | 对象 | 可选 | 让 Stripe 展示适合客户、货币和金额的支付方式。将 enabled 设为 true 即可启用。 |
confirm | 布尔值 | 可选 | 设为 true 可立即尝试确认此 PaymentIntent。 |
currency | 字符串 | 必需 | 小写的三字母 ISO 4217 货币代码。Stripe 必须支持该货币。 |
customer | 字符串 | 可选 | 此 PaymentIntent 所属客户的 ID(如果存在)。 |
description | 字符串 | 可选 | 附加到该对象的任意字符串。 |
payment_method | 字符串 | 可选 | 要附加到此 PaymentIntent 的支付方式 ID。 |
payment_method_types[] | 字符串数组 | 可选 | 此 PaymentIntent 可使用的支付方式类型列表。 |
shipping | 对象 | 可选 | 存储在 PaymentIntent 上的收货地址和收件人详情。 |
statement_descriptor | 字符串 | 可选 | 客户信用卡对账单上显示的文本。 |
statement_descriptor_suffix | 字符串 | 可选 | 为客户信用卡对账单上显示的文本补充细节。 |
expand[] | 字符串数组 | 可选 | 标识需要补充数据并内联返回的嵌套响应对象。 |
响应
成功时 Stripe 返回 200,参数校验失败时返回 400,API 密钥无效时返回 401。完整列表见 Stripe 的错误代码。
200: OK
Response
{
"id": "pi_3Rsx4dDtWMrPDtgt0mUrePJ9",
"object": "payment_intent",
"amount": 212,
"amount_capturable": 0,
"amount_details": {
"tip": {}
},
"amount_received": 0,
"application": null,
"application_fee_amount": null,
"automatic_payment_methods": {
"allow_redirects": "always",
"enabled": true
},
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic_async",
"client_secret": "pi_3Rsx4dDtWMrPDtgt0mUrePJ9_secret_7sqfufxuIYiBhbw52Vi51Z47o",
"confirmation_method": "automatic",
"created": 1754447247,
"currency": "usd",
"customer": null,
"description": null,
"last_payment_error": null,
"latest_charge": null,
"livemode": false,
"metadata": {},
"next_action": null,
"on_behalf_of": null,
"payment_method": null,
"payment_method_configuration_details": {
"id": "pmc_1RsGk1DtWMrPDtgtcaQ0d3Sg",
"parent": null
},
"payment_method_options": {
"amazon_pay": {
"express_checkout_element_session_id": null
},
"card": {
"installments": null,
"mandate_options": null,
"network": null,
"request_three_d_secure": "automatic"
},
"cashapp": {},
"klarna": {
"preferred_locale": null
},
"link": {
"persistent_token": null
}
},
"payment_method_types": [
"card",
"klarna",
"link",
"cashapp",
"amazon_pay"
],
"processing": null,
"receipt_email": null,
"review": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "requires_payment_method",
"transfer_data": null,
"transfer_group": null
}
错误响应
400: Bad Request
Response
{
"error": {
"code": "parameter_invalid_integer",
"doc_url": "https://stripe.com/docs/error-codes/parameter-invalid-integer",
"message": "Invalid integer: <integer>",
"param": "amount",
"request_log_url": "https://dashboard.stripe.com/test/logs/req_UQf6XBwBl9yk66?t=1734829676",
"type": "invalid_request_error"
}
}
401: Unauthorized
Response
{
"error": {
"type": "invalid_request_error",
"message": "Invalid API Key provided: sk_test_********************1234"
}
}