【发布时间】:2016-07-04 16:55:40
【问题描述】:
我正在使用条纹来捕获信用卡。我有我的表格,所以它们是可变输入,而且效果很好。我将<input> 中的信息传递给charge.php 文件,它成功捕获。
当我尝试使用此信息创建订阅时,我无法使用可变金额。我只能创建具有固定金额的订阅。
我希望使用$finalamount 来设置订阅量。
我同意name 和id 与amount 相同。
如何根据用户输入的内容创建包括自定义amount、name 和id 的变量订阅?
<?php
require_once('init.php');
\Stripe\Stripe::setApiKey("sk_test_***********");
// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$amount = $_POST['amount'];
$finalamount = $amount * 100;
\Stripe\Plan::create(array(
"amount" => $finalamount, //this does not work. It only works if there is a present amount.
"interval" => "month",
"name" => "Green Plan",
"currency" => "usd",
"id" => "green")
);
// Create a Customer
$customer = \Stripe\Customer::create(array(
"source" => $token,
"plan" => "green",
"description" => "Description",
"email" => $email)
);
// Charge the Customer instead of the card
\Stripe\Charge::create(array(
"amount" => $finalamount, // amount in cents, again
"currency" => "usd",
"customer" => $customer->id)
);
?>
【问题讨论】:
-
您在尝试代码时遇到的错误是什么?
-
我没有收到错误,只是没有处理。只有在有一定数量时才会处理。
-
您应该启用 PHP 错误记录。默认情况下,这是禁用的,它将停止处理。所以不处理 = 一个没有向您显示的错误。
标签: php api variables stripe-payments