payment api updated and running, invoice print format updated.
This commit is contained in:
@@ -14,9 +14,11 @@ frappe.ui.form.on("Sales Invoice", {
|
||||
|
||||
frm.dashboard.add_indicator("Unpaid", "red");
|
||||
|
||||
frm.add_custom_button("Run Payment", () => {
|
||||
run_payment_flow(frm);
|
||||
}, "Actions");
|
||||
if (frm.doc.outstanding_amount > 0 && frm.doc.docstatus === 1) {
|
||||
frm.add_custom_button("Run Payment", () => {
|
||||
run_payment_flow(frm);
|
||||
}, "Actions");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,26 +46,76 @@ function run_payment_flow(frm) {
|
||||
|
||||
|
||||
function run_autopay(frm) {
|
||||
|
||||
frappe.confirm(
|
||||
`Run AutoPay for $${frm.doc.outstanding_amount}?`,
|
||||
`Run AutoPay for ${format_currency(frm.doc.outstanding_amount)}?`,
|
||||
() => {
|
||||
|
||||
// Change button to processing
|
||||
frm.remove_custom_button("Run Payment");
|
||||
frm.add_custom_button("Processing...", () => {}, null).prop("disabled", true);
|
||||
|
||||
frappe.call({
|
||||
method: "ns_app.api.payments.run_autopay_payment",
|
||||
args: {
|
||||
invoice: frm.doc.name
|
||||
},
|
||||
freeze: true,
|
||||
freeze_message: "Processing payment...",
|
||||
|
||||
callback(r) {
|
||||
frappe.msgprint("Payment successful");
|
||||
frm.reload_doc();
|
||||
|
||||
if (!r.message) {
|
||||
show_payment_failed(frm, "No response from payment processor");
|
||||
return;
|
||||
}
|
||||
|
||||
if (r.message.success) {
|
||||
|
||||
// Success UI
|
||||
frm.remove_custom_button("Run Payment");
|
||||
|
||||
frm.add_custom_button("Paid ✓", () => {})
|
||||
.prop("disabled", true);
|
||||
|
||||
frappe.show_alert({
|
||||
message: `Payment of ${format_currency(frm.doc.outstanding_amount)} received`,
|
||||
indicator: "green"
|
||||
});
|
||||
|
||||
frm.reload_doc();
|
||||
|
||||
} else {
|
||||
|
||||
show_payment_failed(frm, r.message.error || "Payment declined");
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
() => {
|
||||
frm.enable_save();
|
||||
}
|
||||
() => {}
|
||||
);
|
||||
}
|
||||
|
||||
function show_payment_failed(frm, message) {
|
||||
|
||||
// Remove processing button
|
||||
frm.remove_custom_button("Processing...");
|
||||
|
||||
// Add retry button
|
||||
frm.add_custom_button("Retry Payment", () => {
|
||||
run_payment_flow(frm);
|
||||
});
|
||||
|
||||
frappe.msgprint({
|
||||
title: "Payment Failed",
|
||||
indicator: "red",
|
||||
message: message
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function open_manual_payment_form(frm) {
|
||||
const dialog = new frappe.ui.Dialog({
|
||||
|
||||
Reference in New Issue
Block a user