PaymentMethodService.php 4.2 KB

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