PaymentIntentService.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 PaymentIntentService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of PaymentIntents.
  12. *
  13. * @param null|array $params
  14. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  15. *
  16. * @throws \Stripe\Exception\ApiErrorException if the request fails
  17. *
  18. * @return \Stripe\Collection<\Stripe\PaymentIntent>
  19. */
  20. public function all($params = null, $opts = null)
  21. {
  22. return $this->requestCollection('get', '/v1/payment_intents', $params, $opts);
  23. }
  24. /**
  25. * Manually reconcile the remaining amount for a <code>customer_balance</code>
  26. * PaymentIntent.
  27. *
  28. * @param string $id
  29. * @param null|array $params
  30. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  31. *
  32. * @throws \Stripe\Exception\ApiErrorException if the request fails
  33. *
  34. * @return \Stripe\PaymentIntent
  35. */
  36. public function applyCustomerBalance($id, $params = null, $opts = null)
  37. {
  38. return $this->request('post', $this->buildPath('/v1/payment_intents/%s/apply_customer_balance', $id), $params, $opts);
  39. }
  40. /**
  41. * You can cancel a PaymentIntent object when it’s in one of these statuses:
  42. * <code>requires_payment_method</code>, <code>requires_capture</code>,
  43. * <code>requires_confirmation</code>, <code>requires_action</code> or, <a
  44. * href="/docs/payments/intents">in rare cases</a>, <code>processing</code>.
  45. *
  46. * After it’s canceled, no additional charges are made by the PaymentIntent and any
  47. * operations on the PaymentIntent fail with an error. For PaymentIntents with a
  48. * <code>status</code> of <code>requires_capture</code>, the remaining
  49. * <code>amount_capturable</code> is automatically refunded.
  50. *
  51. * You can’t cancel the PaymentIntent for a Checkout Session. <a
  52. * href="/docs/api/checkout/sessions/expire">Expire the Checkout Session</a>
  53. * instead.
  54. *
  55. * @param string $id
  56. * @param null|array $params
  57. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  58. *
  59. * @throws \Stripe\Exception\ApiErrorException if the request fails
  60. *
  61. * @return \Stripe\PaymentIntent
  62. */
  63. public function cancel($id, $params = null, $opts = null)
  64. {
  65. return $this->request('post', $this->buildPath('/v1/payment_intents/%s/cancel', $id), $params, $opts);
  66. }
  67. /**
  68. * Capture the funds of an existing uncaptured PaymentIntent when its status is
  69. * <code>requires_capture</code>.
  70. *
  71. * Uncaptured PaymentIntents are cancelled a set number of days (7 by default)
  72. * after their creation.
  73. *
  74. * Learn more about <a href="/docs/payments/capture-later">separate authorization
  75. * and capture</a>.
  76. *
  77. * @param string $id
  78. * @param null|array $params
  79. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  80. *
  81. * @throws \Stripe\Exception\ApiErrorException if the request fails
  82. *
  83. * @return \Stripe\PaymentIntent
  84. */
  85. public function capture($id, $params = null, $opts = null)
  86. {
  87. return $this->request('post', $this->buildPath('/v1/payment_intents/%s/capture', $id), $params, $opts);
  88. }
  89. /**
  90. * Confirm that your customer intends to pay with current or provided payment
  91. * method. Upon confirmation, the PaymentIntent will attempt to initiate a payment.
  92. * If the selected payment method requires additional authentication steps, the
  93. * PaymentIntent will transition to the <code>requires_action</code> status and
  94. * suggest additional actions via <code>next_action</code>. If payment fails, the
  95. * PaymentIntent transitions to the <code>requires_payment_method</code> status or
  96. * the <code>canceled</code> status if the confirmation limit is reached. If
  97. * payment succeeds, the PaymentIntent will transition to the
  98. * <code>succeeded</code> status (or <code>requires_capture</code>, if
  99. * <code>capture_method</code> is set to <code>manual</code>). If the
  100. * <code>confirmation_method</code> is <code>automatic</code>, payment may be
  101. * attempted using our <a
  102. * href="/docs/stripe-js/reference#stripe-handle-card-payment">client SDKs</a> and
  103. * the PaymentIntent’s <a
  104. * href="#payment_intent_object-client_secret">client_secret</a>. After
  105. * <code>next_action</code>s are handled by the client, no additional confirmation
  106. * is required to complete the payment. If the <code>confirmation_method</code> is
  107. * <code>manual</code>, all payment attempts must be initiated using a secret key.
  108. * If any actions are required for the payment, the PaymentIntent will return to
  109. * the <code>requires_confirmation</code> state after those actions are completed.
  110. * Your server needs to then explicitly re-confirm the PaymentIntent to initiate
  111. * the next payment attempt.
  112. *
  113. * @param string $id
  114. * @param null|array $params
  115. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  116. *
  117. * @throws \Stripe\Exception\ApiErrorException if the request fails
  118. *
  119. * @return \Stripe\PaymentIntent
  120. */
  121. public function confirm($id, $params = null, $opts = null)
  122. {
  123. return $this->request('post', $this->buildPath('/v1/payment_intents/%s/confirm', $id), $params, $opts);
  124. }
  125. /**
  126. * Creates a PaymentIntent object.
  127. *
  128. * After the PaymentIntent is created, attach a payment method and <a
  129. * href="/docs/api/payment_intents/confirm">confirm</a> to continue the payment.
  130. * Learn more about <a href="/docs/payments/payment-intents">the available payment
  131. * flows with the Payment Intents API</a>.
  132. *
  133. * When you use <code>confirm=true</code> during creation, it’s equivalent to
  134. * creating and confirming the PaymentIntent in the same call. You can use any
  135. * parameters available in the <a href="/docs/api/payment_intents/confirm">confirm
  136. * API</a> when you supply <code>confirm=true</code>.
  137. *
  138. * @param null|array $params
  139. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  140. *
  141. * @throws \Stripe\Exception\ApiErrorException if the request fails
  142. *
  143. * @return \Stripe\PaymentIntent
  144. */
  145. public function create($params = null, $opts = null)
  146. {
  147. return $this->request('post', '/v1/payment_intents', $params, $opts);
  148. }
  149. /**
  150. * Perform an incremental authorization on an eligible <a
  151. * href="/docs/api/payment_intents/object">PaymentIntent</a>. To be eligible, the
  152. * PaymentIntent’s status must be <code>requires_capture</code> and <a
  153. * href="/docs/api/charges/object#charge_object-payment_method_details-card_present-incremental_authorization_supported">incremental_authorization_supported</a>
  154. * must be <code>true</code>.
  155. *
  156. * Incremental authorizations attempt to increase the authorized amount on your
  157. * customer’s card to the new, higher <code>amount</code> provided. Similar to the
  158. * initial authorization, incremental authorizations can be declined. A single
  159. * PaymentIntent can call this endpoint multiple times to further increase the
  160. * authorized amount.
  161. *
  162. * If the incremental authorization succeeds, the PaymentIntent object returns with
  163. * the updated <a
  164. * href="/docs/api/payment_intents/object#payment_intent_object-amount">amount</a>.
  165. * If the incremental authorization fails, a <a
  166. * href="/docs/error-codes#card-declined">card_declined</a> error returns, and no
  167. * other fields on the PaymentIntent or Charge update. The PaymentIntent object
  168. * remains capturable for the previously authorized amount.
  169. *
  170. * Each PaymentIntent can have a maximum of 10 incremental authorization attempts,
  171. * including declines. After it’s captured, a PaymentIntent can no longer be
  172. * incremented.
  173. *
  174. * Learn more about <a
  175. * href="/docs/terminal/features/incremental-authorizations">incremental
  176. * authorizations</a>.
  177. *
  178. * @param string $id
  179. * @param null|array $params
  180. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  181. *
  182. * @throws \Stripe\Exception\ApiErrorException if the request fails
  183. *
  184. * @return \Stripe\PaymentIntent
  185. */
  186. public function incrementAuthorization($id, $params = null, $opts = null)
  187. {
  188. return $this->request('post', $this->buildPath('/v1/payment_intents/%s/increment_authorization', $id), $params, $opts);
  189. }
  190. /**
  191. * Retrieves the details of a PaymentIntent that has previously been created.
  192. *
  193. * You can retrieve a PaymentIntent client-side using a publishable key when the
  194. * <code>client_secret</code> is in the query string.
  195. *
  196. * If you retrieve a PaymentIntent with a publishable key, it only returns a subset
  197. * of properties. Refer to the <a href="#payment_intent_object">payment intent</a>
  198. * object reference for more details.
  199. *
  200. * @param string $id
  201. * @param null|array $params
  202. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  203. *
  204. * @throws \Stripe\Exception\ApiErrorException if the request fails
  205. *
  206. * @return \Stripe\PaymentIntent
  207. */
  208. public function retrieve($id, $params = null, $opts = null)
  209. {
  210. return $this->request('get', $this->buildPath('/v1/payment_intents/%s', $id), $params, $opts);
  211. }
  212. /**
  213. * Search for PaymentIntents you’ve previously created using Stripe’s <a
  214. * href="/docs/search#search-query-language">Search Query Language</a>. Don’t use
  215. * search in read-after-write flows where strict consistency is necessary. Under
  216. * normal operating conditions, data is searchable in less than a minute.
  217. * Occasionally, propagation of new or updated data can be up to an hour behind
  218. * during outages. Search functionality is not available to merchants in India.
  219. *
  220. * @param null|array $params
  221. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  222. *
  223. * @throws \Stripe\Exception\ApiErrorException if the request fails
  224. *
  225. * @return \Stripe\SearchResult<\Stripe\PaymentIntent>
  226. */
  227. public function search($params = null, $opts = null)
  228. {
  229. return $this->requestSearchResult('get', '/v1/payment_intents/search', $params, $opts);
  230. }
  231. /**
  232. * Updates properties on a PaymentIntent object without confirming.
  233. *
  234. * Depending on which properties you update, you might need to confirm the
  235. * PaymentIntent again. For example, updating the <code>payment_method</code>
  236. * always requires you to confirm the PaymentIntent again. If you prefer to update
  237. * and confirm at the same time, we recommend updating properties through the <a
  238. * href="/docs/api/payment_intents/confirm">confirm API</a> instead.
  239. *
  240. * @param string $id
  241. * @param null|array $params
  242. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  243. *
  244. * @throws \Stripe\Exception\ApiErrorException if the request fails
  245. *
  246. * @return \Stripe\PaymentIntent
  247. */
  248. public function update($id, $params = null, $opts = null)
  249. {
  250. return $this->request('post', $this->buildPath('/v1/payment_intents/%s', $id), $params, $opts);
  251. }
  252. /**
  253. * Verifies microdeposits on a PaymentIntent object.
  254. *
  255. * @param string $id
  256. * @param null|array $params
  257. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  258. *
  259. * @throws \Stripe\Exception\ApiErrorException if the request fails
  260. *
  261. * @return \Stripe\PaymentIntent
  262. */
  263. public function verifyMicrodeposits($id, $params = null, $opts = null)
  264. {
  265. return $this->request('post', $this->buildPath('/v1/payment_intents/%s/verify_microdeposits', $id), $params, $opts);
  266. }
  267. }