# Charges 与 Payment Intents API 了解 Stripe 的两大核心支付 API 的差别及何时使用它们。 ## 认识 Stripe payment API 现在,在 Stripe 上收款有三种方式: - Stripe Checkout - Charges API - *Payment Intents API* (The Payment Intents API tracks the lifecycle of a customer checkout flow and triggers additional authentication steps when required by regulatory mandates, custom Radar fraud rules, or redirect-based payment methods) [Stripe Checkout](https://docs.stripe.com/payments/checkout.md) 是一个预构建的页面,可将您的客户重定向到这里,方便地完成购买和*订阅* (A Subscription represents the product details associated with the plan that your customer subscribes to. Allows you to charge the customer on a recurring basis)。它提供了很多功能,例如 Apple Pay、Google Pay、国际化及表单验证。 [Charges](https://docs.stripe.com/api/charges.md) 和 [Payment Intents](https://docs.stripe.com/api/payment_intents.md) API 可供您创建自定义的付款流程和使用体验。 Payment Intents API 是所有 Stripe 产品和支付方式的统一 API。虽然我们并未弃用 Charges,但新功能仅在 Payment Intents API 中提供。 关于完整的功能对比,请看下表: | Charges API | Payment Intents API | | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 常由主要客户群在美国/加拿大而想用一种可接受银行卡付款的简单方式的商家使用。 | 接受多种支付方式及银行卡需要验证的公司要求使用(例如,由于欧洲的*强客户验证* (Strong Customer Authentication (SCA) is a regulatory requirement in effect as of September 14, 2019, that impacts many European online payments. It requires customers to use two-factor authentication like 3D Secure to verify their purchase))。 | | 适用于 Web、iOS 和 Android。 | 适用于 Web、iOS 和 Android。也可用于通过 Terminal 进行店内收款。 | | [Sources API](https://docs.stripe.com/sources.md) 支持银行卡及所有支付方式。 | 支持银行卡、需要 3DS 验证的银行卡、iDEAL、SEPA 及[很多其他支付方式](https://docs.stripe.com/payments/payment-methods/overview.md)。 | | **不是 SCA** ready 的 | *是 SCA ready 的* (Strong Customer Authentication (SCA) is a regulatory requirement in effect as of September 14, 2019, that impacts many European online payments. It requires customers to use two-factor authentication like 3D Secure to verify their purchase) | ## 从 Charge 读取的迁移代码 如果您的应用程序涉及多个付款流程,并且想逐个从 Charges API 迁移到 [Payment Intents API](https://docs.stripe.com/payments/payment-intents.md),则应先更新从 [Charge](https://docs.stripe.com/api/charges.md) 对象读取的代码。为帮助实现这一点,Charge 对象的两个额外属性 [payment_method_details](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details) 和 [billing_details](https://docs.stripe.com/api/charges/object.md#charge_object-billing_details) 提供了可供读取收款所用的支付方式的一致界面。 所有的 API 版本以及用 Charges API 和 Payment Intents API 创建的收款对象,都可以使用这些字段。 下表显示的是一笔收款的常用属性,以及如何用其他属性访问同一信息: #### 银行卡和银行账户 | 描述 | 升级前 | 升级后 | | --------------- | --------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | | 用于创建收款的支付方式的详情 | `charge.source` | `charge.payment_method_details` | | 收款所用支付方式的 ID | `charge.source.id` | `charge.payment_method` | | 所用支付方式的类型 | `charge.source.object`(例如 `card` 或 `bank_account`) | `charge.payment_method_details.type` | | 收款的账单信息(例如账单邮编) | `charge.source.address_zip` | `charge.billing_details.address.postal_code` | | 持卡人姓名 | `charge.source.name` | `charge.billing_details.name` | | 所用银行卡的后 4 位 | `charge.source.last4` | `charge.payment_method_details.card.last4` | | 银行卡指纹 | `charge.source.fingerprint` | `charge.payment_method_details.card.fingerprint` | | 收款的 CVC 验证状态 | `charge.source.cvc_check` | `charge.payment_method_details.card.checks.cvc_check` | | 银行卡品牌值 | `charge.source.brand` 可以是下列值之一:`American Express`, `Diners Club`, `Discover`, `JCB`, `MasterCard`, `UnionPay`, `Visa` | `charge.payment_method_details.card.brand` 可以是下列值之一:`amex`, `diners`, `discover`, `jcb`, `mastercard`, `unionpay`, `visa` | | Google Pay 枚举值 | `charge.source.tokenization_method` 是 `android_pay` | `charge.payment_method_details` 内的 `card.wallet.type` 是 `google_pay` | #### 来源 | 描述 | 升级前 | 升级后 | | --------------- | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | | 用于创建收款的支付方式的详情 | `charge.source` | `charge.payment_method_details` | | 收款所用支付方式的 ID | `charge.source.id` (`charge.source.three_d_secure.card`,如果使用了要求 3DS 验证的支付来源) | `charge.payment_method` | | 所用支付方式的类型 | `charge.source.object == 'source' && charge.source.type`(除非 `charge.source.type` 是 `three_d_secure`) | `charge.payment_method_details.type` | | 收款的账单信息(例如账单邮编) | `charge.source.owner.address.postal_code` | `charge.billing_details.address.postal_code` | | 持卡人姓名 | `charge.source.owner.name` | `charge.billing_details.name` | | 所用银行卡的后 4 位 | `charge.source.card.last4` `charge.source.three_d_secure.last4` | `charge.payment_method_details.card.last4` | | 3DS 验证是否成功 | `charge.source.object == 'source' && charge.source.type == 'three_d_secure'` | `charge.payment_method_details.card.three_d_secure.succeeded` | | 银行卡指纹 | `charge.source.card.fingerprint` | `charge.payment_method_details.card.fingerprint` | | 收款的 CVC 验证状态 | `charge.source.card.cvc_check` | `charge.payment_method_details.card.checks.cvc_check` | | 银行卡品牌值 | `charge.source.card.brand` 可以是下列值之一:`American Express`, `Diners Club`, `Discover`, `JCB`, `MasterCard`, `UnionPay`, `Visa` | `charge.payment_method_details.card.brand` 可以是下列值之一:`amex`, `diners`, `discover`, `jcb`, `mastercard`, `unionpay`, `visa` | | Google Pay 枚举值 | `charge.source.card.tokenization_method` 是 `android_pay` | `charge.payment_method_details` 内的 `card.wallet.type` 是 `google_pay` | ## See also - [迁移到 Payment Intents](https://docs.stripe.com/payments/payment-intents/migration.md)