solidusio / solidus_paypal_commerce_platform

💳 Integrate Solidus with Paypal Commerce Platform
https://developer.paypal.com/docs/platforms/
BSD 3-Clause "New" or "Revised" License
17 stars 24 forks source link

Unable To Cancel An Order #120

Closed jakemumu closed 1 year ago

jakemumu commented 3 years ago

Version: solidus_paypal_commerce_platform (0.3.0)

Steps:

  1. Create & Pay For An Order
  2. Attempt To Cancel An Order In The Admin Panel

NotImplementedError (You need to implement try_void for SolidusPaypalCommercePlatform::PaymentMethod. In that return a ActiveMerchant::Billing::Response object if the void succeeds orfalse|nilif the void is not possible anymore. Solidus will refund the amount of the payment then.):

mamhoff commented 1 year ago

Why has this been closed? We're still running into it on 0.6

jakemumu commented 1 year ago

Cause support or even conversations on extensions is pretty non-existent unfortunately

gsmendoza commented 1 year ago

@mamhoff I'm reopening this since you're still running into it on 0.6.

@jakemumu We're sorry we weren't able to respond promptly to this issue last year. We're in the process of updating the extensions. The goal is to move critical extensions to solidusio and ensure that they are always compatible with the latest Solidus versions.

For solidus_paypal_commerce_platform, we have recently released 1.0.0.beta2. We'll test if it still has this issue that you reported.

gsmendoza commented 1 year ago

I've confirmed that the issue is still present in 1.0.0.beta2.

chrean commented 1 year ago

Thanks @gsmendoza . Flagging as bug, let's see if we can fix this in the current or upcoming sprint. Perhaps @elia may help since he has worked on redoing the extension?

elia commented 1 year ago

Looks like we'll need to implement SolidusPaypalCommercePlatform::PaymentMethod#try_void in order for cancel to work, here's a tentative implementation that I spiked looking at solidus_stripe and cleaning up the older APIs that are no longer supported.

    def try_void(payment)
      if payment.completed?

        cancellation_reason = ::Spree::RefundReason.where(
          name: ::Spree::Payment::Cancellation::DEFAULT_REASON
        ).first_or_create!

        refund = payment.refunds.build(
          amount: payment.credit_allowed,
          reason: cancellation_reason,
        ).tap do |refund|
          refund.save!
          refund.perform!
        end

        refund.perform_response
      else
        void(payment.response_code, nil)
      end
    end
mamhoff commented 1 year ago

It looks to me that this function above does too much: See https://github.com/solidusio/solidus/blob/e878076f2ed670d07654ab6293a16588743f2fa6/core/app/models/spree/payment/cancellation.rb#L28-L34 . try_void should only check whether a void can be performed and perform it, otherwise to return false. Spree::Payment::Cancellation will take care of creating the refund if necessary.

If this is inspired by the solidus_stripe gem, then there might be work there, too.

elia commented 1 year ago

@mamhoff good call, not sure why stripe used to do that, but since I'm working on rebuilding I'll keep that in mind 🙏

kennyadsl commented 1 year ago

Fix released in 0.7.0 and 1.0.0.beta3