-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
58 lines (45 loc) · 1.07 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
require __DIR__ . '/vendor/autoload.php';
$stripeKey = getenv("STRIPE_KEY");
\Stripe\Stripe::setApiKey($stripeKey);
// Generate a token
$token = \Stripe\Token::create([
'card' => [
'number' => '4242424242424242',
'exp_month' => 7,
'exp_year' => 2017,
'cvc' => '413'
]
]);
// Create a customer
$customer = \Stripe\Customer::create(
[
"description" => "Test customer",
'source' => $token->id
]
);
// Create a plan
$plan = \Stripe\Plan::create(
[
'amount' => 2000,
'interval' => 'month',
'name' => 'Amazing Test Plan',
'currency' => 'gbp',
'id' => 'amazing-test-plan'
]
);
// Add sub to customer
$customer->subscriptions->create(
[
'plan' => 'amazing-test-plan'
]
);
$cu = \Stripe\Customer::retrieve($customer->id);
$invoices = \Stripe\Invoice::all(
[
'customer' => $cu->id
]
);
$invoiceIdentifier = $invoices->data[0]->id;
$invoiceFetched = \Stripe\Invoice::retrieve($invoiceIdentifier);
echo 'Invoice ID: ' . $invoiceFetched->id .' - Amount due: ' . number_format($invoiceFetched->amount_due);