ShippingRate.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe;
  4. /**
  5. * Shipping rates describe the price of shipping presented to your customers and
  6. * applied to a purchase. For more information, see <a href="https://stripe.com/docs/payments/during-payment/charge-shipping">Charge for shipping</a>.
  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 bool $active Whether the shipping rate can be used for new purchases. Defaults to <code>true</code>.
  11. * @property int $created Time at which the object was created. Measured in seconds since the Unix epoch.
  12. * @property null|\Stripe\StripeObject $delivery_estimate The estimated range for how long shipping will take, meant to be displayable to the customer. This will appear on CheckoutSessions.
  13. * @property null|string $display_name The name of the shipping rate, meant to be displayable to the customer. This will appear on CheckoutSessions.
  14. * @property null|\Stripe\StripeObject $fixed_amount
  15. * @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.
  16. * @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.
  17. * @property null|string $tax_behavior Specifies whether the rate is considered inclusive of taxes or exclusive of taxes. One of <code>inclusive</code>, <code>exclusive</code>, or <code>unspecified</code>.
  18. * @property null|string|\Stripe\TaxCode $tax_code A <a href="https://stripe.com/docs/tax/tax-categories">tax code</a> ID. The Shipping tax code is <code>txcd_92010001</code>.
  19. * @property string $type The type of calculation to use on the shipping rate.
  20. */
  21. class ShippingRate extends ApiResource
  22. {
  23. const OBJECT_NAME = 'shipping_rate';
  24. use ApiOperations\Update;
  25. const TAX_BEHAVIOR_EXCLUSIVE = 'exclusive';
  26. const TAX_BEHAVIOR_INCLUSIVE = 'inclusive';
  27. const TAX_BEHAVIOR_UNSPECIFIED = 'unspecified';
  28. const TYPE_FIXED_AMOUNT = 'fixed_amount';
  29. /**
  30. * Creates a new shipping rate object.
  31. *
  32. * @param null|array $params
  33. * @param null|array|string $options
  34. *
  35. * @throws \Stripe\Exception\ApiErrorException if the request fails
  36. *
  37. * @return \Stripe\ShippingRate the created resource
  38. */
  39. public static function create($params = null, $options = null)
  40. {
  41. self::_validateParams($params);
  42. $url = static::classUrl();
  43. list($response, $opts) = static::_staticRequest('post', $url, $params, $options);
  44. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  45. $obj->setLastResponse($response);
  46. return $obj;
  47. }
  48. /**
  49. * Returns a list of your shipping rates.
  50. *
  51. * @param null|array $params
  52. * @param null|array|string $opts
  53. *
  54. * @throws \Stripe\Exception\ApiErrorException if the request fails
  55. *
  56. * @return \Stripe\Collection<\Stripe\ShippingRate> of ApiResources
  57. */
  58. public static function all($params = null, $opts = null)
  59. {
  60. $url = static::classUrl();
  61. return static::_requestPage($url, \Stripe\Collection::class, $params, $opts);
  62. }
  63. /**
  64. * Returns the shipping rate object with the given ID.
  65. *
  66. * @param array|string $id the ID of the API resource to retrieve, or an options array containing an `id` key
  67. * @param null|array|string $opts
  68. *
  69. * @throws \Stripe\Exception\ApiErrorException if the request fails
  70. *
  71. * @return \Stripe\ShippingRate
  72. */
  73. public static function retrieve($id, $opts = null)
  74. {
  75. $opts = \Stripe\Util\RequestOptions::parse($opts);
  76. $instance = new static($id, $opts);
  77. $instance->refresh();
  78. return $instance;
  79. }
  80. /**
  81. * Updates an existing shipping rate object.
  82. *
  83. * @param string $id the ID of the resource to update
  84. * @param null|array $params
  85. * @param null|array|string $opts
  86. *
  87. * @throws \Stripe\Exception\ApiErrorException if the request fails
  88. *
  89. * @return \Stripe\ShippingRate the updated resource
  90. */
  91. public static function update($id, $params = null, $opts = null)
  92. {
  93. self::_validateParams($params);
  94. $url = static::resourceUrl($id);
  95. list($response, $opts) = static::_staticRequest('post', $url, $params, $opts);
  96. $obj = \Stripe\Util\Util::convertToStripeObject($response->json, $opts);
  97. $obj->setLastResponse($response);
  98. return $obj;
  99. }
  100. }