From 0b52633311a6f43aa4ac54df5f6a9796a79d092e Mon Sep 17 00:00:00 2001 From: James Stevens Date: Wed, 22 Feb 2023 17:42:20 +0000 Subject: [PATCH] paypal payment for orders --- emails/password_changed.html | 16 ++++ htdocs/index.html | 132 +++++++++++++++--------------- htdocs/paypal.js | 75 ++++++++++++----- python/librar/hashstr.py | 2 +- python/librar/policy.py | 1 + python/librar/registry.py | 2 +- python/payments/plugins/paypal.py | 6 +- python/webui/run_webui.py | 19 +++-- tmp/paypal.json | 6 +- 9 files changed, 160 insertions(+), 99 deletions(-) create mode 100644 emails/password_changed.html diff --git a/emails/password_changed.html b/emails/password_changed.html new file mode 100644 index 0000000..6f5d5b5 --- /dev/null +++ b/emails/password_changed.html @@ -0,0 +1,16 @@ +{% include "start.inc" %} +Subject: {{policy.business_name}}: Password changed at {{policy.business_name}} + + + + +Hi {{user.name}},

+ +Your password at {{policy.business_name}} has just been changed.

+ +If this was not you, please contact our technical support as soon as possible.

+ + +{% include "end.html" %} diff --git a/htdocs/index.html b/htdocs/index.html index e6f6292..aa7933e 100644 --- a/htdocs/index.html +++ b/htdocs/index.html @@ -67,11 +67,12 @@ credit: "💳", lock: "🔒", unlock: "🔓", + thumb: "👍", gap: "

", settings_spacer: "
", - def_max_checks: 2 + def_max_checks: 5 }; ctx = {}; @@ -688,7 +689,9 @@ function catch_user_data(reply) { ["failed_basket","transactions","user","domains","orders"].forEach((item) => { - if (item in reply) ctx[item] = reply[item]; + if (item in reply) { + if (Object.keys(reply[item]).length) ctx[item] = reply[item]; else delete ctx[item]; + } }) } @@ -838,7 +841,7 @@ let max = gbl.def_max_checks; - if ((first.registry in gbl.config.registry)&&("max_checks" in gbl.config.registry[first.registry])) + if ((first.registry in gbl.config.registry)&&(gbl.config.registry[first.registry].max_checks)) max = gbl.config.registry[first.registry].max_checks; while((ctx.search.todo.length > 0)&&(srch.length < max)&&(first.registry == ctx.search.todo[0].registry)) { @@ -951,7 +954,7 @@ function userDomainList() { - let x = ""; + let x = "
"; x += ""; @@ -1118,13 +1121,13 @@ function goMarketPlace() { - errMsg("Not yet implemented","marketPlaceBtn"); + errMsg(gbl.thumb+" Coming Soon","marketPlaceBtn"); } -function enable_two_fa() { errMsg("Not yet implemented","2fa_section"); } -function disable_two_fa() { errMsg("Not yet implemented","2fa_section"); } +function enable_two_fa() { errMsg(gbl.thumb+" Coming Soon","2fa_section"); } +function disable_two_fa() { errMsg(gbl.thumb+" Coming Soon","2fa_section"); } @@ -1164,11 +1167,11 @@ x += ""; x += "
"; x += btn("request_transfer(true)","Transfer In","Use an AuthCode to request a domain transfer",100); x += "
"; x += form_prompt("Current Password"); - x += ``; - x += form_prompt("New Password"); - x += ``; - x += form_prompt("Confirm Password"); - x += ``; + x += ``; + x += form_prompt("New Password"); + x += ``; + x += form_prompt("Confirm New Password"); + x += ``; x += ""; x += "
"; @@ -1270,40 +1273,6 @@ -function add_payment() -{ - hidePopUp(); - - let e = document.getElementById("add_payment_type"); - if (!e) return; - - callApi("payments/html",(ok,reply) => { - let p = document.getElementById("add_pay_div"); - if ((ok)&&(p)) { - // # CODE - console.log(reply); - return; - } - def_errMsg("Error getting HTML for payment",reply,"add_pay_div"); - },{ json: {"method":e.value}}); -} - - - -function add_payment_form() -{ - let x = ""; - x += ""; - x += ""; - x += ""; - return x +"
Select method to add:
"+btn("add_payment()","Add","Add payment method",75)+"
"; -} - - function top_up_account() { @@ -1325,24 +1294,33 @@ x += "
"; elm.userSpace.innerHTML = x; - payments[f.top_up_method.value].single(`${policy("business_name","Registrar")}: Top-Up`,format_amount(raw_amt,true)); + payments[f.top_up_method.value].single(`${policy("business_name","Registrar")}: Top-Up`,raw_amt); return false; } + +function make_pay_by_select(name,onchange) +{ + let extra="", x=""; + if (onchange) extra = `onChange="${onchange}(this);"`; + x += `"; + return x; +} + + + function top_up_account_form() { let x = "
"; x += ""; x += ``; x += ""; - x += ""; + x += ""; x += ""; @@ -1376,16 +1354,6 @@ let x="
Top-Up Amount:${gbl.config.currency.symbol}
How to Pay:
"+make_pay_by_select("top_up_method")+"
" x += btn("hideAllPopUp()","Cancel","Cancel this top-up",80); x += "
"; x += "`; x += "
"; - x += generic_popup_btn({ - "name": "AddPayment", - "label": "Add Payment", - "width": 120, - "timeout": null, - "title": "Add a payment method", - "internal": add_payment_form, - "style": "overflow: auto; margin-left: -250;" - }); - x += generic_popup_btn({ "name": "TopUpAcct", "label": "Top-Up Account", @@ -1449,7 +1417,7 @@ x += `
Account Balance :${show_bal}
"; - if ((ctx.orders)&&(ctx.orders.length > 0)) x += order_details(false); + if ((ctx.orders)&&(ctx.orders.length)) x += order_details(false); return x + "" } @@ -1491,11 +1459,28 @@ x += `Amount to Pay :${format_amount(total-ctx.user.acct_current_balance)}`; x += `
`; + x += "Pay Now: "+make_pay_by_select("order_pay_by","pay_for_order")+""; + + x += "
 
"; return x+""; } +function pay_for_order(pay_by) +{ + if (!((pay_by.value in payments)&&(payments[pay_by.value].single))) + return errMsg("Unable to find payment handler for this payment provider","payment-whole"); + + let total = 0; + for(let order of ctx.orders) total += order.price_paid; + + payments[pay_by.value].single(`${policy("business_name","Registrar")}: Domain Names`,total); +} + + + + function domain_of(domain_id) { if (!ctx.domains) return {"name":"Unk1"}; @@ -1557,7 +1542,7 @@ user_info(); let fn = show_new_orders - if ((ctx.orders.length==0)&&(!gbl.basket)) { + if ((!ctx.orders.length)&&(!gbl.basket)) { delete ctx.orders; fn = show_all_orders_processed; } @@ -1566,12 +1551,27 @@ } +function orders_icon() +{ + callApi("orders/details",(ok,reply) => { + if (!ok) return def_errMsg("Failed to load orders",reply,"errorSpan"); + catch_user_data(reply); + show_one_space("userSpace"); + if ((ctx.orders)&&(ctx.orders.length)) { + elm.userSpace.innerHTML = ""+order_details(true)+"
"; + size_one_space(); + } + else show_all_orders_processed(); + }); +} + function show_all_orders_processed() { let x = "
" x += "

All orders processed

"; elm.userSpace.innerHTML = x; + show_one_space("userSpace"); size_one_space(); } @@ -2871,7 +2871,7 @@   - +