Customer.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * <code>Customer</code> objects allow you to perform recurring charges, and to
  6. * track multiple charges, that are associated with the same customer. The API
  7. * allows you to create, delete, and update your customers. You can retrieve
  8. * individual customers as well as a list of all your customers.
  9. *
  10. * Related guide: <a
  11. * href="https://stripe.com/docs/payments/save-during-payment">Save a card during
  12. * payment</a>.
  13. *
  14. * @property string $id Unique identifier for the object.
  15. * @property string $object String representing the object's type. Objects of the same type share the same value.
  16. * @property null|\Stripe\StripeObject $address The customer's address.
  17. * @property 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.
  18. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  19. * @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.
  20. * @property null|string|\Stripe\Account|\Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\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>
  21. * @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>
  22. * @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users.
  23. * @property null|\Stripe\Discount $discount Describes the current discount active on the customer, if there is one.
  24. * @property null|string $email The customer's email address.
  25. * @property null|string $invoice_prefix The prefix for the customer used to generate unique invoice numbers.
  26. * @property \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 \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 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 \Stripe\Collection $sources The customer's payment sources, if any.
  35. * @property \Stripe\Collection $subscriptions The customer's current subscriptions, if any.
  36. * @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>.
  37. * @property \Stripe\Collection $tax_ids The customer's tax IDs.
  38. */
  39. class Customer extends ApiResource
  40. {
  41. const OBJECT_NAME = 'customer';
  42. use ApiOperations\All;
  43. use ApiOperations\Create;
  44. use ApiOperations\Delete;
  45. use ApiOperations\NestedResource;
  46. use ApiOperations\Retrieve;
  47. use ApiOperations\Update;
  48. const TAX_EXEMPT_EXEMPT = 'exempt';
  49. const TAX_EXEMPT_NONE = 'none';
  50. const TAX_EXEMPT_REVERSE = 'reverse';
  51. public static function getSavedNestedResources()
  52. {
  53. static $savedNestedResources = null;
  54. if (null === $savedNestedResources) {
  55. $savedNestedResources = new Util\Set([
  56. 'source',
  57. ]);
  58. }
  59. return $savedNestedResources;
  60. }
  61. /**
  62. * @param null|array $params
  63. * @param null|array|string $opts
  64. *
  65. * @return \Stripe\Customer the updated customer
  66. */
  67. public function deleteDiscount($params = null, $opts = null)
  68. {
  69. $url = $this->instanceUrl() . '/discount';
  70. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  71. $this->refreshFrom(['discount' => null], $opts, true);
  72. }
  73. const PATH_BALANCE_TRANSACTIONS = '/balance_transactions';
  74. /**
  75. * @param string $id the ID of the customer on which to retrieve the customer balance transactions
  76. * @param null|array $params
  77. * @param null|array|string $opts
  78. *
  79. * @throws \Stripe\Exception\ApiErrorException if the request fails
  80. *
  81. * @return \Stripe\Collection the list of customer balance transactions
  82. */
  83. public static function allBalanceTransactions($id, $params = null, $opts = null)
  84. {
  85. return self::_allNestedResources($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
  86. }
  87. /**
  88. * @param string $id the ID of the customer on which to create the customer balance transaction
  89. * @param null|array $params
  90. * @param null|array|string $opts
  91. *
  92. * @throws \Stripe\Exception\ApiErrorException if the request fails
  93. *
  94. * @return \Stripe\CustomerBalanceTransaction
  95. */
  96. public static function createBalanceTransaction($id, $params = null, $opts = null)
  97. {
  98. return self::_createNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $params, $opts);
  99. }
  100. /**
  101. * @param string $id the ID of the customer to which the customer balance transaction belongs
  102. * @param string $balanceTransactionId the ID of the customer balance transaction to retrieve
  103. * @param null|array $params
  104. * @param null|array|string $opts
  105. *
  106. * @throws \Stripe\Exception\ApiErrorException if the request fails
  107. *
  108. * @return \Stripe\CustomerBalanceTransaction
  109. */
  110. public static function retrieveBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
  111. {
  112. return self::_retrieveNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
  113. }
  114. /**
  115. * @param string $id the ID of the customer to which the customer balance transaction belongs
  116. * @param string $balanceTransactionId the ID of the customer balance transaction to update
  117. * @param null|array $params
  118. * @param null|array|string $opts
  119. *
  120. * @throws \Stripe\Exception\ApiErrorException if the request fails
  121. *
  122. * @return \Stripe\CustomerBalanceTransaction
  123. */
  124. public static function updateBalanceTransaction($id, $balanceTransactionId, $params = null, $opts = null)
  125. {
  126. return self::_updateNestedResource($id, static::PATH_BALANCE_TRANSACTIONS, $balanceTransactionId, $params, $opts);
  127. }
  128. const PATH_SOURCES = '/sources';
  129. /**
  130. * @param string $id the ID of the customer on which to retrieve the payment sources
  131. * @param null|array $params
  132. * @param null|array|string $opts
  133. *
  134. * @throws \Stripe\Exception\ApiErrorException if the request fails
  135. *
  136. * @return \Stripe\Collection the list of payment sources (AlipayAccount, BankAccount, BitcoinReceiver, Card or Source)
  137. */
  138. public static function allSources($id, $params = null, $opts = null)
  139. {
  140. return self::_allNestedResources($id, static::PATH_SOURCES, $params, $opts);
  141. }
  142. /**
  143. * @param string $id the ID of the customer on which to create the payment source
  144. * @param null|array $params
  145. * @param null|array|string $opts
  146. *
  147. * @throws \Stripe\Exception\ApiErrorException if the request fails
  148. *
  149. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  150. */
  151. public static function createSource($id, $params = null, $opts = null)
  152. {
  153. return self::_createNestedResource($id, static::PATH_SOURCES, $params, $opts);
  154. }
  155. /**
  156. * @param string $id the ID of the customer to which the payment source belongs
  157. * @param string $sourceId the ID of the payment source to delete
  158. * @param null|array $params
  159. * @param null|array|string $opts
  160. *
  161. * @throws \Stripe\Exception\ApiErrorException if the request fails
  162. *
  163. * @return \Stripe\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  164. */
  165. public static function deleteSource($id, $sourceId, $params = null, $opts = null)
  166. {
  167. return self::_deleteNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  168. }
  169. /**
  170. * @param string $id the ID of the customer to which the payment source belongs
  171. * @param string $sourceId the ID of the payment source to retrieve
  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\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  178. */
  179. public static function retrieveSource($id, $sourceId, $params = null, $opts = null)
  180. {
  181. return self::_retrieveNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  182. }
  183. /**
  184. * @param string $id the ID of the customer to which the payment source belongs
  185. * @param string $sourceId the ID of the payment source to update
  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\AlipayAccount|\Stripe\BankAccount|\Stripe\BitcoinReceiver|\Stripe\Card|\Stripe\Source
  192. */
  193. public static function updateSource($id, $sourceId, $params = null, $opts = null)
  194. {
  195. return self::_updateNestedResource($id, static::PATH_SOURCES, $sourceId, $params, $opts);
  196. }
  197. const PATH_TAX_IDS = '/tax_ids';
  198. /**
  199. * @param string $id the ID of the customer on which to retrieve the tax ids
  200. * @param null|array $params
  201. * @param null|array|string $opts
  202. *
  203. * @throws \Stripe\Exception\ApiErrorException if the request fails
  204. *
  205. * @return \Stripe\Collection the list of tax ids
  206. */
  207. public static function allTaxIds($id, $params = null, $opts = null)
  208. {
  209. return self::_allNestedResources($id, static::PATH_TAX_IDS, $params, $opts);
  210. }
  211. /**
  212. * @param string $id the ID of the customer on which to create the tax id
  213. * @param null|array $params
  214. * @param null|array|string $opts
  215. *
  216. * @throws \Stripe\Exception\ApiErrorException if the request fails
  217. *
  218. * @return \Stripe\TaxId
  219. */
  220. public static function createTaxId($id, $params = null, $opts = null)
  221. {
  222. return self::_createNestedResource($id, static::PATH_TAX_IDS, $params, $opts);
  223. }
  224. /**
  225. * @param string $id the ID of the customer to which the tax id belongs
  226. * @param string $taxIdId the ID of the tax id to delete
  227. * @param null|array $params
  228. * @param null|array|string $opts
  229. *
  230. * @throws \Stripe\Exception\ApiErrorException if the request fails
  231. *
  232. * @return \Stripe\TaxId
  233. */
  234. public static function deleteTaxId($id, $taxIdId, $params = null, $opts = null)
  235. {
  236. return self::_deleteNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
  237. }
  238. /**
  239. * @param string $id the ID of the customer to which the tax id belongs
  240. * @param string $taxIdId the ID of the tax id to retrieve
  241. * @param null|array $params
  242. * @param null|array|string $opts
  243. *
  244. * @throws \Stripe\Exception\ApiErrorException if the request fails
  245. *
  246. * @return \Stripe\TaxId
  247. */
  248. public static function retrieveTaxId($id, $taxIdId, $params = null, $opts = null)
  249. {
  250. return self::_retrieveNestedResource($id, static::PATH_TAX_IDS, $taxIdId, $params, $opts);
  251. }
  252. }