Odoo18-Base/addons/payment_demo/static/src/js/payment_demo_mixin.js
2025-01-06 10:57:38 +07:00

36 lines
1.2 KiB
JavaScript

/** @odoo-module **/
import { _t } from "@web/core/l10n/translation";
import { rpc, RPCError } from "@web/core/network/rpc";
export default {
/**
* Simulate a feedback from a payment provider and redirect the customer to the status page.
*
* @private
* @param {object} processingValues - The processing values of the transaction.
* @return {void}
*/
async processDemoPayment(processingValues) {
const customerInput = document.getElementById('customer_input').value;
const simulatedPaymentState = document.getElementById('simulated_payment_state').value;
rpc('/payment/demo/simulate_payment', {
'reference': processingValues.reference,
'payment_details': customerInput,
'simulated_state': simulatedPaymentState,
}).then(() => {
window.location = '/payment/status';
}).catch(error => {
if (error instanceof RPCError) {
this._displayErrorDialog(_t("Payment processing failed"), error.data.message);
this._enableButton?.(); // This method doesn't exists in Express Checkout form.
} else {
return Promise.reject(error);
}
});
},
};