Transaction.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Tax;
  4. /**
  5. * A Tax Transaction records the tax collected from or refunded to your customer.
  6. *
  7. * Related guide: <a href="https://stripe.com/docs/tax/custom#tax-transaction">Calculate tax in your custom payment flow</a>
  8. *
  9. * @property string $id Unique identifier for the transaction.
  10. * @property string $object String representing the object's type. Objects of the same type share the same value.
  11. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  12. * @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>.
  13. * @property null|string $customer The ID of an existing <a href="https://stripe.com/docs/api/customers/object">Customer</a> used for the resource.
  14. * @property \Stripe\StripeObject $customer_details
  15. * @property null|\Stripe\Collection<\Stripe\Tax\TransactionLineItem> $line_items The tax collected or refunded, by line item.
  16. * @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.
  17. * @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.
  18. * @property int $posted_at The Unix timestamp representing when the tax liability is assumed or reduced.
  19. * @property string $reference A custom unique identifier, such as 'myOrder_123'.
  20. * @property null|\Stripe\StripeObject $reversal If <code>type=reversal</code>, contains information about what was reversed.
  21. * @property null|\Stripe\StripeObject $ship_from_details The details of the ship from location, such as the address.
  22. * @property null|\Stripe\StripeObject $shipping_cost The shipping cost details for the transaction.
  23. * @property int $tax_date Timestamp of date at which the tax rules and rates in effect applies for the calculation.
  24. * @property string $type If <code>reversal</code>, this transaction reverses an earlier transaction.
  25. */
  26. class Transaction extends \Stripe\ApiResource
  27. {
  28. const OBJECT_NAME = 'tax.transaction';
  29. const TYPE_REVERSAL = 'reversal';
  30. const TYPE_TRANSACTION = 'transaction';
  31. /**
  32. * Retrieves a Tax <code>Transaction</code> object.
  33. *
  34. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  35. * @param null|array|string $opts
  36. *
  37. * @throws \Stripe\Exception\ApiErrorException if the request fails
  38. *
  39. * @return \Stripe\Tax\Transaction
  40. */
  41. public static function retrieve($id, $opts = null)
  42. {
  43. $opts = \Stripe\Util\RequestOptions::parse($opts);
  44. $instance = new static($id, $opts);
  45. $instance->refresh();
  46. return $instance;
  47. }
  48. /**
  49. * @param null|array $params
  50. * @param null|array|string $opts
  51. *
  52. * @throws \Stripe\Exception\ApiErrorException if the request fails
  53. *
  54. * @return \Stripe\Tax\Transaction the created transaction
  55. */
  56. public static function createFromCalculation($params = null, $opts = null)
  57. {
  58. $url = static::classUrl() . '/create_from_calculation';
  59. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  60. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  61. $obj->setLastResponse($response);
  62. return $obj;
  63. }
  64. /**
  65. * @param null|array $params
  66. * @param null|array|string $opts
  67. *
  68. * @throws \Stripe\Exception\ApiErrorException if the request fails
  69. *
  70. * @return \Stripe\Tax\Transaction the created transaction
  71. */
  72. public static function createReversal($params = null, $opts = null)
  73. {
  74. $url = static::classUrl() . '/create_reversal';
  75. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  76. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  77. $obj->setLastResponse($response);
  78. return $obj;
  79. }
  80. /**
  81. * @param string $id
  82. * @param null|array $params
  83. * @param null|array|string $opts
  84. *
  85. * @throws \Stripe\Exception\ApiErrorException if the request fails
  86. *
  87. * @return \Stripe\Collection<\Stripe\Tax\TransactionLineItem> list of transaction line items
  88. */
  89. public static function allLineItems($id, $params = null, $opts = null)
  90. {
  91. $url = static::resourceUrl($id) . '/line_items';
  92. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  93. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  94. $obj->setLastResponse($response);
  95. return $obj;
  96. }
  97. }