如何在 Stripe 中创建变量订阅


How to create variable subscriptions in Stripe

我正在使用条纹来捕获信用卡。我有我的表单,所以它们是可变的输入,效果很好。我正在将信息从我的<input>传递到收费.php文件,它成功捕获。

当我尝试使用此信息创建订阅时,我无法使用可变金额。我只能创建具有固定金额的订阅。

我希望使用$finalamount来设置订阅金额。我对nameidamount相同感到满意.

如何根据用户输入的内容创建变量订阅,包括自定义amountnameid

<?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)
);
?>

您需要删除此代码

'Stripe'Charge::create(array(
  "amount" => $finalamount, // amount in cents, again
  "currency" => "usd",
  "customer" => $customer->id)
);

因为当您创建指定计划的客户时,将自动订阅您的客户并向其收费。

希望对:)有所帮助