Completed
Push — master ( 434a6e...b9ac23 )
by ARCANEDEV
10s
created

Subscription::retrieve()   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
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
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
     * Cancel a Subscription.
82
     * @link   https://stripe.com/docs/api/php#cancel_subscription
83
     *
84
     * @param  array|null         $params
85
     * @param  array|string|null  $options
86
     *
87
     * @return self
88
     */
89 10
    public function cancel($params = [], $options = null)
90
    {
91 10
        return self::scopedDelete($params, $options);
92
    }
93
94
    /**
95
     * Update a Subscription.
96
     * @link   https://stripe.com/docs/api/php#update_subscription
97
     *
98
     * @param  array|string|null  $options
99
     *
100
     * @return self
101
     */
102 10
    public function save($options = null)
103
    {
104 10
        return self::scopedSave($options);
105
    }
106
107
    /**
108
     * Delete a Subscription Discount.
109
     * @link   https://stripe.com/docs/api/php#delete_subscription_discount
110
     *
111
     * @return self
112
     */
113 5
    public function deleteDiscount()
114
    {
115 5
        list($response, $opts) = $this->request('delete', $this->instanceUrl() . '/discount');
116
117 5
        $this->refreshFrom(['discount' => null], $opts, true);
118 5
        unset($response);
119
120 5
        return $this;
121
    }
122
}
123