Kenneth P.
Kenneth P.

Reputation: 1816

How to properly initiate a subscriptions initial payment and succeeding payments

I would like to know how to properly initiate a first payment and to succeeding payments to subscriptions of stripe. Like for the example below.

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

right now basically I have this code. Which would successfully create a plan when someone pick it. (there is a code that checks if plan is already existed, but I think i will not include that anymore)

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

Next set of code is to create a customer and then transact. $carddetails variable contains the card information of the customer.

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

Problem was, whenever the customer was created, customer was charged twice, the actual price and the first payment fee. It should be the first charge is $50 only, not $50 and $70.

Can you explain why so? thanks

Upvotes: 1

Views: 659

Answers (1)

colinm
colinm

Reputation: 4288

Subscriptions in Stripe are prepaid. That is, the money is collected as soon as the user begins his subscription.

So, you are:

  • Creating a $50 charge, which immediately bills him $50
  • Subscribing the user to a plan, which immediately bills him $70

There are several approaches to doing what you want, all of which are fairly easy. I'll detail two here.

1. Pass a negative account_balance

When you're creating the customer, you can pass an account_balance property with the rest of his information. If you pass -2000, he'll have a $20.00 credit, making his first month $50.00.

If you use this option, the discount will be applied but there will be no indication to the user of why he had a $20 discount.

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

2. Create an Invoice Item

This option will probably require a little more modification of your code, but it allows you to include the adjustment on the customer's invoice, reminding him why he only paid $50.

If you create an invoice item after creating the user but before creating his subscription, that invoice item will appear on his first invoice. Instead of a mysterious $20 credit, you can have a line item with a description of "First Month Discount":

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

Upvotes: 3

Related Questions