Class: EZPaypal::Cart::RecurringPurchaseCart
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- EZPaypal::Cart::RecurringPurchaseCart
- Defined in:
- lib/core/data.rb
Overview
A cart object that holds all recurring purchase items Note that this cart only support one subscription item at a time
How to use:
-> initialize Cart
-> setup agreement (required)
-> setup summary(required)
-> done (please create profile after this, this cart only shows agreement for recurring items)
Note:
you are responsible for all the cost calculations
Instance Method Summary (collapse)
-
- (Object) cartSize
Max cart size of this cart type.
-
- (Object) reset
Clean the cart.
-
- (Object) setupAgreement(agreement)
Setup recurring payment agreement.
Instance Method Details
- (Object) cartSize
Max cart size of this cart type
122 123 124 |
# File 'lib/core/data.rb', line 122 def cartSize 1 end |
- (Object) reset
Clean the cart
173 174 175 |
# File 'lib/core/data.rb', line 173 def reset self.clear end |
- (Object) setupAgreement(agreement)
Setup recurring payment agreement
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/core/data.rb', line 132 def setupAgreement(agreement) # Check max cart size, make sure do not exceed the limit max = 0 self.each do |key, value| max = max + 1 if key.match(/^L_PAYMENTREQUEST_0_NAME/) end throw "Exceed max cart size: #{cartSize}" if (max+1 > cartSize) item = agreement current_index = max current_item = { "L_PAYMENTREQUEST_0_NAME#{current_index}" => item["item_code"] || "", #"L_PAYMENTREQUEST_0_NUMBER#{current_index}" => item["item_code"] || "", #"L_PAYMENTREQUEST_0_DESC#{current_index}" => item["description"] || "", "L_PAYMENTREQUEST_0_AMT#{current_index}" => item["unit_price"] || "0", "L_PAYMENTREQUEST_0_QTY#{current_index}" => item["quantity"] || "0", "L_PAYMENTREQUEST_0_ITEMCATEGORY#{current_index}" => item["category"] || "Physical", "L_BILLINGTYPE#{current_index}" => "RecurringPayments", "L_BILLINGAGREEMENTDESCRIPTION#{current_index}" => item["item_code"] || "" } summary = { "PAYMENTREQUEST_0_PAYMENTACTION" => item["payment_action"] || "Sale", "PAYMENTREQUEST_0_CURRENCYCODE" => item["currency"] || "USD", #"PAYMENTREQUEST_0_ITEMAMT" => item["total"] || "0", #"PAYMENTREQUEST_0_TAXAMT" => item["tax"] || "0", #"PAYMENTREQUEST_0_SHIPPINGAMT" => item["shipping"] || "0", #"PAYMENTREQUEST_0_HANDLINGAMT" => item["handling"] || "0", #"PAYMENTREQUEST_0_SHIPDISCAMT" => item["shipping_discount"] || "0", #"PAYMENTREQUEST_0_INSURANCEAMT" => item["insurance"] || "0", "PAYMENTREQUEST_0_AMT" => item["amount"] || "0", "ALLOWNOTE" => item["allow_note"] || "0", "NOSHIPPING" => item["disable_change_shipping_info"] || "1" } self.merge!(current_item).merge!(summary) end |