Charge.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 mixed $application_fee
  11. * @property string $balance_transaction
  12. * @property bool $captured
  13. * @property int $created
  14. * @property string $currency
  15. * @property string $customer
  16. * @property mixed $description
  17. * @property mixed $destination
  18. * @property mixed $dispute
  19. * @property mixed $failure_code
  20. * @property mixed $failure_message
  21. * @property mixed $fraud_details
  22. * @property mixed $invoice
  23. * @property bool $livemode
  24. * @property mixed $metadata
  25. * @property mixed $order
  26. * @property bool $paid
  27. * @property mixed $receipt_email
  28. * @property mixed $receipt_number
  29. * @property bool $refunded
  30. * @property mixed $refunds
  31. * @property mixed $shipping
  32. * @property mixed $source
  33. * @property mixed $source_transfer
  34. * @property mixed $statement_descriptor
  35. * @property string $status
  36. *
  37. * @package Stripe
  38. */
  39. class Charge extends ApiResource
  40. {
  41. /**
  42. * @param string $id The ID of the charge to retrieve.
  43. * @param array|string|null $options
  44. *
  45. * @return Charge
  46. */
  47. public static function retrieve($id, $options = null)
  48. {
  49. return self::_retrieve($id, $options);
  50. }
  51. /**
  52. * @param array|null $params
  53. * @param array|string|null $options
  54. *
  55. * @return Collection of Charges
  56. */
  57. public static function all($params = null, $options = null)
  58. {
  59. return self::_all($params, $options);
  60. }
  61. /**
  62. * @param array|null $params
  63. * @param array|string|null $options
  64. *
  65. * @return Charge The created charge.
  66. */
  67. public static function create($params = null, $options = null)
  68. {
  69. return self::_create($params, $options);
  70. }
  71. /**
  72. * @param string $id The ID of the charge to update.
  73. * @param array|null $params
  74. * @param array|string|null $options
  75. *
  76. * @return Charge The updated charge.
  77. */
  78. public static function update($id, $params = null, $options = null)
  79. {
  80. return self::_update($id, $params, $options);
  81. }
  82. /**
  83. * @param array|string|null $options
  84. *
  85. * @return Charge The saved charge.
  86. */
  87. public function save($options = null)
  88. {
  89. return $this->_save($options);
  90. }
  91. /**
  92. * @param array|null $params
  93. * @param array|string|null $options
  94. *
  95. * @return Charge The refunded charge.
  96. */
  97. public function refund($params = null, $options = null)
  98. {
  99. $url = $this->instanceUrl() . '/refund';
  100. list($response, $opts) = $this->_request('post', $url, $params, $options);
  101. $this->refreshFrom($response, $opts);
  102. return $this;
  103. }
  104. /**
  105. * @param array|null $params
  106. * @param array|string|null $options
  107. *
  108. * @return Charge The captured charge.
  109. */
  110. public function capture($params = null, $options = null)
  111. {
  112. $url = $this->instanceUrl() . '/capture';
  113. list($response, $opts) = $this->_request('post', $url, $params, $options);
  114. $this->refreshFrom($response, $opts);
  115. return $this;
  116. }
  117. /**
  118. * @param array|null $params
  119. * @param array|string|null $options
  120. *
  121. * @deprecated Use the `save` method on the Dispute object
  122. *
  123. * @return array The updated dispute.
  124. */
  125. public function updateDispute($params = null, $options = null)
  126. {
  127. $url = $this->instanceUrl() . '/dispute';
  128. list($response, $opts) = $this->_request('post', $url, $params, $options);
  129. $this->refreshFrom(array('dispute' => $response), $opts, true);
  130. return $this->dispute;
  131. }
  132. /**
  133. * @param array|string|null $options
  134. *
  135. * @deprecated Use the `close` method on the Dispute object
  136. *
  137. * @return Charge The updated charge.
  138. */
  139. public function closeDispute($options = null)
  140. {
  141. $url = $this->instanceUrl() . '/dispute/close';
  142. list($response, $opts) = $this->_request('post', $url, null, $options);
  143. $this->refreshFrom($response, $opts);
  144. return $this;
  145. }
  146. /**
  147. * @param array|string|null $opts
  148. *
  149. * @return Charge The updated charge.
  150. */
  151. public function markAsFraudulent($opts = null)
  152. {
  153. $params = array('fraud_details' => array('user_report' => 'fraudulent'));
  154. $url = $this->instanceUrl();
  155. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  156. $this->refreshFrom($response, $opts);
  157. return $this;
  158. }
  159. /**
  160. * @param array|string|null $opts
  161. *
  162. * @return Charge The updated charge.
  163. */
  164. public function markAsSafe($opts = null)
  165. {
  166. $params = array('fraud_details' => array('user_report' => 'safe'));
  167. $url = $this->instanceUrl();
  168. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  169. $this->refreshFrom($response, $opts);
  170. return $this;
  171. }
  172. }