I have a website where I want to integrate the Stripe payment gateway, when a user registers I want to create a customer on Stripe and charge them the first month fee for example $100 and from the next month I want to charge them $50.
How do I create the customer and then charge them simultaneously and setup recurring payment, so far I could only reach find out about one time payment system:
$charge = \Stripe\Charge::create(
array(
"amount" => $amount,
"currency" => "usd",
"source" => $token,
"description" => $email
)
);
For recurring payments, will I have to run this code in a cron or is there any better way ?
Thanks in advance.
EDIT:
I used the following code to create a customer first and then charge that customer with their charge id:
//Create Customer:
$customer = \Stripe\Customer::create(array(
'source' => $token,
'email' => $_POST['email'],
'plan' => "monthly_recurring_setupfee",
));
// Charge the order:
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
"amount" => $amount,
"currency" => "usd",
"description" => "monthly payment",
)
);
this seems to be working.
Another question: I have created two plans monthly_recurring_setupfee
and monthly_recurring
, the previous plan contains the amount that I want to charge plus the one time setup fee and the later plan contains the regular amount that I will be charging from the second month, I was thinking of assigning the user the monthly_recurring_setupfee
plan at the time of registration and if the payment is successful change the plan of the user to monthly_recurring
, is this possible ?