Order.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Climate;
  4. /**
  5. * Orders represent your intent to purchase a particular Climate product. When you create an order, the
  6. * payment is deducted from your merchant balance.
  7. *
  8. * @property string $id Unique identifier for the object.
  9. * @property string $object String representing the object's type. Objects of the same type share the same value.
  10. * @property int $amount_fees Total amount of <a href="https://frontierclimate.com/">Frontier</a>'s service fees in the currency's smallest unit.
  11. * @property int $amount_subtotal Total amount of the carbon removal in the currency's smallest unit.
  12. * @property int $amount_total Total amount of the order including fees in the currency's smallest unit.
  13. * @property null|\Stripe\StripeObject $beneficiary
  14. * @property null|int $canceled_at Time at which the order was canceled. Measured in seconds since the Unix epoch.
  15. * @property null|string $cancellation_reason Reason for the cancellation of this order.
  16. * @property null|string $certificate For delivered orders, a URL to a delivery certificate for the order.
  17. * @property null|int $confirmed_at Time at which the order was confirmed. Measured in seconds since the Unix epoch.
  18. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  19. * @property string $currency Three-letter <a href="https://www.iso.org/iso-4217-currency-codes.html">ISO currency code</a>, in lowercase, representing the currency for this order.
  20. * @property null|int $delayed_at Time at which the order's expected_delivery_year was delayed. Measured in seconds since the Unix epoch.
  21. * @property null|int $delivered_at Time at which the order was delivered. Measured in seconds since the Unix epoch.
  22. * @property \Stripe\StripeObject[] $delivery_details Details about the delivery of carbon removal for this order.
  23. * @property int $expected_delivery_year The year this order is expected to be delivered.
  24. * @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.
  25. * @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.
  26. * @property string $metric_tons Quantity of carbon removal that is included in this order.
  27. * @property string|\Stripe\Climate\Product $product Unique ID for the Climate <code>Product</code> this order is purchasing.
  28. * @property null|int $product_substituted_at Time at which the order's product was substituted for a different product. Measured in seconds since the Unix epoch.
  29. * @property string $status The current status of this order.
  30. */
  31. class Order extends \Stripe\ApiResource
  32. {
  33. const OBJECT_NAME = 'climate.order';
  34. use \Stripe\ApiOperations\Update;
  35. const CANCELLATION_REASON_EXPIRED = 'expired';
  36. const CANCELLATION_REASON_PRODUCT_UNAVAILABLE = 'product_unavailable';
  37. const CANCELLATION_REASON_REQUESTED = 'requested';
  38. const STATUS_AWAITING_FUNDS = 'awaiting_funds';
  39. const STATUS_CANCELED = 'canceled';
  40. const STATUS_CONFIRMED = 'confirmed';
  41. const STATUS_DELIVERED = 'delivered';
  42. const STATUS_OPEN = 'open';
  43. /**
  44. * Creates a Climate order object for a given Climate product. The order will be
  45. * processed immediately after creation and payment will be deducted your Stripe
  46. * balance.
  47. *
  48. * @param null|array $params
  49. * @param null|array|string $options
  50. *
  51. * @throws \Stripe\Exception\ApiErrorException if the request fails
  52. *
  53. * @return \Stripe\Climate\Order the created resource
  54. */
  55. public static function create($params = null, $options = null)
  56. {
  57. self::_validateParams($params);
  58. $url = static::classUrl();
  59. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  60. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  61. $obj->setLastResponse($response);
  62. return $obj;
  63. }
  64. /**
  65. * Lists all Climate order objects. The orders are returned sorted by creation
  66. * date, with the most recently created orders appearing 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\Climate\Order> 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 a Climate order object with the given ID.
  82. *
  83. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  84. * @param null|array|string $opts
  85. *
  86. * @throws \Stripe\Exception\ApiErrorException if the request fails
  87. *
  88. * @return \Stripe\Climate\Order
  89. */
  90. public static function retrieve($id, $opts = null)
  91. {
  92. $opts = \Stripe\Util\RequestOptions::parse($opts);
  93. $instance = new static($id, $opts);
  94. $instance->refresh();
  95. return $instance;
  96. }
  97. /**
  98. * Updates the specified order by setting the values of the parameters passed.
  99. *
  100. * @param string $id the ID of the resource to update
  101. * @param null|array $params
  102. * @param null|array|string $opts
  103. *
  104. * @throws \Stripe\Exception\ApiErrorException if the request fails
  105. *
  106. * @return \Stripe\Climate\Order the updated resource
  107. */
  108. public static function update($id, $params = null, $opts = null)
  109. {
  110. self::_validateParams($params);
  111. $url = static::resourceUrl($id);
  112. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  113. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  114. $obj->setLastResponse($response);
  115. return $obj;
  116. }
  117. /**
  118. * @param null|array $params
  119. * @param null|array|string $opts
  120. *
  121. * @throws \Stripe\Exception\ApiErrorException if the request fails
  122. *
  123. * @return \Stripe\Climate\Order the canceled order
  124. */
  125. public function cancel($params = null, $opts = null)
  126. {
  127. $url = $this->instanceUrl() . '/cancel';
  128. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  129. $this->refreshFrom($response, $opts);
  130. return $this;
  131. }
  132. }