Class: Stripe::Coupon

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Includes:
APIOperations::Delete, APIOperations::Save
Defined in:
lib/stripe/resources/coupon.rb

Overview

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](stripe.com/docs/api#subscriptions), [invoices](stripe.com/docs/api#invoices), [checkout sessions](stripe.com/docs/api/checkout/sessions), [quotes](stripe.com/docs/api#quotes), and more. Coupons do not work with conventional one-off [charges](stripe.com/docs/api#create_charge) or [payment intents](stripe.com/docs/api/payment_intents).

Constant Summary collapse

OBJECT_NAME =
"coupon"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Save

included, #save

Methods included from APIOperations::Delete

included

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Class Method Details

.create(params = {}, opts = {}) ⇒ Object

You can create coupons easily via the [coupon management](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.



22
23
24
# File 'lib/stripe/resources/coupon.rb', line 22

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/coupons", params: params, opts: opts)
end

.delete(id, params = {}, opts = {}) ⇒ Object

You can delete coupons via the [coupon management](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.



27
28
29
30
31
32
33
34
# File 'lib/stripe/resources/coupon.rb', line 27

def self.delete(id, params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/coupons/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts
  )
end

.list(params = {}, opts = {}) ⇒ Object

Returns a list of your coupons.



47
48
49
# File 'lib/stripe/resources/coupon.rb', line 47

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/coupons", params: params, opts: opts)
end

.object_nameObject



15
16
17
# File 'lib/stripe/resources/coupon.rb', line 15

def self.object_name
  "coupon"
end

.update(id, params = {}, opts = {}) ⇒ Object

Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by design, not editable.



52
53
54
55
56
57
58
59
# File 'lib/stripe/resources/coupon.rb', line 52

def self.update(id, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/coupons/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts
  )
end

Instance Method Details

#delete(params = {}, opts = {}) ⇒ Object

You can delete coupons via the [coupon management](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.



37
38
39
40
41
42
43
44
# File 'lib/stripe/resources/coupon.rb', line 37

def delete(params = {}, opts = {})
  request_stripe_object(
    method: :delete,
    path: format("/v1/coupons/%<coupon>s", { coupon: CGI.escape(self["id"]) }),
    params: params,
    opts: opts
  )
end