Changed the opt in for auto pay to be a check box on thecustom form. Improves work flow and is more professional. Added this as checkbox under the zip code entry field. Did no testing on the logic yet.

This commit is contained in:
Ty Reynolds
2026-04-08 08:02:42 -04:00
parent d082c59bc4
commit cc44683972
2 changed files with 130 additions and 78 deletions

View File

@@ -141,6 +141,13 @@ function open_manual_payment_form(frm) {
<input type="text" id="billing_zip_${uid}" class="form-control"/>
</div>
<div class="mt-3">
<label>
<input type="checkbox" id="save_autopay_${uid}" />
Save for Auto Pay
</label>
</div>
<div id="cc_number_${uid}" class="mt-3"></div>
<div id="cc_exp_${uid}" class="mt-2"></div>
<div id="cc_cvv_${uid}" class="mt-2"></div>
@@ -254,15 +261,22 @@ function open_manual_payment_form(frm) {
callback: function (response) {
if (response.token) {
// Get name and ZIP
const enteredName = document.getElementById(`cardholder_name_${uid}`)?.value;
const enteredZip = document.getElementById(`billing_zip_${uid}`)?.value;
// Save name and ZIP
const finalName = enteredName || frm.doc.customer_name;
const finalZip = enteredZip || frm.doc.billing_zip || frm.doc.pincode;
// Check autopay enrollment choice
const save_autopay = document.getElementById(`save_autopay_${uid}`)?.checked;
run_token_payment(frm, response.token, dialog, {
cardholder_name: finalName,
billing_zip: finalZip
billing_zip: finalZip,
save_autopay: save_autopay
});
} else {
@@ -294,49 +308,32 @@ function open_manual_payment_form(frm) {
function run_token_payment(frm, token, dialog, extra_data = {}) {
const save_autopay = extra_data.save_autopay ? 1 : 0;
frappe.call({
method: "ns_app.api.payments.run_token_payment",
args: {
invoice: frm.doc.name,
token: token,
cardholder_name: extra_data.cardholder_name,
billing_zip: extra_data.billing_zip
billing_zip: extra_data.billing_zip,
save_autopay: save_autopay
},
callback(r) {
if (r.message?.success) {
frappe.confirm(
"Payment successful. Save this card for AutoPay?",
() => {
// YES → save to vault
frappe.call({
method: "ns_app.api.payments.save_to_autopay",
args: {
customer: frm.doc.customer,
token: token,
cardholder_name: extra_data.cardholder_name,
billing_zip: extra_data.billing_zip
},
callback(res) {
if (res.message?.success) {
frappe.show_alert({
message: "AutoPay enabled",
indicator: "green"
});
} else {
frappe.msgprint(res.message?.error || "Failed to save AutoPay");
}
}
});
},
() => {
// NO
frappe.show_alert({
message: "Payment completed (not saved)",
indicator: "blue"
});
}
);
if (save_autopay && r.message.vault_id) {
frappe.show_alert({
message: "Payment successful + AutoPay enabled",
indicator: "green"
});
} else {
frappe.show_alert({
message: "Payment successful",
indicator: "green"
});
}
dialog.hide();
frm.reload_doc();