Refund.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * Refund objects allow you to refund a previously created charge that isn't
  6. * refunded yet. Funds are refunded to the credit or debit card that's
  7. * initially charged.
  8. *
  9. * Related guide: <a href="https://stripe.com/docs/refunds">Refunds</a>
  10. *
  11. * @property string $id Unique identifier for the object.
  12. * @property string $object String representing the object's type. Objects of the same type share the same value.
  13. * @property int $amount Amount, in cents (or local equivalent).
  14. * @property null|string|\Stripe\BalanceTransaction $balance_transaction Balance transaction that describes the impact on your account balance.
  15. * @property null|string|\Stripe\Charge $charge ID of the charge that's refunded.
  16. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  17. * @property string $currency Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>, in lowercase. Must be a <a href="https://stripe.com/docs/currencies">supported currency</a>.
  18. * @property null|string $description An arbitrary string attached to the object. You can use this for displaying to users (available on non-card refunds only).
  19. * @property null|\Stripe\StripeObject $destination_details
  20. * @property null|string|\Stripe\BalanceTransaction $failure_balance_transaction After the refund fails, this balance transaction describes the adjustment made on your account balance that reverses the initial balance transaction.
  21. * @property null|string $failure_reason Provides the reason for the refund failure. Possible values are: <code>lost_or_stolen_card</code>, <code>expired_or_canceled_card</code>, <code>charge_for_pending_refund_disputed</code>, <code>insufficient_funds</code>, <code>declined</code>, <code>merchant_request</code>, or <code>unknown</code>.
  22. * @property null|string $instructions_email For payment methods without native refund support (for example, Konbini, PromptPay), provide an email address for the customer to receive refund instructions.
  23. * @property null|\Stripe\StripeObject $metadata Set of <a href="https://stripe.com/docs/api/metadata">key-value pairs</a> that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
  24. * @property null|\Stripe\StripeObject $next_action
  25. * @property null|string|\Stripe\PaymentIntent $payment_intent ID of the PaymentIntent that's refunded.
  26. * @property null|string $reason Reason for the refund, which is either user-provided (<code>duplicate</code>, <code>fraudulent</code>, or <code>requested_by_customer</code>) or generated by Stripe internally (<code>expired_uncaptured_charge</code>).
  27. * @property null|string $receipt_number This is the transaction number that appears on email receipts sent for this refund.
  28. * @property null|string|\Stripe\TransferReversal $source_transfer_reversal The transfer reversal that's associated with the refund. Only present if the charge came from another Stripe account.
  29. * @property null|string $status Status of the refund. This can be <code>pending</code>, <code>requires_action</code>, <code>succeeded</code>, <code>failed</code>, or <code>canceled</code>. Learn more about <a href="https://stripe.com/docs/refunds#failed-refunds">failed refunds</a>.
  30. * @property null|string|\Stripe\TransferReversal $transfer_reversal This refers to the transfer reversal object if the accompanying transfer reverses. This is only applicable if the charge was created using the destination parameter.
  31. */
  32. class Refund extends ApiResource
  33. {
  34. const OBJECT_NAME = 'refund';
  35. use ApiOperations\Update;
  36. const FAILURE_REASON_EXPIRED_OR_CANCELED_CARD = 'expired_or_canceled_card';
  37. const FAILURE_REASON_LOST_OR_STOLEN_CARD = 'lost_or_stolen_card';
  38. const FAILURE_REASON_UNKNOWN = 'unknown';
  39. const REASON_DUPLICATE = 'duplicate';
  40. const REASON_EXPIRED_UNCAPTURED_CHARGE = 'expired_uncaptured_charge';
  41. const REASON_FRAUDULENT = 'fraudulent';
  42. const REASON_REQUESTED_BY_CUSTOMER = 'requested_by_customer';
  43. const STATUS_CANCELED = 'canceled';
  44. const STATUS_FAILED = 'failed';
  45. const STATUS_PENDING = 'pending';
  46. const STATUS_REQUIRES_ACTION = 'requires_action';
  47. const STATUS_SUCCEEDED = 'succeeded';
  48. /**
  49. * When you create a new refund, you must specify a Charge or a PaymentIntent
  50. * object on which to create it.
  51. *
  52. * Creating a new refund will refund a charge that has previously been created but
  53. * not yet refunded. Funds will be refunded to the credit or debit card that was
  54. * originally charged.
  55. *
  56. * You can optionally refund only part of a charge. You can do so multiple times,
  57. * until the entire charge has been refunded.
  58. *
  59. * Once entirely refunded, a charge can’t be refunded again. This method will raise
  60. * an error when called on an already-refunded charge, or when trying to refund
  61. * more money than is left on a charge.
  62. *
  63. * @param null|array $params
  64. * @param null|array|string $options
  65. *
  66. * @throws \Stripe\Exception\ApiErrorException if the request fails
  67. *
  68. * @return \Stripe\Refund the created resource
  69. */
  70. public static function create($params = null, $options = null)
  71. {
  72. self::_validateParams($params);
  73. $url = static::classUrl();
  74. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  75. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  76. $obj->setLastResponse($response);
  77. return $obj;
  78. }
  79. /**
  80. * Returns a list of all refunds you created. We return the refunds in sorted
  81. * order, with the most recent refunds appearing first The 10 most recent refunds
  82. * are always available by default on the Charge object.
  83. *
  84. * @param null|array $params
  85. * @param null|array|string $opts
  86. *
  87. * @throws \Stripe\Exception\ApiErrorException if the request fails
  88. *
  89. * @return \Stripe\Collection<\Stripe\Refund> of ApiResources
  90. */
  91. public static function all($params = null, $opts = null)
  92. {
  93. $url = static::classUrl();
  94. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  95. }
  96. /**
  97. * Retrieves the details of an existing refund.
  98. *
  99. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  100. * @param null|array|string $opts
  101. *
  102. * @throws \Stripe\Exception\ApiErrorException if the request fails
  103. *
  104. * @return \Stripe\Refund
  105. */
  106. public static function retrieve($id, $opts = null)
  107. {
  108. $opts = \Stripe\Util\RequestOptions::parse($opts);
  109. $instance = new static($id, $opts);
  110. $instance->refresh();
  111. return $instance;
  112. }
  113. /**
  114. * Updates the refund that you specify by setting the values of the passed
  115. * parameters. Any parameters that you don’t provide remain unchanged.
  116. *
  117. * This request only accepts <code>metadata</code> as an argument.
  118. *
  119. * @param string $id the ID of the resource to update
  120. * @param null|array $params
  121. * @param null|array|string $opts
  122. *
  123. * @throws \Stripe\Exception\ApiErrorException if the request fails
  124. *
  125. * @return \Stripe\Refund the updated resource
  126. */
  127. public static function update($id, $params = null, $opts = null)
  128. {
  129. self::_validateParams($params);
  130. $url = static::resourceUrl($id);
  131. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  132. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  133. $obj->setLastResponse($response);
  134. return $obj;
  135. }
  136. /**
  137. * @param null|array $params
  138. * @param null|array|string $opts
  139. *
  140. * @throws \Stripe\Exception\ApiErrorException if the request fails
  141. *
  142. * @return \Stripe\Refund the canceled refund
  143. */
  144. public function cancel($params = null, $opts = null)
  145. {
  146. $url = $this->instanceUrl() . '/cancel';
  147. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  148. $this->refreshFrom($response, $opts);
  149. return $this;
  150. }
  151. }