1
|
|
|
<?php namespace Arcanedev\Stripe\Resources; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Stripe\Contracts\Resources\Invoice as InvoiceContract; |
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 InvoiceContract |
48
|
|
|
{ |
49
|
|
|
/* ------------------------------------------------------------------------------------------------ |
50
|
|
|
| Main Functions |
51
|
|
|
| ------------------------------------------------------------------------------------------------ |
52
|
|
|
*/ |
53
|
|
|
/** |
54
|
|
|
* List of all Invoices. |
55
|
|
|
* @link https://stripe.com/docs/api/php#list_customer_invoices |
56
|
|
|
* |
57
|
|
|
* @param array|null $params |
58
|
|
|
* @param array|string|null $options |
59
|
|
|
* |
60
|
|
|
* @return \Arcanedev\Stripe\Collection|array |
61
|
|
|
*/ |
62
|
4 |
|
public static function all($params = [], $options = null) |
63
|
|
|
{ |
64
|
4 |
|
return self::scopedAll($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
|
6 |
|
public static function retrieve($id, $options = null) |
77
|
|
|
{ |
78
|
6 |
|
return self::scopedRetrieve($id, $options); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Create an Invoice. |
83
|
|
|
* @link https://stripe.com/docs/api/php#create_invoice |
84
|
|
|
* |
85
|
|
|
* @param array|null $params |
86
|
|
|
* @param array|string|null $options |
87
|
|
|
* |
88
|
|
|
* @return self|array |
89
|
|
|
*/ |
90
|
10 |
|
public static function create($params = [], $options = null) |
91
|
|
|
{ |
92
|
10 |
|
return self::scopedCreate($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
|
2 |
|
public static function update($id, $params = [], $options = null) |
106
|
|
|
{ |
107
|
2 |
|
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
|
2 |
|
public function save($options = null) |
119
|
|
|
{ |
120
|
2 |
|
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
|
4 |
|
public static function upcoming($params = [], $options = null) |
133
|
|
|
{ |
134
|
|
|
/** @var \Arcanedev\Stripe\Http\Response $response */ |
135
|
4 |
|
list($response, $opts) = self::staticRequest( |
136
|
4 |
|
'get', self::classUrl(get_class()).'/upcoming', $params, $options |
137
|
|
|
); |
138
|
|
|
|
139
|
4 |
|
$object = Util::convertToStripeObject($response->getJson(), $opts); |
140
|
4 |
|
$object->setLastResponse($response); |
141
|
|
|
|
142
|
4 |
|
return $object; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Pay an Invoice. |
147
|
|
|
* @link https://stripe.com/docs/api/php#pay_invoice |
148
|
|
|
* |
149
|
|
|
* @param array|null $params |
150
|
|
|
* @param array|string|null $options |
151
|
|
|
* |
152
|
|
|
* @return self |
153
|
|
|
*/ |
154
|
4 |
|
public function pay($params = [], $options = null) |
155
|
|
|
{ |
156
|
4 |
|
list($response, $opts) = $this->request('post', |
157
|
4 |
|
$this->instanceUrl().'/pay', $params, $options |
158
|
|
|
); |
159
|
4 |
|
$this->refreshFrom($response, $opts); |
160
|
|
|
|
161
|
4 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|