9 * @property string $object
10 * @property int $account_balance
11 * @property string $business_vat_id
12 * @property string $created
13 * @property string $currency
14 * @property string $default_source
15 * @property bool $delinquent
16 * @property string $description
17 * @property Discount $discount
18 * @property string $email
19 * @property string $invoice_prefix
20 * @property bool $livemode
21 * @property StripeObject $metadata
22 * @property mixed $shipping
23 * @property Collection $sources
24 * @property Collection $subscriptions
28 class Customer
extends ApiResource
31 const OBJECT_NAME
= "customer";
33 use ApiOperations\All
;
34 use ApiOperations\Create
;
35 use ApiOperations\Delete
;
36 use ApiOperations\NestedResource
;
37 use ApiOperations\Retrieve
;
38 use ApiOperations\Update
;
40 public static function getSavedNestedResources()
42 static $savedNestedResources = null;
43 if ($savedNestedResources === null) {
44 $savedNestedResources = new Util\
Set([
48 return $savedNestedResources;
51 const PATH_SOURCES
= '/sources';
54 * @param array|null $params
56 * @return InvoiceItem The resulting invoice item.
58 public function addInvoiceItem($params = null)
60 $params = $params ?
: [];
61 $params['customer'] = $this->id
;
62 $ii = InvoiceItem
::create($params, $this->_opts
);
67 * @param array|null $params
69 * @return array An array of the customer's Invoices.
71 public function invoices($params = null)
73 $params = $params ?
: [];
74 $params['customer'] = $this->id
;
75 $invoices = Invoice
::all($params, $this->_opts
);
80 * @param array|null $params
82 * @return array An array of the customer's InvoiceItems.
84 public function invoiceItems($params = null)
86 $params = $params ?
: [];
87 $params['customer'] = $this->id
;
88 $iis = InvoiceItem
::all($params, $this->_opts
);
93 * @param array|null $params
95 * @return array An array of the customer's Charges.
97 public function charges($params = null)
99 $params = $params ?
: [];
100 $params['customer'] = $this->id
;
101 $charges = Charge
::all($params, $this->_opts
);
106 * @param array|null $params
108 * @return Subscription The updated subscription.
110 public function updateSubscription($params = null)
112 $url = $this->instanceUrl() . '/subscription';
113 list($response, $opts) = $this->_request('post', $url, $params);
114 $this->refreshFrom(['subscription' => $response], $opts, true);
115 return $this->subscription
;
119 * @param array|null $params
121 * @return Subscription The cancelled subscription.
123 public function cancelSubscription($params = null)
125 $url = $this->instanceUrl() . '/subscription';
126 list($response, $opts) = $this->_request('delete', $url, $params);
127 $this->refreshFrom(['subscription' => $response], $opts, true);
128 return $this->subscription
;
132 * @return Customer The updated customer.
134 public function deleteDiscount()
136 $url = $this->instanceUrl() . '/discount';
137 list($response, $opts) = $this->_request('delete', $url);
138 $this->refreshFrom(['discount' => null], $opts, true);
142 * @param array|null $id The ID of the customer on which to create the source.
143 * @param array|null $params
144 * @param array|string|null $opts
146 * @return ApiResource
148 public static function createSource($id, $params = null, $opts = null)
150 return self
::_createNestedResource($id, static::PATH_SOURCES
, $params, $opts);
154 * @param array|null $id The ID of the customer to which the source belongs.
155 * @param array|null $sourceId The ID of the source to retrieve.
156 * @param array|null $params
157 * @param array|string|null $opts
159 * @return ApiResource
161 public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
163 return self
::_retrieveNestedResource($id, static::PATH_SOURCES
, $sourceId, $params, $opts);
167 * @param array|null $id The ID of the customer to which the source belongs.
168 * @param array|null $sourceId The ID of the source to update.
169 * @param array|null $params
170 * @param array|string|null $opts
172 * @return ApiResource
174 public static function updateSource($id, $sourceId, $params = null, $opts = null)
176 return self
::_updateNestedResource($id, static::PATH_SOURCES
, $sourceId, $params, $opts);
180 * @param array|null $id The ID of the customer to which the source belongs.
181 * @param array|null $sourceId The ID of the source to delete.
182 * @param array|null $params
183 * @param array|string|null $opts
185 * @return ApiResource
187 public static function deleteSource($id, $sourceId, $params = null, $opts = null)
189 return self
::_deleteNestedResource($id, static::PATH_SOURCES
, $sourceId, $params, $opts);
193 * @param array|null $id The ID of the customer on which to retrieve the sources.
194 * @param array|null $params
195 * @param array|string|null $opts
197 * @return ApiResource
199 public static function allSources($id, $params = null, $opts = null)
201 return self
::_allNestedResources($id, static::PATH_SOURCES
, $params, $opts);