Class: FlexCommerce::PaypalExpress::Setup
- Inherits:
-
Object
- Object
- FlexCommerce::PaypalExpress::Setup
- Includes:
- Api
- Defined in:
- lib/paypal_express/setup.rb
Overview
This is the main class, which talks to ActiveMerchant gem to initiate a transaction using Paypal
Constant Summary
Constants included from Api
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(cart:, gateway_class: ::ActiveMerchant::Billing::PaypalExpressGateway, success_url:, cancel_url:, ip_address:, allow_shipping_change: true, callback_url:, shipping_method_model: FlexCommerce::ShippingMethod, use_mobile_payments: false, description: nil) ⇒ Setup
constructor
@note: For ‘::ActiveMerchant::Billing::PaypalExpressGateway` to work rails-site should include active merchant gem.
Constructor Details
#initialize(cart:, gateway_class: ::ActiveMerchant::Billing::PaypalExpressGateway, success_url:, cancel_url:, ip_address:, allow_shipping_change: true, callback_url:, shipping_method_model: FlexCommerce::ShippingMethod, use_mobile_payments: false, description: nil) ⇒ Setup
@note: For ‘::ActiveMerchant::Billing::PaypalExpressGateway` to work rails-site should include active merchant gem. Ideally this gem should be included in the gemspec. But as we are using custom gem, which is not published to ruby gems, there is no way of including it within this gem dependency
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/paypal_express/setup.rb', line 31 def initialize(cart:, gateway_class: ::ActiveMerchant::Billing::PaypalExpressGateway, success_url:, cancel_url:, ip_address:, allow_shipping_change: true, callback_url:, shipping_method_model: FlexCommerce::ShippingMethod, use_mobile_payments: false, description: nil) self.gateway_class = gateway_class self.cart = cart self.allow_shipping_change = allow_shipping_change self.success_url = success_url self.cancel_url = cancel_url self.ip_address = ip_address self.callback_url = callback_url self.shipping_method_model = shipping_method_model self.use_mobile_payments = use_mobile_payments self.description = description end |
Instance Method Details
#call ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/paypal_express/setup.rb', line 44 def call validate_shipping_method response = gateway.setup_order(convert_amount(cart.total), paypal_params) # If paypal setup went fine, redirect to the paypal page if response.success? PaypalSetup.new(setup_type: "redirect", redirect_url: gateway.redirect_url_for(response.token, mobile: use_mobile_payments)) else # @TODO Find out where to get the message from and add it error = "An error occured communicating with paypal #{response.} \n\n#{response.params.to_json}. Total sent was #{convert_amount(cart.total)} Parameters sent were \n\n#{paypal_params}" raise ::FlexCommerce::PaypalExpress::Exception::AccessDenied.new(error) end rescue ::FlexCommerce::PaypalExpress::Exception::AccessDenied => exception PaypalSetup.new(errors: exception) end |