您好,我在应用程序中集成了 Stripe 来出售一些付费注册。在我的条纹仪表板上,我已经创建了一些 Coupons (优惠券),有些具有折价优惠,一些具有折价优惠。我需要以多种货币向客户收费。 我在向客户收费时遇到问题。 假设我有一个$ 348 /年的计划并提供了
在情况2中,没有问题,并且发票已创建。 但在第一种情况下,它会收取2倍费用:
以下是我的代码:
计划值已更新(已应用优惠券,其中包含“一定金额”)
$cc = $_POST['coupon'];
$actual_amount = $_POST['actual_amount'];
$cpnObj = \Stripe\Coupon::retrieve($cc);
$cpnDtl = $cpnObj->getLastResponse()->json;
if($cpnDtl['id']){
$amount_off = $cpnDtl['amount_off'];
$percent_off = $cpnDtl['percent_off'];
if ($amount_off) {
$discount = $amount_off/100;
$paymoney = $actual_amount - $discount;
}
if ($percent_off) {
$discount = $actual_amount * $percent_off/100;
$paymoney = $actual_amount - $discount;
}
}
稍后通过一些会话变量,我将使用这笔不折不扣的金额向客户的卡收费
$token = $_POST['stripeToken'];
$plan_id = $_POST['plan_id'];
//Creating Customer
$customer = \Stripe\Customer::create([
"description" => "creating the customer",
"email" => "myemail@somedomain.com",
"source" => $token // obtained with Stripe.js
]);
//If Merchant account is created at Stripe end, Charge his Card
if($customer->id != ''){
$chargeCard = \Stripe\Charge::create([
"amount" => $paymoney (calculated above after applying the promo-code),
"currency" => 'USD',
"description" => "subscription for a year",
"capture" => true,
"customer" => $customer->id,
"receipt_email" => "myemail@somedomain.com",
"statement_descriptor" => "card is charged for so and so ... "
]);
}
//If Card is charged successfully, create the Merchant's Subscription at Stripe end
if($chargeCard->id != ''){
$subscription = \Stripe\Subscription::create(array(
"customer" => $customer->id,
"items" => [
[
"plan" => $plan_id,
],
],
"billing" => "charge_automatically",
"cancel_at_period_end" => false
));
}
我在这里https://stripe.com/docs/api/中读到文档,它在创建费用或客户“ 来源”时是可选参数。这是“ 来源”的问题吗?在文档“ 创建客户”中也说
如果客户还没有客户,则必须提供来源 附有有效来源,您正在订阅客户 对于不免费的计划会自动收费。
所以我可以在创建客户并创建收费对象时使用相同的“ 来源”吗?
在这方面,您能帮我吗?
谢谢。
答案 0 :(得分:0)
我认为是您所拥有的费用和订购代码的组合导致了双重费用。您先发出一次性费用。成功后,查看代码,然后立即开始订阅付款。您要付费并创建订阅有特定原因吗?
因为我认为您根本不需要创建第一笔费用,而且您可以使用coupons directly on the subscription creation:
$subscription = \Stripe\Subscription::create(array(
"customer" => $customer->id,
"coupon" => $cc,
"items" => [
[
"plan" => $plan_id,
],
],
"billing" => "charge_automatically",
"cancel_at_period_end" => false
));
因此,您一开始就不需要该计算位。
关于来源(存储卡,银行帐户等)方面的问题:使用客户对象时,它将自动使用其默认来源。除非他们存储了更多的卡并且选择了要使用的卡,否则无需指定它。