Doing this would allow the merchant to manually capture and cancel the payment via Commerce admin UI. This would help to support alternative workflows like asked here: #3013161: Questions regarding the workflow

The OrderTransitionSubscriber should then only act on orders that aren't already fully paid. I've opened a dedicated issue for that to separate concerns: #3013322: OrderTransitionSubscriber should check, if order is already paid, before trying to capture

Comments

agoradesign created an issue. See original summary.

agoradesign’s picture

Issue summary: View changes
agoradesign’s picture

Status: Active » Needs review
StatusFileSize
new3.37 KB
agoradesign’s picture

Issue summary: View changes
tuutti’s picture

Status: Needs review » Needs work

This seems to works great otherwise, but right now you can only capture the full amount. Adding something like

    $request->getRequest()
      ->setCapturedAmount((int) $amount->multiply('100')->getNumber());

would probably fix this.

agoradesign’s picture

good point. I'll try, if this helps... but first, I'm preparing another patch :D

tuutti’s picture

Actually, adding this might cause problems with #3013322: OrderTransitionSubscriber should check, if order is already paid, before trying to capture since it won't be paid fully anymore.

I guess we could change capture request to use $order->getBalance() rather than $order->getTotalPrice().

agoradesign’s picture

Another very good point :)

agoradesign’s picture

Ok, we should leave the other issue as is, because checking for being paid in full is still valid so. Using the balance instead of total price is rather a side effect of this one here, so I'll rather add this here

agoradesign’s picture

Status: Needs work » Needs review
StatusFileSize
new4.99 KB

Updated the patch considering the balance - but haven't tested it so far. Will post my feedback then

tuutti’s picture

I'm not sure what's the use case for using partial captures, but after thinking more about this, I don't think we should capture the remaining funds because they should have a specific reason to not to capture the full amount.

I propose that we check if order has payments, but is not paid in full and then release the remaining amount and let the merchants handle any extra captures they wish to make.

agoradesign’s picture

ok, then two questions arise at least:

  1. Isn't it still better to use the balance instead of the total amount? You never know how fancy any store setups can be. Maybe one is buiding a custom checkout process, capturing 20% via credit card and then the rest via invoice, or something silmilar
  2. Should I change this line back? if ($payment->getPaymentGatewayId() !== $plugin->getEntityId() || $payment->getAmount()->compareTo($order->getTotalPrice()) !== 0) {

If we still do the old amount to total price comparision, theoretically the capture on placement shouldn't take place at all, if there's already a partial payment

agoradesign’s picture

Update to point 2 of my last comment: if the manual capturing has been done via Commerce UI and therefore via capturePayment() as suggested here, then the payment status gets set to completed either way. And that's also correct, as the single payment is completed... So either way, if we compare the amount against the price, or like I suggested, that the payment must be in authorization state, in both cases the automatic capturing on order fulfillment won't take place, as there's no payment to operate on

agoradesign’s picture

How can I help to make progress on this issue? Should I do any changes?

tuutti’s picture

I'm currently testing this.

For some reason this still seems to capture the full amount when order is fulfilled.

After manual capture (200 €):

After manual capture

After fulfilling the order:

After fullfill

tuutti’s picture

Oh, it's because:

if (!$payment = $this->getPayment($order)) {
  throw new \InvalidArgumentException('Payment not found.');
}

is after the createCapture API call.

agoradesign’s picture

oh,, I've thought that I have moved that already!?! in fact not... must have gone lost between all the patches

tuutti’s picture

StatusFileSize
new7.62 KB

I added support for releasing the remaining authorization. Can you test this?

agoradesign’s picture

ok, will have a look

agoradesign’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new101.46 KB

Works! :)

Klarna release test

  • tuutti committed 36256fc on 8.x-1.x authored by agoradesign
    Issue #3013316 by agoradesign, tuutti: Let the gateway implement...
  • tuutti committed 737252b on 8.x-1.x
    Issue #3013316 by agoradesign, tuutti: Let the gateway implement...
tuutti’s picture

Status: Reviewed & tested by the community » Fixed

Nice, thanks!

agoradesign’s picture

wow cool, suddenly there's no more patch needed in our project :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.