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

Invoice::upcoming()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
crap 1
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\InvoiceInterface;
4
use Arcanedev\Stripe\StripeResource;
5
use Arcanedev\Stripe\Utilities\Util;
6
7
/**
8
 * Class     Invoice
9
 *
10
 * @package  Arcanedev\Stripe\Resources
11
 * @author   ARCANEDEV <[email protected]>
12
 * @link     https://stripe.com/docs/api/php#invoice_object
13
 *
14
 * @property  string                                       id
15
 * @property  string                                       object                       // 'invoice'
16
 * @property  int                                          amount_due
17
 * @property  int                                          attempt_count
18
 * @property  bool                                         attempted
19
 * @property  int                                          application_fee
20
 * @property  string                                       charge
21
 * @property  bool                                         closed
22
 * @property  string                                       currency
23
 * @property  string                                       customer
24
 * @property  int                                          date                         // timestamp
25
 * @property  string                                       description
26
 * @property  \Arcanedev\Stripe\Resources\Discount|null    discount
27
 * @property  int                                          ending_balance
28
 * @property  bool                                         forgiven
29
 * @property  \Arcanedev\Stripe\Collection                 lines
30
 * @property  bool                                         livemode
31
 * @property  \Arcanedev\Stripe\AttachedObject             metadata
32
 * @property  int                                          next_payment_attempt
33
 * @property  bool                                         paid
34
 * @property  int                                          period_end                   // timestamp
35
 * @property  int                                          period_start                 // timestamp
36
 * @property  string                                       receipt_number
37
 * @property  int                                          starting_balance
38
 * @property  string                                       statement_descriptor
39
 * @property  string                                       subscription
40
 * @property  int                                          subscription_proration_date
41
 * @property  int                                          subtotal
42
 * @property  int                                          tax
43
 * @property  float                                        tax_percent
44
 * @property  int                                          total
45
 * @property  int                                          webhooks_delivered_at        // timestamp
46
 */
47
class Invoice extends StripeResource implements InvoiceInterface
48
{
49
    /* ------------------------------------------------------------------------------------------------
50
     |  CRUD Functions
51
     | ------------------------------------------------------------------------------------------------
52
     */
53
    /**
54
     * Create an Invoice.
55
     * @link   https://stripe.com/docs/api/php#create_invoice
56
     *
57
     * @param  array|null         $params
58
     * @param  array|string|null  $options
59
     *
60
     * @return self|array
61
     */
62 20
    public static function create($params = [], $options = null)
63
    {
64 20
        return self::scopedCreate($params, $options);
65
    }
66
67
    /**
68
     * Retrieving an Invoice
69
     * @link   https://stripe.com/docs/api/php#retrieve_invoice
70
     *
71
     * @param  string             $id
72
     * @param  array|string|null  $options
73
     *
74
     * @return self
75
     */
76 10
    public static function retrieve($id, $options = null)
77
    {
78 10
        return self::scopedRetrieve($id, $options);
79
    }
80
81
    /**
82
     * List of all Invoices.
83
     * @link   https://stripe.com/docs/api/php#list_customer_invoices
84
     *
85
     * @param  array|null         $params
86
     * @param  array|string|null  $options
87
     *
88
     * @return \Arcanedev\Stripe\Collection|array
89
     */
90 10
    public static function all($params = [], $options = null)
91
    {
92 10
        return self::scopedAll($params, $options);
93
    }
94
95
    /**
96
     * Update an invoice.
97
     * @link   https://stripe.com/docs/api/php#update_invoice
98
     *
99
     * @param  string             $id
100
     * @param  array|null         $params
101
     * @param  array|string|null  $options
102
     *
103
     * @return self
104
     */
105
    public static function update($id, $params = [], $options = null)
106
    {
107
        return self::scopedUpdate($id, $params, $options);
108
    }
109
110
    /**
111
     * Update/Save an invoice.
112
     * @link   https://stripe.com/docs/api/php#update_invoice
113
     *
114
     * @param  array|string|null  $options
115
     *
116
     * @return self
117
     */
118 5
    public function save($options = null)
119
    {
120 5
        return self::scopedSave($options);
121
    }
122
123
    /**
124
     * Retrieve Upcoming Invoice.
125
     * @link   https://stripe.com/docs/api/php#retrieve_customer_invoice
126
     *
127
     * @param  array|null         $params
128
     * @param  array|string|null  $options
129
     *
130
     * @return self|array
131
     */
132 10
    public static function upcoming($params = [], $options = null)
133
    {
134
        /** @var \Arcanedev\Stripe\Http\Response $response */
135 10
        list($response, $opts) = self::staticRequest(
136 10
            'get', self::classUrl(get_class()) . '/upcoming', $params, $options
137 8
        );
138
139 10
        $object = Util::convertToStripeObject($response->getJson(), $opts);
0 ignored issues
show
Bug Compatibility introduced by
The expression \Arcanedev\Stripe\Utilit...nse->getJson(), $opts); of type array|Arcanedev\Stripe\StripeObject adds the type Arcanedev\Stripe\StripeObject to the return on line 142 which is incompatible with the return type declared by the interface Arcanedev\Stripe\Contrac...oiceInterface::upcoming of type Arcanedev\Stripe\Contrac...\InvoiceInterface|array.
Loading history...
140 10
        $object->setLastResponse($response);
141
142 10
        return $object;
143
    }
144
145
    /**
146
     * Pay an Invoice.
147
     * @link   https://stripe.com/docs/api/php#pay_invoice
148
     *
149
     * @param  array|string|null  $options
150
     *
151
     * @return self
152
     */
153 5
    public function pay($options = null)
154
    {
155 5
        list($response, $opts) = $this->request('post',
156 5
            $this->instanceUrl() . '/pay', [], $options
157 4
        );
158 5
        $this->refreshFrom($response, $opts);
159
160 5
        return $this;
161
    }
162
}
163