From d99c9ca12430ad65b3f94bad2f3b072f7e226575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nshimiyimana=20S=C3=A9na?= Date: Fri, 30 Sep 2022 16:37:52 +0000 Subject: [PATCH] [FIX] payment_alipay: format Alipay API parameter total_fee correctly Steps to reproduce: * setup Alipay in test mode (note that Alipay's test node only support one currency: the USD) * create an invoice. Make sure the invoice's total has decimal places * generate a payment link for that invoice * go to the generated link * select Alipay as the payment method and click pay. You should be met with an INVALID_PARAMETER message. Cause: Alipay's doc states that the parameter 'total_fee' can only have two decimal places. Currently, this requirement is not always respected opw-2996278 closes odoo/odoo#102088 X-original-commit: 2e6e338e8c4e042a671814673c6f3d0e4e4f50dc Signed-off-by: Antoine Vandevenne (anv) --- addons/payment_alipay/models/payment_transaction.py | 2 +- addons/payment_alipay/tests/test_alipay.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/payment_alipay/models/payment_transaction.py b/addons/payment_alipay/models/payment_transaction.py index 6ba77737a8b..10ebd9003a6 100644 --- a/addons/payment_alipay/models/payment_transaction.py +++ b/addons/payment_alipay/models/payment_transaction.py @@ -44,7 +44,7 @@ class PaymentTransaction(models.Model): 'partner': self.provider_id.alipay_merchant_partner_id, 'return_url': urls.url_join(base_url, AlipayController._return_url), 'subject': self.reference, - 'total_fee': total_fee, + 'total_fee': f'{total_fee:.2f}', } if self.provider_id.alipay_payment_method == 'standard_checkout': # https://global.alipay.com/docs/ac/global/create_forex_trade diff --git a/addons/payment_alipay/tests/test_alipay.py b/addons/payment_alipay/tests/test_alipay.py index 26a37f57ceb..d081efeac3d 100644 --- a/addons/payment_alipay/tests/test_alipay.py +++ b/addons/payment_alipay/tests/test_alipay.py @@ -118,7 +118,7 @@ class AlipayTest(AlipayCommon, PaymentHttpCommon): processing_values = tx._get_processing_values() redirect_form_data = self._extract_values_from_html_form(processing_values['redirect_form_html']) - self.assertEqual(redirect_form_data['inputs']['total_fee'], str(total_fee)) + self.assertEqual(redirect_form_data['inputs']['total_fee'], f'{total_fee:.2f}') def test_21_standard_checkout_feedback(self): self.alipay.alipay_payment_method = 'standard_checkout'