SwedbankPay / swedbank-pay-woocommerce-checkout

Swedbank Pay Checkout for WooCommerce (Beta)
https://wordpress.org/plugins/swedbank-pay-checkout/
Apache License 2.0
5 stars 1 forks source link

Refund when tax value includes digits #120

Closed christianz123 closed 2 years ago

christianz123 commented 2 years ago

Hi I cant do a refund from the wp-admin interface if the tax includes digits. 4.00kr is OK but not 4,20kr. The log payex-checkout indicates that the digits are not correctly handled. The log from a failed refund:

_>>>>>>>> BEGIN PAYEX API CLIENT REQUEST DEBUG INFO >>>>>>>>

Request Method: POST
Request URL: https://api.payex.com/psp/paymentorders/325f130a-834d-40de-6787-08d9e075b055/reversals
Request Headers: Accept: application/json
Session-Id: 6fd435bf-3735-4597-b82b-9a73e02940e1
Forwarded: for=213.80.116.139; proto=https
Authorization:  Bearer <redacted>
Content-Type: application/json; charset=utf-8
Content-Length: 1007
Request Body:
{
    "transaction": {
        "amount": 600,
        "description": "Refund for Order #294496. Amount: 6",
        "orderItems": [
            {
                "amount": 625,
                "class": "ProductGroup1",
                "description": "TestprodC1 - S",
                "imageUrl": "https:\/\/staging.agency.hemsida.eu\/st03\/wp-content\/uploads\/woocommerce-placeholder.png",
                "itemUrl": "https:\/\/staging.agency.hemsida.eu\/st03\/produkt\/testprodc1\/?attribute_pa_size=s",
                "name": "TestprodC1 - S",
                "quantity": 1,
                "quantityUnit": "pcs",
                "reference": "6y6Ff9o24Em1",
                "restrictedToInstruments": null,
                "type": "PRODUCT",
                "unitPrice": 625,
                "vatAmount": 125,
                "vatPercent": 2500
            }
        ],
        "payeeReference": "294496xiuygq",
        "receiptReference": "294496xjuyzt",
        "vatAmount": 100
    }
}

Response Code: 400
Response Body:
{"type":"https://api.payex.com/psp/errordetail/inputerror","title":"Error in input data","status":400,"instance":"https://api.payex.com/psp/probleminstance/00-829004282e914fd9aa28d7d8e368fb01-943e50044253e8d9-01","detail":"Input validation failed, error description in problems node!","problems":[{"name":"Transaction.Amount","description":"The Amount field must match the summed up value of Amount in OrderItems."},{"name":"Transaction.VatAmount","description":"The VatAmount field must match the summed up value of VatAmount in OrderItems."},{"name":"Transaction.OrderItems","description":"The Amount field must match the summed up value of Amount in OrderItems. The VatAmount field must match the summed up value of VatAmount in OrderItems."}]}

<<<<<<<< END PAYEX API CLIENT REQUEST DEBUG INFO <<<<<<<<_

Everything works fine if the tax includes no digits. See log:

_>>>>>>>> BEGIN PAYEX API CLIENT REQUEST DEBUG INFO >>>>>>>>

Request Method: POST
Request URL: https://api.payex.com/psp/paymentorders/325f130a-834d-40de-6787-08d9e075b055/reversals
Request Headers: Accept: application/json
Session-Id: 80995000-3af4-4fad-8ea6-50274a5419e6
Forwarded: for=213.80.116.139; proto=https
Authorization:  Bearer <redacted>
Content-Type: application/json; charset=utf-8
Content-Length: 1007
Request Body:
{
    "transaction": {
        "amount": 500,
        "description": "Refund for Order #294496. Amount: 5",
        "orderItems": [
            {
                "amount": 500,
                "class": "ProductGroup1",
                "description": "TestprodC1 - S",
                "imageUrl": "https:\/\/staging.agency.hemsida.eu\/st03\/wp-content\/uploads\/woocommerce-placeholder.png",
                "itemUrl": "https:\/\/staging.agency.hemsida.eu\/st03\/produkt\/testprodc1\/?attribute_pa_size=s",
                "name": "TestprodC1 - S",
                "quantity": 1,
                "quantityUnit": "pcs",
                "reference": "5n9mbNiBqnC4",
                "restrictedToInstruments": null,
                "type": "PRODUCT",
                "unitPrice": 500,
                "vatAmount": 100,
                "vatPercent": 2500
            }
        ],
        "payeeReference": "294496xzxspe",
        "receiptReference": "294496xbmdki",
        "vatAmount": 100
    }
}

Response Code: 200
Response Body:
{"payment":"/psp/creditaccount/payments/cc410e0f-3a0b-4b05-643e-08d9dfda75ba","reversal":{"id":"/psp/creditaccount/payments/cc410e0f-3a0b-4b05-643e-08d9dfda75ba/reversals/9c005919-4f0d-493a-f3f9-08da0c87333b","transaction":{"id":"/psp/creditaccount/payments/cc410e0f-3a0b-4b05-643e-08d9dfda75ba/transactions/9c005919-4f0d-493a-f3f9-08da0c87333b","created":"2022-03-31T19:04:36.3188902Z","updated":"2022-03-31T19:04:36.6097556Z","type":"Reversal","state":"Completed","number":17100028452,"amount":500,"vatAmount":100,"description":"Refund for Order #294496. Amount: 5","payeeReference":"294496xzxspe","isOperational":false,"reconciliationNumber":738244,"operations":[]}}}

<<<<<<<< END PAYEX API CLIENT REQUEST DEBUG INFO <<<<<<<<_

Any ideas what could be wrong?

Thanks

christianz123 commented 2 years ago

Any updates?

aait commented 2 years ago

There's wrong transaction amount value and sum of amount items. I guess there's the rounding issue, probably from WooCommerce core. I think we should add amount checking in the plugin

christianz123 commented 2 years ago

Do you know if it will be included in the next update? When? Thanks

ghost commented 2 years ago

Hi @aait ! Trying to find what can be a fix for this issue, could it be in this section?

`// Calculate VAT amount $vat_amount = array_sum( array_column( $items, OrderItemInterface::FIELD_VAT_AMOUNT ) ) / 100;

        $result = $this->core->refundCheckout( $order->get_id(), $amount, $vat_amount, $items );`
ghost commented 2 years ago

@asbjornu Hi!

We're having a lot of issues with refunds with this plugin and need some support. We've got some developers looking into this on our end but help is appreciated.

See below for some ideas of what the problem could be?

swedbank-pay-checkout/includes/class-wc-gateway-swedbank-pay-checkout.php image 2 image

swedbank-pay-checkout/vendor/swedbank-pay/swedbank-pay-woocommerce-core/src/SwedbankPay/Core/Library/Methods/Checkout.php image 3

olegisk commented 2 years ago

@craftycrafter90 Hello, could explain what problem do you have in details please? Please attach logs if possible.

olegisk commented 2 years ago

I prepare some changes https://github.com/SwedbankPay/swedbank-pay-woocommerce-checkout/pull/127

olegisk commented 2 years ago

Changes were merged, so i'm closing this issue