From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../payment_authorize/static/description/icon.png | Bin 0 -> 6290 bytes .../payment_authorize/static/description/icon.svg | 1 + .../static/src/img/authorize_icon.png | Bin 0 -> 2966 bytes .../static/src/js/payment_form.js | 160 +++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 addons/payment_authorize/static/description/icon.png create mode 100644 addons/payment_authorize/static/description/icon.svg create mode 100644 addons/payment_authorize/static/src/img/authorize_icon.png create mode 100644 addons/payment_authorize/static/src/js/payment_form.js (limited to 'addons/payment_authorize/static') diff --git a/addons/payment_authorize/static/description/icon.png b/addons/payment_authorize/static/description/icon.png new file mode 100644 index 00000000..235f1adb Binary files /dev/null and b/addons/payment_authorize/static/description/icon.png differ diff --git a/addons/payment_authorize/static/description/icon.svg b/addons/payment_authorize/static/description/icon.svg new file mode 100644 index 00000000..c2755ee6 --- /dev/null +++ b/addons/payment_authorize/static/description/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/addons/payment_authorize/static/src/img/authorize_icon.png b/addons/payment_authorize/static/src/img/authorize_icon.png new file mode 100644 index 00000000..5f039387 Binary files /dev/null and b/addons/payment_authorize/static/src/img/authorize_icon.png differ diff --git a/addons/payment_authorize/static/src/js/payment_form.js b/addons/payment_authorize/static/src/js/payment_form.js new file mode 100644 index 00000000..54007ce4 --- /dev/null +++ b/addons/payment_authorize/static/src/js/payment_form.js @@ -0,0 +1,160 @@ +odoo.define('payment_authorize.payment_form', function (require) { +"use strict"; + +var ajax = require('web.ajax'); +var core = require('web.core'); +var PaymentForm = require('payment.payment_form'); + +var _t = core._t; + +PaymentForm.include({ + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * Returns the parameters for the AcceptUI button that AcceptJS will use. + * + * @private + * @param {Object} formData data obtained by getFormData + * @returns {Object} params for the AcceptJS button + */ + _acceptJsParams: function (formData) { + return { + 'class': 'AcceptUI d-none', + 'data-apiLoginID': formData.login_id, + 'data-clientKey': formData.client_key, + 'data-billingAddressOptions': '{"show": false, "required": false}', + 'data-responseHandler': 'responseHandler' + }; + }, + + /** + * called when clicking on pay now or add payment event to create token for credit card/debit card. + * + * @private + * @param {Event} ev + * @param {DOMElement} checkedRadio + * @param {Boolean} addPmEvent + */ + _createAuthorizeToken: function (ev, $checkedRadio, addPmEvent) { + var self = this; + if (ev.type === 'submit') { + var button = $(ev.target).find('*[type="submit"]')[0] + } else { + var button = ev.target; + } + var acquirerID = this.getAcquirerIdFromRadio($checkedRadio); + var acquirerForm = this.$('#o_payment_add_token_acq_' + acquirerID); + var inputsForm = $('input', acquirerForm); + var formData = self.getFormData(inputsForm); + if (this.options.partnerId === undefined) { + console.warn('payment_form: unset partner_id when adding new token; things could go wrong'); + } + var AcceptJs = false; + if (formData.acquirer_state === 'enabled') { + AcceptJs = 'https://js.authorize.net/v3/AcceptUI.js'; + } else { + AcceptJs = 'https://jstest.authorize.net/v3/AcceptUI.js'; + } + + window.responseHandler = function (response) { + _.extend(formData, response); + + if (response.messages.resultCode === "Error") { + var errorMessage = ""; + _.each(response.messages.message, function (message) { + errorMessage += message.code + ": " + message.text; + }) + acquirerForm.removeClass('d-none'); + return self.displayError(_t('Server Error'), errorMessage); + } + + self._rpc({ + route: formData.data_set, + params: formData + }).then (function (data) { + if (addPmEvent) { + if (formData.return_url) { + window.location = formData.return_url; + } else { + window.location.reload(); + } + } else { + $checkedRadio.val(data.id); + self.el.submit(); + } + }).guardedCatch(function (error) { + // if the rpc fails, pretty obvious + error.event.preventDefault(); + acquirerForm.removeClass('d-none'); + self.displayError( + _t('Server Error'), + _t("We are not able to add your payment method at the moment.") + + self._parseError(error) + ); + }); + }; + + if (this.$button === undefined) { + this.$button = $('