1
|
|
|
<?php namespace Arcanedev\Stripe\Resources; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Stripe\Contracts\Resources\Transfer as TransferContract; |
4
|
|
|
use Arcanedev\Stripe\StripeResource; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Transfer |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\Stripe\Resources |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
* @link https://stripe.com/docs/api/php#transfer_object |
12
|
|
|
* |
13
|
|
|
* @property string id |
14
|
|
|
* @property string object // 'transfer' |
15
|
|
|
* @property int amount |
16
|
|
|
* @property int amount_reversed |
17
|
|
|
* @property string balance_transaction |
18
|
|
|
* @property int created // timestamp |
19
|
|
|
* @property string currency |
20
|
|
|
* @property int date // timestamp |
21
|
|
|
* @property string destination |
22
|
|
|
* @property string destination_payment |
23
|
|
|
* @property bool livemode |
24
|
|
|
* @property \Arcanedev\Stripe\AttachedObject metadata |
25
|
|
|
* @property \Arcanedev\Stripe\Collection reversals |
26
|
|
|
* @property bool reversed |
27
|
|
|
* @property string source_transaction |
28
|
|
|
*/ |
29
|
|
|
class Transfer extends StripeResource implements TransferContract |
30
|
|
|
{ |
31
|
|
|
/* ------------------------------------------------------------------------------------------------ |
32
|
|
|
| Main Functions |
33
|
|
|
| ------------------------------------------------------------------------------------------------ |
34
|
|
|
*/ |
35
|
|
|
/** |
36
|
|
|
* List all Transfers. |
37
|
|
|
* @link https://stripe.com/docs/api/php#list_transfers |
38
|
|
|
* |
39
|
|
|
* @param array|null $params |
40
|
|
|
* @param array|string|null $options |
41
|
|
|
* |
42
|
|
|
* @return \Arcanedev\Stripe\Collection|array |
43
|
|
|
*/ |
44
|
2 |
|
public static function all($params = [], $options = null) |
45
|
|
|
{ |
46
|
2 |
|
return self::scopedAll($params, $options); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Retrieve a Transfer. |
51
|
|
|
* @link https://stripe.com/docs/api/php#retrieve_transfer |
52
|
|
|
* |
53
|
|
|
* @param string $id |
54
|
|
|
* @param array|string|null $options |
55
|
|
|
* |
56
|
|
|
* @return self |
57
|
|
|
*/ |
58
|
6 |
|
public static function retrieve($id, $options = null) |
59
|
|
|
{ |
60
|
6 |
|
return self::scopedRetrieve($id, $options); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Create a transfer. |
65
|
|
|
* @link https://stripe.com/docs/api/php#create_transfer |
66
|
|
|
* |
67
|
|
|
* @param array|null $params |
68
|
|
|
* @param array|string|null $options |
69
|
|
|
* |
70
|
|
|
* @return self|array |
71
|
|
|
*/ |
72
|
10 |
|
public static function create($params = [], $options = null) |
73
|
|
|
{ |
74
|
10 |
|
return self::scopedCreate($params, $options); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Update a Transfer. |
79
|
|
|
* @link https://stripe.com/docs/api/php#update_transfer |
80
|
|
|
* |
81
|
|
|
* @param string $id |
82
|
|
|
* @param array|null $params |
83
|
|
|
* @param array|string|null $options |
84
|
|
|
* |
85
|
|
|
* @return self |
86
|
|
|
*/ |
87
|
|
|
public static function update($id, $params = [], $options = null) |
88
|
|
|
{ |
89
|
|
|
return self::scopedUpdate($id, $params, $options); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Update/Save a Transfer. |
94
|
|
|
* @link https://stripe.com/docs/api/php#update_transfer |
95
|
|
|
* |
96
|
|
|
* @param array|string|null $options |
97
|
|
|
* |
98
|
|
|
* @return self |
99
|
|
|
*/ |
100
|
4 |
|
public function save($options = null) |
101
|
|
|
{ |
102
|
4 |
|
return self::scopedSave($options); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Cancel a Transfer. |
107
|
|
|
* @link https://stripe.com/docs/api/php#cancel_transfer |
108
|
|
|
* |
109
|
|
|
* @return self |
110
|
|
|
*/ |
111
|
|
|
public function cancel() |
112
|
|
|
{ |
113
|
|
|
list($response, $opts) = $this->request('post', $this->instanceUrl().'/cancel'); |
114
|
|
|
$this->refreshFrom($response, $opts); |
115
|
|
|
|
116
|
|
|
return $this; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Created transfer reversal. |
121
|
|
|
* |
122
|
|
|
* @param array|null $params |
123
|
|
|
* @param array|string|null $options |
124
|
|
|
* |
125
|
|
|
* @return \Arcanedev\Stripe\Resources\TransferReversal |
126
|
|
|
*/ |
127
|
|
|
public function reverse($params = [], $options = null) |
128
|
|
|
{ |
129
|
|
|
list($response, $opts) = $this->request( |
130
|
|
|
'post', $this->instanceUrl().'/reversals', $params, $options |
131
|
|
|
); |
132
|
|
|
$this->refreshFrom($response, $opts); |
133
|
|
|
|
134
|
|
|
return $this; |
|
|
|
|
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.