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

Account::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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 2
cts 2
cp 1
crap 1
rs 10
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\AccountInterface;
4
use Arcanedev\Stripe\StripeResource;
5
6
/**
7
 * Class     Account
8
 *
9
 * @package  Arcanedev\Stripe\Resources
10
 * @author   ARCANEDEV <[email protected]>
11
 * @link     https://stripe.com/docs/api/php#account_object
12
 *
13
 * @property  null                              id
14
 * @property  string                            object                   // 'account'
15
 * @property  string|null                       business_logo
16
 * @property  string                            business_name
17
 * @property  string|null                       business_url
18
 * @property  bool                              charges_enabled
19
 * @property  string                            country
20
 * @property  bool                              debit_negative_balances  // managed accounts only
21
 * @property  \Arcanedev\Stripe\StripeObject    decline_charge_on
22
 * @property  string                            default_currency
23
 * @property  bool                              details_submitted
24
 * @property  string                            display_name
25
 * @property  string                            email
26
 * @property  \Arcanedev\Stripe\Collection      external_accounts        // managed accounts only
27
 * @property  \Arcanedev\Stripe\AttachedObject  legal_entity             // managed accounts only
28
 * @property  bool                              managed
29
 * @property  string|null                       product_description      // managed accounts only
30
 * @property  string|null                       statement_descriptor
31
 * @property  string|null                       support_email
32
 * @property  string|null                       support_phone
33
 * @property  string|null                       support_url
34
 * @property  string                            timezone
35
 * @property  \Arcanedev\Stripe\AttachedObject  tos_acceptance           // managed accounts only
36
 * @property  \Arcanedev\Stripe\AttachedObject  transfer_schedule        // managed accounts only
37
 * @property  bool                              transfers_enabled
38
 * @property  \Arcanedev\Stripe\AttachedObject  verification
39
 */
40
class Account extends StripeResource implements AccountInterface
41
{
42
    /* ------------------------------------------------------------------------------------------------
43
     |  Main Functions
44
     | ------------------------------------------------------------------------------------------------
45
     */
46
    /**
47
     * Get the instance url.
48
     *
49
     * @return string
50
     */
51 35
    public function instanceUrl()
52
    {
53 35
        return is_null($this['id']) ? '/v1/account' : parent::instanceUrl();
54
    }
55
56
    /* ------------------------------------------------------------------------------------------------
57
     |  CRUD Functions
58
     | ------------------------------------------------------------------------------------------------
59
     */
60
    /**
61
     * Retrieve an Account.
62
     * @link   https://stripe.com/docs/api/php#retrieve_account
63
     *
64
     * @param  string|null        $id
65
     * @param  array|string|null  $options
66
     *
67
     * @return self
68
     */
69 15
    public static function retrieve($id = null, $options = null)
70
    {
71
        if (
72 15
            ! $options &&
73 15
            is_string($id) &&
74 11
            substr($id, 0, 3) === 'sk_'
75 12
        ) {
76
            $options = $id;
77
            $id      = null;
78
        }
79
80 15
        return self::scopedRetrieve($id, $options);
81
    }
82
83
    /**
84
     * Create an Account.
85
     * @link   https://stripe.com/docs/api/php#create_account
86
     *
87
     * @param  array|null         $params
88
     * @param  array|string|null  $options
89
     *
90
     * @return self
91
     */
92 35
    public static function create($params = [], $options = null)
93
    {
94 35
        return self::scopedCreate($params, $options);
95
    }
96
97
    /**
98
     * Update an Account.
99
     * @link   https://stripe.com/docs/api/php#update_account
100
     * 
101
     * @param  string             $id
102
     * @param  array|null         $params
103
     * @param  array|string|null  $options
104
     *
105
     * @return self
106
     */
107 5
    public static function update($id, $params = [], $options = null)
108
    {
109 5
        return self::scopedUpdate($id, $params, $options);
110
    }
111
112
    /**
113
     * Save an Account.
114
     * @link   https://stripe.com/docs/api/php#update_account
115
     *
116
     * @param  array|string|null  $options
117
     *
118
     * @return self
119
     */
120 10
    public function save($options = null)
121
    {
122 10
        return $this->scopedSave($options);
123
    }
124
125
    /**
126
     * Get all Accounts.
127
     * @link   https://stripe.com/docs/api/php#list_accounts
128
     *
129
     * @param  array|null         $params
130
     * @param  array|string|null  $options
131
     *
132
     * @return \Arcanedev\Stripe\Collection|array
133
     */
134
    public static function all($params = [], $options = null)
135
    {
136
        return self::scopedAll($params, $options);
137
    }
138
139
    /**
140
     * Delete an Account.
141
     * @link   https://stripe.com/docs/api/php#delete_account
142
     *
143
     * @param  array|null         $params
144
     * @param  array|string|null  $options
145
     *
146
     * @return self
147
     */
148 5
    public function delete($params = [], $options = null)
149
    {
150 5
        return $this->scopedDelete($params, $options);
151
    }
152
153
    /**
154
     * Reject an Account.
155
     * @link   https://stripe.com/docs/api/php#reject_account
156
     *
157
     * @param  array|null         $params
158
     * @param  array|string|null  $options
159
     *
160
     * @return self
161
     */
162 5
    public function reject($params = [], $options = null)
163
    {
164 5
        return $this->scopedPostCall(
165 5
            $this->instanceUrl() . '/reject', $params, $options
166 4
        );
167
    }
168
}
169