Adyen / adyen-magento2

Adyen Payment plugin for Magento2
MIT License
150 stars 196 forks source link

Undefined array key "giftcard" in /app/xxx/vendor/adyen/module-payment/Helper/GiftcardPayment.php on line 116 #2584

Closed machiapply closed 2 months ago

machiapply commented 2 months ago

Hello,

We're trying to build a Gift Card partial payment following this documentation.

As we use the headless version, we're calling adyenPaymentMethodsBalance query and adyenSaveStateData mutation first, that work fine.

Then calling placeOrder when there's enough balance, errors with this (https://github.com/Adyen/adyen-magento2/blob/develop/Gateway/Http/Client/TransactionPayment.php#L124):

Undefined array key \"giftcard\" in \/app\/xxx\/vendor\/adyen\/module-payment\/Gateway\/Http\/Client\/TransactionPayment.php on line 124

Or calling adyenRedeemedGiftcards also errors with similar message in different place (https://github.com/Adyen/adyen-magento2/blob/develop/Helper/GiftcardPayment.php#L116):

Undefined array key \"giftcard\" in \/app\/xxx\/vendor\/adyen\/module-payment\/Helper\/GiftcardPayment.php on line 116

Both are pointing to the same value $stateData['giftcard']['balance']['value']. Once adyenSaveStateData mutation call, any orders after that errors for the same reason above, even if I change the payment with other payment methods. The stateData I am sending for adyenSaveStateData looks like:

{
    "operationName": "adyenSaveStateData",
    "variables": {
        "cartId": "semhf5MBzSHPDdf5VzbdNiGrSeLC1mzZ",
        "stateData": "{\"paymentMethod\":{\"encryptedCardNumber\":\"eyJhbGciOiJSU0EtT...\",\"type\":\"giftcard\",\"brand\":\"svs\",\"encryptedSecurityCode\":\"eyJhbGciOiJSU0EtT0...\"},\"storePaymentMethod\":false,\"shopperLocale\":\"en-US\",\"channel\":\"iOS\",\"amount\":{\"currency\":\"CAD\",\"value\":9968},\"reference\":\"xxx\",\"shopperReference\":\"xxx\",\"countryCode\":\"CA\",\"merchantAccount\":\"ARC-CAD-ECOM\",\"additionalData\":{\"allow3DS2\":true},\"returnUrl\":\"arcteryxapp://checkout/confirmation\",\"giftcard\":{\"pspReference\":\"DTNJPTC8BGKV9ST5\",\"resultCode\":\"NotEnoughBalance\",\"balance\":{\"currency\":\"CAD\",\"value\":5000}}}"
    },
    "query": "mutation adyenSaveStateData($stateData: String!, $cartId: String!) {\n  adyenSaveStateData(stateData: $stateData, cartId: $cartId) {\n    stateDataId\n  }\n}"
}

(I thought the error is looking for \"balance\":{\"currency\":\"CAD\",\"value\":5000}, so I added in the call, but still failing for the same error) its response looks fine:

{
        "adyenSaveStateData": {
            "stateDataId": "101"
        }
}

The placeOrder mutation example:

{
    "operationName": "setPaymentMethodAndPlaceOrder",
    "variables": {
        "input": {
            "adyen_additional_data": {
                "brand_code": "svs",
                "stateData": "{\"storePaymentMethod\":false,\"paymentMethod\":{\"encryptedCardNumber\":\"eyJhbGciOiJSU0...\",\"type\":\"giftcard\",\"brand\":\"svs\",\"encryptedSecurityCode\":\"eyJhbGciOiJSU..."},\"shopperLocale\":\"en-US\",\"channel\":\"iOS\",\"amount\":{\"currency\":\"CAD\",\"value\":9968},\"reference\":\"xxx\",\"shopperReference\":\"xxx\",\"countryCode\":\"CA\",\"merchantAccount\":\"ARC-CAD-ECOM\",\"additionalData\":{\"allow3DS2\":true},\"returnUrl\":\"arcteryxapp://checkout/confirmation\"}"
            },
            "code": "adyen_giftcard"
        },
        "cartId": "semhf5MBzSHPDdf5VzbdNiGrSeLC1mzZ",
        "additionalData": ""
    },
    "query": "mutation setPaymentMethodAndPlaceOrder($cartId: String!, $input: PaymentMethodInput!, $additionalData: String) {\n  setPaymentMethodOnCart(input: {cart_id: $cartId, payment_method: $input}) {\n    cart {\n      selected_payment_method {\n        code\n        title\n      }\n    }\n  }\n  placeOrder(input: {cart_id: $cartId, additional_data: $additionalData}) {\n    order {\n      order_number\n      cart_id\n      adyen_payment_status {\n        isFinal\n        resultCode\n        additionalData\n        action\n      }\n    }\n  }\n}"
}

Response:

{
    "errors": [{
        "message": "Warning: Undefined array key \"giftcard\" in \/app\/xxx\/vendor\/adyen\/module-payment\/Gateway\/Http\/Client\/TransactionPayment.php on line 124"
    }],
    "data": {
        "setPaymentMethodOnCart": {
            "cart": {
                "selected_payment_method": {
                    "code": "adyen_giftcard",
                    "title": "Giftcard"
                }
            }
        },
        "placeOrder": null
    }
}

Can anybody see what I am doing wrong here? Please advise. Thank you!

Magento version [e.g. 2.4.1]

Plugin version 9.4.0 (Magento 2 plugin adyen-php-api-library/17.2.0)

Smartphone (please complete the following information): Testing on iPhone XR (OS 17.3.1), Galaxy S9 (Android 10)

machiapply commented 2 months ago

after I added the missing \"balance\":{\"currency\":\"CAD\",\"value\":5000}, I needed to delete the cart to re-test it. it was already fixed, sorry for false alarm!