如何正确启动订阅初始付款和后续付款

时间:2013-10-29 15:22:13

标签: stripe-payments

我想知道如何正确发起第一笔付款以及成功支付条款订阅费用。 就像下面的例子一样。

( $50.00 USD for the first month then, $70.00 USD for each moneht.)

现在基本上我有这个代码。当有人选择它时,哪个会成功制定计划。 (有一个代码可以检查计划是否已经存在,但我想我不会再包含它了)

$price = 70;
$first_payment = 50;
$createPlan = array(
  "amount" => $price*100,
  "interval_count" => array("period" => "1", "time"=> "month"),
  "name" => 'Product name test',
  "currency" => 'USD',
  "id" => 'product_id_1234'
);
Stripe_Plan::create($createPlan);

下一组代码是创建客户然后进行交易。 $carddetails变量包含客户的卡信息。

$customer = Stripe_Customer::create($carddetails);
Stripe_Charge::create(array(
  "customer" => $customer->id,
  "amount" => $first_payment * 100,
  "currency" => 'USD',
  "description" => 'First payment charge'
));

问题是,无论何时创建客户,客户都被收取两次,实际价格和第一笔付款费用。 这应该是第一次收费只有50美元,而不是50美元和70美元。

你能解释一下为什么吗?感谢

1 个答案:

答案 0 :(得分:3)

Stripe中的订阅是预付费的。也就是说,一旦用户开始订阅就收集钱。

所以,你是:

  • 立即收取50美元的费用
  • 订阅用户计划,立即向他收取70美元

有几种方法可以做你想要的,所有这些都很容易。我在这里详述两个。

<强> 1。通过否定account_balance

当您创建客户时,您可以传递account_balance属性以及其余信息。如果你通过-2000,他将获得$ 20.00的积分,使他的第一个月$ 50.00。

如果您使用此选项,将应用折扣,但不会向用户显示为什么他有20美元的折扣。

$customer = Stripe_Customer::create(array(
  "description" => "Kenneth Palaganas",
  "account_balance" => -2000,
  "card" => "tok_1a2b3c4de",
  "plan" => "basic"
));

<强> 2。创建发票项目

此选项可能需要对您的代码进行一些修改,但它允许您将调整包含在客户的发票上,提醒他为什么他只支付50美元。

如果在创建用户之后创建发票项目,但在创建订阅之前,则该发票项目将显示在他的第一张发票上。您可以使用描述为“第一个月折扣”的订单项,而不是神秘的20美元信用额度:

$customer = Stripe_Customer::create($carddetails);
Stripe_InvoiceItem::create(array(
    "customer" => $customer->id,
    "amount" => -2000,
    "currency" => "usd",
    "description" => "First Month Discount - Welcome!")
);
$customer->updateSubscription(array("plan" => "basic", "prorate" => false));