Class: Stripe::CouponService
- Inherits:
-
StripeService
- Object
- StripeService
- Stripe::CouponService
- Defined in:
- lib/stripe/services/coupon_service.rb
Instance Method Summary collapse
-
#create(params = {}, opts = {}) ⇒ Object
You can create coupons easily via the coupon management page of the Stripe dashboard.
-
#delete(coupon, params = {}, opts = {}) ⇒ Object
You can delete coupons via the coupon management page of the Stripe dashboard.
-
#list(params = {}, opts = {}) ⇒ Object
Returns a list of your coupons.
-
#retrieve(coupon, params = {}, opts = {}) ⇒ Object
Retrieves the coupon with the given ID.
-
#update(coupon, params = {}, opts = {}) ⇒ Object
Updates the metadata of a coupon.
Methods inherited from StripeService
#initialize, #request, #request_stream
Constructor Details
This class inherits a constructor from Stripe::StripeService
Instance Method Details
#create(params = {}, opts = {}) ⇒ Object
You can create coupons easily via the coupon management page of the Stripe dashboard. Coupon creation is also accessible via the API if you need to create coupons on the fly.
A coupon has either a percent_off or an amount_off and currency. If you set an amount_off, that amount will be subtracted from any invoice's subtotal. For example, an invoice with a subtotal of 100 will have a final total of 0 if a coupon with an amount_off of 200 is applied to it and an invoice with a subtotal of 300 will have a final total of 100 if a coupon with an amount_off of 200 is applied to it.
9 10 11 |
# File 'lib/stripe/services/coupon_service.rb', line 9 def create(params = {}, opts = {}) request(method: :post, path: "/v1/coupons", params: params, opts: opts, base_address: :api) end |
#delete(coupon, params = {}, opts = {}) ⇒ Object
You can delete coupons via the coupon management page of the Stripe dashboard. However, deleting a coupon does not affect any customers who have already applied the coupon; it means that new customers can't redeem the coupon. You can also delete coupons via the API.
14 15 16 17 18 19 20 21 22 |
# File 'lib/stripe/services/coupon_service.rb', line 14 def delete(coupon, params = {}, opts = {}) request( method: :delete, path: format("/v1/coupons/%<coupon>s", { coupon: CGI.escape(coupon) }), params: params, opts: opts, base_address: :api ) end |
#list(params = {}, opts = {}) ⇒ Object
Returns a list of your coupons.
25 26 27 |
# File 'lib/stripe/services/coupon_service.rb', line 25 def list(params = {}, opts = {}) request(method: :get, path: "/v1/coupons", params: params, opts: opts, base_address: :api) end |
#retrieve(coupon, params = {}, opts = {}) ⇒ Object
Retrieves the coupon with the given ID.
30 31 32 33 34 35 36 37 38 |
# File 'lib/stripe/services/coupon_service.rb', line 30 def retrieve(coupon, params = {}, opts = {}) request( method: :get, path: format("/v1/coupons/%<coupon>s", { coupon: CGI.escape(coupon) }), params: params, opts: opts, base_address: :api ) end |
#update(coupon, params = {}, opts = {}) ⇒ Object
Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by design, not editable.
41 42 43 44 45 46 47 48 49 |
# File 'lib/stripe/services/coupon_service.rb', line 41 def update(coupon, params = {}, opts = {}) request( method: :post, path: format("/v1/coupons/%<coupon>s", { coupon: CGI.escape(coupon) }), params: params, opts: opts, base_address: :api ) end |