Transfer.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * A <code>Transfer</code> object is created when you move funds between Stripe accounts as
  6. * part of Connect.
  7. *
  8. * Before April 6, 2017, transfers also represented movement of funds from a
  9. * Stripe account to a card or bank account. This behavior has since been split
  10. * out into a <a href="https://stripe.com/docs/api#payout_object">Payout</a> object, with corresponding payout endpoints. For more
  11. * information, read about the
  12. * <a href="https://stripe.com/docs/transfer-payout-split">transfer/payout split</a>.
  13. *
  14. * Related guide: <a href="https://stripe.com/docs/connect/separate-charges-and-transfers">Creating separate charges and transfers</a>
  15. *
  16. * @property string $id Unique identifier for the object.
  17. * @property string $object String representing the object's type. Objects of the same type share the same value.
  18. * @property int $amount Amount in cents (or local equivalent) to be transferred.
  19. * @property int $amount_reversed Amount in cents (or local equivalent) reversed (can be less than the amount attribute on the transfer if a partial reversal was issued).
  20. * @property null|string|\Stripe\BalanceTransaction $balance_transaction Balance transaction that describes the impact of this transfer on your account balance.
  21. * @property int $created Time that this record of the transfer was first created.
  22. * @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>.
  23. * @property null|string $description An arbitrary string attached to the object. Often useful for displaying to users.
  24. * @property null|string|\Stripe\Account $destination ID of the Stripe account the transfer was sent to.
  25. * @property null|string|\Stripe\Charge $destination_payment If the destination is a Stripe account, this will be the ID of the payment that the destination account received for the transfer.
  26. * @property bool $livemode Has the value <code>true</code> if the object exists in live mode or the value <code>false</code> if the object exists in test mode.
  27. * @property \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.
  28. * @property \Stripe\Collection<\Stripe\TransferReversal> $reversals A list of reversals that have been applied to the transfer.
  29. * @property bool $reversed Whether the transfer has been fully reversed. If the transfer is only partially reversed, this attribute will still be false.
  30. * @property null|string|\Stripe\Charge $source_transaction ID of the charge or payment that was used to fund the transfer. If null, the transfer was funded from the available balance.
  31. * @property null|string $source_type The source balance this transfer came from. One of <code>card</code>, <code>fpx</code>, or <code>bank_account</code>.
  32. * @property null|string $transfer_group A string that identifies this transaction as part of a group. See the <a href="https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-options">Connect documentation</a> for details.
  33. */
  34. class Transfer extends ApiResource
  35. {
  36. const OBJECT_NAME = 'transfer';
  37. use ApiOperations\NestedResource;
  38. use ApiOperations\Update;
  39. const SOURCE_TYPE_BANK_ACCOUNT = 'bank_account';
  40. const SOURCE_TYPE_CARD = 'card';
  41. const SOURCE_TYPE_FPX = 'fpx';
  42. /**
  43. * To send funds from your Stripe account to a connected account, you create a new
  44. * transfer object. Your <a href="#balance">Stripe balance</a> must be able to
  45. * cover the transfer amount, or you’ll receive an “Insufficient Funds” error.
  46. *
  47. * @param null|array $params
  48. * @param null|array|string $options
  49. *
  50. * @throws \Stripe\Exception\ApiErrorException if the request fails
  51. *
  52. * @return \Stripe\Transfer the created resource
  53. */
  54. public static function create($params = null, $options = null)
  55. {
  56. self::_validateParams($params);
  57. $url = static::classUrl();
  58. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  59. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  60. $obj->setLastResponse($response);
  61. return $obj;
  62. }
  63. /**
  64. * Returns a list of existing transfers sent to connected accounts. The transfers
  65. * are returned in sorted order, with the most recently created transfers appearing
  66. * first.
  67. *
  68. * @param null|array $params
  69. * @param null|array|string $opts
  70. *
  71. * @throws \Stripe\Exception\ApiErrorException if the request fails
  72. *
  73. * @return \Stripe\Collection<\Stripe\Transfer> of ApiResources
  74. */
  75. public static function all($params = null, $opts = null)
  76. {
  77. $url = static::classUrl();
  78. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  79. }
  80. /**
  81. * Retrieves the details of an existing transfer. Supply the unique transfer ID
  82. * from either a transfer creation request or the transfer list, and Stripe will
  83. * return the corresponding transfer information.
  84. *
  85. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  86. * @param null|array|string $opts
  87. *
  88. * @throws \Stripe\Exception\ApiErrorException if the request fails
  89. *
  90. * @return \Stripe\Transfer
  91. */
  92. public static function retrieve($id, $opts = null)
  93. {
  94. $opts = \Stripe\Util\RequestOptions::parse($opts);
  95. $instance = new static($id, $opts);
  96. $instance->refresh();
  97. return $instance;
  98. }
  99. /**
  100. * Updates the specified transfer by setting the values of the parameters passed.
  101. * Any parameters not provided will be left unchanged.
  102. *
  103. * This request accepts only metadata as an argument.
  104. *
  105. * @param string $id the ID of the resource to update
  106. * @param null|array $params
  107. * @param null|array|string $opts
  108. *
  109. * @throws \Stripe\Exception\ApiErrorException if the request fails
  110. *
  111. * @return \Stripe\Transfer the updated resource
  112. */
  113. public static function update($id, $params = null, $opts = null)
  114. {
  115. self::_validateParams($params);
  116. $url = static::resourceUrl($id);
  117. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  118. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  119. $obj->setLastResponse($response);
  120. return $obj;
  121. }
  122. const PATH_REVERSALS = '/reversals';
  123. /**
  124. * @param string $id the ID of the transfer on which to retrieve the transfer reversals
  125. * @param null|array $params
  126. * @param null|array|string $opts
  127. *
  128. * @throws \Stripe\Exception\ApiErrorException if the request fails
  129. *
  130. * @return \Stripe\Collection<\Stripe\TransferReversal> the list of transfer reversals
  131. */
  132. public static function allReversals($id, $params = null, $opts = null)
  133. {
  134. return self::_allNestedResources($id, static::PATH_REVERSALS, $params, $opts);
  135. }
  136. /**
  137. * @param string $id the ID of the transfer on which to create the transfer reversal
  138. * @param null|array $params
  139. * @param null|array|string $opts
  140. *
  141. * @throws \Stripe\Exception\ApiErrorException if the request fails
  142. *
  143. * @return \Stripe\TransferReversal
  144. */
  145. public static function createReversal($id, $params = null, $opts = null)
  146. {
  147. return self::_createNestedResource($id, static::PATH_REVERSALS, $params, $opts);
  148. }
  149. /**
  150. * @param string $id the ID of the transfer to which the transfer reversal belongs
  151. * @param string $reversalId the ID of the transfer reversal to retrieve
  152. * @param null|array $params
  153. * @param null|array|string $opts
  154. *
  155. * @throws \Stripe\Exception\ApiErrorException if the request fails
  156. *
  157. * @return \Stripe\TransferReversal
  158. */
  159. public static function retrieveReversal($id, $reversalId, $params = null, $opts = null)
  160. {
  161. return self::_retrieveNestedResource($id, static::PATH_REVERSALS, $reversalId, $params, $opts);
  162. }
  163. /**
  164. * @param string $id the ID of the transfer to which the transfer reversal belongs
  165. * @param string $reversalId the ID of the transfer reversal to update
  166. * @param null|array $params
  167. * @param null|array|string $opts
  168. *
  169. * @throws \Stripe\Exception\ApiErrorException if the request fails
  170. *
  171. * @return \Stripe\TransferReversal
  172. */
  173. public static function updateReversal($id, $reversalId, $params = null, $opts = null)
  174. {
  175. return self::_updateNestedResource($id, static::PATH_REVERSALS, $reversalId, $params, $opts);
  176. }
  177. }