【发布时间】:2016-04-16 04:56:03
【问题描述】:
我已经建立了基于订阅的网站,允许人们进行多个订阅。我决定使用 Stripe 进行支付和卡处理。将它集成到我的 Symfony2 项目中花费了很短的时间。我能够在几个小时内创建订阅、客户和添加卡片。然后我遇到了一个问题。如果客户有多张卡,我希望能够让他们在创建新订阅时选择要使用的卡。听起来很容易。经过 2 天和大约 30 个小时的梳理他们的文档后,我不得不说我无法弄清楚如何让它发挥作用。
我的设置方式是,当客户创建卡片时,我将“卡片 ID”与品牌一起存储在我的数据库中。这使得在请求页面时在服务器端加载详细信息变得容易。创建新订阅的客户会看到他们的卡片并选择要用于新订阅的卡片。这通过 AJAX 传递给我的 php 脚本以创建新订阅。但是,当我尝试使用特定卡时,我收到 400 错误,表明“卡 ID”不是令牌。我知道它不是令牌,因为令牌用于将卡添加到客户帐户,但是我到底如何指定客户想要使用的确切卡?
注意:使用新令牌会创建卡片的另一个实例。不是一个选项。
PHP:
require_once('../stripe-php/init.php');
//Set Secret API Key
\Stripe\Stripe::setApiKey("sk_test_XXXXXXXXXXXXXXXXXXXXX");
//Retrieve Customer
$cu = \Stripe\Customer::retrieve($_POST['customer_id']);
//Create Subscription using saved customer "card id"
$createSubscription = $cu->subscriptions->create(array("plan" => $_POST['sub_option'], "source" => $card));
张贴到条纹:
plan: "500-2016"
source: "card_xxxxxxxxxxxxxxxxxxxxx"
条纹错误:400 型
error:
type: "invalid_request_error"
message: "No such token: card_xxxxxxxxxxxxxxxxxxxxxxx"
param: "source"
【问题讨论】:
标签: php subscription