Class: EZPaypal::Cart::OneTimePurchaseCart
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- EZPaypal::Cart::OneTimePurchaseCart
- Defined in:
- lib/core/data.rb
Overview
A cart object that holds all one time purchase items
How to use:
-> initialize Cart
-> add items (optional)
-> setup shipping info(optional)
-> setup summary(required)
-> done (if involve recurring purchase, please create profile, this cart only shows agreement for recurring items)
Note:
you are responsible for all the cost calculations
Instance Method Summary (collapse)
-
- (Object) addItem(item)
Add item to the cart (optional).
-
- (Object) cartSize
Max cart size of this cart type.
-
- (Object) reset
Clean the cart.
-
- (Object) setupShippingInfo(shipping)
Setup shipping info (optional).
-
- (Object) setupSummary(summary)
Add cart summary, please calculate yourself (required).
Instance Method Details
- (Object) addItem(item)
Add item to the cart (optional)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/core/data.rb', line 35 def addItem(item) # 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) # Add item to cart current_index = max current_item = { "L_PAYMENTREQUEST_0_ITEMCATEGORY#{current_index}" => item["category"] || "Physical", "L_PAYMENTREQUEST_0_NAME#{current_index}" => item["name"] || "", "L_PAYMENTREQUEST_0_NUMBER#{current_index}" => item["item_code"] || "", "L_PAYMENTREQUEST_0_DESC#{current_index}" => item["description"] || "", "L_PAYMENTREQUEST_0_AMT#{current_index}" => item["amount"] || "0", "L_PAYMENTREQUEST_0_QTY#{current_index}" => item["quantity"] || "0" } self.merge!(current_item) end |
- (Object) cartSize
Max cart size of this cart type
27 28 29 |
# File 'lib/core/data.rb', line 27 def cartSize 10 end |
- (Object) reset
Clean the cart
102 103 104 |
# File 'lib/core/data.rb', line 102 def reset self.clear end |
- (Object) setupShippingInfo(shipping)
Setup shipping info (optional)
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/core/data.rb', line 60 def setupShippingInfo(shipping) item = shipping = { "PAYMENTREQUEST_0_SHIPTONAME" => item["name"] || "", "PAYMENTREQUEST_0_SHIPTOSTREET" => item["street"] || "", "PAYMENTREQUEST_0_SHIPTOSTREET2" => item["street2"] || "", "PAYMENTREQUEST_0_SHIPTOCITY" => item["city"] || "", "PAYMENTREQUEST_0_SHIPTOSTATE" => item["state"] || "", "PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE" => item["country"] || "", "PAYMENTREQUEST_0_SHIPTOZIP" => item["zip"] || "", "PAYMENTREQUEST_0_SHIPTOPHONENUM" => item["phone"] || "" } self.merge!() end |
- (Object) setupSummary(summary)
Add cart summary, please calculate yourself (required)
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/core/data.rb', line 81 def setupSummary (summary) item = summary = { "PAYMENTREQUEST_0_PAYMENTACTION" => item["payment_action"] || "Sale", "PAYMENTREQUEST_0_CURRENCYCODE" => item["currency"] || "USD", "PAYMENTREQUEST_0_ITEMAMT" => item["subtotal"] || "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["total"] || "0", "ALLOWNOTE" => item["allow_note"] || "0", "NOSHIPPING" => item["disable_change_shipping_info"] || "1" } self.merge!() end |