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 an underlying promotion. You can create multiple codes for a single promotion.

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: Promotion, Restrictions

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

#==, #[], #[]=, #_get_inner_class_type, 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.



66
67
68
# File 'lib/stripe/resources/promotion_code.rb', line 66

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).



68
69
70
# File 'lib/stripe/resources/promotion_code.rb', line 68

def code
  @code
end

#createdObject (readonly)

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



70
71
72
# File 'lib/stripe/resources/promotion_code.rb', line 70

def created
  @created
end

#customerObject (readonly)

The customer that this promotion code can be used by.



72
73
74
# File 'lib/stripe/resources/promotion_code.rb', line 72

def customer
  @customer
end

#expires_atObject (readonly)

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



74
75
76
# File 'lib/stripe/resources/promotion_code.rb', line 74

def expires_at
  @expires_at
end

#idObject (readonly)

Unique identifier for the object.



76
77
78
# File 'lib/stripe/resources/promotion_code.rb', line 76

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.



78
79
80
# File 'lib/stripe/resources/promotion_code.rb', line 78

def livemode
  @livemode
end

#max_redemptionsObject (readonly)

Maximum number of times this promotion code can be redeemed.



80
81
82
# File 'lib/stripe/resources/promotion_code.rb', line 80

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.



82
83
84
# File 'lib/stripe/resources/promotion_code.rb', line 82

def 
  @metadata
end

#objectObject (readonly)

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



84
85
86
# File 'lib/stripe/resources/promotion_code.rb', line 84

def object
  @object
end

#promotionObject (readonly)

Attribute for field promotion



86
87
88
# File 'lib/stripe/resources/promotion_code.rb', line 86

def promotion
  @promotion
end

#restrictionsObject (readonly)

Attribute for field restrictions



88
89
90
# File 'lib/stripe/resources/promotion_code.rb', line 88

def restrictions
  @restrictions
end

#times_redeemedObject (readonly)

Number of times this promotion code has been used.



90
91
92
# File 'lib/stripe/resources/promotion_code.rb', line 90

def times_redeemed
  @times_redeemed
end

Class Method Details

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

A promotion code points to an underlying promotion. You can optionally restrict the code to a specific customer, redemption limit, and expiration date.



93
94
95
# File 'lib/stripe/resources/promotion_code.rb', line 93

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

.field_remappingsObject



116
117
118
# File 'lib/stripe/resources/promotion_code.rb', line 116

def self.field_remappings
  @field_remappings = {}
end

.inner_class_typesObject



112
113
114
# File 'lib/stripe/resources/promotion_code.rb', line 112

def self.inner_class_types
  @inner_class_types = { promotion: Promotion, restrictions: Restrictions }
end

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

Returns a list of your promotion codes.



98
99
100
# File 'lib/stripe/resources/promotion_code.rb', line 98

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.



103
104
105
106
107
108
109
110
# File 'lib/stripe/resources/promotion_code.rb', line 103

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