mirror of
https://gitlab.com/flectra-hq/flectra.git
synced 2026-10-31 10:04:02 -05:00
[ADD] upstream patch for payment_adyen, payment_authorize, payment_stripe
This commit is contained in:
1 parent
3892c1e7d1
commit
6ef9349d44
5 files changed
+64
-19
No files matched your search
@@ -18,6 +18,31 @@ from flectra.tools.pycompat import to_native
|
||||
|
||||
_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'
|
||||
@@ -27,6 +52,16 @@ class AcquirerAdyen(models.Model):
|
||||
adyen_skin_code = fields.Char('Skin Code', required_if_provider='adyen', groups='base.group_user')
|
||||
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 """
|
||||
@@ -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,
|
||||
|
||||
@@ -6,6 +6,7 @@ from datetime import datetime
|
||||
import hashlib
|
||||
import hmac
|
||||
import logging
|
||||
import string
|
||||
import time
|
||||
|
||||
from flectra import _, api, fields, models
|
||||
@@ -53,8 +54,16 @@ class PaymentAcquirerAuthorize(models.Model):
|
||||
values['x_fp_sequence'],
|
||||
values['x_fp_timestamp'],
|
||||
values['x_amount'],
|
||||
values['x_currency_code']])
|
||||
return hmac.new(values['x_trans_key'].encode('utf-8'), data.encode('utf-8'), hashlib.md5).hexdigest()
|
||||
values['x_currency_code']]).encode('utf-8')
|
||||
|
||||
# [BACKWARD COMPATIBILITY] Check that the merchant did update his transaction
|
||||
# key to signature key (end of MD5 support from Authorize.net)
|
||||
# The signature key is now '128-character hexadecimal format', while the
|
||||
# transaction key was only 16-character.
|
||||
if len(values['x_trans_key']) == 128:
|
||||
return hmac.new(values['x_trans_key'].decode("hex").encode('utf-8'), data, hashlib.sha512).hexdigest().upper()
|
||||
else:
|
||||
return hmac.new(values['x_trans_key'].encode('utf-8'), data, hashlib.md5).hexdigest()
|
||||
|
||||
@api.multi
|
||||
def authorize_form_generate_values(self, values):
|
||||
@@ -181,7 +190,7 @@ class TxAuthorize(models.Model):
|
||||
def _authorize_form_get_tx_from_data(self, data):
|
||||
""" Given a data dict coming from authorize, verify it and find the related
|
||||
transaction record. """
|
||||
reference, trans_id, fingerprint = data.get('x_invoice_num'), data.get('x_trans_id'), data.get('x_MD5_Hash')
|
||||
reference, trans_id, fingerprint = data.get('x_invoice_num'), data.get('x_trans_id'), data.get('x_SHA2_Hash') or data.get('x_MD5_Hash')
|
||||
if not reference or not trans_id or not fingerprint:
|
||||
error_msg = _('Authorize: received data with missing reference (%s) or trans_id (%s) or fingerprint (%s)') % (reference, trans_id, fingerprint)
|
||||
_logger.info(error_msg)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import hashlib
|
||||
import hmac
|
||||
import time
|
||||
import unittest
|
||||
from lxml import objectify
|
||||
@@ -32,15 +30,6 @@ class AuthorizeCommon(PaymentAcquirerCommon):
|
||||
@flectra.tests.common.post_install(True)
|
||||
class AuthorizeForm(AuthorizeCommon):
|
||||
|
||||
def _authorize_generate_hashing(self, values):
|
||||
data = '^'.join([
|
||||
values['x_login'],
|
||||
values['x_fp_sequence'],
|
||||
values['x_fp_timestamp'],
|
||||
values['x_amount'],
|
||||
]) + '^'
|
||||
return hmac.new(values['x_trans_key'].encode('utf-8'), data.encode('utf-8'), hashlib.md5).hexdigest()
|
||||
|
||||
def test_10_Authorize_form_render(self):
|
||||
self.assertEqual(self.authorize.environment, 'test', 'test without test environment')
|
||||
|
||||
@@ -85,7 +74,7 @@ class AuthorizeForm(AuthorizeCommon):
|
||||
'x_ship_to_state': None,
|
||||
}
|
||||
|
||||
form_values['x_fp_hash'] = self._authorize_generate_hashing(form_values)
|
||||
form_values['x_fp_hash'] = self.env['payment.acquirer']._authorize_generate_hashing(form_values)
|
||||
# render the button
|
||||
res = self.authorize.render('SO004', 56.16, self.currency_usd.id, values=self.buyer_values)
|
||||
# check form result
|
||||
@@ -112,7 +101,9 @@ class AuthorizeForm(AuthorizeCommon):
|
||||
# typical data posted by authorize after client has successfully paid
|
||||
authorize_post_data = {
|
||||
'return_url': u'/shop/payment/validate',
|
||||
# x_MD5_Hash will be empty starting the 28th March 2019
|
||||
'x_MD5_Hash': u'7934485E1C105940BE854208D10FAB4F',
|
||||
'x_SHA2_Hash': u'7D3AC844BE8CA3F649AB885A90D22CFE35B850338EC91D1A5ADD819A85FF948A3D777334A18CDE36821DC8F2B42A6E1950C1FF96B52B60F23201483A656195FB',
|
||||
'x_account_number': u'XXXX0027',
|
||||
'x_address': u'Huge Street 2/543',
|
||||
'x_amount': u'320.00',
|
||||
|
||||
@@ -21,9 +21,13 @@ flectra.define('payment_stripe.stripe', function(require) {
|
||||
$.blockUI.defaults.css["background-color"] = '';
|
||||
$.blockUI.defaults.overlayCSS["opacity"] = '0.9';
|
||||
}
|
||||
var stripeHandler;
|
||||
function getStripeHandler()
|
||||
{
|
||||
var handler = StripeCheckout.configure({
|
||||
if (stripeHandler) {
|
||||
return stripeHandler;
|
||||
}
|
||||
var handler = stripeHandler = StripeCheckout.configure({
|
||||
key: $("input[name='stripe_key']").val(),
|
||||
image: $("input[name='stripe_image']").val(),
|
||||
locale: 'auto',
|
||||
|
||||
@@ -21,7 +21,12 @@
|
||||
<input type='hidden' name='email' t-att-value='email'/>
|
||||
<input id="acquirer_stripe" type='hidden' name="acquirer" t-att-value="acquirer.id"/>
|
||||
<input type='hidden' name="stripe_key" t-att-value="acquirer.stripe_publishable_key"/>
|
||||
<script type="text/javascript" src="/payment_stripe/static/src/js/stripe.js"></script>
|
||||
<script type="text/javascript">
|
||||
odoo.define(function (require) {
|
||||
var ajax = require('web.ajax');
|
||||
ajax.loadJS("/payment_stripe/static/src/js/stripe.js");
|
||||
});
|
||||
</script>
|
||||
</template>
|
||||
|
||||
<template id="stripe_s2s_form">
|
||||
|
||||
Reference in new issue
Block a user