CouponService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. // File generated from our OpenAPI spec
  3. namespace Stripe\Service;
  4. /**
  5. * @phpstan-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  6. * @psalm-import-type RequestOptionsArray from \Stripe\Util\RequestOptions
  7. */
  8. class CouponService extends \Stripe\Service\AbstractService
  9. {
  10. /**
  11. * Returns a list of your coupons.
  12. *
  13. * @param null|array $params
  14. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  15. *
  16. * @throws \Stripe\Exception\ApiErrorException if the request fails
  17. *
  18. * @return \Stripe\Collection<\Stripe\Coupon>
  19. */
  20. public function all($params = null, $opts = null)
  21. {
  22. return $this->requestCollection('get', '/v1/coupons', $params, $opts);
  23. }
  24. /**
  25. * You can create coupons easily via the <a
  26. * href="https://dashboard.stripe.com/coupons">coupon management</a> page of the
  27. * Stripe dashboard. Coupon creation is also accessible via the API if you need to
  28. * create coupons on the fly.
  29. *
  30. * A coupon has either a <code>percent_off</code> or an <code>amount_off</code> and
  31. * <code>currency</code>. If you set an <code>amount_off</code>, that amount will
  32. * be subtracted from any invoice’s subtotal. For example, an invoice with a
  33. * subtotal of <currency>100</currency> will have a final total of
  34. * <currency>0</currency> if a coupon with an <code>amount_off</code> of
  35. * <amount>200</amount> is applied to it and an invoice with a subtotal of
  36. * <currency>300</currency> will have a final total of <currency>100</currency> if
  37. * a coupon with an <code>amount_off</code> of <amount>200</amount> is applied to
  38. * it.
  39. *
  40. * @param null|array $params
  41. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  42. *
  43. * @throws \Stripe\Exception\ApiErrorException if the request fails
  44. *
  45. * @return \Stripe\Coupon
  46. */
  47. public function create($params = null, $opts = null)
  48. {
  49. return $this->request('post', '/v1/coupons', $params, $opts);
  50. }
  51. /**
  52. * You can delete coupons via the <a
  53. * href="https://dashboard.stripe.com/coupons">coupon management</a> page of the
  54. * Stripe dashboard. However, deleting a coupon does not affect any customers who
  55. * have already applied the coupon; it means that new customers can’t redeem the
  56. * coupon. You can also delete coupons via the API.
  57. *
  58. * @param string $id
  59. * @param null|array $params
  60. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  61. *
  62. * @throws \Stripe\Exception\ApiErrorException if the request fails
  63. *
  64. * @return \Stripe\Coupon
  65. */
  66. public function delete($id, $params = null, $opts = null)
  67. {
  68. return $this->request('delete', $this->buildPath('/v1/coupons/%s', $id), $params, $opts);
  69. }
  70. /**
  71. * Retrieves the coupon with the given ID.
  72. *
  73. * @param string $id
  74. * @param null|array $params
  75. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  76. *
  77. * @throws \Stripe\Exception\ApiErrorException if the request fails
  78. *
  79. * @return \Stripe\Coupon
  80. */
  81. public function retrieve($id, $params = null, $opts = null)
  82. {
  83. return $this->request('get', $this->buildPath('/v1/coupons/%s', $id), $params, $opts);
  84. }
  85. /**
  86. * Updates the metadata of a coupon. Other coupon details (currency, duration,
  87. * amount_off) are, by design, not editable.
  88. *
  89. * @param string $id
  90. * @param null|array $params
  91. * @param null|RequestOptionsArray|\Stripe\Util\RequestOptions $opts
  92. *
  93. * @throws \Stripe\Exception\ApiErrorException if the request fails
  94. *
  95. * @return \Stripe\Coupon
  96. */
  97. public function update($id, $params = null, $opts = null)
  98. {
  99. return $this->request('post', $this->buildPath('/v1/coupons/%s', $id), $params, $opts);
  100. }
  101. }