-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-price.php
83 lines (82 loc) · 2.25 KB
/
create-price.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once 'config.php';
$stripe = new \Stripe\StripeClient(
config('secret_key')
);
if (!empty($_POST)) {
try {
$price = $stripe->prices->create([
'product' => $_POST['product_id'],
'unit_amount' => $_POST['unit_amount'] * 100,
'currency' => 'usd',
'recurring' => [
'interval' => $_POST['interval'],
],
]);
$products = $stripe->products->all();
$prices = $stripe->prices->all();
echo json_encode($price);
} catch (\Stripe\Exception\ApiErrorException $e) {
}
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Create Price</title>
</head>
<body>
<table border="1" width="100%">
<thead>
<tr>
<th>Price ID</th>
<th>Amount</th>
<th>Type</th>
<th>Recurring Interval</th>
</tr>
</thead>
<?php
if (!empty($prices)) {
foreach ($prices as $price) {
?>
<tr>
<td><?= $price->id ?></td>
<td><?= $price->unit_amount ?></td>
<td><?= $price->type ?></td>
<td><?= $price->type == 'recurring' ? $price->recurring->interval : '' ?></td>
</tr>
<?php
}
}
?>
</table>
<hr>
<h3>Add New Price</h3>
<form action="" method="post">
<label for="product_id">Select Product</label>
<select name="product_id" id="product_id">
<?php
if (!empty($products)) {
foreach ($products as $product) {
?>
<option value="<?= $product->id ?>"><?= $product->name ?></option>
<?php
}
}
?>
</select>
<label for="unit_amount">Amount</label>
<input type="number" name="unit_amount">
<label for="interval">Select Type</label>
<select name="interval" id="interval">
<option value="month">Monthly</option>
<option value="year">Yearly</option>
</select>
<input type="submit" name="create_price" value="Create">
</form>
</body>
</html>