app/services/plugins/ecommerce/cart_service.rb in camaleon_ecommerce-1.2 vs app/services/plugins/ecommerce/cart_service.rb in camaleon_ecommerce-1.2.1

- old
+ new

@@ -5,11 +5,11 @@ end attr_reader :site, :cart def pay_with_authorize_net(options={}) - payment_method = options[:payment_method] || site_service.payment_method('authorize_net') + payment_method = options[:payment_method] || site.payment_method('authorize_net') billing_address = cart.get_meta("billing_address") details = cart.get_meta("details") amount = Plugins::Ecommerce::UtilService.ecommerce_money_to_cents(cart.total_amount) payment_params = { order_id: cart.slug, @@ -59,19 +59,12 @@ return {error: credit_card.validate.map{|k, v| "#{k}: #{v.join(', ')}"}.join('<br>')} end end def pay_with_paypal(options={}) - payment_method = options[:payment_method] || site_service.payment_method('paypal') billing_address = cart.get_meta("billing_address") - ActiveMerchant::Billing::Base.mode = payment_method.options[:paypal_sandbox].to_s.to_bool ? :test : :production - paypal_options = { - login: payment_method.options[:paypal_login], - password: payment_method.options[:paypal_password], - signature: payment_method.options[:paypal_signature] - } - gateway = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options) + gateway = cart.paypal_gateway amount_in_cents = Plugins::Ecommerce::UtilService.ecommerce_money_to_cents(cart.total_amount) gateway_request = { brand_name: site.name, items: [{ number: cart.slug, @@ -104,21 +97,21 @@ {redirect_url: gateway.redirect_url_for(response.token)} end def pay_with_stripe(options) require 'stripe' - payment_method = options[:payment_method] || site_service.payment_method('stripe') + payment_method = options[:payment_method] || site.payment_method('stripe') Stripe.api_key = payment_method.options[:stripe_id] customer = Stripe::Customer.create( email: options[:email], source: options[:stripe_token]) amount_in_cents = Plugins::Ecommerce::UtilService.ecommerce_money_to_cents(cart.total_amount) begin charge = Stripe::Charge.create( customer: customer.id, amount: amount_in_cents, description: "Payment Products: #{cart.products_title}", - currency: site_service.currency, + currency: site.currency_code, ) payment_data = { email: options[:email], customer: customer.id, charge: charge.id, @@ -137,13 +130,7 @@ cart.prepare_to_pay cart.update_amounts cart.mark_paid(status) cart.convert_to_order end - end - - private - - def site_service - @site_service ||= Plugins::Ecommerce::SiteService.new(site) end end