【发布时间】:2019-04-10 10:17:42
【问题描述】:
您好,我在我的应用程序中集成了 Stripe 以出售一些付费注册。在我的条纹仪表板中,我已经创建了一些 优惠券 一些有折扣和一些固定价值。我需要以多种货币向我的客户收费。 我在向客户收费时遇到问题。 假设我有一个每年 348 美元的计划并提供
- 客户 C1 使用优惠券 CP1 可享受 347 美元的优惠(因此费用仅为 1 美元)
- 客户 C2 一张优惠券 CP2 可享受 50% 的折扣(因此费用为 174 美元)
如果情况 2 没有问题并创建发票。 但在情况 1 中,它会收取 2 次费用:
- 1 美元首发(折扣价)
- 总金额 348 美元(不知道为什么要收费)
下面是我的代码:
计划价值已更新(已应用的优惠券有“一定金额的折扣)
$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/ 的文档,在创建费用或客户时,“来源”是可选参数。这是“Source”的问题吗?同样在文档“creating a customer”中说
如果客户还没有来源,您必须提供来源 附加的有效来源,并且您正在订阅客户 对非免费计划自动收费。
那么我可以在创建客户和创建收费对象时使用相同的“Source”吗?
在这方面你能帮帮我吗?
提前致谢。
【问题讨论】:
标签: stripe-payments