CouponService.php 3.6 KB

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