Subscription   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 106
rs 10
c 0
b 0
f 0
ccs 17
cts 17
cp 1
wmc 7
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A retrieve() 0 4 1
A create() 0 4 1
A update() 0 4 1
A cancel() 0 4 1
A save() 0 4 1
A deleteDiscount() 0 9 1
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\Subscription as SubscriptionContract;
4
use Arcanedev\Stripe\StripeResource;
5
6
/**
7
 * Class     Subscription
8
 *
9
 * @package  Arcanedev\Stripe\Resources
10
 * @author   ARCANEDEV <[email protected]>
11
 * @link     https://stripe.com/docs/api/php#subscription_object
12
 *
13
 * @property  string                                id
14
 * @property  string                                object                   // 'subscription'
15
 * @property  float                                 application_fee_percent
16
 * @property  boolean                               cancel_at_period_end
17
 * @property  int                                   canceled_at              // timestamp
18
 * @property  int                                   current_period_end       // timestamp
19
 * @property  int                                   current_period_start     // timestamp
20
 * @property  string                                customer
21
 * @property  \Arcanedev\Stripe\Resources\Discount  discount
22
 * @property  int                                   ended_at                 // timestamp
23
 * @property  \Arcanedev\Stripe\Collection          items
24
 * @property  \Arcanedev\Stripe\AttachedObject      metadata
25
 * @property  \Arcanedev\Stripe\Resources\Plan      plan
26
 * @property  int                                   quantity
27
 * @property  int                                   start                    // timestamp
28
 * @property  string                                status
29
 * @property  float                                 tax_percent
30
 * @property  int                                   trial_end                // timestamp
31
 * @property  int                                   trial_start              // timestamp
32
 */
33
class Subscription extends StripeResource implements SubscriptionContract
34
{
35
    /* ------------------------------------------------------------------------------------------------
36
     |  Main Functions
37
     | ------------------------------------------------------------------------------------------------
38
     */
39
    /**
40
     * List all Subscriptions.
41
     * @link   https://stripe.com/docs/api/php#list_subscriptions
42
     *
43
     * @param  array|null         $params
44
     * @param  array|string|null  $options
45
     *
46
     * @return \Arcanedev\Stripe\Collection|array
47
     */
48 2
    public static function all($params = [], $options = null)
49
    {
50 2
        return self::scopedAll($params, $options);
51
    }
52
53
    /**
54
     * Retrieve a Subscription by id.
55
     * @link   https://stripe.com/docs/api/php#retrieve_subscription
56
     *
57
     * @param  string             $id       The ID of the subscription to retrieve.
58
     * @param  array|string|null  $options
59
     *
60
     * @return self
61
     */
62 2
    public static function retrieve($id, $options = null)
63
    {
64 2
        return self::scopedRetrieve($id, $options);
65
    }
66
67
    /**
68
     * Create a Subscription.
69
     * @link   https://stripe.com/docs/api/php#create_subscription
70
     *
71
     * @param  array|null         $params
72
     * @param  array|string|null  $options
73
     *
74
     * @return self
75
     */
76 6
    public static function create($params = [], $options = null)
77
    {
78 6
        return self::scopedCreate($params, $options);
79
    }
80
81
    /**
82
     * Updated a subscription.
83
     * @link   https://stripe.com/docs/api/php#update_subscription
84
     *
85
     * @param  string             $id
86
     * @param  array|null         $params
87
     * @param  array|string|null  $options
88
     *
89
     * @return self
90
     */
91 4
    public static function update($id, $params = [], $options = null)
92
    {
93 4
        return self::scopedUpdate($id, $params, $options);
94
    }
95
96
    /**
97
     * Cancel a Subscription.
98
     * @link   https://stripe.com/docs/api/php#cancel_subscription
99
     *
100
     * @param  array|null         $params
101
     * @param  array|string|null  $options
102
     *
103
     * @return self
104
     */
105 4
    public function cancel($params = [], $options = null)
106
    {
107 4
        return self::scopedDelete($params, $options);
108
    }
109
110
    /**
111
     * Update a Subscription.
112
     * @link   https://stripe.com/docs/api/php#update_subscription
113
     *
114
     * @param  array|string|null  $options
115
     *
116
     * @return self
117
     */
118 4
    public function save($options = null)
119
    {
120 4
        return self::scopedSave($options);
121
    }
122
123
    /**
124
     * Delete a Subscription Discount.
125
     * @link   https://stripe.com/docs/api/php#delete_subscription_discount
126
     *
127
     * @return self
128
     */
129 2
    public function deleteDiscount()
130
    {
131 2
        list($response, $opts) = $this->request('delete', $this->instanceUrl().'/discount');
132 2
        $this->refreshFrom(['discount' => null], $opts, true);
133
134 2
        unset($response);
135
136 2
        return $this;
137
    }
138
}
139