lib/shoppe/paypal.rb in shoppe-paypal-1.0.0 vs lib/shoppe/paypal.rb in shoppe-paypal-1.1.0
- old
+ new
@@ -1,8 +1,10 @@
require 'shoppe/paypal/version'
require 'shoppe/paypal/engine'
+require 'paypal-sdk-rest'
+
require 'shoppe/paypal/order_extensions'
require 'shoppe/paypal/payment_extensions'
module Shoppe
module Paypal
@@ -12,44 +14,44 @@
def client_id
Shoppe.settings.paypal_client_id
end
def client_secret
- Shoppe.settings.paypal_secret_id
+ Shoppe.settings.paypal_client_secret
end
def currency
Shoppe.settings.paypal_currency
end
def setup
# Set the configuration
- Shoppe.add_settings_group :paypal, [:paypal_client_id, :paypal_secret_id, :currency]
+ Shoppe.add_settings_group :paypal, [:paypal_client_id, :paypal_client_secret, :paypal_currency]
- # Require the PayPal library
- require 'paypal-sdk-rest'
-
- include PayPal::SDK::REST
-
- # Configure the PayPal library
- PayPal::SDK.configure({
- mode: (Rails.env.production? ? "live" : "sandbox"),
- client_id: Shoppe.settings.paypal_client_id,
- client_secret: Shoppe.settings.paypal_secret_id
- })
-
# When an order is accepted, attempt to capture/execute the payment
Shoppe::Order.before_acceptance do
+ Shoppe::Paypal.setup_paypal
+
self.payments.where(confirmed: false, method: "PayPal").each do |payment|
begin
payment.paypal_payment.execute(payer_id: payment.order.properties["paypal_payer_id"])
payment.update_attribute(:confirmed, true)
rescue
raise Shoppe::Errors::PaymentDeclined, "Payment ##{payment.id} could not be captured by PayPal. Investigate with PayPal. Do not accept the order."
end
end
end
+ end
+ # Setup the PayPal configuration
+ def setup_paypal
+ include PayPal::SDK::REST
+
+ PayPal::SDK.configure({
+ mode: (Rails.env.production? ? "live" : "sandbox"),
+ client_id: client_id,
+ client_secret: client_secret
+ })
end
end
end
end