app/models/spree/gateway/affirm.rb in spree_affirm-0.2.22 vs app/models/spree/gateway/affirm.rb in spree_affirm-0.2.30

- old
+ new

@@ -1,11 +1,11 @@ module Spree class Gateway::Affirm < Gateway preference :api_key, :string preference :secret_key, :string - preference :server, :string, default: 'www.affirm.com' - preference :product_key, :string + preference :test_mode, :boolean, default: true + preference :server, :string, default: 'sandbox.affirm.com' def provider_class ActiveMerchant::Billing::Affirm end @@ -34,25 +34,18 @@ end def cancel(charge_ari) _payment = Spree::Payment.valid.where( response_code: charge_ari, - source_type: "#{payment_source_class}" + source_type: payment_source_class.to_s ).first return if _payment.nil? if _payment.pending? _payment.void_transaction! - - elsif _payment.completed? and _payment.can_credit? - - # create adjustment - _payment.order.adjustments.create label: "Refund - Canceled Order", amount: -_payment.credit_allowed.to_f - _payment.order.update! - - _payment.credit! - + elsif _payment.completed? && _payment.can_credit? + provider.refund(_payment.credit_allowed.to_money.cents, charge_ari) end end end end