Class: RailsPaypalGem::ExpressCheckout
- Inherits:
-
RailsPaypalGem
- Object
- RailsPaypalGem
- RailsPaypalGem::ExpressCheckout
- Defined in:
- lib/services/express_checkout.rb
Constant Summary
Constants included from RailsPaypalGem
Instance Attribute Summary collapse
-
#line_items ⇒ Object
Returns the value of attribute line_items.
-
#params ⇒ Object
Returns the value of attribute params.
-
#token ⇒ Object
Returns the value of attribute token.
Class Method Summary collapse
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(line_items, currency = 'EUR') ⇒ ExpressCheckout
constructor
A new instance of ExpressCheckout.
- #redirect_url ⇒ Object
- #set(action = 'Sale', currency = 'EUR') ⇒ Object
Constructor Details
#initialize(line_items, currency = 'EUR') ⇒ ExpressCheckout
Returns a new instance of ExpressCheckout.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/services/express_checkout.rb', line 6 def initialize(line_items, currency = 'EUR') self.line_items = line_items self.params = {} total = 0.0 line_items.each_with_index do |li, i| self.params["L_PAYMENTREQUEST_0_NAME#{i}"] = li[:name] if li.has_key?(:name) self.params["L_PAYMENTREQUEST_0_QTY#{i}"] = li[:quantity] if li.has_key?(:quantity) self.params["L_PAYMENTREQUEST_0_AMT#{i}"] = li[:price] self.params["L_PAYMENTREQUEST_0_DESC#{i}"] = li[:description] if li.has_key?(:description) total += (li[:price].to_f * li[:quantity].to_i) end params["PAYMENTREQUEST_0_AMT"] = total.to_s params["PAYMENTREQUEST_0_CURRENCYCODE"] = currency end |
Instance Attribute Details
#line_items ⇒ Object
Returns the value of attribute line_items.
4 5 6 |
# File 'lib/services/express_checkout.rb', line 4 def line_items @line_items end |
#params ⇒ Object
Returns the value of attribute params.
2 3 4 |
# File 'lib/services/express_checkout.rb', line 2 def params @params end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/services/express_checkout.rb', line 3 def token @token end |
Class Method Details
.do(token, payer_id, amount, currency = "EUR") ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/services/express_checkout.rb', line 52 def self.do(token, payer_id, amount, currency="EUR") ret = call({ "TOKEN" => token, "PAYERID" => payer_id, "AMT" => amount, "PAYMENTACTION" => 'Sale', "METHOD" => "DoExpressCheckoutPayment", "CURRENCYCODE" => currency}) if ret["PAYMENTSTATUS"] == 'Completed' ret["TRANSACTIONID"] else puts "#{ret.inspect}" end end |
.get(token) ⇒ Object
48 49 50 |
# File 'lib/services/express_checkout.rb', line 48 def self.get(token) call({"TOKEN" => token, "METHOD" => "GetExpressCheckoutDetails"}) end |
Instance Method Details
#get ⇒ Object
34 35 36 37 |
# File 'lib/services/express_checkout.rb', line 34 def get set if self.token.nil? self.class.get(self.token) end |
#redirect_url ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/services/express_checkout.rb', line 39 def redirect_url set if self.token.nil? if Rails.env == "development" "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=" + self.token elsif Rails.env == "production" "https://www.paypal.com/webscr?cmd=_express-checkout&token=" + self.token end end |
#set(action = 'Sale', currency = 'EUR') ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/services/express_checkout.rb', line 22 def set(action = 'Sale', currency = 'EUR') self.params["PAYMENTREQUEST_0_CURRENCYCODE"] = currency self.params["PAYMENTREQUEST_0_PAYMENTACTION"] = action self.params["METHOD"] = 'SetExpressCheckout' response = self.class.call(self.params) if response["ACK"] == 'Success' self.token = response["TOKEN"] else raise response["L_ERRORCODE0"]+":"+response["L_LONGMESSAGE0"] end end |