簡體   English   中英

使用卡上的條紋付款

[英]Make payment with stripe from Card

我是 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 托管來做到這一點。 我提前感謝大家抽出時間!

數據來源: 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。

雖然@Juan 已經使用 Charges API 回答了上述問題,但對於支持強客戶身份驗證的集成,我建議使用 Payment Intents API。

您可以通讀創建支付的端到端指南,其中包括各種語言(包括 PHP)的客戶端和服務器代碼片段。 這是推薦模式。

由於您已經擁有card_123如果您想在沒有 SCA 支持的情況下嘗試付款,您實際上可以直接創建付款

\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,
]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM