class ActivePayment::Gateways::PaypalExpressCheckout
Attributes
purchase_token[RW]
sales[RW]
Public Class Methods
new()
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 12 def initialize @gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options) end
Public Instance Methods
external_id_from_request(request)
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 47 def external_id_from_request(request) request.params[:token] end
livemode?()
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 51 def livemode? ActiveMerchant::Billing::Base.mode != :test end
setup_purchase(sales)
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 16 def setup_purchase(sales) @sales = sales payables = @sales.map(&:payable) amount = @sales.amount_in_cents.to_i response = @gateway.setup_purchase(amount, paypal_data(payables)) raise ActivePayment::InvalidGatewayResponseError.new(response) unless response.success? @purchase_token = response.token @gateway.redirect_url_for(response.token) end
verify_purchase(params)
click to toggle source
return boolean
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 30 def verify_purchase(params) token = params[:token] begin response = @gateway.details_for(token) fail ActivePayment::InvalidGatewayResponseError.new(response) unless response.success? amount = params[:amount] purchase_response = @gateway.purchase(amount, params.merge(payer_id: response.payer_id)) fail ActivePayment::InvalidGatewayResponseError.new(purchase_response) unless purchase_response.success? rescue ActivePayment::InvalidGatewayResponseError return false end true end
Private Instance Methods
cancel_return_url()
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 80 def cancel_return_url url_for(controller: 'active_payment/paypal_express_checkout_callback', action: :cancel, only_path: false, host: ActivePayment.configuration.default_url_host) end
paypal_data(payables)
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 65 def paypal_data(payables) { items: payables.map(&:to_paypal_hash), return_url: return_url, cancel_return_url: cancel_return_url, currency: @sales.currency, allow_note: false, allow_guest_checkout: true } end
paypal_options()
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 57 def paypal_options { login: ActivePayment.configuration.paypal_login, password: ActivePayment.configuration.paypal_password, signature: ActivePayment.configuration.paypal_signature, } end
return_url()
click to toggle source
# File lib/active_payment/gateways/paypal_express_checkout.rb, line 76 def return_url url_for(controller: 'active_payment/paypal_express_checkout_callback', action: :success, only_path: false, host: ActivePayment.configuration.default_url_host) end