· 4 years ago · Mar 16, 2021, 06:24 AM
1<?php
2// Set Stripe API key
3$stripe = new Stripe\StripeClient(DB::STRIPE_API_KEY);
4
5// Create customer and subscription, send email and auto billing with cron job
6$token = $stripe->tokens->create([
7 'card' => [
8 'number' => '4242424242424242',
9 'exp_month' => 3,
10 'exp_year' => 2022,
11 'cvc' => '314',
12 ],
13]);
14$customer = $stripe->customers->create([
15 'email' => 'mofizul21@gmail.com',
16 'source' => $token->id
17]);
18
19$priceCents = round(1500 * 100);
20$plan = $stripe->plans->create([
21 'amount' => $priceCents,
22 'currency' => 'usd',
23 'interval' => 'day',
24 'product' => [
25 'name' => 'Test product by Mofi'
26 ],
27]);
28//printor($plan);die;
29$today = time();
30$cancelAt = strtotime('+30 day', $today);
31$subscription = $stripe->subscriptions->create([
32 'customer' => $customer->id,
33 'cancel_at' => $cancelAt,
34 //'cancel_at_period_end' => true,
35 // 'collection_method' => 'send_invoice',
36 // 'days_until_due' => 30,
37 'items' => [
38 ['plan' => $plan->id],
39 ],
40
41]);
42//printor($subscription); die;
43$inv = $stripe->invoiceItems->all();
44$invoice = $stripe->invoices->create([
45 'customer' => $customer->id,
46 'collection_method' => 'send_invoice',
47 'days_until_due' => 30,
48]);
49//printor($invoice); die;
50$invoice->sendInvoice();
51?>