SwedbankPay/swedbank-pay-woocommerce-payments

Conditional AutoCapture

marteinn opened this issue · 2 comments

Currently there are no way to do conditional "AutoCapture" in this plugin (it's either on or off), I propose a solution that works the same way as instant capture, where the user can select a couple of different criterias for "AutoCapture" to be applied.

Why not use the existing Instant Capture feature?
We have a store with two types of products, one with traditional products and another with membership registrations and gifts. The membership/gifts has a CRM integration where we need to pass a external order id as a "payeeReference" to get it properly added into a the Swedbank Pay generated report.

For "AutoCapture" the external payeeReference can be added in the initial transaction, but for Authorize/Capture it needs to be added into the "Capture" transaction, which makes the integration more difficult.

Right now we have a forked library (and open issue on the payeeInfo hooks: SwedbankPay/swedbank-pay-woocommerce-core#40) where we patch payeeInfo using hooks. Adding them in the initial transaction is pretty straightforward:

But making sure payeeReference is set on Capture requires us to pass intent in those filters: Frojd/swedbank-pay-woocommerce-core@854bd39 and to keep a separate hook for capture: Frojd/swedbank-pay-woocommerce-core@a61cb71#diff-942c4630b41bf0a412d3749ec4b8906ca112f2eeb63193f6a6db3c6b6059bef8

I think having a conditional "AutoCapture" would simplify this.

Another suggestion is to clarify what Instant Capture is, as I think its easy to mistake "Instant Capture" for a conditional "AutoCapture" (that's at least what I did).

aait commented

@marteinn Hello. Unfortunelly, these changes don't use the sdk library, so we can't add it.
But you can use swedbank_pay_payee_reference and swedbank_pay_payment_object hooks which were added in the latest version.
Please check SwedbankPay/swedbank-pay-woocommerce-core#59 (comment)

aait commented

@marteinn You can implement this behavior using this example:

add_filter( 'swedbank_pay_payment_object', 'swedbank_pay_payment_object', 2, 10 );
function swedbank_pay_payment_object($object, $order_id) {
    $payment = $object->getPayment();
    $payment->setIntent(self::INTENT_AUTHORIZATION);
    $object->setPayment($payment);

    return $object;
}