Php 如何更新客户以取消订阅计划或添加订阅计划
我这里有几件事。请耐心等待,因为我试图详细概述它。我正在尝试将“取消”和“添加计划”选项添加到“客户帐户”页面。有多个计划可供选择(1-5),他们可以选择任何或所有计划 1.>我正在尝试为现有客户添加计划。我注意到,每次单击stripe payment按钮时,stripe都会创建一个新的客户id,即使它们存在于数据库中。我希望他们能够单击“添加计划”(对于特定计划),然后他们被重定向到查看页面,在那里他们可以单击“立即付款”条带付款按钮,付款,程序将更新他们现有条带帐户中的新计划。此外,我希望计划续签日期与他们现有的其他计划的现有每月续签(收费)日期相匹配 2.>我正在尝试取消现有客户的计划。我希望他们能够点击取消(对于一个特定的计划,有多个可用),被重定向到取消审查页面,然后他们可以点击取消按钮和。。。从那里,我想更新条带中的现有客户以取消该特定计划(在周期结束时取消) 我能够在注册时创建客户、费用、计划等。从那里,我将条带客户ID存储在数据库中。除了数据库中的条带ID之外,我不知道如何检索所需的数据,也不知道如何使用它来完成上述步骤 StripeAPI非常好,但有些东西对我来说非常广泛和混乱(编程新手) 任何帮助都将不胜感激。如果你能提供例子和解释,那将是难以置信的!提前谢谢你 以下是迄今为止的一些代码:Php 如何更新客户以取消订阅计划或添加订阅计划,php,stripe-payments,Php,Stripe Payments,我这里有几件事。请耐心等待,因为我试图详细概述它。我正在尝试将“取消”和“添加计划”选项添加到“客户帐户”页面。有多个计划可供选择(1-5),他们可以选择任何或所有计划 1.>我正在尝试为现有客户添加计划。我注意到,每次单击stripe payment按钮时,stripe都会创建一个新的客户id,即使它们存在于数据库中。我希望他们能够单击“添加计划”(对于特定计划),然后他们被重定向到查看页面,在那里他们可以单击“立即付款”条带付款按钮,付款,程序将更新他们现有条带帐户中的新计划。此外,我希望计
require_once('stripe-php-6.28.0/init.php');
$stripe = [
"secret_key" => "sk_test_secret",
"publishable_key" => "pk_test_publish",
];
\Stripe\Stripe::setApiKey($stripe['secret_key']);
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$mplan = 'plan_m'; //I pulled this from stripe dashboard
//cancel m category------------------------------------
if(isset($mcancel)){
echo "<p>You are about to cancel your Subscription.</p>" . "<p>Press CANCEL button, below, to complete, or return to your <a href=http://example.com/Account-Details>Account Details page.</a></p>";
?>
<form id="mcancelnow" name="mcancelnow" action=""<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>>
<input type="submit" value="CANCEL Subscription NOW" id="mcancelnow" name="mcancelnow" /><br /><br />
<?php
}
if(isset($mcancelnow)){
$sqlstripem = "SELECT * FROM idaccount WHERE ID = '".$_SESSION['session']."'";
$resultstripem = mysqli_query($dbcon, $sqlstripem) or die("Error");
while($row = mysqli_fetch_assoc($resultstripem)){
echo "<br />" . "Stripe Customer ID: " . $row['stripecustid'] . "!";
$customeridstripe = $row['stripecustid'];
echo $customeridstripe; // is returning expected result if I take the isset condition out.
}
// Retrieve the request's body and parse it as JSON:
$input = @file_get_contents('php://input');
$event_json = json_decode($input);
// Do something with $event_json
http_response_code(200); // PHP 5.4 or greater
//update customer to cancel m plan on STRIPE
$cu = \Stripe\Customer::retrieve($customeridstripe);
$subscription = $cu->subscription;
$plan = $cu->plan($mplan);
$plan->active = false;
$cu->save();
echo "subscription: " . $subscription . "plan: " . $plan; //nothing returned for subscription or plan
echo "token: " . $token; //nothing returned for token
}
?>
require_once('stripe-php-6.28.0/init.php');
$stripe=[
“密钥”=>“密钥测试密钥”,
“可发布密钥”=>“pk\U测试\U发布”,
];
\Stripe\Stripe::setApiKey($Stripe['secret_key']);
$token=$_POST['stripeToken'];
$email=$_POST['stripeEmail'];
$mplan='plan_m'//我从仪表板上取的
//取消m类------------------------------------
if(isset($McCancel)){
echo“您将要取消订阅。”按下面的“取消”按钮以完成订阅,或返回您的”;
?>
$cu=Stripe\u Customer::retrieve($customeridstripe);
应该是$cu=\Stripe\Customer::retrieve($customeridstripe);
嘿,你能在这里发布你的代码吗(删除条带凭据)那么有人能更好地帮助你吗?@Máté:我已经添加了到目前为止我拥有的代码。我不知道正确的调用或方法。代码显示了我问题的取消部分。谢谢你的查看。
//update customer to cancel m plan on STRIPE
$cu = \Stripe\Customer::retrieve($customeridstripe);
echo $cu . "<br />"; //returns expected result
$subid = $cu->subscriptions->data[0]->id;
echo "subscription id: " . $subid . "<br />"; //returns expected result
$subid2 = \Stripe\Subscription::retrieve($subid);
echo "subid2: " . $subid2 . "<br />"; //returns expected result
$plan = $subid2->id('plan_idhere');
echo "plan id: " . $plan . "<br />"; //nothing returned CODE HALTS HERE
$planresult = $plan->active = false;
echo "plan result: " . $planresult . "<br />"; //nothing returned
$cu->save();
echo "sub id: " . $subid; //nothing returned