Class: Simplify::Coupon

Inherits:
Hash
  • Object
show all
Defined in:
lib/simplify/coupon.rb

Overview

A Coupon object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#private_keyObject

Private key used to access the API.



40
41
42
# File 'lib/simplify/coupon.rb', line 40

def private_key
  @private_key
end

#public_keyObject

Public key used to access the API.



37
38
39
# File 'lib/simplify/coupon.rb', line 37

def public_key
  @public_key
end

Class Method Details

.create(parms, public_key = nil, private_key = nil) ⇒ Object

Creates an Coupon object

parms

a hash of parameters; valid keys are:

  • amountOff Amount off of the price of the product in minor units in the currency of the merchant. While this field is optional, you must provide either amountOff or percentOff for a coupon. Example: 1000 = 10.00

  • couponCode Code that identifies the coupon to be used. required

  • description A brief section that describes the coupon.

  • durationInMonths Duration in months that the coupon will be applied after it has first been selected.

  • endDate Last date of the coupon in UTC millis that the coupon can be applied to a subscription. This ends at 23:59:59 of the merchant timezone.

  • maxRedemptions Maximum number of redemptions allowed for the coupon. A redemption is defined as when the coupon is applied to the subscription for the first time.

  • percentOff Percentage off of the price of the product. While this field is optional, you must provide either amountOff or percentOff for a coupon. The percent off is a whole number.

  • startDate First date of the coupon in UTC millis that the coupon can be applied to a subscription. This starts at midnight of the merchant timezone. required

public_key

Public to use for the API call. If nil, the value of Simplify::public_key will be used.

private_key

Private key to use for the API call. If nil, the value of Simplify::private_key will be used.

Returns a Coupon object.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/simplify/coupon.rb', line 58

def self.create(parms, public_key = nil, private_key = nil)
    if public_key == nil then
        public_key = Simplify::public_key
    end
    if private_key == nil then
        private_key = Simplify::private_key
    end

    h = Simplify::PaymentsApi.execute("coupon", 'create', parms, public_key, private_key)
    obj = Coupon.new()
    obj.public_key = public_key
    obj.private_key = private_key
    obj = obj.merge(h)
    obj
end

.find(id, public_key = nil, private_key = nil) ⇒ Object

Retrieve a Coupon object from the API

id

ID of object to retrieve

public_key

Public to use for the API call. If nil, the value of Simplify::public_key will be used.

private_key

Private key to use for the API call. If nil, the value of Simplify::private_key will be used.

Returns a Coupon object.



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/simplify/coupon.rb', line 115

def self.find(id, public_key = nil, private_key = nil)
    if public_key == nil then
         public_key = Simplify::public_key
    end
    if private_key == nil then
        private_key = Simplify::private_key
    end

    h = Simplify::PaymentsApi.execute("coupon", 'show', {"id" => id}, public_key, private_key)
    obj = Coupon.new()
    obj.public_key = public_key
    obj.private_key = private_key
    obj = obj.merge(h)
    obj
end

.list(criteria = nil, public_key = nil, private_key = nil) ⇒ Object

Retrieve Coupon objects.

criteria

a hash of parameters; valid keys are:

  • filter Filters to apply to the list.

  • max Allows up to a max of 50 list items to return. default:20

  • offset Used in paging of the list. This is the start offset of the page. default:0

  • sorting Allows for ascending or descending sorting of the list. The value maps properties to the sort direction (either asc for ascending or desc for descending). Sortable properties are: dateCreated maxRedemptions timesRedeemed id startDate endDate percentOff couponCode durationInMonths amountOff.

public_key

Public to use for the API call. If nil, the value of Simplify::public_key will be used.

private_key

Private key to use for the API call. If nil, the value of Simplify::private_key will be used.

Returns an object where the list property contains the list of Coupon objects and the total property contains the total number of Coupon objects available for the given criteria.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/simplify/coupon.rb', line 91

def self.list(criteria = nil, public_key = nil, private_key = nil)

    if public_key == nil then
        public_key = Simplify::public_key
    end
    if private_key == nil then
       private_key = Simplify::private_key
    end

    h = Simplify::PaymentsApi.execute("coupon", 'list', criteria, public_key, private_key)
    obj = Coupon.new()
    obj.public_key = public_key
    obj.private_key = private_key
    obj = obj.merge(h)
    obj

end

Instance Method Details

#deleteObject

Delete this object



75
76
77
78
79
# File 'lib/simplify/coupon.rb', line 75

def delete()
    h = Simplify::PaymentsApi.execute("coupon", 'delete', self, self.public_key, self.private_key)
    self.merge!(h)
    self
end

#updateObject

  • maxRedemptions Maximum number of redemptions allowed for the coupon. A redemption is defined as when the coupon is applied to the subscription for the first time.



136
137
138
139
140
# File 'lib/simplify/coupon.rb', line 136

def update()
      h = Simplify::PaymentsApi.execute("coupon", 'update', self, self.public_key, self.private_key)
      self.merge!(h)
      self
end