From b335ae0348ac74b2edb6d5ea56cc230e276ef283 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 2 Aug 2017 11:01:46 +0200 Subject: [PATCH] [FIX] payment_stripe: integer currencies The currencies with zero decimal should not be multiplied by 100. See https://stripe.com/docs/currencies#zero-decimal opw-760707 --- addons/payment_stripe/static/src/js/stripe.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/addons/payment_stripe/static/src/js/stripe.js b/addons/payment_stripe/static/src/js/stripe.js index 7338313e245..77570e9b3ce 100644 --- a/addons/payment_stripe/static/src/js/stripe.js +++ b/addons/payment_stripe/static/src/js/stripe.js @@ -1,6 +1,14 @@ odoo.define('payment_stripe.stripe', function(require) { "use strict"; + var ajax = require('web.ajax'); + // The following currencies are integer only, see + // https://stripe.com/docs/currencies#zero-decimal + var int_currencies = [ + 'BIF', 'XAF', 'XPF', 'CLP', 'KMF', 'DJF', 'GNF', 'JPY', 'MGA', 'PYGí', + 'RWF', 'KRW', 'VUV', 'VND', 'XOF' + ]; + var handler = StripeCheckout.configure({ key: $("input[name='stripe_key']").val(), image: $("input[name='stripe_image']").val(), @@ -50,19 +58,31 @@ odoo.define('payment_stripe.stripe', function(require) { e.preventDefault(); if ($('.o_website_payment').length !== 0) { + var currency = $("input[name='currency']").val(); + var amount = parseFloat($("input[name='amount']").val() || '0.0'); + if (!_.contains(int_currencies, currency)) { + amount = amount*100; + } + ajax.jsonRpc('/website_payment/transaction', 'call', { reference: $("input[name='invoice_num']").val(), - amount: $("input[name='amount']").val(), - currency_id: $("input[name='currency_id']").val(), + amount: amount, + currency_id: currency, acquirer_id: acquirer_id }) handler.open({ name: $("input[name='merchant']").val(), description: $("input[name='invoice_num']").val(), - currency: $("input[name='currency']").val(), - amount: $("input[name='amount']").val()*100 + currency: currency, + amount: amount, }); } else { + var currency = $("input[name='currency']").val(); + var amount = parseFloat($("input[name='amount']").val() || '0.0'); + if (!_.contains(int_currencies, currency)) { + amount = amount*100; + } + ajax.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', { so_id: so_id, so_token: so_token @@ -71,8 +91,8 @@ odoo.define('payment_stripe.stripe', function(require) { handler.open({ name: $("input[name='merchant']").val(), description: $("input[name='invoice_num']").val(), - currency: $("input[name='currency']").val(), - amount: $("input[name='amount']").val()*100 + currency: currency, + amount: amount, }); }); }