1
|
|
|
<?php namespace Arcanedev\Stripe\Resources; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Stripe\Contracts\Resources\Charge as ChargeContract; |
4
|
|
|
use Arcanedev\Stripe\StripeResource; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Charge |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\Stripe\Resources |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
* @link https://stripe.com/docs/api/php#charge_object |
12
|
|
|
* |
13
|
|
|
* @property string id |
14
|
|
|
* @property string object // 'charge' |
15
|
|
|
* @property int amount |
16
|
|
|
* @property int amount_refunded |
17
|
|
|
* @property string|null application_fee |
18
|
|
|
* @property string balance_transaction |
19
|
|
|
* @property bool captured |
20
|
|
|
* @property int created // timestamp |
21
|
|
|
* @property string currency |
22
|
|
|
* @property string customer |
23
|
|
|
* @property string description |
24
|
|
|
* @property string destination |
25
|
|
|
* @property string|null dispute |
26
|
|
|
* @property string failure_code |
27
|
|
|
* @property string failure_message |
28
|
|
|
* @property array fraud_details |
29
|
|
|
* @property string invoice |
30
|
|
|
* @property bool livemode |
31
|
|
|
* @property \Arcanedev\Stripe\AttachedObject metadata |
32
|
|
|
* @property string order |
33
|
|
|
* @property bool paid |
34
|
|
|
* @property string receipt_email |
35
|
|
|
* @property string receipt_number |
36
|
|
|
* @property bool refunded |
37
|
|
|
* @property \Arcanedev\Stripe\Collection refunds |
38
|
|
|
* @property array shipping |
39
|
|
|
* @property \Arcanedev\Stripe\Resources\Card source |
40
|
|
|
* @property string source_transfer |
41
|
|
|
* @property string statement_descriptor |
42
|
|
|
* @property string status |
43
|
|
|
* @property string transfer |
44
|
|
|
*/ |
45
|
|
|
class Charge extends StripeResource implements ChargeContract |
46
|
|
|
{ |
47
|
|
|
/* ----------------------------------------------------------------- |
48
|
|
|
| Constants |
49
|
|
|
| ----------------------------------------------------------------- |
50
|
|
|
*/ |
51
|
|
|
|
52
|
|
|
const SAFE = 'safe'; |
53
|
|
|
const FRAUDULENT = 'fraudulent'; |
54
|
|
|
|
55
|
|
|
/* ----------------------------------------------------------------- |
56
|
|
|
| Main Methods |
57
|
|
|
| ----------------------------------------------------------------- |
58
|
|
|
*/ |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* List all Charges. |
62
|
|
|
* @link https://stripe.com/docs/api/php#list_charges |
63
|
|
|
* |
64
|
|
|
* @param array|null $params |
65
|
|
|
* @param array|string|null $options |
66
|
|
|
* |
67
|
|
|
* @return \Arcanedev\Stripe\Collection|array |
68
|
|
|
*/ |
69
|
4 |
|
public static function all($params = [], $options = null) |
70
|
|
|
{ |
71
|
4 |
|
return self::scopedAll($params, $options); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Retrieve a Charge. |
76
|
|
|
* @link https://stripe.com/docs/api/php#retrieve_charge |
77
|
|
|
* |
78
|
|
|
* @param string $id |
79
|
|
|
* @param array|string|null $options |
80
|
|
|
* |
81
|
|
|
* @return self |
82
|
|
|
*/ |
83
|
20 |
|
public static function retrieve($id, $options = null) |
84
|
|
|
{ |
85
|
20 |
|
return self::scopedRetrieve($id, $options); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Create a new charge (charging a credit card). |
90
|
|
|
* @link https://stripe.com/docs/api/php#create_charge |
91
|
|
|
* |
92
|
|
|
* @param array $params |
93
|
|
|
* @param array|string|null $options |
94
|
|
|
* |
95
|
|
|
* @return self|array |
96
|
|
|
*/ |
97
|
62 |
|
public static function create($params = [], $options = null) |
98
|
|
|
{ |
99
|
62 |
|
return self::scopedCreate($params, $options); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Save/Update a Charge. |
104
|
|
|
* @link https://stripe.com/docs/api/php#update_charge |
105
|
|
|
* |
106
|
|
|
* @param array|string|null $options |
107
|
|
|
* |
108
|
|
|
* @return self |
109
|
|
|
*/ |
110
|
4 |
|
public function save($options = null) |
111
|
|
|
{ |
112
|
4 |
|
return self::scopedSave($options); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Update a Charge. |
117
|
|
|
* @link https://stripe.com/docs/api/php#update_charge |
118
|
|
|
* |
119
|
|
|
* @param string $id |
120
|
|
|
* @param array|null $params |
121
|
|
|
* @param array|string|null $options |
122
|
|
|
* |
123
|
|
|
* @return self |
124
|
|
|
*/ |
125
|
2 |
|
public static function update($id, $params = [], $options = null) |
126
|
|
|
{ |
127
|
2 |
|
return self::scopedUpdate($id, $params, $options); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Creating a new refund. |
132
|
|
|
* @link https://stripe.com/docs/api/php#create_refund |
133
|
|
|
* |
134
|
|
|
* @param array|null $params |
135
|
|
|
* @param array|string|null $options |
136
|
|
|
* |
137
|
|
|
* @return self |
138
|
|
|
*/ |
139
|
4 |
|
public function refund($params = [], $options = null) |
140
|
|
|
{ |
141
|
4 |
|
return self::scopedPostCall( |
142
|
4 |
|
$this->instanceUrl().'/refund', $params, $options |
143
|
|
|
); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Capture a charge. |
148
|
|
|
* @link https://stripe.com/docs/api/php#capture_charge |
149
|
|
|
* |
150
|
|
|
* @param array|null $params |
151
|
|
|
* @param array|string|null $options |
152
|
|
|
* |
153
|
|
|
* @return self |
154
|
|
|
*/ |
155
|
2 |
|
public function capture($params = [], $options = null) |
156
|
|
|
{ |
157
|
2 |
|
return self::scopedPostCall( |
158
|
2 |
|
$this->instanceUrl().'/capture', $params, $options |
159
|
|
|
); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Mark charge as Fraudulent. |
164
|
|
|
* @param array|string|null $options |
165
|
|
|
* |
166
|
|
|
* @return self |
167
|
|
|
*/ |
168
|
2 |
|
public function markAsFraudulent($options = null) |
169
|
|
|
{ |
170
|
2 |
|
return $this->updateFraudDetails(false); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Mark charge as Safe. |
175
|
|
|
* @param array|string|null $options |
176
|
|
|
* |
177
|
|
|
* @return self |
178
|
|
|
*/ |
179
|
2 |
|
public function markAsSafe($options = null) |
180
|
|
|
{ |
181
|
2 |
|
return $this->updateFraudDetails(true); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/* ----------------------------------------------------------------- |
185
|
|
|
| Other Methods |
186
|
|
|
| ----------------------------------------------------------------- |
187
|
|
|
*/ |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Update charge's fraud details. |
191
|
|
|
* |
192
|
|
|
* @param bool $safe |
193
|
|
|
* @param array|string|null $options |
194
|
|
|
* |
195
|
|
|
* @return self |
196
|
|
|
*/ |
197
|
4 |
|
private function updateFraudDetails($safe = false, $options = null) |
198
|
|
|
{ |
199
|
4 |
|
return $this->scopedPostCall($this->instanceUrl(), [ |
200
|
|
|
'fraud_details' => [ |
201
|
4 |
|
'user_report' => $safe ? self::SAFE : self::FRAUDULENT, |
202
|
|
|
], |
203
|
4 |
|
], $options); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|