Quote.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. Once
  6. * accepted, it will automatically create an invoice, subscription or subscription
  7. * schedule.
  8. *
  9. * @property string $id Unique identifier for the object.
  10. * @property string $object String representing the object's type. Objects of the same type share the same value.
  11. * @property int $amount_subtotal Total before any discounts or taxes are applied.
  12. * @property int $amount_total Total after discounts and taxes are applied.
  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 subtotal 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. 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 (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 null|\Stripe\StripeObject $invoice_settings All invoices will be billed using the specified settings.
  30. * @property \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\All;
  48. use ApiOperations\Create;
  49. use ApiOperations\Retrieve;
  50. use ApiOperations\Update;
  51. const COLLECTION_METHOD_CHARGE_AUTOMATICALLY = 'charge_automatically';
  52. const COLLECTION_METHOD_SEND_INVOICE = 'send_invoice';
  53. const STATUS_ACCEPTED = 'accepted';
  54. const STATUS_CANCELED = 'canceled';
  55. const STATUS_DRAFT = 'draft';
  56. const STATUS_OPEN = 'open';
  57. /**
  58. * @param callable $readBodyChunkCallable
  59. * @param null|array $params
  60. * @param null|array|string $opts
  61. *
  62. * @throws \Stripe\Exception\ApiErrorException if the request fails
  63. */
  64. public function pdf($readBodyChunkCallable, $params = null, $opts = null)
  65. {
  66. $opts = \Stripe\Util\RequestOptions::parse($opts);
  67. if (null === $opts->apiBase) {
  68. $opts->apiBase = Stripe::$apiUploadBase;
  69. }
  70. $url = $this->instanceUrl() . '/pdf';
  71. $this->_requestStream('get', $url, $readBodyChunkCallable, $params, $opts);
  72. }
  73. /**
  74. * @param null|array $params
  75. * @param null|array|string $opts
  76. *
  77. * @throws \Stripe\Exception\ApiErrorException if the request fails
  78. *
  79. * @return \Stripe\Quote the accepted quote
  80. */
  81. public function accept($params = null, $opts = null)
  82. {
  83. $url = $this->instanceUrl() . '/accept';
  84. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  85. $this->refreshFrom($response, $opts);
  86. return $this;
  87. }
  88. /**
  89. * @param null|array $params
  90. * @param null|array|string $opts
  91. *
  92. * @throws \Stripe\Exception\ApiErrorException if the request fails
  93. *
  94. * @return \Stripe\Quote the canceled quote
  95. */
  96. public function cancel($params = null, $opts = null)
  97. {
  98. $url = $this->instanceUrl() . '/cancel';
  99. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  100. $this->refreshFrom($response, $opts);
  101. return $this;
  102. }
  103. /**
  104. * @param null|array $params
  105. * @param null|array|string $opts
  106. *
  107. * @throws \Stripe\Exception\ApiErrorException if the request fails
  108. *
  109. * @return \Stripe\Quote the finalized quote
  110. */
  111. public function finalizeQuote($params = null, $opts = null)
  112. {
  113. $url = $this->instanceUrl() . '/finalize';
  114. list($response, $opts) = $this->_request('post', $url, $params, $opts);
  115. $this->refreshFrom($response, $opts);
  116. return $this;
  117. }
  118. /**
  119. * @param null|array $params
  120. * @param null|array|string $opts
  121. * @param mixed $id
  122. *
  123. * @throws \Stripe\Exception\ApiErrorException if the request fails
  124. *
  125. * @return \Stripe\Collection<\Stripe\Quote> list of LineItems
  126. */
  127. public static function allComputedUpfrontLineItems($id, $params = null, $opts = null)
  128. {
  129. $url = static::resourceUrl($id) . '/computed_upfront_line_items';
  130. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  131. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  132. $obj->setLastResponse($response);
  133. return $obj;
  134. }
  135. /**
  136. * @param null|array $params
  137. * @param null|array|string $opts
  138. * @param mixed $id
  139. *
  140. * @throws \Stripe\Exception\ApiErrorException if the request fails
  141. *
  142. * @return \Stripe\Collection<\Stripe\Quote> list of LineItems
  143. */
  144. public static function allLineItems($id, $params = null, $opts = null)
  145. {
  146. $url = static::resourceUrl($id) . '/line_items';
  147. list($response, $opts) = static::_staticRequest('get', $url, $params, $opts);
  148. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  149. $obj->setLastResponse($response);
  150. return $obj;
  151. }
  152. }