• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stripe / stripe-php / #7087

pending completion
#7087

push

php-coveralls

pakrym-stripe
Bump version to 10.14.0-beta.2

1831 of 2732 relevant lines covered (67.02%)

3.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.97
/lib/Customer.php
1
<?php
2

3
// File generated from our OpenAPI spec
4

5
namespace Stripe;
6

7
/**
8
 * This object represents a customer of your business. It lets you create recurring charges and track payments that belong to the same customer.
9
 *
10
 * Related guide: <a href="https://stripe.com/docs/payments/save-during-payment">Save a card during payment</a>
11
 *
12
 * @property string $id Unique identifier for the object.
13
 * @property string $object String representing the object's type. Objects of the same type share the same value.
14
 * @property null|\Stripe\StripeObject $address The customer's address.
15
 * @property null|int $balance Current balance, if any, being stored on the customer. If negative, the customer has credit to apply to their next invoice. If positive, the customer has an amount owed that will be added to their next invoice. The balance does not refer to any unpaid invoices; it solely takes into account amounts that have yet to be successfully applied to any invoice. This balance is only taken into account as invoices are finalized.
16
 * @property null|\Stripe\CashBalance $cash_balance The current funds being held by Stripe on behalf of the customer. These funds can be applied towards payment intents with source &quot;cash_balance&quot;. The settings[reconciliation_mode] field describes whether these funds are applied to such payment intents manually or automatically.
17
 * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
18
 * @property null|string $currency Three-letter <a href="https://stripe.com/docs/currencies">ISO code for the currency</a> the customer can be charged in for recurring billing purposes.
19
 * @property null|string|\Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source $default_source <p>ID of the default payment source for the customer.</p><p>If you are using payment methods created via the PaymentMethods API, see the <a href="https://stripe.com/docs/api/customers/object#customer_object-invoice_settings-default_payment_method">invoice_settings.default_payment_method</a> field instead.</p>
20
 * @property null|bool $delinquent <p>When the customer's latest invoice is billed by charging automatically, <code>delinquent</code> is <code>true</code> if the invoice's latest charge failed. When the customer's latest invoice is billed by sending an invoice, <code>delinquent</code> is <code>true</code> if the invoice isn't paid by its due date.</p><p>If an invoice is marked uncollectible by <a href="https://stripe.com/docs/billing/automatic-collection">dunning</a>, <code>delinquent</code> doesn't get reset to <code>false</code>.</p>
21
 * @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users.
22
 * @property null|\Stripe\Discount $discount Describes the current discount active on the customer, if there is one.
23
 * @property null|string $email The customer's email address.
24
 * @property null|\Stripe\StripeObject $invoice_credit_balance The current multi-currency balances, if any, being stored on the customer. If positive in a currency, the customer has a credit to apply to their next invoice denominated in that currency. If negative, the customer has an amount owed that will be added to their next invoice denominated in that currency. These balances do not refer to any unpaid invoices. They solely track amounts that have yet to be successfully applied to any invoice. A balance in a particular currency is only applied to any invoice as an invoice in that currency is finalized.
25
 * @property null|string $invoice_prefix The prefix for the customer used to generate unique invoice numbers.
26
 * @property null|\Stripe\StripeObject $invoice_settings
27
 * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
28
 * @property null|\Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
29
 * @property null|string $name The customer's full name or business name.
30
 * @property null|int $next_invoice_sequence The suffix of the customer's next invoice number, e.g., 0001.
31
 * @property null|string $phone The customer's phone number.
32
 * @property null|string[] $preferred_locales The customer's preferred locales (languages), ordered by preference.
33
 * @property null|\Stripe\StripeObject $shipping Mailing and shipping address for the customer. Appears on invoices emailed to this customer.
34
 * @property null|\Stripe\Collection<\Stripe\Account|\Stripe\BankAccount|\Stripe\Card|\Stripe\Source> $sources The customer's payment sources, if any.
35
 * @property null|\Stripe\Collection<\Stripe\Subscription> $subscriptions The customer's current subscriptions, if any.
36
 * @property null|\Stripe\StripeObject $tax
37
 * @property null|string $tax_exempt Describes the customer's tax exemption status. One of <code>none</code>, <code>exempt</code>, or <code>reverse</code>. When set to <code>reverse</code>, invoice and receipt PDFs include the text <strong>&quot;Reverse charge&quot;</strong>.
38
 * @property null|\Stripe\Collection<\Stripe\TaxId> $tax_ids The customer's tax IDs.
39
 * @property null|string|\Stripe\TestHelpers\TestClock $test_clock ID of the test clock this customer belongs to.
40
 */
41
class Customer extends ApiResource
42
{
43
    const OBJECT_NAME = 'customer';
44

45
    use ApiOperations\All;
46
    use ApiOperations\Create;
47
    use ApiOperations\Delete;
48
    use ApiOperations\NestedResource;
49
    use ApiOperations\Retrieve;
50
    use ApiOperations\Search;
51
    use ApiOperations\Update;
52

53
    const TAX_EXEMPT_EXEMPT = 'exempt';
54
    const TAX_EXEMPT_NONE = 'none';
55
    const TAX_EXEMPT_REVERSE = 'reverse';
56

57
    public static function getSavedNestedResources()
58
    {
59
        static $savedNestedResources = null;
2✔
60
        if (null === $savedNestedResources) {
2✔
61
            $savedNestedResources = new Util\Set([
1✔
62
                'source',
1✔
63
            ]);
1✔
64
        }
65

66
        return $savedNestedResources;
2✔
67
    }
68

69
    /**
70
     * @param null|array $params
71
     * @param null|array|string $opts
72
     *
73
     * @return \Stripe\Customer the updated customer
74
     */
75
    public function deleteDiscount($params = null, $opts = null)
76
    {
77
        $url = $this->instanceUrl() . '/discount';
1✔
78
        list($response, $opts) = $this->_request('delete', $url, $params, $opts);
1✔
79
        $this->refreshFrom(['discount' => null], $opts, true);
1✔
80

81
        return $this;
1✔
82
    }
83

84
    /**
85
     * @param string $id
86
     * @param null|array $params
87
     * @param null|array|string $opts
88
     *
89
     * @throws \Stripe\Exception\ApiErrorException if the request fails
90
     *
91
     * @return \Stripe\Collection<\Stripe\PaymentMethod> list of PaymentMethods
92
     */
93
    public static function allPaymentMethods($id, $params = null, $opts = null)
94
    {
95
        $url = static::resourceUrl($id) . '/payment_methods';
×
96
        list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
×
97
        $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
×
98
        $obj->setLastResponse($response);
×
99

100
        return $obj;
×
101
    }
102

103
    /**
104
     * @param string $payment_method
105
     * @param null|array $params
106
     * @param null|array|string $opts
107
     *
108
     * @throws \Stripe\Exception\ApiErrorException if the request fails
109
     *
110
     * @return \Stripe\Customer the retrieved customer
111
     */
112
    public function retrievePaymentMethod($payment_method, $params = null, $opts = null)
113
    {
114
        $url = $this->instanceUrl() . '/payment_methods/' . $payment_method;
×
115
        list($response, $opts) = $this->_request('get', $url, $params, $opts);
×
116
        $obj = \Stripe\Util\Util::convertToStripeObject($response, $opts);
×
117
        $obj->setLastResponse($response);
×
118

119
        return $obj;
×
120
    }
121

122
    /**
123
     * @param null|array $params
124
     * @param null|array|string $opts
125
     *
126
     * @throws \Stripe\Exception\ApiErrorException if the request fails
127
     *
128
     * @return \Stripe\SearchResult<Customer> the customer search results
129
     */
130
    public static function search($params = null, $opts = null)
131
    {
132
        $url = '/v1/customers/search';
×
133

134
        return self::_searchResource($url, $params, $opts);
×
135
    }
136

137
    const PATH_CASH_BALANCE = '/cash_balance';
138

139
    /**
140
     * @param string $id the ID of the customer to which the cash balance belongs
141
     * @param null|array $params
142
     * @param null|array|string $opts
143
     * @param mixed $cashBalanceId
144
     *
145
     * @throws \Stripe\Exception\ApiErrorException if the request fails
146
     *
147
     * @return \Stripe\CashBalance
148
     */
149
    public static function retrieveCashBalance($id, $cashBalanceId, $params = null, $opts = null)
150
    {
151
        return self::_retrieveNestedResource($id, static::PATH_CASH_BALANCE, $params, $opts);
×
152
    }
153

154
    /**
155
     * @param string $id the ID of the customer to which the cash balance belongs
156
     * @param null|array $params
157
     * @param null|array|string $opts
158
     * @param mixed $cashBalanceId
159
     *
160
     * @throws \Stripe\Exception\ApiErrorException if the request fails
161
     *
162
     * @return \Stripe\CashBalance
163
     */
164
    public static function updateCashBalance($id, $cashBalanceId, $params = null, $opts = null)
165
    {
166
        return self::_updateNestedResource($id, static::PATH_CASH_BALANCE, $params, $opts);
×
167
    }
168
    const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';
169

170
    /**
171
     * @param string $id the ID of the customer on which to retrieve the customer balance transactions
172
     * @param null|array $params
173
     * @param null|array|string $opts
174
     *
175
     * @throws \Stripe\Exception\ApiErrorException if the request fails
176
     *
177
     * @return \Stripe\Collection<\Stripe\CustomerBalanceTransaction> the list of customer balance transactions
178
     */
179
    public static function allBalanceTransactions($id, $params = null, $opts = null)
180
    {
181
        return self::_allNestedResources($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
1✔
182
    }
183

184
    /**
185
     * @param string $id the ID of the customer on which to create the customer balance transaction
186
     * @param null|array $params
187
     * @param null|array|string $opts
188
     *
189
     * @throws \Stripe\Exception\ApiErrorException if the request fails
190
     *
191
     * @return \Stripe\CustomerBalanceTransaction
192
     */
193
    public static function createBalanceTransaction($id, $params = null, $opts = null)
194
    {
195
        return self::_createNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
1✔
196
    }
197

198
    /**
199
     * @param string $id the ID of the customer to which the customer balance transaction belongs
200
     * @param string $balanceTransactionId the ID of the customer balance transaction to retrieve
201
     * @param null|array $params
202
     * @param null|array|string $opts
203
     *
204
     * @throws \Stripe\Exception\ApiErrorException if the request fails
205
     *
206
     * @return \Stripe\CustomerBalanceTransaction
207
     */
208
    public static function retrieveBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
209
    {
210
        return self::_retrieveNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
1✔
211
    }
212

213
    /**
214
     * @param string $id the ID of the customer to which the customer balance transaction belongs
215
     * @param string $balanceTransactionId the ID of the customer balance transaction to update
216
     * @param null|array $params
217
     * @param null|array|string $opts
218
     *
219
     * @throws \Stripe\Exception\ApiErrorException if the request fails
220
     *
221
     * @return \Stripe\CustomerBalanceTransaction
222
     */
223
    public static function updateBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
224
    {
225
        return self::_updateNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
1✔
226
    }
227
    const PATH_CASH_BALANCE_TRANSACTIONS = '/cash_balance_transactions';
228

229
    /**
230
     * @param string $id the ID of the customer on which to retrieve the customer cash balance transactions
231
     * @param null|array $params
232
     * @param null|array|string $opts
233
     *
234
     * @throws \Stripe\Exception\ApiErrorException if the request fails
235
     *
236
     * @return \Stripe\Collection<\Stripe\CustomerCashBalanceTransaction> the list of customer cash balance transactions
237
     */
238
    public static function allCashBalanceTransactions($id, $params = null, $opts = null)
239
    {
240
        return self::_allNestedResources($id, static::PATH_CASH_BALANCE_TRANSACTIONS, $params, $opts);
×
241
    }
242

243
    /**
244
     * @param string $id the ID of the customer to which the customer cash balance transaction belongs
245
     * @param string $cashBalanceTransactionId the ID of the customer cash balance transaction to retrieve
246
     * @param null|array $params
247
     * @param null|array|string $opts
248
     *
249
     * @throws \Stripe\Exception\ApiErrorException if the request fails
250
     *
251
     * @return \Stripe\CustomerCashBalanceTransaction
252
     */
253
    public static function retrieveCashBalanceTransaction($id, $cashBalanceTransactionId, $params = null, $opts = null)
254
    {
255
        return self::_retrieveNestedResource($id, static::PATH_CASH_BALANCE_TRANSACTIONS, $cashBalanceTransactionId, $params, $opts);
×
256
    }
257
    const PATH_SOURCES = '/sources';
258

259
    /**
260
     * @param string $id the ID of the customer on which to retrieve the payment sources
261
     * @param null|array $params
262
     * @param null|array|string $opts
263
     *
264
     * @throws \Stripe\Exception\ApiErrorException if the request fails
265
     *
266
     * @return \Stripe\Collection<\Stripe\BankAccount|\Stripe\Card|\Stripe\Source> the list of payment sources (BankAccount, Card or Source)
267
     */
268
    public static function allSources($id, $params = null, $opts = null)
269
    {
270
        return self::_allNestedResources($id, static::PATH_SOURCES, $params, $opts);
1✔
271
    }
272

273
    /**
274
     * @param string $id the ID of the customer on which to create the payment source
275
     * @param null|array $params
276
     * @param null|array|string $opts
277
     *
278
     * @throws \Stripe\Exception\ApiErrorException if the request fails
279
     *
280
     * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
281
     */
282
    public static function createSource($id, $params = null, $opts = null)
283
    {
284
        return self::_createNestedResource($id, static::PATH_SOURCES, $params, $opts);
1✔
285
    }
286

287
    /**
288
     * @param string $id the ID of the customer to which the payment source belongs
289
     * @param string $sourceId the ID of the payment source to delete
290
     * @param null|array $params
291
     * @param null|array|string $opts
292
     *
293
     * @throws \Stripe\Exception\ApiErrorException if the request fails
294
     *
295
     * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
296
     */
297
    public static function deleteSource($id, $sourceId, $params = null, $opts = null)
298
    {
299
        return self::_deleteNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
1✔
300
    }
301

302
    /**
303
     * @param string $id the ID of the customer to which the payment source belongs
304
     * @param string $sourceId the ID of the payment source to retrieve
305
     * @param null|array $params
306
     * @param null|array|string $opts
307
     *
308
     * @throws \Stripe\Exception\ApiErrorException if the request fails
309
     *
310
     * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
311
     */
312
    public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
313
    {
314
        return self::_retrieveNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
1✔
315
    }
316

317
    /**
318
     * @param string $id the ID of the customer to which the payment source belongs
319
     * @param string $sourceId the ID of the payment source to update
320
     * @param null|array $params
321
     * @param null|array|string $opts
322
     *
323
     * @throws \Stripe\Exception\ApiErrorException if the request fails
324
     *
325
     * @return \Stripe\BankAccount|\Stripe\Card|\Stripe\Source
326
     */
327
    public static function updateSource($id, $sourceId, $params = null, $opts = null)
328
    {
329
        return self::_updateNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
1✔
330
    }
331
    const PATH_TAX_IDS = '/tax_ids';
332

333
    /**
334
     * @param string $id the ID of the customer on which to retrieve the tax ids
335
     * @param null|array $params
336
     * @param null|array|string $opts
337
     *
338
     * @throws \Stripe\Exception\ApiErrorException if the request fails
339
     *
340
     * @return \Stripe\Collection<\Stripe\TaxId> the list of tax ids
341
     */
342
    public static function allTaxIds($id, $params = null, $opts = null)
343
    {
344
        return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts);
1✔
345
    }
346

347
    /**
348
     * @param string $id the ID of the customer on which to create the tax id
349
     * @param null|array $params
350
     * @param null|array|string $opts
351
     *
352
     * @throws \Stripe\Exception\ApiErrorException if the request fails
353
     *
354
     * @return \Stripe\TaxId
355
     */
356
    public static function createTaxId($id, $params = null, $opts = null)
357
    {
358
        return self::_createNestedResource($id, static::PATH_TAX_IDS, $params, $opts);
1✔
359
    }
360

361
    /**
362
     * @param string $id the ID of the customer to which the tax id belongs
363
     * @param string $taxIdId the ID of the tax id to delete
364
     * @param null|array $params
365
     * @param null|array|string $opts
366
     *
367
     * @throws \Stripe\Exception\ApiErrorException if the request fails
368
     *
369
     * @return \Stripe\TaxId
370
     */
371
    public static function deleteTaxId($id, $taxIdId, $params = null, $opts = null)
372
    {
373
        return self::_deleteNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
1✔
374
    }
375

376
    /**
377
     * @param string $id the ID of the customer to which the tax id belongs
378
     * @param string $taxIdId the ID of the tax id to retrieve
379
     * @param null|array $params
380
     * @param null|array|string $opts
381
     *
382
     * @throws \Stripe\Exception\ApiErrorException if the request fails
383
     *
384
     * @return \Stripe\TaxId
385
     */
386
    public static function retrieveTaxId($id, $taxIdId, $params = null, $opts = null)
387
    {
388
        return self::_retrieveNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
1✔
389
    }
390
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc