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

Transfer::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
cc 1
eloc 2
nc 1
nop 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\TransferInterface;
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                                   application_fee
18
 * @property  string                                   balance_transaction
19
 * @property  int                                      created               // timestamp
20
 * @property  string                                   currency
21
 * @property  int                                      date                  // timestamp
22
 * @property  string                                   description
23
 * @property  string                                   destination
24
 * @property  string                                   destination_payment
25
 * @property  string                                   failure_code
26
 * @property  string                                   failure_message
27
 * @property  bool                                     livemode
28
 * @property  \Arcanedev\Stripe\AttachedObject         metadata
29
 * @property  \Arcanedev\Stripe\Collection             reversals
30
 * @property  bool                                     reversed
31
 * @property  string                                   source_transaction
32
 * @property  string                                   source_type           // 'card', 'bank_account', 'bitcoin_receiver', or 'alipay_account'
33
 * @property  string                                   statement_descriptor
34
 * @property  string                                   status                // 'paid', 'pending', 'in_transit', 'canceled' or 'failed'
35
 * @property  string                                   type                  //  'card', 'bank_account', or 'stripe_account'
36
 */
37
class Transfer extends StripeResource implements TransferInterface
38
{
39
    /* ------------------------------------------------------------------------------------------------
40
     |  CRUD Functions
41
     | ------------------------------------------------------------------------------------------------
42
     */
43
    /**
44
     * List all Transfers.
45
     * @link   https://stripe.com/docs/api/php#list_transfers
46
     *
47
     * @param  array|null         $params
48
     * @param  array|string|null  $options
49
     *
50
     * @return \Arcanedev\Stripe\Collection|array
51
     */
52 10
    public static function all($params = [], $options = null)
53
    {
54 10
        return self::scopedAll($params, $options);
55
    }
56
57
    /**
58
     * Retrieve a Transfer.
59
     * @link   https://stripe.com/docs/api/php#retrieve_transfer
60
     *
61
     * @param  string             $id
62
     * @param  array|string|null  $options
63
     *
64
     * @return self
65
     */
66 20
    public static function retrieve($id, $options = null)
67
    {
68 20
        return self::scopedRetrieve($id, $options);
69
    }
70
71
    /**
72
     * Create a transfer.
73
     * @link   https://stripe.com/docs/api/php#create_transfer
74
     *
75
     * @param  array|null         $params
76
     * @param  array|string|null  $options
77
     *
78
     * @return self|array
79
     */
80 30
    public static function create($params = [], $options = null)
81
    {
82 30
        return self::scopedCreate($params, $options);
83
    }
84
85
    /**
86
     * Update a Transfer.
87
     * @link   https://stripe.com/docs/api/php#update_transfer
88
     *
89
     * @param  string             $id
90
     * @param  array|null         $params
91
     * @param  array|string|null  $options
92
     *
93
     * @return self
94
     */
95
    public static function update($id, $params = [], $options = null)
96
    {
97
        return self::scopedUpdate($id, $params, $options);
98
    }
99
100
    /**
101
     * Update/Save a Transfer.
102
     * @link   https://stripe.com/docs/api/php#update_transfer
103
     *
104
     * @param  array|string|null  $options
105
     *
106
     * @return self
107
     */
108 10
    public function save($options = null)
109
    {
110 10
        return self::scopedSave($options);
111
    }
112
113
    /**
114
     * Cancel a Transfer.
115
     * @link   https://stripe.com/docs/api/php#cancel_transfer
116
     *
117
     * @return self
118
     */
119
    public function cancel()
120
    {
121
        list($response, $opts) = $this->request('post', $this->instanceUrl() . '/cancel');
122
        $this->refreshFrom($response, $opts);
123
124
        return $this;
125
    }
126
127
    /**
128
     * Created transfer reversal.
129
     *
130
     * @param  array|null         $params
131
     * @param  array|string|null  $options
132
     *
133
     * @return \Arcanedev\Stripe\Resources\TransferReversal
134
     */
135
    public function reverse($params = [], $options = null)
136
    {
137
        list($response, $options) = $this->request(
138
            'post', $this->instanceUrl() . '/reversals', $params, $options
139
        );
140
        $this->refreshFrom($response, $options);
141
142
        return $this;
143
    }
144
}
145