Skip to content

Commit

Permalink
[REL] v14.0.0.9 released (QR code support)
Browse files Browse the repository at this point in the history
  • Loading branch information
odoo-mvds committed Mar 3, 2022
1 parent cc0f321 commit 73bac83
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 6 deletions.
2 changes: 1 addition & 1 deletion payment_mollie_official/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
'name': 'Mollie Payments',
'version': '14.0.0.8',
'version': '14.0.0.9',
'category': 'eCommerce',
'license': 'LGPL-3',
'author': 'Mollie',
Expand Down
1 change: 1 addition & 0 deletions payment_mollie_official/models/mollie_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MolliePaymentMethod(models.Model):
fees_dom_var = fields.Float('Variable domestic fees (in percents)')
fees_int_fixed = fields.Float('Fixed international fees')
fees_int_var = fields.Float('Variable international fees (in percents)')
enable_qr_payment = fields.Boolean(string="Enable QR payment")

mollie_voucher_ids = fields.One2many('mollie.voucher.line', 'method_id', string='Mollie Voucher Config')

Expand Down
14 changes: 10 additions & 4 deletions payment_mollie_official/models/payment_acquirer.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def mollie_form_generate_values(self, tx_values):

# check if order api is supportable by selected mehtod
method_record = self._mollie_get_method_record(transaction.mollie_payment_method)
if method_record.supports_order_api:
if method_record.supports_order_api and not method_record.enable_qr_payment: # QR does not support order api
result = self._mollie_create_order(transaction)

# Fallback to payment method
Expand All @@ -265,6 +265,7 @@ def mollie_form_generate_values(self, tx_values):
transaction.form_feedback(result, "mollie")
else:
tx_values['checkout_url'] = result["_links"]["checkout"]["href"]
tx_values['qr_src'] = result.get('details', {}).get('qrCode', {}).get('src')
tx_values['status'] = result.get('status')
return tx_values

Expand Down Expand Up @@ -374,7 +375,12 @@ def _mollie_create_payment(self, transaction):
if mollie_customer_id:
payment_data['customerId'] = mollie_customer_id

result = self._api_mollie_create_payment(payment_data)
# Add QR parameter if enabled
params = {}
method_record = self._mollie_get_method_record(transaction.mollie_payment_method)
if method_record.enable_qr_payment:
params['include'] = 'details.qrCode'
result = self._api_mollie_create_payment(payment_data, params)

# We are setting acquirer reference as we are receiving it before 3DS payment
# So we can identify transaction with mollie respose
Expand Down Expand Up @@ -424,10 +430,10 @@ def _api_mollie_get_client(self):
mollie_client.set_user_agent_component('MollieOdoo', self.env.ref('base.module_payment_mollie_official').installed_version)
return mollie_client

def _api_mollie_create_payment(self, payment_data):
def _api_mollie_create_payment(self, payment_data, params={}):
mollie_client = self._api_mollie_get_client()
try:
result = mollie_client.payments.create(payment_data)
result = mollie_client.payments.create(payment_data, **params)
except UnprocessableEntityError as e:
return {'error': str(e)}
return result
Expand Down
9 changes: 9 additions & 0 deletions payment_mollie_official/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ <h1 style="color: #000;font-weight: bold;/* font-size: 50px; */" class="mt-5 tex
<span style="width:73px;height: 10px;display:inline-block;border-radius: 4px;background-color: #0077ff;"> </span>
</div>

<div class="card mx-auto w-md-75">
<div class="card-header bg-200">
<h4 class="m-0">v14.0.0.9</h4>
</div>
<div class="card-body">
<div> <b class="text-success"> NEW </b> Added QR code support for bancontact. </div>
</div>
</div>

<div class="card mx-auto w-md-75">
<div class="card-header bg-200">
<h4 class="m-0">v14.0.0.8</h4>
Expand Down
18 changes: 17 additions & 1 deletion payment_mollie_official/static/src/js/payment_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var core = require('web.core');
var Dialog = require('web.Dialog');
var publicWidget = require('web.public.widget');
var ajax = require('web.ajax');
const qrDialog = require('mollie.qr.dialog');

var _t = core._t;

Expand Down Expand Up @@ -216,7 +217,22 @@ publicWidget.registry.PaymentForm.include({
self.enableButton(button);
return new Promise(function () { });
}

var qrInput = $(newForm).find("input[name='qr_src']"); // qr image src
if (qrInput.length) {
var dialog = new qrDialog(self, {
qrImgSrc: qrInput.val(),
submitRedirectForm: function () {newForm.submit()},
size: 'small',
title: _t('Scan QR'),
renderFooter: false
});
var dialogDef = dialog.opened().then(() => {
// $.unblockUI();
self.enableButton(button);
});
dialog.open();
return dialogDef;
}
if (action_url) {
newForm.submit(); // and finally submit the form
return new Promise(function () { });
Expand Down
101 changes: 101 additions & 0 deletions payment_mollie_official/static/src/js/qr_dialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
odoo.define('mollie.qr.dialog', function (require) {
"use strict";

var core = require('web.core');
const config = require('web.config');
var Dialog = require('web.Dialog');

var _t = core._t;
var qweb = core.qweb;

var QrModel = Dialog.extend({
template: 'mollie.qr.dialog',
xmlDependencies: (Dialog.prototype.xmlDependencies || []).concat(['/payment_mollie_official/static/src/xml/dialog.xml']),
events: {
"click .dr_continue_checkout": '_onClickContinue',
},
/**
* @override
* @param {Object} options
*/
init: function (parent, options) {
options = options || {};
this.qrImgSrc = options.qrImgSrc;
this.submitRedirectForm = options.submitRedirectForm;
this._super(parent, $.extend(true, {}, options));
},

/**
* @override
*
* We start payment status poll from this method.
*
*/
start: function() {
this._poll();
return this._super.apply(this, arguments);
},

/**
* @private
*
* This method recalls pall after few seconds
*
* Note:-
* This is not optimal solution. websocket or long polling would be perfect solution.
* But there is no proper way to manage it in odoo at the moment.
* Odoo it self uses timeout based poll for payment.
* See: https://github.com/odoo/odoo/blob/15.0/addons/payment/static/src/js/post_processing.js
*/
_recallPolling: function () {
setTimeout(this._poll.bind(this), 5000);
},

/**
* @private
*
* This method make rpc to get status of transaction.
* It will be redirected to the payment page, if the
* transaction has status other than 'draft'.
*/
_poll: function () {
var self = this;
this._rpc({
route: '/payment/process/poll',
params: {
'csrf_token': core.csrf_token,
}
}).then(function(data) {
console.log(data);
if(data.success === true) {
if (data.transactions.length > 0) {
if (data.transactions[0].state != 'draft') {
window.location = data.transactions[0].return_url;
return;
}
}
}
self._recallPolling();
}).guardedCatch(function() {
self._recallPolling();
});
},

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* @private
* @param {MouseEvent} ev
*
* This will submit the redirect form and resume the default payment flow
*/
_onClickContinue: function (ev) {
this.submitRedirectForm();
}

});

return QrModel;
});
14 changes: 14 additions & 0 deletions payment_mollie_official/static/src/xml/dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">


<t t-name="mollie.qr.dialog">
<div class="text-center">
<h5> Open the app and scan QR </h5>
<img class="img img-fluid mb-2" t-att-src="widget.qrImgSrc"/>
<h5 class="mb-2"> OR </h5>
<button class="btn btn-primary btn-block dr_continue_checkout"> Continue without QR Code </button>
</div>
</t>

</templates>
2 changes: 2 additions & 0 deletions payment_mollie_official/views/payment_mollie_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
<input type="hidden" name="checkout_url" t-att-value="checkout_url"/>
<input type="hidden" name="error_msg" t-att-value="error_msg"/>
<input type="hidden" name="status" t-att-data-value="status"/>
<input t-if="qr_src" type="hidden" name="qr_src" t-att-value="qr_src"/>
</template>

<template id="assets_frontend" inherit_id="web.assets_frontend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/payment_mollie_official/static/src/js/payment_form.js"></script>
<script type="text/javascript" src="/payment_mollie_official/static/src/js/qr_dialog.js"></script>
<link rel="stylesheet" type="text/scss" href="/payment_mollie_official/static/src/scss/payment_form.scss"/>
</xpath>
</template>
Expand Down
1 change: 1 addition & 0 deletions payment_mollie_official/views/payment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<field name="active" invisible="1"/>
<field name="active_on_shop" widget="boolean_toggle"/>
<field name="journal_id"/>
<field name="enable_qr_payment" widget="boolean_toggle" attrs="{'invisible': [('method_id_code', 'not in', ['bancontact'])]}"/>
</group>
<group>
<field name="payment_icon_ids" widget="many2many_tags"/>
Expand Down

0 comments on commit 73bac83

Please sign in to comment.