forked from mollie/mollie-odoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REL] v14.0.0.9 released (QR code support)
- Loading branch information
Showing
9 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters