Added card holder name and zip to manual payment form. Known bug for loading Collect.Js after 1st instance post cache clear. Working on a fix.
This commit is contained in:
@@ -118,14 +118,28 @@ def call_payment_api(payload):
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def run_token_payment(invoice, token):
|
||||
def run_token_payment(invoice, token, cardholder_name=None, billing_zip=None):
|
||||
inv = frappe.get_doc("Sales Invoice", invoice)
|
||||
|
||||
url = "https://secure.nmi.com/api/transact.php"
|
||||
|
||||
# Get and parse customer name.
|
||||
customer_name = inv.customer_name or inv.customer or "Customer"
|
||||
parts = customer_name.split(" ", 1)
|
||||
# Fallback logic
|
||||
customer_name = (
|
||||
cardholder_name
|
||||
or inv.customer_name
|
||||
or inv.customer
|
||||
or "Customer"
|
||||
)
|
||||
|
||||
billing_zip = (
|
||||
billing_zip
|
||||
or inv.get("billing_zip")
|
||||
or inv.get("pincode")
|
||||
or ""
|
||||
)
|
||||
|
||||
# Name Split
|
||||
parts = customer_name.strip().split(" ", 1)
|
||||
first_name = parts[0]
|
||||
last_name = parts[1] if len(parts) > 1 else "."
|
||||
|
||||
@@ -139,11 +153,15 @@ def run_token_payment(invoice, token):
|
||||
"first_name": first_name,
|
||||
"last_name": last_name,
|
||||
"email": inv.contact_email or "",
|
||||
|
||||
"zip": billing_zip,
|
||||
}
|
||||
|
||||
response = requests.post(url, data=data)
|
||||
result = urllib.parse.parse_qs(response.text)
|
||||
|
||||
frappe.logger("payments").info(f"NMI RESPONSE: {response.text}")
|
||||
|
||||
success = result.get("response", ["0"])[0]
|
||||
transaction_id = result.get("transactionid", [""])[0]
|
||||
|
||||
@@ -157,18 +175,33 @@ def run_token_payment(invoice, token):
|
||||
|
||||
return {"success": True}
|
||||
|
||||
return {"success": False, "error": result.get("responsetext", ["Error"])[0]}
|
||||
|
||||
return {
|
||||
"success": False,
|
||||
"error": result.get("responsetext", ["Error"])[0]
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def save_to_autopay(customer, token):
|
||||
def save_to_autopay(customer, token, cardholder_name=None, billing_zip=None):
|
||||
import requests
|
||||
import urllib.parse
|
||||
|
||||
inv_customer = frappe.get_doc("Customer", customer)
|
||||
|
||||
customer_name = (inv_customer.customer_name or "Customer").strip()
|
||||
# Fallback logic
|
||||
customer_name = (
|
||||
cardholder_name
|
||||
or inv_customer.customer_name
|
||||
or "Customer"
|
||||
).strip()
|
||||
|
||||
billing_zip = (
|
||||
billing_zip
|
||||
or inv_customer.get("billing_zip")
|
||||
or inv_customer.get("pincode")
|
||||
or ""
|
||||
)
|
||||
|
||||
# name split
|
||||
if " " in customer_name:
|
||||
first_name, last_name = customer_name.split(" ", 1)
|
||||
else:
|
||||
@@ -182,6 +215,9 @@ def save_to_autopay(customer, token):
|
||||
|
||||
"first_name": first_name,
|
||||
"last_name": last_name,
|
||||
|
||||
"zip": billing_zip,
|
||||
|
||||
"customer_vault": "add_customer"
|
||||
}
|
||||
|
||||
@@ -194,6 +230,8 @@ def save_to_autopay(customer, token):
|
||||
|
||||
result = urllib.parse.parse_qs(response.text)
|
||||
|
||||
frappe.logger("payments").info(f"NMI VAULT RESPONSE: {response.text}")
|
||||
|
||||
success = result.get("response", ["0"])[0]
|
||||
vault_id = result.get("customer_vault_id", [""])[0]
|
||||
message = result.get("responsetext", ["Failed"])[0]
|
||||
|
||||
Reference in New Issue
Block a user