如何在Stripe中创建变量订阅 [英] How to create variable subscriptions in Stripe

查看:351
本文介绍了如何在Stripe中创建变量订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用条纹捕获信用卡.我有自己的表格,因此它们是可变的输入,并且效果很好.我正在将信息从我的<input>传递到charge.php文件,并且成功捕获了该文件.

I am using stripe to capture credit cards. I have my forms so that they are variable inputs, and it works great. I am passing the information from my <input> to a charge.php file and it captures successfully.

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

When I try to use this information to create subscriptions, I am unable to use variable amounts. I can only create a subscription that has a set amount.

我希望使用$finalamount来设置订阅量. 我对nameidamount相同是可以的.

I was hoping to use the $finalamount to set the amount of the subscription. I am okay with the name and id to be the same as the amount.

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

How can I create a variable subscription including custom amount, name, and id based on what the user inputs?

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

因为创建客户指定计划时,系统会自动为您的客户订阅并收费.

because when you create a customer specifying plan your customer is subscribed and charged automatically.

希望它会有所帮助:)

这篇关于如何在Stripe中创建变量订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆