lib/shoppe/paypal.rb in shoppe-paypal-1.2.1 vs lib/shoppe/paypal.rb in shoppe-paypal-1.2.2

- old
+ new

@@ -6,13 +6,11 @@ require 'shoppe/paypal/order_extensions' require 'shoppe/paypal/payment_extensions' module Shoppe module Paypal - class << self - def client_id Shoppe.settings.paypal_client_id end def client_secret @@ -20,14 +18,18 @@ end def currency Shoppe.settings.paypal_currency end - + + def mode + Shoppe.settings.paypal_mode == 'live' ? 'live' : 'sandbox' + end + def setup # Set the configuration - Shoppe.add_settings_group :paypal, [:paypal_client_id, :paypal_client_secret, :paypal_currency] + Shoppe.add_settings_group :paypal, [:paypal_client_id, :paypal_client_secret, :paypal_currency, :paypal_mode] # When an order is accepted, attempt to capture/execute the payment Shoppe::Order.before_acceptance do Shoppe::Paypal.setup_paypal @@ -55,37 +57,34 @@ @refund = @sale.refund({ :amount => { :currency => Shoppe::Paypal.currency, :total => "#{'%.2f' % self.refundable_amount}"} }) - + # Check refund status if @refund.success? true else - raise Shoppe::Errors::RefundFailed, message: "Unable to Refund" + raise Shoppe::Errors::RefundFailed, message: "Unable to Refund" logger.error "Unable to Refund" logger.error @refund.error.inspect end rescue - raise Shoppe::Errors::RefundFailed, message: "PayPal Sale '#{self.reference}' Not Found" - + raise Shoppe::Errors::RefundFailed, message: "PayPal Sale '#{self.reference}' Not Found" end end end - end # Setup the PayPal configuration def setup_paypal include PayPal::SDK::REST PayPal::SDK.configure({ - mode: (Rails.env.production? ? "live" : "sandbox"), + mode: mode, client_id: client_id, client_secret: client_secret }) end - end end end