adyen-magento2 icon indicating copy to clipboard operation
adyen-magento2 copied to clipboard

[PW-8375] Possible incorrect implementation of `isFullInvoiceAmountManuallyCaptured`

Open maaarghk opened this issue 1 year ago • 6 comments

Adyen\Payment\Helper\Invoice::isFullInvoiceAmountManuallyCaptured seems like it may have a bug on multi-currency setups.

I'm not sure about generic reproduction steps but this is an accurate description of behaviour I'm seeing in prod:

  • Magento: GBP base currency with alternative currencies enabled
  • Adyen: GBP only
  1. Enable manual capture
  2. As customer select alternative currency (JPY and USD both seem affected)
  3. Place order
  4. As admin, note order with base_grand_total = 1000 GBP, grand_total = 150000 JPY
  5. Create invoice, observe same figures on invoice
  6. Capture from interface and await webhook

Observe:

  • adyen_invoice has amount = 1000; status = successful
  • adyen_order_payment has amount = 1000; status = manually captured
  • isFullInvoiceAmountManuallyCaptured compares $invoiceAmountCents based on sales_invoice.grand_total in alternative currency:
    $invoiceAmountCents = $this->adyenDataHelper->formatAmount(
        $invoice->getGrandTotal(),
        $invoice->getOrderCurrencyCode()
    );
    
    with $invoiceCapturedAmount based on adyen_invoice.amount in store base currency:
    $invoiceCapturedAmount += $adyenInvoice[\Adyen\Payment\Api\Data\InvoiceInterface::AMOUNT];
    
    and therefore returns false
  • Magento\Sales\Model\Order\Invoice::pay() is never called and order remains in pending state

Expected behavior isFullInvoiceAmountManuallyCaptured should be aware of the adyen_invoice.amount currency and do a comparison on the appropriate sales_order.<base_>grand_total amount

Magento version

            "name": "adyen/module-payment",
            "version": "8.14.0",
            "name": "adyen/php-api-library",
            "version": "13.0.4",
            "name": "adyen/php-webhook-module",
            "version": "0.6.0",
            "name": "magento/magento2-base",
            "version": "2.4.3-p3",

maaarghk avatar Feb 10 '23 14:02 maaarghk