Class: Opay::Providers::Paypal
- Inherits:
-
Object
- Object
- Opay::Providers::Paypal
- Defined in:
- lib/opay/providers/paypal.rb
Class Method Summary collapse
- .create_payment(session_id, description, ip, confirm_url, cancel_url) ⇒ Object
- .process(token, payer_id, ip) ⇒ Object
Class Method Details
.create_payment(session_id, description, ip, confirm_url, cancel_url) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/opay/providers/paypal.rb', line 7 def self.create_payment(session_id, description, ip, confirm_url, cancel_url) # for future items list payment = Opay::Payment.where(session_id: session_id).first! response = geteway.setup_purchase(payment.amount.to_i, ip: ip, return_url: confirm_url, cancel_return_url: cancel_url, order_id: session_id, currency: Opay.config.paypal_currency, items: [{ name: description, quantity: 1, amount: payment.amount.to_i }] ) # check if response is success if response.success? payment.update_attribute(:session_id, response.token) geteway.redirect_url_for(response.token) end end |
.process(token, payer_id, ip) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/opay/providers/paypal.rb', line 31 def self.process(token, payer_id, ip) payment = Opay::Payment.where(session_id: token).first! if Opay.config.process_payments_localy payment.payable.finish return true end response = geteway.purchase(payment.amount, { ip: ip, token: token, currency: Opay.config.paypal_currency, payer_id: payer_id }) if response.success? payment.payable.finish return true else # Rails.logger.error(response.inspect) end false end |