Class: Stripe::PromotionCode
- Inherits:
-
APIResource
- Object
- StripeObject
- APIResource
- Stripe::PromotionCode
- Extended by:
- APIOperations::Create, APIOperations::List
- Includes:
- APIOperations::Save
- Defined in:
- lib/stripe/resources/promotion_code.rb
Overview
A Promotion Code represents a customer-redeemable code for a [coupon](stripe.com/docs/api#coupons). It can be used to create multiple codes for a single coupon.
Defined Under Namespace
Classes: Restrictions
Constant Summary collapse
- OBJECT_NAME =
"promotion_code"
Constants inherited from StripeObject
StripeObject::RESERVED_FIELD_NAMES
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Whether the promotion code is currently active.
-
#code ⇒ Object
readonly
The customer-facing code.
-
#coupon ⇒ Object
readonly
A coupon contains information about a percent-off or amount-off discount you might want to apply to a customer.
-
#created ⇒ Object
readonly
Time at which the object was created.
-
#customer ⇒ Object
readonly
The customer that this promotion code can be used by.
-
#expires_at ⇒ Object
readonly
Date at which the promotion code can no longer be redeemed.
-
#id ⇒ Object
readonly
Unique identifier for the object.
-
#livemode ⇒ Object
readonly
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
-
#max_redemptions ⇒ Object
readonly
Maximum number of times this promotion code can be redeemed.
-
#metadata ⇒ Object
readonly
Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object.
-
#object ⇒ Object
readonly
String representing the object’s type.
-
#restrictions ⇒ Object
readonly
Attribute for field restrictions.
-
#times_redeemed ⇒ Object
readonly
Number of times this promotion code has been used.
Attributes inherited from APIResource
Attributes inherited from StripeObject
Class Method Summary collapse
-
.create(params = {}, opts = {}) ⇒ Object
A promotion code points to a coupon.
-
.list(filters = {}, opts = {}) ⇒ Object
Returns a list of your promotion codes.
- .object_name ⇒ Object
-
.update(id, params = {}, opts = {}) ⇒ Object
Updates the specified promotion code by setting the values of the parameters passed.
Methods included from APIOperations::Create
Methods included from APIOperations::List
Methods included from APIOperations::Save
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
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
Instance Attribute Details
#active ⇒ Object (readonly)
Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid.
24 25 26 |
# File 'lib/stripe/resources/promotion_code.rb', line 24 def active @active end |
#code ⇒ Object (readonly)
The customer-facing code. Regardless of case, this code must be unique across all active promotion codes for each customer. Valid characters are lower case letters (a-z), upper case letters (A-Z), and digits (0-9).
26 27 28 |
# File 'lib/stripe/resources/promotion_code.rb', line 26 def code @code end |
#coupon ⇒ Object (readonly)
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).
30 31 32 |
# File 'lib/stripe/resources/promotion_code.rb', line 30 def coupon @coupon end |
#created ⇒ Object (readonly)
Time at which the object was created. Measured in seconds since the Unix epoch.
32 33 34 |
# File 'lib/stripe/resources/promotion_code.rb', line 32 def created @created end |
#customer ⇒ Object (readonly)
The customer that this promotion code can be used by.
34 35 36 |
# File 'lib/stripe/resources/promotion_code.rb', line 34 def customer @customer end |
#expires_at ⇒ Object (readonly)
Date at which the promotion code can no longer be redeemed.
36 37 38 |
# File 'lib/stripe/resources/promotion_code.rb', line 36 def expires_at @expires_at end |
#id ⇒ Object (readonly)
Unique identifier for the object.
38 39 40 |
# File 'lib/stripe/resources/promotion_code.rb', line 38 def id @id end |
#livemode ⇒ Object (readonly)
Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.
40 41 42 |
# File 'lib/stripe/resources/promotion_code.rb', line 40 def livemode @livemode end |
#max_redemptions ⇒ Object (readonly)
Maximum number of times this promotion code can be redeemed.
42 43 44 |
# File 'lib/stripe/resources/promotion_code.rb', line 42 def max_redemptions @max_redemptions end |
#metadata ⇒ Object (readonly)
Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
44 45 46 |
# File 'lib/stripe/resources/promotion_code.rb', line 44 def @metadata end |
#object ⇒ Object (readonly)
String representing the object’s type. Objects of the same type share the same value.
46 47 48 |
# File 'lib/stripe/resources/promotion_code.rb', line 46 def object @object end |
#restrictions ⇒ Object (readonly)
Attribute for field restrictions
48 49 50 |
# File 'lib/stripe/resources/promotion_code.rb', line 48 def restrictions @restrictions end |
#times_redeemed ⇒ Object (readonly)
Number of times this promotion code has been used.
50 51 52 |
# File 'lib/stripe/resources/promotion_code.rb', line 50 def times_redeemed @times_redeemed end |
Class Method Details
.create(params = {}, opts = {}) ⇒ Object
A promotion code points to a coupon. You can optionally restrict the code to a specific customer, redemption limit, and expiration date.
53 54 55 |
# File 'lib/stripe/resources/promotion_code.rb', line 53 def self.create(params = {}, opts = {}) request_stripe_object(method: :post, path: "/v1/promotion_codes", params: params, opts: opts) end |
.list(filters = {}, opts = {}) ⇒ Object
Returns a list of your promotion codes.
58 59 60 |
# File 'lib/stripe/resources/promotion_code.rb', line 58 def self.list(filters = {}, opts = {}) request_stripe_object(method: :get, path: "/v1/promotion_codes", params: filters, opts: opts) end |
.object_name ⇒ Object
13 14 15 |
# File 'lib/stripe/resources/promotion_code.rb', line 13 def self.object_name "promotion_code" end |
.update(id, params = {}, opts = {}) ⇒ Object
Updates the specified promotion code by setting the values of the parameters passed. Most fields are, by design, not editable.
63 64 65 66 67 68 69 70 |
# File 'lib/stripe/resources/promotion_code.rb', line 63 def self.update(id, params = {}, opts = {}) request_stripe_object( method: :post, path: format("/v1/promotion_codes/%<id>s", { id: CGI.escape(id) }), params: params, opts: opts ) end |