Open matchapat opened 10 years ago
Getting the same error as well. The issue is in Spree::Payment::Processing#credit!
method:
if payment_method.payment_profiles_supported?
response = payment_method.credit(credit_cents, source, response_code, gateway_options)
else
response = payment_method.credit(credit_cents, response_code, gateway_options)
end
From here on I'm confused on how to add a customized credit
method to Paypal::SDK::Merchant::API (see https://github.com/paypal/merchant-sdk-ruby/blob/master/lib/paypal-sdk/merchant/api.rb)
There's already a method on the gateway called refund
which should do this.
We should probably alias the credit
method to refund
for this gateway, at a guess. I am not certain if that would absolutely fix the problem, but it's worth investigating.
It appears this issue was never fixed. Due to updates in spree it now raises a NotImplementedError for cancel. I couldn't find where the refund method is actually used. Could we just rework it into a cancel method?
:+1:
We would appreciate a fix for this issue because canceling orders paid via PayPal is impossible like this :-(
:+1:
+1
The site I'm running into this issue w/ is pretty low volume and PayPal is our only PaymentMethod, so I just modified the controller to display an error telling the user to cancel the payment manually in PayPal and added an empty credit
method on Spree::Gateway::PayPalExpress
Part of the problem is that PayPalExpress stores the transaction ID in the payment.source and the response code is nil on the payment. I can fix this, but don't have the time right now unless someone wanted to hire me for an hour or 2.
My hack: paypal_express_hack.rb
Spree::Gateway::PayPalExpress.class_eval do
def credit(credit_cents, response_code, gateway_options)
# TODO: this should use the `refund` method, but it needs some work.
# Doing nothing for now to prevent an error and allow orders to be cancelled.
OpenStruct.new(success?:true,warning:'PayPal credit method not implemented, make sure payments are cancelled manually')
end
end
orders_controller_decorator.rb
Spree::Admin::OrdersController.class_eval do
def cancel
@order.cancel!
flash[:error] = 'Order cancelled - You must cancel the payment in PayPal manually!'
redirect_to :back
end
end
As it appears this still hasn't been fixed I'm taking a stab at my own implementation. I'll update if it works. if seeing this post revitalized reminds anyone of a proper fix for this that they've seen in the interim, please post it here.
Thanks @imme5150, your solution was exactly what I needed to address my use case!
I'm receiving an error when I click the "Cancel" button on a completed order, made through a Paypal sandbox account. I've tried removing
gem 'spree_gateway'
andgem 'activemerchant'
just in case there was a weird conflict withgem 'spree_paypal_express'
.Error:
Gemfile:
Trace: