PaymentMethodService.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. /**
  5. * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  6. * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  7. */
  8. class PaymentMethodService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of PaymentMethods for Treasury flows. If you want to list the
  12. * PaymentMethods attached to a Customer for payments, you should use the <a
  13. * href="/docs/api/payment_methods/customer_list">List a Customer’s
  14. * PaymentMethods</a> API instead.
  15. *
  16. * @param null|array $params
  17. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  18. *
  19. * @throws \Stripe\Exception\ApiErrorException if the request fails
  20. *
  21. * @return \Stripe\Collection<\Stripe\PaymentMethod>
  22. */
  23. public function all($params = null, $opts = null)
  24. {
  25. return $this->requestCollection('get', '/v1/payment_methods', $params, $opts);
  26. }
  27. /**
  28. * Attaches a PaymentMethod object to a Customer.
  29. *
  30. * To attach a new PaymentMethod to a customer for future payments, we recommend
  31. * you use a <a href="/docs/api/setup_intents">SetupIntent</a> or a PaymentIntent
  32. * with <a
  33. * href="/docs/api/payment_intents/create#create_payment_intent-setup_future_usage">setup_future_usage</a>.
  34. * These approaches will perform any necessary steps to set up the PaymentMethod
  35. * for future payments. Using the <code>/v1/payment_methods/:id/attach</code>
  36. * endpoint without first using a SetupIntent or PaymentIntent with
  37. * <code>setup_future_usage</code> does not optimize the PaymentMethod for future
  38. * use, which makes later declines and payment friction more likely. See <a
  39. * href="/docs/payments/payment-intents#future-usage">Optimizing cards for future
  40. * payments</a> for more information about setting up future payments.
  41. *
  42. * To use this PaymentMethod as the default for invoice or subscription payments,
  43. * set <a
  44. * href="/docs/api/customers/update#update_customer-invoice_settings-default_payment_method"><code>invoice_settings.default_payment_method</code></a>,
  45. * on the Customer to the PaymentMethod’s ID.
  46. *
  47. * @param string $id
  48. * @param null|array $params
  49. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  50. *
  51. * @throws \Stripe\Exception\ApiErrorException if the request fails
  52. *
  53. * @return \Stripe\PaymentMethod
  54. */
  55. public function attach($id, $params = null, $opts = null)
  56. {
  57. return $this->request('post', $this->buildPath('/v1/payment_methods/%s/attach', $id), $params, $opts);
  58. }
  59. /**
  60. * Creates a PaymentMethod object. Read the <a
  61. * href="/docs/stripe-js/reference#stripe-create-payment-method">Stripe.js
  62. * reference</a> to learn how to create PaymentMethods via Stripe.js.
  63. *
  64. * Instead of creating a PaymentMethod directly, we recommend using the <a
  65. * href="/docs/payments/accept-a-payment">PaymentIntents</a> API to accept a
  66. * payment immediately or the <a
  67. * href="/docs/payments/save-and-reuse">SetupIntent</a> API to collect payment
  68. * method details ahead of a future payment.
  69. *
  70. * @param null|array $params
  71. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  72. *
  73. * @throws \Stripe\Exception\ApiErrorException if the request fails
  74. *
  75. * @return \Stripe\PaymentMethod
  76. */
  77. public function create($params = null, $opts = null)
  78. {
  79. return $this->request('post', '/v1/payment_methods', $params, $opts);
  80. }
  81. /**
  82. * Detaches a PaymentMethod object from a Customer. After a PaymentMethod is
  83. * detached, it can no longer be used for a payment or re-attached to a Customer.
  84. *
  85. * @param string $id
  86. * @param null|array $params
  87. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  88. *
  89. * @throws \Stripe\Exception\ApiErrorException if the request fails
  90. *
  91. * @return \Stripe\PaymentMethod
  92. */
  93. public function detach($id, $params = null, $opts = null)
  94. {
  95. return $this->request('post', $this->buildPath('/v1/payment_methods/%s/detach', $id), $params, $opts);
  96. }
  97. /**
  98. * Retrieves a PaymentMethod object attached to the StripeAccount. To retrieve a
  99. * payment method attached to a Customer, you should use <a
  100. * href="/docs/api/payment_methods/customer">Retrieve a Customer’s
  101. * PaymentMethods</a>.
  102. *
  103. * @param string $id
  104. * @param null|array $params
  105. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  106. *
  107. * @throws \Stripe\Exception\ApiErrorException if the request fails
  108. *
  109. * @return \Stripe\PaymentMethod
  110. */
  111. public function retrieve($id, $params = null, $opts = null)
  112. {
  113. return $this->request('get', $this->buildPath('/v1/payment_methods/%s', $id), $params, $opts);
  114. }
  115. /**
  116. * Updates a PaymentMethod object. A PaymentMethod must be attached a customer to
  117. * be updated.
  118. *
  119. * @param string $id
  120. * @param null|array $params
  121. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  122. *
  123. * @throws \Stripe\Exception\ApiErrorException if the request fails
  124. *
  125. * @return \Stripe\PaymentMethod
  126. */
  127. public function update($id, $params = null, $opts = null)
  128. {
  129. return $this->request('post', $this->buildPath('/v1/payment_methods/%s', $id), $params, $opts);
  130. }
  131. }