Source.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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.
  6. * They represent a customer's payment instrument, and can be used with the Stripe
  7. * API just like a <code>Card</code> object: once chargeable, they can be charged,
  8. * or can be attached to customers.
  9. *
  10. * Related guides: <a href="https://stripe.com/docs/sources">Sources API</a> and <a
  11. * href="https://stripe.com/docs/sources/customers">Sources &amp; Customers</a>.
  12. *
  13. * @property string $id Unique identifier for the object.
  14. * @property string $object String representing the object's type. Objects of the same type share the same value.
  15. * @property \Stripe\StripeObject $ach_credit_transfer
  16. * @property \Stripe\StripeObject $ach_debit
  17. * @property \Stripe\StripeObject $acss_debit
  18. * @property \Stripe\StripeObject $alipay
  19. * @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.
  20. * @property \Stripe\StripeObject $au_becs_debit
  21. * @property \Stripe\StripeObject $bancontact
  22. * @property \Stripe\StripeObject $card
  23. * @property \Stripe\StripeObject $card_present
  24. * @property string $client_secret The client secret of the source. Used for client-side retrieval using a publishable key.
  25. * @property \Stripe\StripeObject $code_verification
  26. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  27. * @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.
  28. * @property 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.
  29. * @property \Stripe\StripeObject $eps
  30. * @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>.
  31. * @property \Stripe\StripeObject $giropay
  32. * @property \Stripe\StripeObject $ideal
  33. * @property \Stripe\StripeObject $klarna
  34. * @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.
  35. * @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.
  36. * @property \Stripe\StripeObject $multibanco
  37. * @property null|\Stripe\StripeObject $owner Information about the owner of the payment instrument that may be used or required by particular source types.
  38. * @property \Stripe\StripeObject $p24
  39. * @property \Stripe\StripeObject $receiver
  40. * @property \Stripe\StripeObject $redirect
  41. * @property \Stripe\StripeObject $sepa_credit_transfer
  42. * @property \Stripe\StripeObject $sepa_debit
  43. * @property \Stripe\StripeObject $sofort
  44. * @property \Stripe\StripeObject $source_order
  45. * @property null|string $statement_descriptor Extra information about a source. This will appear on your customer's statement every time you charge the source.
  46. * @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.
  47. * @property \Stripe\StripeObject $three_d_secure
  48. * @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.
  49. * @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.
  50. * @property \Stripe\StripeObject $wechat
  51. */
  52. class Source extends ApiResource
  53. {
  54. const OBJECT_NAME = 'source';
  55. use ApiOperations\Create;
  56. use ApiOperations\Retrieve;
  57. use ApiOperations\Update;
  58. const FLOW_CODE_VERIFICATION = 'code_verification';
  59. const FLOW_NONE = 'none';
  60. const FLOW_RECEIVER = 'receiver';
  61. const FLOW_REDIRECT = 'redirect';
  62. const STATUS_CANCELED = 'canceled';
  63. const STATUS_CHARGEABLE = 'chargeable';
  64. const STATUS_CONSUMED = 'consumed';
  65. const STATUS_FAILED = 'failed';
  66. const STATUS_PENDING = 'pending';
  67. const USAGE_REUSABLE = 'reusable';
  68. const USAGE_SINGLE_USE = 'single_use';
  69. use ApiOperations\NestedResource;
  70. /**
  71. * @param null|array $params
  72. * @param null|array|string $opts
  73. *
  74. * @throws \Stripe\Exception\UnexpectedValueException if the source is not attached to a customer
  75. * @throws \Stripe\Exception\ApiErrorException if the request fails
  76. *
  77. * @return \Stripe\Source the detached source
  78. */
  79. public function detach($params = null, $opts = null)
  80. {
  81. self::_validateParams($params);
  82. $id = $this['id'];
  83. if (!$id) {
  84. $class = static::class;
  85. $msg = "Could not determine which URL to request: {$class} instance "
  86. . "has invalid ID: {$id}";
  87. throw new Exception\UnexpectedValueException($msg, null);
  88. }
  89. if ($this['customer']) {
  90. $base = Customer::classUrl();
  91. $parentExtn = \urlencode(Util\Util::utf8($this['customer']));
  92. $extn = \urlencode(Util\Util::utf8($id));
  93. $url = "{$base}/{$parentExtn}/sources/{$extn}";
  94. list($response, $opts) = $this->_request('delete', $url, $params, $opts);
  95. $this->refreshFrom($response, $opts);
  96. return $this;
  97. }
  98. $message = 'This source object does not appear to be currently attached '
  99. . 'to a customer object.';
  100. throw new Exception\UnexpectedValueException($message);
  101. }
  102. /**
  103. * @deprecated sourceTransactions is deprecated. Please use Source::allSourceTransactions instead.
  104. *
  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\Collection the list of source transactions
  111. */
  112. public function sourceTransactions($params = null, $opts = null)
  113. {
  114. $url = $this->instanceUrl() . '/source_transactions';
  115. list($response, $opts) = $this->_request('get', $url, $params, $opts);
  116. $obj = \Stripe\Util\Util::convertToStripeObject($response, $opts);
  117. $obj->setLastResponse($response);
  118. return $obj;
  119. }
  120. /**
  121. * @param string $id
  122. * @param null|array $params
  123. * @param null|array|string $opts
  124. *
  125. * @throws \Stripe\Exception\ApiErrorException if the request fails
  126. *
  127. * @return \Stripe\Collection the list of source transactions
  128. */
  129. public static function allSourceTransactions($id, $params = null, $opts = null)
  130. {
  131. return self::_allNestedResources($id, '/source_transactions', $params, $opts);
  132. }
  133. /**
  134. * @param null|array $params
  135. * @param null|array|string $opts
  136. *
  137. * @throws \Stripe\Exception\ApiErrorException if the request fails
  138. *
  139. * @return Source the verified source
  140. */
  141. public function verify($params = null, $opts = null)
  142. {
  143. $url = $this->instanceUrl() . '/verify';
  144. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  145. $this->refreshFrom($response, $opts);
  146. return $this;
  147. }
  148. }