【问题标题】:Make payment with stripe from Card使用卡上的条纹付款
【发布时间】:2020-10-06 14:04:18
【问题描述】:

总的来说,我是 Stripe 和支付集成的新手。

我想在我的应用程序中实现支付系统。我已经设置了信用卡输入,也是通过创建这种类型的token来验证的:

{
    "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",
        "cvc_check": "unchecked",
        "dynamic_last4": null,
        "exp_month": 12,
        "exp_year": 2025,
        "funding": "credit",
        "id": "card_1HZFtCHAdtJCId9lZP626zJI",
        "last4": "4242",
        "name": null,
        "object": "card",
        "tokenization_method": null
    },
    "client_ip": "5.171.212.113",
    "created": 1601989654,
    "id": "tok_1HZFtCHAdtJCId9lxdU1jFVa",
    "livemode": false,
    "object": "token",
    "type": "card",
    "used": false
}

到目前为止一切顺利,我应该做的是将此令牌发送到我的 php 服务器(没有安装任何特定库的外部主机)。谁能向我解释如何从后端处理付款?我检查了文档,但没有一个解释如何使用普通的 php 托管。我提前感谢大家抽出宝贵的时间!

【问题讨论】:

    标签: php stripe-payments backend


    【解决方案1】:

    数据来源:https://stripe.com/docs/api/

    考虑到您已经安装了条带,您将按照以下步骤操作。 如果没有,你应该使用 composer 来安装它。

    composer require stripe/stripe-php
    

    1)认证

    Stripe API 使用 API 密钥对请求进行身份验证,因此您必须首先使用您的 API 密钥进行身份验证才能使用任何内容。 https://dashboard.stripe.com/login?redirect=/account/apikeys

    $stripe = new \Stripe\StripeClient(INSERT_API_KEY_HERE);
    

    2)创建费用

    您已经拿到了您的卡,因此您可以对其进行收费。

    编辑:您可以通过使用 api 发出请求来获取所需的所有数据。当您在应用程序中创建用户时,您还应该使用条带创建客户并将其条带 ID 保存在您的数据库中,以便您可以访问他们的数据。

    创建客户

    $customer = $stripe->customers->create(['description' => 'My First Test Customer',]);
    // Save your customer ID using $customer->id
    

    为卡充电

    $stripe->charges->create([
      'amount' => 2000,
      'currency' => 'usd',
      'source' => 'INSERT_CARD_ID',
      'description' => 'My First Test Charge',
    ]);
    

    来源:

    要收费的付款来源。这可以是卡(即信用卡或借记卡)、银行账户、来源、令牌或关联账户的 ID。对于某些来源(即卡、银行账户和附加来源),您还必须传递关联客户的 ID。

    【讨论】:

    【解决方案2】:

    虽然@Juan 已使用 Charges API 回答了上述问题,但对于支持 Strong Customer Authentication 的集成,我建议使用 Payment Intents API。

    您可以阅读end-to-end guide for creating a payment,其中包括各种语言(包括 PHP)的客户端和服务器代码 sn-ps。这是推荐模式。

    由于您已经拥有card_123,如果您想在没有 SCA 支持的情况下尝试付款,您实际上可以直接转到creating the payment

    \Stripe\PaymentIntent::create([
      'amount' => 1234,
      'currency' => 'usd',
      // 'customer' => 'cus_567', // only if you've attached the card
      'payment_method' => 'card_123',
      'error_on_requires_action' => true,
      'confirm' => true,
    ]);
    

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 2017-05-20
      • 2021-03-17
      • 2021-07-02
      • 1970-01-01
      • 2015-08-30
      • 2023-02-03
      • 2021-09-27
      • 2020-12-01
      相关资源
      最近更新 更多