PaymentMethodService.php 4.7 KB

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