Completed
Pull Request — master (#22)
by ARCANEDEV
07:43
created

Subscription::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
cc 1
eloc 2
nc 1
nop 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\SubscriptionInterface;
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\AttachedObject      metadata
24
 * @property  \Arcanedev\Stripe\Resources\Plan      plan
25
 * @property  int                                   quantity
26
 * @property  int                                   start                    // timestamp
27
 * @property  string                                status
28
 * @property  float                                 tax_percent
29
 * @property  int                                   trial_end                // timestamp
30
 * @property  int                                   trial_start              // timestamp
31
 */
32
class Subscription extends StripeResource implements SubscriptionInterface
33
{
34
    /* ------------------------------------------------------------------------------------------------
35
     |  CRUD Functions
36
     | ------------------------------------------------------------------------------------------------
37
     */
38
    /**
39
     * Retrieve a Subscription by id.
40
     * @link   https://stripe.com/docs/api/php#retrieve_subscription
41
     *
42
     * @param  string             $id       The ID of the subscription to retrieve.
43
     * @param  array|string|null  $options
44
     *
45
     * @return self
46
     */
47 5
    public static function retrieve($id, $options = null)
48
    {
49 5
        return self::scopedRetrieve($id, $options);
50
    }
51
52
    /**
53
     * List all Subscriptions.
54
     * @link   https://stripe.com/docs/api/php#list_subscriptions
55
     *
56
     * @param  array|null         $params
57
     * @param  array|string|null  $options
58
     *
59
     * @return \Arcanedev\Stripe\Collection|array
60
     */
61 5
    public static function all($params = [], $options = null)
62
    {
63 5
        return self::scopedAll($params, $options);
64
    }
65
66
    /**
67
     * Create a Subscription.
68
     * @link   https://stripe.com/docs/api/php#create_subscription
69
     *
70
     * @param  array|null         $params
71
     * @param  array|string|null  $options
72
     *
73
     * @return self
74
     */
75 5
    public static function create($params = [], $options = null)
76
    {
77 5
        return self::scopedCreate($params, $options);
78
    }
79
80
    /**
81
     * Updated a subscription.
82
     * @link   https://stripe.com/docs/api/php#update_subscription
83
     *
84
     * @param  string             $id
85
     * @param  array|null         $params
86
     * @param  array|string|null  $options
87
     *
88
     * @return self
89
     */
90 5
    public static function update($id, $params = [], $options = null)
91
    {
92 5
        return self::scopedUpdate($id, $params, $options);
93
    }
94
95
    /**
96
     * Cancel a Subscription.
97
     * @link   https://stripe.com/docs/api/php#cancel_subscription
98
     *
99
     * @param  array|null         $params
100
     * @param  array|string|null  $options
101
     *
102
     * @return self
103
     */
104 10
    public function cancel($params = [], $options = null)
105
    {
106 10
        return self::scopedDelete($params, $options);
107
    }
108
109
    /**
110
     * Update a Subscription.
111
     * @link   https://stripe.com/docs/api/php#update_subscription
112
     *
113
     * @param  array|string|null  $options
114
     *
115
     * @return self
116
     */
117 10
    public function save($options = null)
118
    {
119 10
        return self::scopedSave($options);
120
    }
121
122
    /**
123
     * Delete a Subscription Discount.
124
     * @link   https://stripe.com/docs/api/php#delete_subscription_discount
125
     *
126
     * @return self
127
     */
128 5
    public function deleteDiscount()
129
    {
130 5
        list($response, $opts) = $this->request('delete', $this->instanceUrl() . '/discount');
131
132 5
        $this->refreshFrom(['discount' => null], $opts, true);
133 5
        unset($response);
134
135 5
        return $this;
136
    }
137
}
138