• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Freegle / iznik-server / 5e9e4b03-c3c5-45e7-aaa1-3908a8f073e5

29 Nov 2024 12:31PM UTC coverage: 92.434% (-0.2%) from 92.626%
5e9e4b03-c3c5-45e7-aaa1-3908a8f073e5

push

circleci

edwh
WIP Stripe subscriptions

0 of 4 new or added lines in 1 file covered. (0.0%)

10 existing lines in 1 file now uncovered.

25474 of 27559 relevant lines covered (92.43%)

31.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/http/api/stripecreatesubscription.php
1
<?php
2
namespace Freegle\Iznik;
3

4
function stripecreatesubscription() {
5
    global $dbhr, $dbhm;
×
6

7
    $ret = [ 'ret' => 1, 'status' => 'Unknown verb' ];
×
8

9
    $me = Session::whoAmI($dbhr, $dbhm);
×
10

11
    switch ($_REQUEST['type']) {
×
12
        case 'POST': {
×
13
            $ret = ['ret' => 1, 'status' => 'Not logged in'];
×
14

15
            if ($me) {
×
16
                $amount = Utils::presint('amount', $_REQUEST, 0);
×
17
                $test = Utils::presbool('test', $_REQUEST, FALSE);
×
18
                $stripe = new \Stripe\StripeClient($test ? STRIPE_SECRET_KEY_TEST : STRIPE_SECRET_KEY);
×
19

20
                # TODO Email and uid might change - how to handle?
21
                $customer = $stripe->customers->create([
×
22
                                                           'email' => $me->getEmailPreferred(),
×
23
                                                           'name' => $me->getName(),
×
24
                                                           'metadata' => [ 'uid' => $me->getId() ],
×
25
                                                       ]);
×
26

27
                $price = NULL;
×
28

29
                switch ($amount) {
30
                    case 1: {
×
31
                        $price = 'price_1QPo6pP3oIVajsTkjR41BjuL';
×
32
                        break;
×
33
                    }
34
                    case 2: {
×
35
                        $price = 'price_1QK244P3oIVajsTkYcUs6kEM';
×
36
                        break;
×
37
                    }
38
                    case 5: {
×
39
                        $price = 'price_1QPo7cP3oIVajsTkdGnF7kI4';
×
40
                        break;
×
41
                    }
42
                    case 10: {
×
43
                        $price = 'price_1QJv7GP3oIVajsTkTG7RGAUA';
×
44
                        break;
×
45
                    }
46
                    case 15: {
×
47
                        $price = 'price_1QK24rP3oIVajsTkwkXPms9B';
×
48
                        break;
×
49
                    }
50
                    case 25: {
×
51
                        $price = 'price_1QK24VP3oIVajsTk3e57kF5S';
×
52
                        break;
×
53
                    }
54
                }
55

56
                $subscription = $stripe->subscriptions->create([
×
57
                                                                   'customer' => $customer->id,
×
58
                                                                   'items' => [[
×
59
                                                                       'price' => $price
×
60
                                                                   ]],
×
61
                                                                   'payment_behavior' => 'default_incomplete',
×
62
                                                                   'payment_settings' => ['save_default_payment_method' => 'on_subscription'],
×
63
                                                                   'expand' => ['latest_invoice.payment_intent'],
×
NEW
64
                                                                   'metadata' => [
×
NEW
65
                                                                       'uid' => $me->getId(),
×
NEW
66
                                                                       'monthly' => TRUE
×
NEW
67
                                                                   ],
×
68
                                                               ]);
×
69

70
                $ret = [
×
71
                    'ret' => 0,
×
72
                    'status' => 'Success',
×
73
                    'subscriptionId' => $subscription->id,
×
74
                    'clientSecret' => $subscription->latest_invoice->payment_intent->client_secret,
×
75
                ];
×
76
            }
77
            break;
×
78
        }
79
    }
80

81
    return($ret);
×
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc