From bab9d6b8a79df9e6905aa49b5ad6f3534354ffe1 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 2 Dec 2011 21:37:42 +0100 Subject: [PATCH] payment: Add a button to easily adjust the payment In case the payment calculation is off.. one can manipulate the adjustments and then press the adjust button to make the payment match the total. PayPal allows to capture up to 115%. --- .../spree/billing_integration/paypal_express_base.rb | 8 +++++++- app/models/spree/paypal_account.rb | 6 +++++- config/locales/en.yml | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/models/spree/billing_integration/paypal_express_base.rb b/app/models/spree/billing_integration/paypal_express_base.rb index 393dfb3..f326a5a 100644 --- a/app/models/spree/billing_integration/paypal_express_base.rb +++ b/app/models/spree/billing_integration/paypal_express_base.rb @@ -33,6 +33,12 @@ class Spree::BillingIntegration::PaypalExpressBase < Spree::BillingIntegration provider.credit(amount, response_code, :currency => preferred_currency) end + def adjust(payment, account_or_response_code, gateway_options) + payment.amount = payment.order.total + payment.save + end + + def find_authorization(payment) logs = payment.log_entries.all(:order => 'created_at DESC') logs.each do |log| @@ -60,4 +66,4 @@ class Spree::BillingIntegration::PaypalExpressBase < Spree::BillingIntegration (100 * amount).to_i end -end \ No newline at end of file +end diff --git a/app/models/spree/paypal_account.rb b/app/models/spree/paypal_account.rb index 8980ab1..be03636 100644 --- a/app/models/spree/paypal_account.rb +++ b/app/models/spree/paypal_account.rb @@ -3,13 +3,17 @@ class Spree::PaypalAccount < ActiveRecord::Base has_many :payments, :as => :source def actions - %w{capture credit} + %w{capture credit adjust} end def can_capture?(payment) !echeck?(payment) && payment.state == "pending" end + def can_adjust?(payment) + can_capture?(payment) + end + def can_credit?(payment) return false unless payment.state == "completed" return false unless payment.order.payment_state == "credit_owed" diff --git a/config/locales/en.yml b/config/locales/en.yml index 423c8df..bb8c445 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -23,6 +23,7 @@ en: verified: verified unverified: unverified comment: Comment + adjust: Adjust account_details: Account Details finalize: paypalexpress: Capture Payment