Source.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * <code>Source</code> objects allow you to accept a variety of payment methods. They
  6. * represent a customer's payment instrument, and can be used with the Stripe API
  7. * just like a <code>Card</code> object: once chargeable, they can be charged, or can be
  8. * attached to customers.
  9. *
  10. * Stripe doesn't recommend using the deprecated <a href="https://stripe.com/docs/api/sources">Sources API</a>.
  11. * We recommend that you adopt the <a href="https://stripe.com/docs/api/payment_methods">PaymentMethods API</a>.
  12. * This newer API provides access to our latest features and payment method types.
  13. *
  14. * Related guides: <a href="https://stripe.com/docs/sources">Sources API</a> and <a href="https://stripe.com/docs/sources/customers">Sources &amp; Customers</a>.
  15. *
  16. * @property string $id Unique identifier for the object.
  17. * @property string $object String representing the object's type. Objects of the same type share the same value.
  18. * @property null|\Stripe\StripeObject $ach_credit_transfer
  19. * @property null|\Stripe\StripeObject $ach_debit
  20. * @property null|\Stripe\StripeObject $acss_debit
  21. * @property null|\Stripe\StripeObject $alipay
  22. * @property null|int $amount A positive integer in the smallest currency unit (that is, 100 cents for $1.00, or 1 for ¥1, Japanese Yen being a zero-decimal currency) representing the total amount associated with the source. This is the amount for which the source will be chargeable once ready. Required for <code>single_use</code> sources.
  23. * @property null|\Stripe\StripeObject $au_becs_debit
  24. * @property null|\Stripe\StripeObject $bancontact
  25. * @property null|\Stripe\StripeObject $card
  26. * @property null|\Stripe\StripeObject $card_present
  27. * @property string $client_secret The client secret of the source. Used for client-side retrieval using a publishable key.
  28. * @property null|\Stripe\StripeObject $code_verification
  29. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  30. * @property null|string $currency Three-letter <a href="https://stripe.com/docs/currencies">ISO code for the currency</a> associated with the source. This is the currency for which the source will be chargeable once ready. Required for <code>single_use</code> sources.
  31. * @property null|string $customer The ID of the customer to which this source is attached. This will not be present when the source has not been attached to a customer.
  32. * @property null|\Stripe\StripeObject $eps
  33. * @property string $flow The authentication <code>flow</code> of the source. <code>flow</code> is one of <code>redirect</code>, <code>receiver</code>, <code>code_verification</code>, <code>none</code>.
  34. * @property null|\Stripe\StripeObject $giropay
  35. * @property null|\Stripe\StripeObject $ideal
  36. * @property null|\Stripe\StripeObject $klarna
  37. * @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.
  38. * @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.
  39. * @property null|\Stripe\StripeObject $multibanco
  40. * @property null|\Stripe\StripeObject $owner Information about the owner of the payment instrument that may be used or required by particular source types.
  41. * @property null|\Stripe\StripeObject $p24
  42. * @property null|\Stripe\StripeObject $receiver
  43. * @property null|\Stripe\StripeObject $redirect
  44. * @property null|\Stripe\StripeObject $sepa_credit_transfer
  45. * @property null|\Stripe\StripeObject $sepa_debit
  46. * @property null|\Stripe\StripeObject $sofort
  47. * @property null|\Stripe\StripeObject $source_order
  48. * @property null|string $statement_descriptor Extra information about a source. This will appear on your customer's statement every time you charge the source.
  49. * @property string $status The status of the source, one of <code>canceled</code>, <code>chargeable</code>, <code>consumed</code>, <code>failed</code>, or <code>pending</code>. Only <code>chargeable</code> sources can be used to create a charge.
  50. * @property null|\Stripe\StripeObject $three_d_secure
  51. * @property string $type The <code>type</code> of the source. The <code>type</code> is a payment method, one of <code>ach_credit_transfer</code>, <code>ach_debit</code>, <code>alipay</code>, <code>bancontact</code>, <code>card</code>, <code>card_present</code>, <code>eps</code>, <code>giropay</code>, <code>ideal</code>, <code>multibanco</code>, <code>klarna</code>, <code>p24</code>, <code>sepa_debit</code>, <code>sofort</code>, <code>three_d_secure</code>, or <code>wechat</code>. An additional hash is included on the source with a name matching this value. It contains additional information specific to the <a href="https://stripe.com/docs/sources">payment method</a> used.
  52. * @property null|string $usage Either <code>reusable</code> or <code>single_use</code>. Whether this source should be reusable or not. Some source types may or may not be reusable by construction, while others may leave the option at creation. If an incompatible value is passed, an error will be returned.
  53. * @property null|\Stripe\StripeObject $wechat
  54. */
  55. class Source extends ApiResource
  56. {
  57. const OBJECT_NAME = 'source';
  58. use ApiOperations\Update;
  59. const FLOW_CODE_VERIFICATION = 'code_verification';
  60. const FLOW_NONE = 'none';
  61. const FLOW_RECEIVER = 'receiver';
  62. const FLOW_REDIRECT = 'redirect';
  63. const STATUS_CANCELED = 'canceled';
  64. const STATUS_CHARGEABLE = 'chargeable';
  65. const STATUS_CONSUMED = 'consumed';
  66. const STATUS_FAILED = 'failed';
  67. const STATUS_PENDING = 'pending';
  68. const TYPE_ACH_CREDIT_TRANSFER = 'ach_credit_transfer';
  69. const TYPE_ACH_DEBIT = 'ach_debit';
  70. const TYPE_ACSS_DEBIT = 'acss_debit';
  71. const TYPE_ALIPAY = 'alipay';
  72. const TYPE_AU_BECS_DEBIT = 'au_becs_debit';
  73. const TYPE_BANCONTACT = 'bancontact';
  74. const TYPE_CARD = 'card';
  75. const TYPE_CARD_PRESENT = 'card_present';
  76. const TYPE_EPS = 'eps';
  77. const TYPE_GIROPAY = 'giropay';
  78. const TYPE_IDEAL = 'ideal';
  79. const TYPE_KLARNA = 'klarna';
  80. const TYPE_MULTIBANCO = 'multibanco';
  81. const TYPE_P24 = 'p24';
  82. const TYPE_SEPA_CREDIT_TRANSFER = 'sepa_credit_transfer';
  83. const TYPE_SEPA_DEBIT = 'sepa_debit';
  84. const TYPE_SOFORT = 'sofort';
  85. const TYPE_THREE_D_SECURE = 'three_d_secure';
  86. const TYPE_WECHAT = 'wechat';
  87. const USAGE_REUSABLE = 'reusable';
  88. const USAGE_SINGLE_USE = 'single_use';
  89. /**
  90. * Creates a new source object.
  91. *
  92. * @param null|array $params
  93. * @param null|array|string $options
  94. *
  95. * @throws \Stripe\Exception\ApiErrorException if the request fails
  96. *
  97. * @return \Stripe\Source the created resource
  98. */
  99. public static function create($params = null, $options = null)
  100. {
  101. self::_validateParams($params);
  102. $url = static::classUrl();
  103. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  104. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  105. $obj->setLastResponse($response);
  106. return $obj;
  107. }
  108. /**
  109. * Retrieves an existing source object. Supply the unique source ID from a source
  110. * creation request and Stripe will return the corresponding up-to-date source
  111. * object information.
  112. *
  113. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  114. * @param null|array|string $opts
  115. *
  116. * @throws \Stripe\Exception\ApiErrorException if the request fails
  117. *
  118. * @return \Stripe\Source
  119. */
  120. public static function retrieve($id, $opts = null)
  121. {
  122. $opts = \Stripe\Util\RequestOptions::parse($opts);
  123. $instance = new static($id, $opts);
  124. $instance->refresh();
  125. return $instance;
  126. }
  127. /**
  128. * Updates the specified source by setting the values of the parameters passed. Any
  129. * parameters not provided will be left unchanged.
  130. *
  131. * This request accepts the <code>metadata</code> and <code>owner</code> as
  132. * arguments. It is also possible to update type specific information for selected
  133. * payment methods. Please refer to our <a href="/docs/sources">payment method
  134. * guides</a> for more detail.
  135. *
  136. * @param string $id the ID of the resource to update
  137. * @param null|array $params
  138. * @param null|array|string $opts
  139. *
  140. * @throws \Stripe\Exception\ApiErrorException if the request fails
  141. *
  142. * @return \Stripe\Source the updated resource
  143. */
  144. public static function update($id, $params = null, $opts = null)
  145. {
  146. self::_validateParams($params);
  147. $url = static::resourceUrl($id);
  148. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  149. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  150. $obj->setLastResponse($response);
  151. return $obj;
  152. }
  153. use ApiOperations\NestedResource;
  154. /**
  155. * @param null|array $params
  156. * @param null|array|string $opts
  157. *
  158. * @throws \Stripe\Exception\UnexpectedValueException if the source is not attached to a customer
  159. * @throws \Stripe\Exception\ApiErrorException if the request fails
  160. *
  161. * @return \Stripe\Source the detached source
  162. */
  163. public function detach($params = null, $opts = null)
  164. {
  165. self::_validateParams($params);
  166. $id = $this['id'];
  167. if (!$id) {
  168. $class = static::class;
  169. $msg = "Could not determine which URL to request: {$class} instance "
  170. . "has invalid ID: {$id}";
  171. throw new Exception\UnexpectedValueException($msg, null);
  172. }
  173. if ($this['customer']) {
  174. $base = Customer::classUrl();
  175. $parentExtn = \urlencode(Util\Util::utf8($this['customer']));
  176. $extn = \urlencode(Util\Util::utf8($id));
  177. $url = "{$base}/{$parentExtn}/sources/{$extn}";
  178. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  179. $this->refreshFrom($response, $opts);
  180. return $this;
  181. }
  182. $message = 'This source object does not appear to be currently attached '
  183. . 'to a customer object.';
  184. throw new Exception\UnexpectedValueException($message);
  185. }
  186. /**
  187. * @param string $id
  188. * @param null|array $params
  189. * @param null|array|string $opts
  190. *
  191. * @throws \Stripe\Exception\ApiErrorException if the request fails
  192. *
  193. * @return \Stripe\Collection<\Stripe\SourceTransaction> list of source transactions
  194. */
  195. public static function allSourceTransactions($id, $params = null, $opts = null)
  196. {
  197. $url = static::resourceUrl($id) . '/source_transactions';
  198. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  199. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  200. $obj->setLastResponse($response);
  201. return $obj;
  202. }
  203. /**
  204. * @param null|array $params
  205. * @param null|array|string $opts
  206. *
  207. * @throws \Stripe\Exception\ApiErrorException if the request fails
  208. *
  209. * @return \Stripe\Source the verified source
  210. */
  211. public function verify($params = null, $opts = null)
  212. {
  213. $url = $this->instanceUrl() . '/verify';
  214. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  215. $this->refreshFrom($response, $opts);
  216. return $this;
  217. }
  218. }