Charge.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace Stripe;
  3. /**
  4. * Class Charge
  5. *
  6. * @property string $id
  7. * @property string $object
  8. * @property int $amount
  9. * @property int $amount_refunded
  10. * @property string $application
  11. * @property string $application_fee
  12. * @property string $balance_transaction
  13. * @property bool $captured
  14. * @property int $created
  15. * @property string $currency
  16. * @property string $customer
  17. * @property string $description
  18. * @property string $destination
  19. * @property string $dispute
  20. * @property string $failure_code
  21. * @property string $failure_message
  22. * @property mixed $fraud_details
  23. * @property string $invoice
  24. * @property bool $livemode
  25. * @property StripeObject $metadata
  26. * @property string $on_behalf_of
  27. * @property string $order
  28. * @property mixed $outcome
  29. * @property bool $paid
  30. * @property string $receipt_email
  31. * @property string $receipt_number
  32. * @property bool $refunded
  33. * @property Collection $refunds
  34. * @property string $review
  35. * @property mixed $shipping
  36. * @property mixed $source
  37. * @property string $source_transfer
  38. * @property string $statement_descriptor
  39. * @property string $status
  40. * @property string $transfer
  41. * @property string $transfer_group
  42. *
  43. * @package Stripe
  44. */
  45. class Charge extends ApiResource
  46. {
  47. const OBJECT_NAME = "charge";
  48. use ApiOperations\All;
  49. use ApiOperations\Create;
  50. use ApiOperations\Retrieve;
  51. use ApiOperations\Update;
  52. /**
  53. * Possible string representations of decline codes.
  54. * These strings are applicable to the decline_code property of the \Stripe\Error\Card exception.
  55. * @link https://stripe.com/docs/declines/codes
  56. */
  57. const DECLINED_APPROVE_WITH_ID = 'approve_with_id';
  58. const DECLINED_CALL_ISSUER = 'call_issuer';
  59. const DECLINED_CARD_NOT_SUPPORTED = 'card_not_supported';
  60. const DECLINED_CARD_VELOCITY_EXCEEDED = 'card_velocity_exceeded';
  61. const DECLINED_CURRENCY_NOT_SUPPORTED = 'currency_not_supported';
  62. const DECLINED_DO_NOT_HONOR = 'do_not_honor';
  63. const DECLINED_DO_NOT_TRY_AGAIN = 'do_not_try_again';
  64. const DECLINED_DUPLICATED_TRANSACTION = 'duplicate_transaction';
  65. const DECLINED_EXPIRED_CARD = 'expired_card';
  66. const DECLINED_FRAUDULENT = 'fraudulent';
  67. const DECLINED_GENERIC_DECLINE = 'generic_decline';
  68. const DECLINED_INCORRECT_NUMBER = 'incorrect_number';
  69. const DECLINED_INCORRECT_CVC = 'incorrect_cvc';
  70. const DECLINED_INCORRECT_PIN = 'incorrect_pin';
  71. const DECLINED_INCORRECT_ZIP = 'incorrect_zip';
  72. const DECLINED_INSUFFICIENT_FUNDS = 'insufficient_funds';
  73. const DECLINED_INVALID_ACCOUNT = 'invalid_account';
  74. const DECLINED_INVALID_AMOUNT = 'invalid_amount';
  75. const DECLINED_INVALID_CVC = 'invalid_cvc';
  76. const DECLINED_INVALID_EXPIRY_YEAR = 'invalid_expiry_year';
  77. const DECLINED_INVALID_NUMBER = 'invalid_number';
  78. const DECLINED_INVALID_PIN = 'invalid_pin';
  79. const DECLINED_ISSUER_NOT_AVAILABLE = 'issuer_not_available';
  80. const DECLINED_LOST_CARD = 'lost_card';
  81. const DECLINED_NEW_ACCOUNT_INFORMATION_AVAILABLE = 'new_account_information_available';
  82. const DECLINED_NO_ACTION_TAKEN = 'no_action_taken';
  83. const DECLINED_NOT_PERMITTED = 'not_permitted';
  84. const DECLINED_PICKUP_CARD = 'pickup_card';
  85. const DECLINED_PIN_TRY_EXCEEDED = 'pin_try_exceeded';
  86. const DECLINED_PROCESSING_ERROR = 'processing_error';
  87. const DECLINED_REENTER_TRANSACTION = 'reenter_transaction';
  88. const DECLINED_RESTRICTED_CARD = 'restricted_card';
  89. const DECLINED_REVOCATION_OF_ALL_AUTHORIZATIONS = 'revocation_of_all_authorizations';
  90. const DECLINED_REVOCATION_OF_AUTHORIZATION = 'revocation_of_authorization';
  91. const DECLINED_SECURITY_VIOLATION = 'security_violation';
  92. const DECLINED_SERVICE_NOT_ALLOWED = 'service_not_allowed';
  93. const DECLINED_STOLEN_CARD = 'stolen_card';
  94. const DECLINED_STOP_PAYMENT_ORDER = 'stop_payment_order';
  95. const DECLINED_TESTMODE_DECLINE = 'testmode_decline';
  96. const DECLINED_TRANSACTION_NOT_ALLOWED = 'transaction_not_allowed';
  97. const DECLINED_TRY_AGAIN_LATER = 'try_again_later';
  98. const DECLINED_WITHDRAWAL_COUNT_LIMIT_EXCEEDED = 'withdrawal_count_limit_exceeded';
  99. /**
  100. * @param array|null $params
  101. * @param array|string|null $options
  102. *
  103. * @return Charge The refunded charge.
  104. */
  105. public function refund($params = null, $options = null)
  106. {
  107. $url = $this->instanceUrl() . '/refund';
  108. list($response, $opts) = $this->_request('post', $url, $params, $options);
  109. $this->refreshFrom($response, $opts);
  110. return $this;
  111. }
  112. /**
  113. * @param array|null $params
  114. * @param array|string|null $options
  115. *
  116. * @return Charge The captured charge.
  117. */
  118. public function capture($params = null, $options = null)
  119. {
  120. $url = $this->instanceUrl() . '/capture';
  121. list($response, $opts) = $this->_request('post', $url, $params, $options);
  122. $this->refreshFrom($response, $opts);
  123. return $this;
  124. }
  125. /**
  126. * @param array|null $params
  127. * @param array|string|null $options
  128. *
  129. * @deprecated Use the `save` method on the Dispute object
  130. *
  131. * @return array The updated dispute.
  132. */
  133. public function updateDispute($params = null, $options = null)
  134. {
  135. $url = $this->instanceUrl() . '/dispute';
  136. list($response, $opts) = $this->_request('post', $url, $params, $options);
  137. $this->refreshFrom(['dispute' => $response], $opts, true);
  138. return $this->dispute;
  139. }
  140. /**
  141. * @param array|string|null $options
  142. *
  143. * @deprecated Use the `close` method on the Dispute object
  144. *
  145. * @return Charge The updated charge.
  146. */
  147. public function closeDispute($options = null)
  148. {
  149. $url = $this->instanceUrl() . '/dispute/close';
  150. list($response, $opts) = $this->_request('post', $url, null, $options);
  151. $this->refreshFrom($response, $opts);
  152. return $this;
  153. }
  154. /**
  155. * @param array|string|null $opts
  156. *
  157. * @return Charge The updated charge.
  158. */
  159. public function markAsFraudulent($opts = null)
  160. {
  161. $params = ['fraud_details' => ['user_report' => 'fraudulent']];
  162. $url = $this->instanceUrl();
  163. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  164. $this->refreshFrom($response, $opts);
  165. return $this;
  166. }
  167. /**
  168. * @param array|string|null $opts
  169. *
  170. * @return Charge The updated charge.
  171. */
  172. public function markAsSafe($opts = null)
  173. {
  174. $params = ['fraud_details' => ['user_report' => 'safe']];
  175. $url = $this->instanceUrl();
  176. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  177. $this->refreshFrom($response, $opts);
  178. return $this;
  179. }
  180. }