Class: EZPaypal::Cart::RecurringProfile

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/core/data.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ RecurringProfile

Setup profile

Parameters:

  • profile (Hash)

    “email”, “currency” => “USD” (default “USD”),

    “item_code”, “unit_price”, “quantity”, “amount”, “initial_amount” => “0” (recurring profile will do auto-charge since begining! do not use this if you are not sure), “start_date” => “2012/02/02” (Default Time.now), “period” => “Day/Week/Month/Year” (default “Month”), “frequency” => “1” (how many periods a purchase, default 1), “cycles” => “0” (total cycles of recurring billing, default 0 means infinite)

    
    


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/core/data.rb', line 190

def initialize(profile)
  item = profile
  options = {
      "TOKEN" => item["token"],
      "EMAIL" => item["email"],
      "CURRENCYCODE" => item["currency"] || "USD",
      "FAILEDINITAMTACTION" => "CancelOnFailure", #ContinueOnFailure / CancelOnFailure

      # Display details
      "L_PAYMENTREQUEST_0_ITEMCATEGORY0" => item["category"] || "Physical",
      "L_PAYMENTREQUEST_0_NAME0" => item["item_code"] || "",
      "L_PAYMENTREQUEST_0_AMT0" => item["unit_price"] || "0",
      "L_PAYMENTREQUEST_0_QTY0" => item["quantity"] || "0",

      # Profile details
      "DESC" => item["item_code"] || "",
      "AMT" => item["amount"] || "0",
      "QTY" => item["quantity"] || "0",
      "INITAMT" => item["initial_amount"] || "0",

      # Recurring details
      "PROFILESTARTDATE" => item["start_date"] || Time.now,
      "BILLINGFREQUENCY" => item["frequency"] || "1",
      "BILLINGPERIOD" => item["period"] || "Month",
      "TOTALBILLINGCYCLES" => item["cycles"] || "0"

  }

  self.merge!(options)
end

Class Method Details

.ConvertFromCheckoutDetails(checkout_details) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/core/data.rb', line 221

def self.ConvertFromCheckoutDetails (checkout_details)
  profile = {
      "token" => checkout_details["TOKEN"],
      "email" => checkout_details["EMAIL"],
      "item_code" => checkout_details["L_PAYMENTREQUEST_0_NAME0"],
      "unit_price" => checkout_details["L_PAYMENTREQUEST_0_AMT0"],
      "quantity" => checkout_details["L_PAYMENTREQUEST_0_QTY0"],
      "amount" => checkout_details["PAYMENTREQUEST_0_AMT"],
      "start_date" => Time.now,
      "period" => "Month",
      "frequency" => "1"
  }

  profile = self.new(profile)
end