diff options
| author | Christophe Simonis <chs@odoo.com> | 2019-03-25 19:45:26 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2019-03-25 19:45:26 +0100 |
| commit | f00c490be8688d80f211f6755b5ada541eefd602 (patch) | |
| tree | 39fad5136327db80653801f8a40f3c5c807c65d0 /addons/payment_adyen/models | |
| parent | 28a1371035fae9892e1ceeb6c9edd7ddda806ed5 (diff) | |
| parent | 11b1e12cde37cc002e475d11793be61d9d108290 (diff) | |
[MERGE] forward port branch 12.0 up to 11b1e12cde3
Diffstat (limited to 'addons/payment_adyen/models')
| -rw-r--r-- | addons/payment_adyen/models/payment.py | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/addons/payment_adyen/models/payment.py b/addons/payment_adyen/models/payment.py index a18bd385f50..818de84dc20 100644 --- a/addons/payment_adyen/models/payment.py +++ b/addons/payment_adyen/models/payment.py @@ -18,6 +18,31 @@ from odoo.tools.pycompat import to_text _logger = logging.getLogger(__name__) +# https://docs.adyen.com/developers/development-resources/currency-codes +CURRENCY_CODE_MAPS = { + "BHD": 3, + "CVE": 0, + "DJF": 0, + "GNF": 0, + "IDR": 0, + "JOD": 3, + "JPY": 0, + "KMF": 0, + "KRW": 0, + "KWD": 3, + "LYD": 3, + "OMR": 3, + "PYG": 0, + "RWF": 0, + "TND": 3, + "UGX": 0, + "VND": 0, + "VUV": 0, + "XAF": 0, + "XOF": 0, + "XPF": 0, +} + class AcquirerAdyen(models.Model): _inherit = 'payment.acquirer' @@ -28,6 +53,16 @@ class AcquirerAdyen(models.Model): adyen_skin_hmac_key = fields.Char('Skin HMAC Key', required_if_provider='adyen', groups='base.group_user') @api.model + def _adyen_convert_amount(self, amount, currency): + """ + Adyen requires the amount to be multiplied by 10^k, + where k depends on the currency code. + """ + k = CURRENCY_CODE_MAPS.get(currency.name, 2) + paymentAmount = int(tools.float_round(amount, k) * (10**k)) + return paymentAmount + + @api.model def _get_adyen_urls(self, environment): """ Adyen URLs: yhpp: hosted payment page: pay.shtml for single, select.shtml for multiple """ return { @@ -120,12 +155,13 @@ class AcquirerAdyen(models.Model): import datetime from dateutil import relativedelta + paymentAmount = self._adyen_convert_amount(values['amount'], values['currency']) if self.provider == 'adyen' and len(self.adyen_skin_hmac_key) == 64: tmp_date = datetime.datetime.today() + relativedelta.relativedelta(days=1) values.update({ 'merchantReference': values['reference'], - 'paymentAmount': '%d' % int(tools.float_round(values['amount'], 2) * 100), + 'paymentAmount': '%d' % paymentAmount, 'currencyCode': values['currency'] and values['currency'].name or '', 'shipBeforeDate': tmp_date.strftime('%Y-%m-%d'), 'skinCode': self.adyen_skin_code, @@ -143,7 +179,7 @@ class AcquirerAdyen(models.Model): values.update({ 'merchantReference': values['reference'], - 'paymentAmount': '%d' % int(tools.float_round(values['amount'], 2) * 100), + 'paymentAmount': '%d' % paymentAmount, 'currencyCode': values['currency'] and values['currency'].name or '', 'shipBeforeDate': tmp_date, 'skinCode': self.adyen_skin_code, |
