2012-05-31 06:54:05 +00:00
|
|
|
class Spree::BillingIntegration::PaypalExpressBase < Spree::BillingIntegration
|
|
|
|
preference :login, :string
|
|
|
|
preference :password, :password
|
|
|
|
preference :signature, :string
|
|
|
|
preference :review, :boolean, :default => false
|
|
|
|
preference :no_shipping, :boolean, :default => false
|
2012-11-12 03:18:37 +00:00
|
|
|
preference :cart_checkout, :boolean, :default => false
|
2012-05-31 06:54:05 +00:00
|
|
|
preference :currency, :string, :default => 'USD'
|
|
|
|
preference :allow_guest_checkout, :boolean, :default => false
|
|
|
|
|
2012-11-12 03:18:37 +00:00
|
|
|
attr_accessible :preferred_login, :preferred_password, :preferred_signature, :preferred_review, :preferred_no_shipping, :preferred_currency, :preferred_allow_guest_checkout, :preferred_server, :preferred_test_mode, :preferred_cart_checkout
|
2012-05-31 06:54:05 +00:00
|
|
|
|
|
|
|
def provider_class
|
|
|
|
ActiveMerchant::Billing::PaypalExpressGateway
|
|
|
|
end
|
|
|
|
|
|
|
|
def payment_profiles_supported?
|
|
|
|
!!preferred_review
|
|
|
|
end
|
2012-05-31 22:06:16 +00:00
|
|
|
|
|
|
|
def capture(payment_or_amount, account_or_response_code, gateway_options)
|
|
|
|
if payment_or_amount.is_a?(Spree::Payment)
|
|
|
|
authorization = find_authorization(payment_or_amount)
|
|
|
|
provider.capture(amount_in_cents(payment_or_amount.amount), authorization.params["transaction_id"], :currency => preferred_currency)
|
|
|
|
else
|
|
|
|
provider.capture(payment_or_amount, account_or_response_code, :currency => preferred_currency)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-05-31 22:36:42 +00:00
|
|
|
def credit(*args)
|
|
|
|
amount = args.shift
|
|
|
|
response_code = args.first.is_a?(String) ? args.first : args[1]
|
2012-05-31 22:06:16 +00:00
|
|
|
provider.credit(amount, response_code, :currency => preferred_currency)
|
|
|
|
end
|
|
|
|
|
2011-12-02 20:37:42 +00:00
|
|
|
def adjust(payment, account_or_response_code, gateway_options)
|
|
|
|
payment.amount = payment.order.total
|
|
|
|
payment.save
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-05-31 22:06:16 +00:00
|
|
|
def find_authorization(payment)
|
|
|
|
logs = payment.log_entries.all(:order => 'created_at DESC')
|
|
|
|
logs.each do |log|
|
|
|
|
details = YAML.load(log.details) # return the transaction details
|
|
|
|
if (details.params['payment_status'] == 'Pending' && details.params['pending_reason'] == 'authorization')
|
|
|
|
return details
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_capture(payment)
|
|
|
|
#find the transaction associated with the original authorization/capture
|
|
|
|
logs = payment.log_entries.all(:order => 'created_at DESC')
|
|
|
|
logs.each do |log|
|
|
|
|
details = YAML.load(log.details) # return the transaction details
|
|
|
|
if details.params['payment_status'] == 'Completed'
|
|
|
|
return details
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def amount_in_cents(amount)
|
|
|
|
(100 * amount).to_i
|
|
|
|
end
|
|
|
|
|
2011-12-02 20:37:42 +00:00
|
|
|
end
|