Quote.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * A Quote is a way to model prices that you'd like to provide to a customer.
  6. * Once accepted, it will automatically create an invoice, subscription or subscription schedule.
  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_subtotal Total before any discounts or taxes are applied.
  11. * @property int $amount_total Total after discounts and taxes are applied.
  12. * @property null|string|\Stripe\Application $application ID of the Connect Application that created the quote.
  13. * @property null|int $application_fee_amount The amount of the application fee (if any) that will be requested to be applied to the payment and transferred to the application owner's Stripe account. Only applicable if there are no line items with recurring prices on the quote.
  14. * @property null|float $application_fee_percent A non-negative decimal between 0 and 100, with at most two decimal places. This represents the percentage of the subscription invoice total that will be transferred to the application owner's Stripe account. Only applicable if there are line items with recurring prices on the quote.
  15. * @property \Stripe\StripeObject $automatic_tax
  16. * @property string $collection_method Either <code>charge_automatically</code>, or <code>send_invoice</code>. When charging automatically, Stripe will attempt to pay invoices at the end of the subscription cycle or on finalization using the default payment method attached to the subscription or customer. When sending an invoice, Stripe will email your customer an invoice with payment instructions and mark the subscription as <code>active</code>. Defaults to <code>charge_automatically</code>.
  17. * @property \Stripe\StripeObject $computed
  18. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  19. * @property null|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>.
  20. * @property null|string|\Stripe\Customer $customer The customer which this quote belongs to. A customer is required before finalizing the quote. Once specified, it cannot be changed.
  21. * @property null|(string|\Stripe\TaxRate)[] $default_tax_rates The tax rates applied to this quote.
  22. * @property null|string $description A description that will be displayed on the quote PDF.
  23. * @property (string|\Stripe\Discount)[] $discounts The discounts applied to this quote.
  24. * @property int $expires_at The date on which the quote will be canceled if in <code>open</code> or <code>draft</code> status. Measured in seconds since the Unix epoch.
  25. * @property null|string $footer A footer that will be displayed on the quote PDF.
  26. * @property null|\Stripe\StripeObject $from_quote Details of the quote that was cloned. See the <a href="https://stripe.com/docs/quotes/clone">cloning documentation</a> for more details.
  27. * @property null|string $header A header that will be displayed on the quote PDF.
  28. * @property null|string|\Stripe\Invoice $invoice The invoice that was created from this quote.
  29. * @property \Stripe\StripeObject $invoice_settings
  30. * @property null|\Stripe\Collection<\Stripe\LineItem> $line_items A list of items the customer is being quoted for.
  31. * @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.
  32. * @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.
  33. * @property null|string $number A unique number that identifies this particular quote. This number is assigned once the quote is <a href="https://stripe.com/docs/quotes/overview#finalize">finalized</a>.
  34. * @property null|string|\Stripe\Account $on_behalf_of The account on behalf of which to charge. See the <a href="https://support.stripe.com/questions/sending-invoices-on-behalf-of-connected-accounts">Connect documentation</a> for details.
  35. * @property string $status The status of the quote.
  36. * @property \Stripe\StripeObject $status_transitions
  37. * @property null|string|\Stripe\Subscription $subscription The subscription that was created or updated from this quote.
  38. * @property \Stripe\StripeObject $subscription_data
  39. * @property null|string|\Stripe\SubscriptionSchedule $subscription_schedule The subscription schedule that was created or updated from this quote.
  40. * @property null|string|\Stripe\TestHelpers\TestClock $test_clock ID of the test clock this quote belongs to.
  41. * @property \Stripe\StripeObject $total_details
  42. * @property null|\Stripe\StripeObject $transfer_data The account (if any) the payments will be attributed to for tax reporting, and where funds from each payment will be transferred to for each of the invoices.
  43. */
  44. class Quote extends ApiResource
  45. {
  46. const OBJECT_NAME = 'quote';
  47. use ApiOperations\Update;
  48. const COLLECTION_METHOD_CHARGE_AUTOMATICALLY = 'charge_automatically';
  49. const COLLECTION_METHOD_SEND_INVOICE = 'send_invoice';
  50. const STATUS_ACCEPTED = 'accepted';
  51. const STATUS_CANCELED = 'canceled';
  52. const STATUS_DRAFT = 'draft';
  53. const STATUS_OPEN = 'open';
  54. /**
  55. * A quote models prices and services for a customer. Default options for
  56. * <code>header</code>, <code>description</code>, <code>footer</code>, and
  57. * <code>expires_at</code> can be set in the dashboard via the <a
  58. * href="https://dashboard.stripe.com/settings/billing/quote">quote template</a>.
  59. *
  60. * @param null|array $params
  61. * @param null|array|string $options
  62. *
  63. * @throws \Stripe\Exception\ApiErrorException if the request fails
  64. *
  65. * @return \Stripe\Quote the created resource
  66. */
  67. public static function create($params = null, $options = null)
  68. {
  69. self::_validateParams($params);
  70. $url = static::classUrl();
  71. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  72. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  73. $obj->setLastResponse($response);
  74. return $obj;
  75. }
  76. /**
  77. * Returns a list of your quotes.
  78. *
  79. * @param null|array $params
  80. * @param null|array|string $opts
  81. *
  82. * @throws \Stripe\Exception\ApiErrorException if the request fails
  83. *
  84. * @return \Stripe\Collection<\Stripe\Quote> of ApiResources
  85. */
  86. public static function all($params = null, $opts = null)
  87. {
  88. $url = static::classUrl();
  89. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  90. }
  91. /**
  92. * Retrieves the quote with the given ID.
  93. *
  94. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  95. * @param null|array|string $opts
  96. *
  97. * @throws \Stripe\Exception\ApiErrorException if the request fails
  98. *
  99. * @return \Stripe\Quote
  100. */
  101. public static function retrieve($id, $opts = null)
  102. {
  103. $opts = \Stripe\Util\RequestOptions::parse($opts);
  104. $instance = new static($id, $opts);
  105. $instance->refresh();
  106. return $instance;
  107. }
  108. /**
  109. * A quote models prices and services for a customer.
  110. *
  111. * @param string $id the ID of the resource to update
  112. * @param null|array $params
  113. * @param null|array|string $opts
  114. *
  115. * @throws \Stripe\Exception\ApiErrorException if the request fails
  116. *
  117. * @return \Stripe\Quote the updated resource
  118. */
  119. public static function update($id, $params = null, $opts = null)
  120. {
  121. self::_validateParams($params);
  122. $url = static::resourceUrl($id);
  123. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  124. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  125. $obj->setLastResponse($response);
  126. return $obj;
  127. }
  128. /**
  129. * @param null|array $params
  130. * @param null|array|string $opts
  131. *
  132. * @throws \Stripe\Exception\ApiErrorException if the request fails
  133. *
  134. * @return \Stripe\Quote the accepted quote
  135. */
  136. public function accept($params = null, $opts = null)
  137. {
  138. $url = $this->instanceUrl() . '/accept';
  139. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  140. $this->refreshFrom($response, $opts);
  141. return $this;
  142. }
  143. /**
  144. * @param null|array $params
  145. * @param null|array|string $opts
  146. *
  147. * @throws \Stripe\Exception\ApiErrorException if the request fails
  148. *
  149. * @return \Stripe\Quote the canceled quote
  150. */
  151. public function cancel($params = null, $opts = null)
  152. {
  153. $url = $this->instanceUrl() . '/cancel';
  154. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  155. $this->refreshFrom($response, $opts);
  156. return $this;
  157. }
  158. /**
  159. * @param null|array $params
  160. * @param null|array|string $opts
  161. *
  162. * @throws \Stripe\Exception\ApiErrorException if the request fails
  163. *
  164. * @return \Stripe\Quote the finalized quote
  165. */
  166. public function finalizeQuote($params = null, $opts = null)
  167. {
  168. $url = $this->instanceUrl() . '/finalize';
  169. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  170. $this->refreshFrom($response, $opts);
  171. return $this;
  172. }
  173. /**
  174. * @param string $id
  175. * @param null|array $params
  176. * @param null|array|string $opts
  177. *
  178. * @throws \Stripe\Exception\ApiErrorException if the request fails
  179. *
  180. * @return \Stripe\Collection<\Stripe\LineItem> list of line items
  181. */
  182. public static function allComputedUpfrontLineItems($id, $params = null, $opts = null)
  183. {
  184. $url = static::resourceUrl($id) . '/computed_upfront_line_items';
  185. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  186. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  187. $obj->setLastResponse($response);
  188. return $obj;
  189. }
  190. /**
  191. * @param string $id
  192. * @param null|array $params
  193. * @param null|array|string $opts
  194. *
  195. * @throws \Stripe\Exception\ApiErrorException if the request fails
  196. *
  197. * @return \Stripe\Collection<\Stripe\LineItem> list of line items
  198. */
  199. public static function allLineItems($id, $params = null, $opts = null)
  200. {
  201. $url = static::resourceUrl($id) . '/line_items';
  202. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  203. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  204. $obj->setLastResponse($response);
  205. return $obj;
  206. }
  207. /**
  208. * @param callable $readBodyChunkCallable
  209. * @param null|array $params
  210. * @param null|array|string $opts
  211. *
  212. * @throws \Stripe\Exception\ApiErrorException if the request fails
  213. *
  214. * @return void
  215. */
  216. public function pdf($readBodyChunkCallable, $params = null, $opts = null)
  217. {
  218. $opts = \Stripe\Util\RequestOptions::parse($opts);
  219. if (!isset($opts->apiBase)) {
  220. $opts->apiBase = \Stripe\Stripe::$apiUploadBase;
  221. }
  222. $url = $this->instanceUrl() . '/pdf';
  223. $this->_requestStream('get', $url, $readBodyChunkCallable, $params, $opts);
  224. }
  225. }