Version 1 of Collect.JS no autopay, invoice payment feature.
This commit is contained in:
@@ -115,23 +115,49 @@ def call_payment_api(payload):
|
||||
"success": False,
|
||||
"error": message
|
||||
}
|
||||
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_collect_checkout_url(invoice):
|
||||
def run_token_payment(invoice, token):
|
||||
inv = frappe.get_doc("Sales Invoice", invoice)
|
||||
|
||||
security_key = frappe.conf.get("nmi_security_key")
|
||||
url = "https://secure.nmi.com/api/transact.php"
|
||||
|
||||
if not security_key:
|
||||
frappe.throw("NMI security key not configured")
|
||||
# Get and parse customer name.
|
||||
customer_name = inv.customer_name or inv.customer or "Customer"
|
||||
parts = customer_name.split(" ", 1)
|
||||
first_name = parts[0]
|
||||
last_name = parts[1] if len(parts) > 1 else "."
|
||||
|
||||
return (
|
||||
"https://crystalclear.transactiongateway.com/collect/checkout"
|
||||
f"?security_key={security_key}"
|
||||
f"&amount={inv.outstanding_amount}"
|
||||
f"&orderid={inv.name}"
|
||||
)
|
||||
data = {
|
||||
"security_key": frappe.conf.get("nmi_security_key"),
|
||||
"type": "sale",
|
||||
"payment_token": token,
|
||||
"amount": inv.outstanding_amount,
|
||||
"orderid": inv.name,
|
||||
|
||||
"first_name": first_name,
|
||||
"last_name": last_name,
|
||||
"email": inv.contact_email or "",
|
||||
}
|
||||
|
||||
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]
|
||||
|
||||
if success == "1":
|
||||
create_payment_entry(
|
||||
invoice=invoice,
|
||||
amount=inv.outstanding_amount,
|
||||
transaction_id=transaction_id,
|
||||
mode_of_payment="Credit Card"
|
||||
)
|
||||
|
||||
return {"success": True}
|
||||
|
||||
return {"success": False, "error": result.get("responsetext", ["Error"])[0]}
|
||||
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
|
||||
Reference in New Issue
Block a user