# File generated from our OpenAPI spec # frozen_string_literal: true module Stripe # A coupon contains information about a percent-off or amount-off discount you # might want to apply to a customer. Coupons may be applied to [subscriptions](https://stripe.com/docs/api#subscriptions), [invoices](https://stripe.com/docs/api#invoices), # [checkout sessions](https://stripe.com/docs/api/checkout/sessions), [quotes](https://stripe.com/docs/api#quotes), and more. Coupons do not work with conventional one-off [charges](https://stripe.com/docs/api#create_charge) or [payment intents](https://stripe.com/docs/api/payment_intents). class Coupon < APIResource extend Stripe::APIOperations::Create include Stripe::APIOperations::Delete extend Stripe::APIOperations::List include Stripe::APIOperations::Save OBJECT_NAME = "coupon" def self.object_name "coupon" end # You can create coupons easily via the [coupon management](https://dashboard.stripe.com/coupons) 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. def self.create(params = {}, opts = {}) request_stripe_object(method: :post, path: "/v1/coupons", params: params, opts: opts) end # You can delete coupons via the [coupon management](https://dashboard.stripe.com/coupons) 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. def self.delete(id, params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/coupons/%s", { id: CGI.escape(id) }), params: params, opts: opts ) end # You can delete coupons via the [coupon management](https://dashboard.stripe.com/coupons) 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. def delete(params = {}, opts = {}) request_stripe_object( method: :delete, path: format("/v1/coupons/%s", { coupon: CGI.escape(self["id"]) }), params: params, opts: opts ) end # Returns a list of your coupons. def self.list(filters = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/coupons", params: filters, opts: opts) end # Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by design, not editable. def self.update(id, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/coupons/%s", { id: CGI.escape(id) }), params: params, opts: opts ) end end end