ChargeService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 ChargeService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of charges you’ve previously created. The charges are returned in
  12. * sorted order, with the most recent charges appearing first.
  13. *
  14. * @param null|array $params
  15. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  16. *
  17. * @throws \Stripe\Exception\ApiErrorException if the request fails
  18. *
  19. * @return \Stripe\Collection<\Stripe\Charge>
  20. */
  21. public function all($params = null, $opts = null)
  22. {
  23. return $this->requestCollection('get', '/v1/charges', $params, $opts);
  24. }
  25. /**
  26. * Capture the payment of an existing, uncaptured charge that was created with the
  27. * <code>capture</code> option set to false.
  28. *
  29. * Uncaptured payments expire a set number of days after they are created (<a
  30. * href="/docs/charges/placing-a-hold">7 by default</a>), after which they are
  31. * marked as refunded and capture attempts will fail.
  32. *
  33. * Don’t use this method to capture a PaymentIntent-initiated charge. Use <a
  34. * href="/docs/api/payment_intents/capture">Capture a PaymentIntent</a>.
  35. *
  36. * @param string $id
  37. * @param null|array $params
  38. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  39. *
  40. * @throws \Stripe\Exception\ApiErrorException if the request fails
  41. *
  42. * @return \Stripe\Charge
  43. */
  44. public function capture($id, $params = null, $opts = null)
  45. {
  46. return $this->request('post', $this->buildPath('/v1/charges/%s/capture', $id), $params, $opts);
  47. }
  48. /**
  49. * This method is no longer recommended—use the <a
  50. * href="/docs/api/payment_intents">Payment Intents API</a> to initiate a new
  51. * payment instead. Confirmation of the PaymentIntent creates the
  52. * <code>Charge</code> object used to request payment.
  53. *
  54. * @param null|array $params
  55. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  56. *
  57. * @throws \Stripe\Exception\ApiErrorException if the request fails
  58. *
  59. * @return \Stripe\Charge
  60. */
  61. public function create($params = null, $opts = null)
  62. {
  63. return $this->request('post', '/v1/charges', $params, $opts);
  64. }
  65. /**
  66. * Retrieves the details of a charge that has previously been created. Supply the
  67. * unique charge ID that was returned from your previous request, and Stripe will
  68. * return the corresponding charge information. The same information is returned
  69. * when creating or refunding the charge.
  70. *
  71. * @param string $id
  72. * @param null|array $params
  73. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  74. *
  75. * @throws \Stripe\Exception\ApiErrorException if the request fails
  76. *
  77. * @return \Stripe\Charge
  78. */
  79. public function retrieve($id, $params = null, $opts = null)
  80. {
  81. return $this->request('get', $this->buildPath('/v1/charges/%s', $id), $params, $opts);
  82. }
  83. /**
  84. * Search for charges you’ve previously created using Stripe’s <a
  85. * href="/docs/search#search-query-language">Search Query Language</a>. Don’t use
  86. * search in read-after-write flows where strict consistency is necessary. Under
  87. * normal operating conditions, data is searchable in less than a minute.
  88. * Occasionally, propagation of new or updated data can be up to an hour behind
  89. * during outages. Search functionality is not available to merchants in India.
  90. *
  91. * @param null|array $params
  92. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  93. *
  94. * @throws \Stripe\Exception\ApiErrorException if the request fails
  95. *
  96. * @return \Stripe\SearchResult<\Stripe\Charge>
  97. */
  98. public function search($params = null, $opts = null)
  99. {
  100. return $this->requestSearchResult('get', '/v1/charges/search', $params, $opts);
  101. }
  102. /**
  103. * Updates the specified charge by setting the values of the parameters passed. Any
  104. * parameters not provided will be left unchanged.
  105. *
  106. * @param string $id
  107. * @param null|array $params
  108. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  109. *
  110. * @throws \Stripe\Exception\ApiErrorException if the request fails
  111. *
  112. * @return \Stripe\Charge
  113. */
  114. public function update($id, $params = null, $opts = null)
  115. {
  116. return $this->request('post', $this->buildPath('/v1/charges/%s', $id), $params, $opts);
  117. }
  118. }