stripe支付

Payment logic is central to any product that deals with money. After all, a well-designed payment architecture, if properly tested, saves tons of time in the future.

付款逻辑对于任何涉及金钱的产品都是至关重要的。 毕竟,精心设计的付款架构(如果经过正确测试)可以在未来节省大量时间。

But it may take too long to master the top level of working with popular payment gateways.

但是,掌握顶级与流行的支付网关的合作关系可能需要花费太长时间。

To help you out, I wrote this guide on designing payment logic on Stripe. It includes use cases, project examples, and a bit of theory with code samples.

为了帮助您,我编写了有关在Stripe上设计支付逻辑的指南。 它包括用例,项目示例以及一些带有代码示例的理论。

This guide is mostly for QA engineers as it helps to understand how to test payment logic based on Stripe. But don't come off, PMs and developers. We have lots of interesting details for you too.

本指南主要面向质量检查工程师,因为它有助于了解如何测试基于Stripe的支付逻辑。 但是,PM和开发人员请不要失望。 我们也为您提供许多有趣的细节。

条纹如何工作 (How Stripe Works)

Let’s start with the basics and review the Stripe payment scheme.

让我们从基础开始,回顾一下Stripe付款方案。

This scheme works for users that buy content on websites or through mobile apps. Visitors don't need to register and add link credit cards to their profiles – Stripe allows paying for the content seamlessly.

该方案适用于在网站上或通过移动应用程序购买内容的用户。 访客无需注册链接信用卡并将其添加到他们的个人资料中-Stripe允许无缝地为内容付费。

All they need to do is enter credit card details, and the magic happens:

他们所需要做的就是输入信用卡详细信息,神奇的事情发生了:

  1. Credentials are sent to Stripe.

    凭据将发送到Stripe。
  2. Stripe tokenizes the data and returns a token to the back-end.

    Stripe对数据进行令牌化,然后将令牌返回到后端。
  3. Back-end creates a charge.

    后端产生费用。
  4. The data is sent to Stripe again, and it shares the details with payment systems.

    数据再次发送到Stripe,并与付款系统共享详细信息。
  5. Payment systems respond to Stripe and state whether everything alright. Or report about issues.

    支付系统对Stripe做出响应,并说明一切是否正常。 或报告有关问题。
  6. Stripe responds to the server about the state of the transaction.

    Stripe响应服务器有关事务状态的信息。

If everything goes smoothly, the user gets content. If not, an error message.

如果一切顺利,则用户可以获得内容。 如果不是,则显示错误消息。

Besides, there are two necessary conditions to use Stripe:

此外,使用Stripe有两个必要条件:

  • you have a bank account

    你有一个银行帐户
  • you are a resident of one of the 25 supported countries

    您是25个受支持国家之一的居民

将卡连接到Stripe (Connecting a card to Stripe)

Linking your product user with Stripe customer goes on the server-side. And it looks like this:

将您的产品用户与Stripe客户链接起来是在服务器端。 它看起来像这样:

  1. Credit card credentials go to Stripe (from app or website);

    信用卡凭证转到Stripe(从应用程序或网站);
  2. Stripe returns a token, then it goes to the back-end;

    Stripe返回一个令牌,然后转到后端;
  3. Back-end sends it back to Stripe;

    后端将其发送回Stripe;
  4. Stripe checks whether the customer exists (if yes, the card is added, not – it creates a new customer and adds the card).

    Stripe检查客户是否存在(如果是,则添加卡,否-创建新客户并添加卡)。

The first card added is the default payment method. Stripe will use it to make the transaction.

添加的第一张卡是默认付款方式。 Stripe将使用它进行交易。

与Stripe帐户连接 (Connecting with a Stripe account)

If you’re building an on-demand app like Uber and want users to get paid in it (like Uber drivers), ask them to create an account first.

如果您要构建像Uber这样的按需应用程序,并希望用户从中获得报酬(例如Uber驱动程序),请先要求他们创建一个帐户。

There are three types of Stripe accounts:

条带化帐户有三种类型:

  • Standard. An already existing account with the required credentials. Registered by the user, validated by Stripe and a bank.

    标准 。 具有所需凭据的现有帐户。 由用户注册,由Stripe和一家银行验证。

  • Express. Enables easy on-boarding: you create an account on your own, and the user fills it with details. Works within the US.

    快递 。 启用简单的入职流程:您可以自己创建一个帐户,然后用户在其中填写详细信息。 在美国境内工作。

  • Custom. Comes with the highest level of flexibility and allows you to modify multiple parameters. In turn, the platform is responsible for every interaction with users.

    自定义 。 具有最高的灵活性,并允许您修改多个参数。 反过来,该平台负责与用户的每次交互。

条纹核心功能 (Stripe Core Features)

Still on the subject of how Stripe works, I suggest taking a look at its features.

仍然关于Stripe的工作原理,我建议看看它的功能。

收费标准 (Charges)

Stripe makes two kinds of charges – direct and destination.

条纹产生两种费用- 直接费用和目的地费用。

Direct charge

直接充电

Let's get back to the Uber model. The platform charges a certain amount from riders, and that money goes directly to the linked accounts, to drivers. Direct charge implies that drivers pay all the fees. Plus, Uber also charges a fixed percentage.

让我们回到Uber模型。 该平台向骑车人收取一定的费用,而这笔钱将直接进入关联帐户,并转给驾驶员。 直接收费意味着驾驶员要支付所有费用。 此外,Uber还收取固定百分比的费用。

Destination charge

目的地收费

In this case, the platform pays all the fees, and you get the net worth. First, the amount goes to the Stripe account of your platform, and then there’s an automatic transfer to the partner (drivers).

在这种情况下,平台将支付所有费用,您将获得净资产。 首先,金额转到您平台的Stripe帐户,然后自动转移到合作伙伴(驱动程序)。

授权和捕获
(Authorize and capture)

Stripe supports two-step payments that enable users to authorize a charge first and capture it later. Card issuers guarantee that auth payments and the required amount gets frozen on the customer's card.

Stripe支持两步支付,使用户能够先授权费用然后再收取费用。 发卡机构保证将授权付款和所需的金额冻结在客户的卡上。

If the charge isn't captured for this period, authorization is canceled.

如果在此期间未收取费用,则取消授权。

Here's how it works in Uber: a rider sees an approximate cost of the trip while booking the ride. If they agree to it, this amount gets frozen on their cards until they finish their trip.

这是Uber的运作方式:车手在预订车票时会看到大概的行程费用。 如果他们同意,这笔款项将冻结在他们的信用卡中,直到他们完成旅行。

When they finish the ride, Uber calculates the final price and charges it from the card.

当他们完成行程后,Uber会计算最终价格并从卡中收取费用。

That’s the reason product owners choose Stripe for their P2P payment app development. As trust matters the most when it comes to peer-to-peer transactions.

这就是产品所有者选择Stripe进行P2P支付应用程序开发的原因 。 在对等交易中,信任最重要。

Finally, here come another three Stripe features I’d like to mention.

最后,我还要提及另外三个Stripe功能。

Transfers. Transfers go from the platform account to suppliers. For instance, Uber drivers link Stripe accounts with their profiles to get the pay.

转移 。 从平台帐户转移到供应商。 例如,Uber司机将Stripe帐户与他们的个人资料链接以获得报酬。

Subscriptions. This feature is quite flexible and enables users to set intervals, trial periods, and adjust the subscription to their needs.

订阅 。 此功能非常灵活,使用户可以设置时间间隔,试用期以及根据需要调整订阅。

Refunds. If buyers want to get their money back, Stripe users can easily issue a refund to the customers’ card.

退款 。 如果买家想取回他们的钱,Stripe用户可以轻松地将退款退还给客户的卡。

处理条纹对象 (Handling Stripe Objects)

Next, we’re moving to the Stripe objects. And here come the code samples I’ve promised.

接下来,我们转到Stripe对象。 这是我所承诺的代码示例。

源对象 (Source object)

Here's a checklist for the source object.

这是源对象的清单。

KeyValue
customercustomer’s stripe id
idstripe_id of added card
last4last 4 numbers of added card
brandcredit card company (Visa, AE)
exp_month, exp_yearexpiration date of the card
顾客 客户的条纹编号
ID 已添加卡的stripe_id
最后4 最后4张已添加的卡号
信用卡公司(维萨,AE)
exp_month,exp_year 卡的有效期

The object keeps a payment method that helps to complete the charge. It's also possible to link the source object with users. This allows them to store all the payment methods there.

该对象保留有助于完成费用的付款方式。 也可以将源对象与用户链接。 这使他们可以将所有付款方式存储在那里。

When testing, it's crucial to make sure a payment method corresponds with the returned value. Check last4 and exp_month/year for this.

在测试时,确保付款方式与返回值相对应至关重要。 检查last4exp_month / year为此。

If the source object is linked with a customer and you want to make sure it belongs to the right person, check the customer id. Here's a JSON of the object:

如果源对象与客户链接,并且您想确保它属于合适的人,请检查客户ID 。 这是该对象的JSON:

{
        "id": "card_1CboP4CLud4t5fBlZMiVrzBq",
        "object": "card",
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": null,
        "address_zip_check": null,
        "brand": "Visa",
        "country": "US",
        "customer": "cus_D1s9PQgvr6U46j",
        "cvc_check": "pass",
        "dynamic_last4": null,
        "exp_month": 4,
        "exp_year": 2024,
        "fingerprint": "soMjdt25OvcMcObY",
        "funding": "credit",
        "last4": "4242",
        "metadata": {},
        "name": null,
        "tokenization_method": null
      }

客户对象 (Customer object)

Starting with the checklist again.

再次从清单开始。

KeyValue
subscriptionsthe list of Subscriptions
idcustomer stripe_id
default_sourcestripe_id of the default card
sourceslist of Sources
订阅 订阅列表
ID 客户stripe_id
default_source 默认卡的stripe_id
资料来源 来源清单

The customer object stores payment methods including the default one. And contains information about users and their subscriptions.

客户对象存储包括默认付款方式在内的付款方式。 并包含有关用户及其订阅的信息。

It also recalls users' credit cards and the primary payment method set. You can charge users manually based on this data.

它还会调出用户的信用卡和主要付款方式集。 您可以根据此数据手动向用户收费。

Same with subscriptions – Stripe manages them and withdraws fees automatically.

与订阅相同– Stripe管理它们并自动提取费用。

{
  "id": "cus_D1s9PQgvr6U46j",
  "object": "customer",
  "account_balance": 0,
  "created": 1528717303,
  "currency": null,
  "default_source": "card_1CboP4CLud4t5fBlZMiVrzBq",
  "delinquent": false,
  "description": null,
  "discount": null,
  "email": null,
  "invoice_prefix": "4A178DE",
  "livemode": false,
  "metadata": {},
  "shipping": null,
  "sources": {
    "object": "list",
    "data": [
      {
        "id": "card_1CboP4CLud4t5fBlZMiVrzBq",
        "object": "card",
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": null,
        "address_zip_check": null,
        "brand": "Visa",
        "country": "US",
        "customer": "cus_D1s9PQgvr6U46j",
        "cvc_check": "pass",
        "dynamic_last4": null,
        "exp_month": 4,
        "exp_year": 2024,
        "fingerprint": "soMjdt25OvcMcObY",
        "funding": "credit",
        "last4": "4242",
        "metadata": {},
        "name": null,
        "tokenization_method": null
      },
      {
        "id": "card_1CcC3uCLud4t5fBlW2UMknUW",
        "object": "card",
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": null,
        "address_zip_check": null,
        "brand": "Visa",
        "country": "US",
        "customer": "cus_D1s9PQgvr6U46j",
        "cvc_check": "pass",
        "dynamic_last4": null,
        "exp_month": 4,
        "exp_year": 2024,
        "fingerprint": "soMjdt25OvcMcObY",
        "funding": "credit",
        "last4": "4242",
        "metadata": {},
        "name": null,
        "tokenization_method": null
      }
    ],
    "has_more": false,
    "total_count": 2,
    "url": "/v1/customers/cus_D1s9PQgvr6U46j/sources"
  },
  "subscriptions": {
    "object": "list",
    "data": [],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/customers/cus_D1s9PQgvr6U46j/subscriptions"
  }
}

充电对象
(Charge object)

Checklist for the charge object:

收费对象清单:

KeyValue
destinationstripe account of payee
idcharge stripe_id
amountpayment amount in cents
amount_refundedrefunded amount in cents
customercustomer_id of a payer
capturedtrue - payment is made, false - authorized
目的地 收款人的条纹账户
ID 充电stripe_id
付款金额(分)
退款金额 退款金额(以美分计)
顾客 付款人的customer_id
被俘 正确-已付款,错误-已授权
  • amount – you should always check which amount was charged during the testing process. It may be in cents, euro cents, and so on.

    金额 –您应始终检查测试过程中收取的金额。 可能是美分,欧元美分,等等。

  • amount_refunded – this field has a value different from zero if the whole amount of transaction (or its part) was refunded.

    amount_refunded –如果已退还全部交易金额(或其一部分),则此字段的值不为零。

  • customer – id of your customer

    客户 –您客户的ID

  • captured – indicates the status of the transaction. Money can be held on the user's credit card or can be charged.

    已捕获 -指示交易状态。 钱可以存放在用户的信用卡上或可以收取。

  • destination – destination key will store user's Stripe account you've transferred the money to.

    destination-目标密钥将存储您转账到的用户的Stripe帐户。

"fingerprint": "soMjdt25OvcMcObY",
    "funding": "credit",
    "last4": "4242",
    "metadata": {},
    "name": null,
    "tokenization_method": null
  },
  "source_transfer": null,
  "statement_descriptor": null,
  "status": "succeeded",
  "transfer_group": null
}

Refund object

退款对象

The refund object is embedded in the charge object in case any part of the payment (or the whole payment) gets refunded to the buyer.

如果付款的任何部分(或全部付款)退还给买方,则退款对象将嵌入到收费对象中。

KeyValue
statussuccess / pending / failed
idrefund stripe_id
amountpayment amount in cents
状态 成功/未决/失败
ID 退款stripe_id
付款金额(分)
{
  "id": "re_1CcY10CLud4t5fBlN23KtYq7",
  "object": "refund",
  "amount": 999,
  "balance_transaction": "txn_1CcY10CLud4t5fBlhlmzzJuK",
  "charge": "ch_1CcD7dCLud4t5fBlC1srZNIB",
  "created": 1528892634,
  "currency": "usd",
  "metadata": {},
  "reason": null,
  "receipt_number": null,
  "status": "succeeded"
}

Transfer object

转移对象

KeyValue
reversalslist of reverse transfer objects
idtransfer_id
amountpayout amount in cents
destinationlinked account of a payee
reversedfalse - money transaction, true - reverse
逆转 反向传输对象列表
ID transfer_id
付款金额(以美分计)
目的地 收款人的关联帐户
倒转 假-货币交易,真-反向

The transfer object keeps information related to the transfer from the platform balance to other accounts. Like payouts to platform's partners – Uber drivers.

转帐对象保留与从平台余额转帐到其他帐户有关的信息。 就像支付给平台合作伙伴的付款-Uber司机。

Mind that all the transactions should be loginized in the database. This way, during testing, you'll see the transfer id. Go to Stripe and check the following:

注意所有事务都应该在数据库中登录。 这样,在测试期间,您将看到传输ID。 转到Stripe并检查以下内容:

  • amount – the sum paid to a payee

    金额 –支付给收款人的金额

  • destination – Stripe account of the user who gets the payment

    目的地 –获得付款的用户的分条帐户

  • reversed – if you need to cancel a transaction, the key acts as an indicator. It shows a false value if the transaction succeeded. True – if reversed

    反向 –如果您需要取消交易,则该键用作指示。 如果交易成功,它将显示一个假值。 正确–如果反转

  • reversals – stores a list of objects in case any part of the transfer was reversed

    冲销 –存储对象列表,以防转移的任何部分被冲销

{
  "id": "tr_1CcApyCLud4t5fBlZyx5mEPI",
  "object": "transfer",
  "amount": 250,
  "amount_reversed": 0,
  "balance_transaction": "txn_1CcApyCLud4t5fBlfA5cgXBz",
  "created": 1528803538,
  "currency": "usd",
  "description": null,
  "destination": "acct_18bAS3KcT341ksb9",
  "destination_payment": "py_1CcApyKcT341ksb9VawxIJdS",
  "livemode": false,
  "metadata": {},
  "reversals": {
    "object": "list",
    "data": [],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/transfers/tr_1CcApyCLud4t5fBlZyx5mEPI/reversals"
  },
  "reversed": false,
  "source_transaction": null,
  "source_type": "card",
  "transfer_group": null
}

Balance Transaction object

余额交易对象

KeyValue
typetype of transaction (charge, refund, transfer)
idrefund stripe_id
amountpayment amount in cents (pay attention to +/- signs)
available_ondate when money will be available for a payee
feeamount of Stripe fee
fee_detailslist of fee objects
netamount of net income/expenditure
statuscurrent status of operation
类型 交易类型(收费,退款,转移)
ID 退款stripe_id
付款金额(美分)(请注意+/-号)
available_on 收款人有钱的日期
费用 条纹费金额
费用详情 收费对象清单
净收入/支出额
状态 经营现状

The object stores data about any changes to the application balance. You don't actually need to test this object. It’s rather for understanding where the fees come from.

该对象存储有关应用程序余额的任何更改的数据。 您实际上不需要测试该对象。 而是为了了解收费的来源。

  • amount – payment amount in cents

    金额 –付款金额,以美分计

  • available_on – the money sent to partners will be available for them in time, and this key tells when exactly

    available_on –发送给合作伙伴的钱将及时提供给他们,并且此键告诉您确切的时间

  • fee – amount of the Stripe fee

    费用 –条纹费用的金额

  • fee_details – list of fee objects with a description why the fee was charged

    fee_details –费用对象的列表,说明为什么要收取费用

  • net – amount of net income

    净额 –净收入额

  • status – the status of operation success

    状态 –操作成功的状态

  • type – type of the object (charge, refund, transfer)

    类型 –对象的类型(费用,退款,转移)

Code sample of balance transaction for transfer:

余额交易的代码示例:

{
  "id": "txn_1CcApyCLud4t5fBlfA5cgXBz",
  "object": "balance_transaction",
  "amount": -250,
  "available_on": 1528803538,
  "created": 1528803538,
  "currency": "usd",
  "description": null,
  "exchange_rate": null,
  "fee": 0,
  "fee_details": [],
  "net": -250,
  "source": "tr_1CcApyCLud4t5fBlZyx5mEPI",
  "status": "available",
  "type": "transfer"
}

Code sample of balance transaction for charge:

收费余额交易的代码示例:

{
  "id": "txn_1CbrRTCLud4t5fBlhRfMLdq1",
  "object": "balance_transaction",
  "amount": 10000,
  "available_on": 1529280000,
  "created": 1528728983,
  "currency": "usd",
  "description": "Charge user asdf11@example for instructor sodom@example lesson id: 77",
  "exchange_rate": null,
  "fee": 320,
  "fee_details": [
    {
      "amount": 320,
      "application": null,
      "currency": "usd",
      "description": "Stripe processing fees",
      "type": "stripe_fee"
    }
  ],
  "net": 9680,
  "source": "ch_1CbrP3CLud4t5fBlztHMxVzv",
  "status": "pending",
  "type": "charge"
}

Subscription object

订阅对象

KeyValue
planrules for subscription: amount, interval, trial days
idsubscription stripe_id
application_fee_percent% charged for the subscription
billingautomatic charge or sending invoice
billing_cycle_anchortime of the next cycle of subscription
current_period_start current_period_endtimeframes of current subscription period
计划 订阅规则:金额,间隔,试用天数
ID 订阅stripe_id
application_fee_percent 订阅费用的百分比
开票 自动收费或发送发票
billing_cycle_anchor 下一个订阅周期的时间
current_period_start current_period_end 当前订阅期的时间表
  • application_fee_percent – percent of the overall amount the app charges, the rest is paid by the content owner

    application_fee_percent-应用总费用的百分比,其余由内容所有者支付

  • billing – responsible for how the billing process goes – automatically or manually (through the invoice)

    计费 -负责计费过程的进行方式-自动或手动(通过发票)

  • billing_cycle_anchor – contains the due date of the next payment for renewal of the subscription

    billing_cycle_anchor –包含用于续订的下一次付款的到期日期

  • current_period_start & current_period_end – validity period of customer's subscription

    current_period_start和current_period_end –客户订阅的有效期

  • plan – stores the object of a subscription plan, includes a set of rules (amount to pay, interval, number of trial days, and more)

    计划 –存储订阅计划的对象,包括一组规则(支付金额,间隔,试用天数等)

{
  "id": "sub_D2JskPBqcW24hu",
  "object": "subscription",
  "application_fee_percent": null,
  "billing": "charge_automatically",
  "billing_cycle_anchor": 1528820423,
  "cancel_at_period_end": false,
  "canceled_at": null,
  "created": 1528820423,
  "current_period_end": 1531412423,
  "current_period_start": 1528820423,
  "customer": "cus_D2Jsi3JgT5zPh1",
  "days_until_due": null,
  "discount": null,
  "ended_at": null,
  "items": {
    "object": "list",
    "data": [
      {
        "id": "si_D2Js7N4mYxzAaY",
        "object": "subscription_item",
        "created": 1528820424,
        "metadata": {
        },
        "plan": {
          "id": "ivory-express-917",
          "object": "plan",
          "active": true,
          "aggregate_usage": null,
          "amount": 999,
          "billing_scheme": "per_unit",
          "created": 1528819224,
          "currency": "usd",
          "interval": "month",
          "interval_count": 1,
          "livemode": false,
          "metadata": {
          },
          "name": "Ivory Express",
          "nickname": null,
          "product": "prod_D2JYysdjdQ2gwT",
          "statement_descriptor": null,
          "tiers": null,
          "tiers_mode": null,
          "transform_usage": null,
          "trial_period_days": null,
          "usage_type": "licensed"
        },
        "quantity": 1,
        "subscription": "sub_D2JskPBqcW24hu"
      }
    ],
    "has_more": false,
    "total_count": 1,
    "url": "/v1/subscription_items?subscription=sub_D2JskPBqcW24hu"
  },
  "livemode": false,
  "metadata": {
  },
  "plan": {
    "id": "ivory-express-917",
    "object": "plan",
    "active": true,
    "aggregate_usage": null,
    "amount": 999,
    "billing_scheme": "per_unit",
    "created": 1528819224,
    "currency": "usd",
    "interval": "month",
    "interval_count": 1,
    "livemode": false,
    "metadata": {
    },
    "name": "Ivory Express",
    "nickname": null,
    "product": "prod_D2JYysdjdQ2gwT",
    "statement_descriptor": null,
    "tiers": null,
    "tiers_mode": null,
    "transform_usage": null,
    "trial_period_days": null,
    "usage_type": "licensed"
  },
  "quantity": 1,
  "start": 1528820423,
  "status": "active",
  "tax_percent": null,
  "trial_end": null,
  "trial_start": null
}

用例 (Use Cases)

Finally, we move to use cases. So let’s find out how we build the business logic using Stripe.

最后,我们转到用例。 因此,让我们了解一下如何使用Stripe构建业务逻辑。

订阅内容 (Subscriptions )

Case: Users pay $5/month for getting access to the content. Its author earns 80% of the overall cost. Customers have five trial days.

案例 :用户每月支付5美元即可访问内容。 作者的收入占总费用的80%。 客户有五个试用期。

How to make it work:

如何运作:

  1. Create the subscription plan in Stripe, specify the cost, % of app fee, and the interval.

    在Stripe中创建订阅计划,指定费用,应用费百分比和间隔。
  2. Integrate webhooks for the server to understand when someone subscribes and when they’re charged.

    集成服务器的webhook,以了解何时有人订阅以及何时向他们收费。
  3. Integrate emails to send users invoices/receipts.

    集成电子邮件以向用户发送发票/收据。
  4. When a user buys the subscription, Stripe counts down five days from that moment and then makes the charge.

    当用户购买订阅时,Stripe从那一刻起倒数5天,然后收费。
  5. The author gets money, the platform gets its fee.

    作者得到钱,平台得到了费用。

Fee: 2.9% + 30 cents

费用 :2.9%+ 30美分

内容购买 (Content purchase)

Case: Users purchase content on a website or mobile application.

案例 :用户在网站或移动应用程序上购买内容。

How to make it work:

如何运作:

  1. The customer tokenizes a card.

    客户令牌化一张卡。
  2. Backend makes the Charge.

    后端负责。
  3. If the Charge is successful, the platform's business logic allows the customer to get the content.

    如果收费成功,则平台的业务逻辑允许客户获取内容。

Fees: 2.9% from the charge + 30 cents.

费用收费的 2.9%+ 30美分。

按需平台(Uber) (On-demand platform (Uber))

Case: The client pays for the ride, the platform charges 20%, the driver gets 80%.

案例 :客户为乘车付费,平台收费20%,驾驶员收费80%。

Preconditions:

前提条件

  • Driver linked an account

    驱动程序关联了一个帐户
  • User added a card

    用户添加了卡

In this case, you need to create transfers on your own after the rider completes the payment.

在这种情况下,您需要在骑手完成付款后自行创建转帐。

First, authorize the payment when they book the ride and capture it when the ride's complete.

首先,在他们预定行程时授权付款,并在行程完成后收取。

Next, create a transfer for the driver – 80% of the total sum. Pay the Stripe fee, and the rest will be the net income.

接下来,为驱动程序创建转账–总计的80%。 支付Stripe费用,其余为净收入。

And the fee is: 2.9% + 30 cents

费用为 :2.9%+ 30美分

按需平台2 (On-demand platform 2)

Uber-like apps are perfect for showing how Stripe works. So here goes another use case.

类似Uber的应用非常适合展示Stripe的工作原理。 因此,这里有另一个用例。

Case: Customer pays for the service, the platform charges 20%, the driver gets 80%. Plus, the driver can pay $5 for the priority booking right.

案例 :客户为服务付费,平台收费20%,驾驶员收费80%。 另外,驾驶员可以为优先预订权支付5美元。

Works if the driver linked their account, and the rider added a credit card.

如果驾驶员链接了他们的帐户,并且驾驶员添加了信用卡,则可以使用。

  • Variant #1. You charge $5 from the driver (in case of the priority option), authorize payment for the customer, do the capture when the ride ends, make a transfer for the driver. And keep the rest. In this case, you pay 2.9% fee + 30 cent for each charge.

    变体#1。 您向驾驶员收取$ 5的费用(在使用优先选项的情况下),为客户授权付款,在旅程结束时进行捕获,并为驾驶员进行转帐。 并保留其余部分。 在这种情况下,您需要支付2.9%的费用+每笔费用30美分。

  • Variant #2. You can skip fees by creating the inner monetization on your platform. When you get money from the customer, you calculate the driver's share and transfer those funds to the inner balance.

    变体#2。 您可以通过在平台上创建内部获利来跳过费用。 当您从客户那里获得资金时,您可以计算出驾驶员的份额并将这些资金转移到内部余额中。

结论 (In conclusion)

As you see, the implementation of payment logic and its testing are not as hard as they seem. All you need to do is handle the Stripe objects in the right way. And figure out how to use Stripe on your platform.I hope this guide will come handy when you get started with designing Stripe-based payment logic and its testing.

如您所见,支付逻辑的实现及其测试并不像看起来那样困难。 您所需要做的就是以正确的方式处理Stripe对象。 并弄清楚如何在平台上使用Stripe,希望当您开始设计基于Stripe的支付逻辑及其测试时,本指南会派上用场。

翻译自: https://www.freecodecamp/news/how-to-design-payment-logic-on-stripe-and-apply-it/

stripe支付

更多推荐

stripe支付_如何在Stripe上设计支付逻辑(并将其应用)