PaymentMethod.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * PaymentMethod objects represent your customer's payment instruments.
  6. * You can use them with <a href="https://stripe.com/docs/payments/payment-intents">PaymentIntents</a> to collect payments or save them to
  7. * Customer objects to store instrument details for future payments.
  8. *
  9. * Related guides: <a href="https://stripe.com/docs/payments/payment-methods">Payment Methods</a> and <a href="https://stripe.com/docs/payments/more-payment-scenarios">More Payment Scenarios</a>.
  10. *
  11. * @property string $id Unique identifier for the object.
  12. * @property string $object String representing the object's type. Objects of the same type share the same value.
  13. * @property null|\Stripe\StripeObject $acss_debit
  14. * @property null|\Stripe\StripeObject $affirm
  15. * @property null|\Stripe\StripeObject $afterpay_clearpay
  16. * @property null|\Stripe\StripeObject $alipay
  17. * @property null|string $allow_redisplay This field indicates whether this payment method can be shown again to its customer in a checkout flow. Stripe products such as Checkout and Elements use this field to determine whether a payment method can be shown as a saved payment method in a checkout flow. The field defaults to “unspecified”.
  18. * @property null|\Stripe\StripeObject $amazon_pay
  19. * @property null|\Stripe\StripeObject $au_becs_debit
  20. * @property null|\Stripe\StripeObject $bacs_debit
  21. * @property null|\Stripe\StripeObject $bancontact
  22. * @property \Stripe\StripeObject $billing_details
  23. * @property null|\Stripe\StripeObject $blik
  24. * @property null|\Stripe\StripeObject $boleto
  25. * @property null|\Stripe\StripeObject $card
  26. * @property null|\Stripe\StripeObject $card_present
  27. * @property null|\Stripe\StripeObject $cashapp
  28. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  29. * @property null|string|\Stripe\Customer $customer The ID of the Customer to which this PaymentMethod is saved. This will not be set when the PaymentMethod has not been saved to a Customer.
  30. * @property null|\Stripe\StripeObject $customer_balance
  31. * @property null|\Stripe\StripeObject $eps
  32. * @property null|\Stripe\StripeObject $fpx
  33. * @property null|\Stripe\StripeObject $giropay
  34. * @property null|\Stripe\StripeObject $grabpay
  35. * @property null|\Stripe\StripeObject $ideal
  36. * @property null|\Stripe\StripeObject $interac_present
  37. * @property null|\Stripe\StripeObject $klarna
  38. * @property null|\Stripe\StripeObject $konbini
  39. * @property null|\Stripe\StripeObject $link
  40. * @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.
  41. * @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.
  42. * @property null|\Stripe\StripeObject $mobilepay
  43. * @property null|\Stripe\StripeObject $multibanco
  44. * @property null|\Stripe\StripeObject $oxxo
  45. * @property null|\Stripe\StripeObject $p24
  46. * @property null|\Stripe\StripeObject $paynow
  47. * @property null|\Stripe\StripeObject $paypal
  48. * @property null|\Stripe\StripeObject $pix
  49. * @property null|\Stripe\StripeObject $promptpay
  50. * @property null|\Stripe\StripeObject $radar_options Options to configure Radar. See <a href="https://stripe.com/docs/radar/radar-session">Radar Session</a> for more information.
  51. * @property null|\Stripe\StripeObject $revolut_pay
  52. * @property null|\Stripe\StripeObject $sepa_debit
  53. * @property null|\Stripe\StripeObject $sofort
  54. * @property null|\Stripe\StripeObject $swish
  55. * @property null|\Stripe\StripeObject $twint
  56. * @property string $type The type of the PaymentMethod. An additional hash is included on the PaymentMethod with a name matching this value. It contains additional information specific to the PaymentMethod type.
  57. * @property null|\Stripe\StripeObject $us_bank_account
  58. * @property null|\Stripe\StripeObject $wechat_pay
  59. * @property null|\Stripe\StripeObject $zip
  60. */
  61. class PaymentMethod extends ApiResource
  62. {
  63. const OBJECT_NAME = 'payment_method';
  64. use ApiOperations\Update;
  65. const ALLOW_REDISPLAY_ALWAYS = 'always';
  66. const ALLOW_REDISPLAY_LIMITED = 'limited';
  67. const ALLOW_REDISPLAY_UNSPECIFIED = 'unspecified';
  68. const TYPE_ACSS_DEBIT = 'acss_debit';
  69. const TYPE_AFFIRM = 'affirm';
  70. const TYPE_AFTERPAY_CLEARPAY = 'afterpay_clearpay';
  71. const TYPE_ALIPAY = 'alipay';
  72. const TYPE_AMAZON_PAY = 'amazon_pay';
  73. const TYPE_AU_BECS_DEBIT = 'au_becs_debit';
  74. const TYPE_BACS_DEBIT = 'bacs_debit';
  75. const TYPE_BANCONTACT = 'bancontact';
  76. const TYPE_BLIK = 'blik';
  77. const TYPE_BOLETO = 'boleto';
  78. const TYPE_CARD = 'card';
  79. const TYPE_CARD_PRESENT = 'card_present';
  80. const TYPE_CASHAPP = 'cashapp';
  81. const TYPE_CUSTOMER_BALANCE = 'customer_balance';
  82. const TYPE_EPS = 'eps';
  83. const TYPE_FPX = 'fpx';
  84. const TYPE_GIROPAY = 'giropay';
  85. const TYPE_GRABPAY = 'grabpay';
  86. const TYPE_IDEAL = 'ideal';
  87. const TYPE_INTERAC_PRESENT = 'interac_present';
  88. const TYPE_KLARNA = 'klarna';
  89. const TYPE_KONBINI = 'konbini';
  90. const TYPE_LINK = 'link';
  91. const TYPE_MOBILEPAY = 'mobilepay';
  92. const TYPE_MULTIBANCO = 'multibanco';
  93. const TYPE_OXXO = 'oxxo';
  94. const TYPE_P24 = 'p24';
  95. const TYPE_PAYNOW = 'paynow';
  96. const TYPE_PAYPAL = 'paypal';
  97. const TYPE_PIX = 'pix';
  98. const TYPE_PROMPTPAY = 'promptpay';
  99. const TYPE_REVOLUT_PAY = 'revolut_pay';
  100. const TYPE_SEPA_DEBIT = 'sepa_debit';
  101. const TYPE_SOFORT = 'sofort';
  102. const TYPE_SWISH = 'swish';
  103. const TYPE_TWINT = 'twint';
  104. const TYPE_US_BANK_ACCOUNT = 'us_bank_account';
  105. const TYPE_WECHAT_PAY = 'wechat_pay';
  106. const TYPE_ZIP = 'zip';
  107. /**
  108. * Creates a PaymentMethod object. Read the <a
  109. * href="/docs/stripe-js/reference#stripe-create-payment-method">Stripe.js
  110. * reference</a> to learn how to create PaymentMethods via Stripe.js.
  111. *
  112. * Instead of creating a PaymentMethod directly, we recommend using the <a
  113. * href="/docs/payments/accept-a-payment">PaymentIntents</a> API to accept a
  114. * payment immediately or the <a
  115. * href="/docs/payments/save-and-reuse">SetupIntent</a> API to collect payment
  116. * method details ahead of a future payment.
  117. *
  118. * @param null|array $params
  119. * @param null|array|string $options
  120. *
  121. * @throws \Stripe\Exception\ApiErrorException if the request fails
  122. *
  123. * @return \Stripe\PaymentMethod the created resource
  124. */
  125. public static function create($params = null, $options = null)
  126. {
  127. self::_validateParams($params);
  128. $url = static::classUrl();
  129. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  130. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  131. $obj->setLastResponse($response);
  132. return $obj;
  133. }
  134. /**
  135. * Returns a list of PaymentMethods for Treasury flows. If you want to list the
  136. * PaymentMethods attached to a Customer for payments, you should use the <a
  137. * href="/docs/api/payment_methods/customer_list">List a Customer’s
  138. * PaymentMethods</a> API instead.
  139. *
  140. * @param null|array $params
  141. * @param null|array|string $opts
  142. *
  143. * @throws \Stripe\Exception\ApiErrorException if the request fails
  144. *
  145. * @return \Stripe\Collection<\Stripe\PaymentMethod> of ApiResources
  146. */
  147. public static function all($params = null, $opts = null)
  148. {
  149. $url = static::classUrl();
  150. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  151. }
  152. /**
  153. * Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a
  154. * payment method attached to a Customer, you should use <a
  155. * href="/docs/api/payment_methods/customer">Retrieve a Customer’s
  156. * PaymentMethods</a>.
  157. *
  158. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  159. * @param null|array|string $opts
  160. *
  161. * @throws \Stripe\Exception\ApiErrorException if the request fails
  162. *
  163. * @return \Stripe\PaymentMethod
  164. */
  165. public static function retrieve($id, $opts = null)
  166. {
  167. $opts = \Stripe\Util\RequestOptions::parse($opts);
  168. $instance = new static($id, $opts);
  169. $instance->refresh();
  170. return $instance;
  171. }
  172. /**
  173. * Updates a PaymentMethod object. A PaymentMethod must be attached a customer to
  174. * be updated.
  175. *
  176. * @param string $id the ID of the resource to update
  177. * @param null|array $params
  178. * @param null|array|string $opts
  179. *
  180. * @throws \Stripe\Exception\ApiErrorException if the request fails
  181. *
  182. * @return \Stripe\PaymentMethod the updated resource
  183. */
  184. public static function update($id, $params = null, $opts = null)
  185. {
  186. self::_validateParams($params);
  187. $url = static::resourceUrl($id);
  188. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  189. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  190. $obj->setLastResponse($response);
  191. return $obj;
  192. }
  193. /**
  194. * @param null|array $params
  195. * @param null|array|string $opts
  196. *
  197. * @throws \Stripe\Exception\ApiErrorException if the request fails
  198. *
  199. * @return \Stripe\PaymentMethod the attached payment method
  200. */
  201. public function attach($params = null, $opts = null)
  202. {
  203. $url = $this->instanceUrl() . '/attach';
  204. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  205. $this->refreshFrom($response, $opts);
  206. return $this;
  207. }
  208. /**
  209. * @param null|array $params
  210. * @param null|array|string $opts
  211. *
  212. * @throws \Stripe\Exception\ApiErrorException if the request fails
  213. *
  214. * @return \Stripe\PaymentMethod the detached payment method
  215. */
  216. public function detach($params = null, $opts = null)
  217. {
  218. $url = $this->instanceUrl() . '/detach';
  219. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  220. $this->refreshFrom($response, $opts);
  221. return $this;
  222. }
  223. }