使用Card的条纹付款

时间:2020-10-06 14:04:18

标签: php stripe-payments backend

我是Stripe和支付集成的新手。

我想在我的应用程序中实施支付系统。我已经设置了信用卡输入,还可以通过创建以下类型的令牌来验证该信用卡输入:

{
    "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托管进行操作。我预先感谢大家抽出宝贵的时间!

2 个答案:

答案 0 :(得分:1)

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

考虑到您已经安装了Stripe,请按照以下步骤操作。 如果没有,您应该使用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进行请求来获取所需的所有数据。在应用程序中创建用户时,还应该使用stripe创建一个Customer并将其stripe-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。

答案 1 :(得分:0)

虽然@Juan在上面使用Charges API进行了回答,但是对于支持Strong Customer Authentication的集成,我建议您使用Payment Intents API。

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

由于您已经拥有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,
]);