Class: Stripe::PromotionCode

Inherits:
APIResource show all
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). You can create multiple codes for a single coupon.

If you enable promotion codes in your [customer portal configuration](stripe.com/docs/customer-management/configure-portal), then customers can redeem a code themselves when updating a subscription in the portal. Customers can also view the currently active promotion codes and coupons on each of their subscriptions in the portal.

Defined Under Namespace

Classes: CreateParams, ListParams, Restrictions, UpdateParams

Constant Summary collapse

OBJECT_NAME =
"promotion_code"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Save

included, #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

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

Instance Attribute Details

#activeObject (readonly)

Whether the promotion code is currently active. A promotion code is only active if the coupon is also valid.



204
205
206
# File 'lib/stripe/resources/promotion_code.rb', line 204

def active
  @active
end

#codeObject (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).



206
207
208
# File 'lib/stripe/resources/promotion_code.rb', line 206

def code
  @code
end

#couponObject (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).



210
211
212
# File 'lib/stripe/resources/promotion_code.rb', line 210

def coupon
  @coupon
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



212
213
214
# File 'lib/stripe/resources/promotion_code.rb', line 212

def created
  @created
end

#customerObject (readonly)

The customer that this promotion code can be used by.



214
215
216
# File 'lib/stripe/resources/promotion_code.rb', line 214

def customer
  @customer
end

#expires_atObject (readonly)

Date at which the promotion code can no longer be redeemed.



216
217
218
# File 'lib/stripe/resources/promotion_code.rb', line 216

def expires_at
  @expires_at
end

#idObject (readonly)

Unique identifier for the object.



218
219
220
# File 'lib/stripe/resources/promotion_code.rb', line 218

def id
  @id
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



220
221
222
# File 'lib/stripe/resources/promotion_code.rb', line 220

def livemode
  @livemode
end

#max_redemptionsObject (readonly)

Maximum number of times this promotion code can be redeemed.



222
223
224
# File 'lib/stripe/resources/promotion_code.rb', line 222

def max_redemptions
  @max_redemptions
end

#metadataObject (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.



224
225
226
# File 'lib/stripe/resources/promotion_code.rb', line 224

def 
  @metadata
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



226
227
228
# File 'lib/stripe/resources/promotion_code.rb', line 226

def object
  @object
end

#restrictionsObject (readonly)

Attribute for field restrictions



228
229
230
# File 'lib/stripe/resources/promotion_code.rb', line 228

def restrictions
  @restrictions
end

#times_redeemedObject (readonly)

Number of times this promotion code has been used.



230
231
232
# File 'lib/stripe/resources/promotion_code.rb', line 230

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.



233
234
235
# File 'lib/stripe/resources/promotion_code.rb', line 233

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

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

Returns a list of your promotion codes.



238
239
240
# File 'lib/stripe/resources/promotion_code.rb', line 238

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

.object_nameObject



16
17
18
# File 'lib/stripe/resources/promotion_code.rb', line 16

def self.object_name
  "promotion_code"
end

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

Updates the specified promotion code by setting the values of the parameters passed. Most fields are, by design, not editable.



243
244
245
246
247
248
249
250
# File 'lib/stripe/resources/promotion_code.rb', line 243

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