Skip to content

Commit

Permalink
paypal payment for orders
Browse files Browse the repository at this point in the history
  • Loading branch information
james-stevens committed Feb 22, 2023
1 parent fcaa52e commit 0b52633
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 99 deletions.
16 changes: 16 additions & 0 deletions emails/password_changed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% include "start.inc" %}
Subject: {{policy.business_name}}: Password changed at {{policy.business_name}}

<html>
<style type='text/css'>
{% include "dark.css" %}
</style>
<body>
<font size=+1>Hi {{user.name}},</font><p>

Your password at {{policy.business_name}} has just been changed.<P>

If this was not you, please contact our technical support as soon as possible.<P>


{% include "end.html" %}
132 changes: 66 additions & 66 deletions htdocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@
credit: "&#x1F4B3;",
lock: "&#x1F512;",
unlock: "&#x1F513;",
thumb: "&#x1F44d;",

gap: "<div style='height: 7px;'></div>",
settings_spacer: "<tr><td><div style='height: 70px;'></div></td></tr>",

def_max_checks: 2
def_max_checks: 5
};

ctx = {};
Expand Down Expand Up @@ -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];
}
})
}

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -951,7 +954,7 @@

function userDomainList()
{
let x = "<table align=center cellspacing=1 cellpadding=0 border=0>";
let x = "<table style='min-width: 75%;' align=center cellspacing=1 cellpadding=0 border=0>";
x += "<tr><td colspan=6 id=domListBtnBar class=btmBtnBar>";
x += btn("request_transfer(true)","Transfer In","Use an AuthCode to request a domain transfer",100);
x += "</td></tr>";
Expand Down Expand Up @@ -1118,13 +1121,13 @@

function goMarketPlace()
{
errMsg("Not yet implemented","marketPlaceBtn");
errMsg(gbl.thumb+"&nbsp;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+"&nbsp;Coming Soon","2fa_section"); }
function disable_two_fa() { errMsg(gbl.thumb+"&nbsp;Coming Soon","2fa_section"); }



Expand Down Expand Up @@ -1164,11 +1167,11 @@
x += "<form name=editUserPassword method=post action=# onSubmit='postUserPassword(); return false;'>";
x += "<table id=editUserPassword width=100%><colgroup><col width=30%/><col/><col width=10%/></colgroup>";
x += form_prompt("Current Password");
x += `<input style="width: 300px;" autocomplete="current-password" placeholder="Your current password" type=password id='password'></td></tr>`;
x += form_prompt("New Password");
x += `<input style="width: 300px;" autocomplete="new-password" placeholder="Your new password" type=password id='new_password'></td></tr>`;
x += form_prompt("Confirm Password");
x += `<input style="width: 300px;" autocomplete="new-password" placeholder="Confirm your new password" type=password id='confirm_password'></td></tr>`;
x += `<input style="width: 300px;" autocomplete="current-password" placeholder="Current password" type=password id='password'></td></tr>`;
x += form_prompt("<b>New</b> Password");
x += `<input style="width: 300px;" autocomplete="new-password" placeholder="New password" type=password id='new_password'></td></tr>`;
x += form_prompt("Confirm <b>New</b> Password");
x += `<input style="width: 300px;" autocomplete="new-password" placeholder="Confirm New Password" type=password id='confirm_password'></td></tr>`;
x += "<tr><td colspan=2></td><td align=right><input style='width: 135px;' type=submit class=myBtn value='Change'></td></tr>";
x += "</table></form></td></tr>";

Expand Down Expand Up @@ -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 = "<table>";
x += "<tr><td class=formPrompt>Select method to add:</td>";
x += "<td><select id=add_payment_type>"
for(let i in gbl.config.payment) {
x += `<option value='${i}'>${gbl.config.payment[i]}`;
}
x += "</select></td></tr>";
x += "<tr><td colspan=2 class=btmBtnBar>"+btn("add_payment()","Add","Add payment method",75)+"</td></tr>";
return x +"</table>";
}



function top_up_account()
{
Expand All @@ -1325,24 +1294,33 @@
x += "<div id='payment-whole'></div>";
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 += `<select ${extra} id=top_up_method><option value=''>--- Select Payment Method ---`;
for(let i in payments)
if ((i in gbl.config.payment)&&(payments[i].single)) x += `<option value='${i}'>${payments[i].desc}`;
x += "</select>";
return x;
}



function top_up_account_form()
{
let x = "<form name=top_up_form onSubmit='return top_up_account();' action=# method=post><table>";
x += "<tr><td class=formPrompt>Top-Up Amount:</td>";
x += `<td>${gbl.config.currency.symbol}<input id='top_up_amount' style="width: 250px;"></td></tr>`;
x += "<tr><td class=formPrompt>How to Pay:</td>";
x += "<td><select id=top_up_method><option value=''>--- Select Method ---"
for(let i in payments) {
if ((i in gbl.config.payment)&&(payments[i].single))
x += `<option value='${i}'>${payments[i].desc}`;
}
x += "</select></td></tr>";
x += "<td>"+make_pay_by_select("top_up_method")+"</td></tr>";
x += "<tr><td colspan=2 class=btmBtnBar>"
x += btn("hideAllPopUp()","Cancel","Cancel this top-up",80);
x += "<input class=myBtn type=submit value='Top-Up' title='Make top-up payment now' style='width: 120px;'></td></tr>";
Expand Down Expand Up @@ -1376,16 +1354,6 @@
let x="<table width=75% align=center cellspacing=1 cellpadding=0 border=0>";
x += "<tr><td class=btmBtnBar>";

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",
Expand Down Expand Up @@ -1449,7 +1417,7 @@
x += `<tr><td class=promptCell>Account Balance :</td><td class=dataCell>${show_bal}</td></tr>`;
x += "</td></tr></table>";

if ((ctx.orders)&&(ctx.orders.length > 0)) x += order_details(false);
if ((ctx.orders)&&(ctx.orders.length)) x += order_details(false);

return x + "</table>"
}
Expand Down Expand Up @@ -1491,11 +1459,28 @@
x += `<tr><td colspan=5 class=promptCell>Amount to Pay :</td><td align=right>${format_amount(total-ctx.user.acct_current_balance)}</td></tr>`;
x += `<tr><td colspan=6><div class="line"/></td></tr>`;

x += "<tr><td colspan=6 align=right>Pay Now: "+make_pay_by_select("order_pay_by","pay_for_order")+"</td></tr>";

x += "<tr><td colspan=6><div id='payment-whole'>&nbsp;</div></td></tr>";
return x+"</table></td></tr>";
}



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"};
Expand Down Expand Up @@ -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;
}
Expand All @@ -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 = "<table align=center width=75% border=0>"+order_details(true)+"</table>";
size_one_space();
}
else show_all_orders_processed();
});
}


function show_all_orders_processed()
{
let x = "<table align=center width=50% border=0><tr><td>"
x += "<h2>All orders processed</h2></td></tr></table>";
elm.userSpace.innerHTML = x;
show_one_space("userSpace");
size_one_space();
}

Expand Down Expand Up @@ -2871,7 +2871,7 @@
<colgroup><col width=20%/><col width=20%/><col width=60%/></colgroup>
<tr><td><span id="errorSpan">&nbsp;</span></td>
<td><span title="Please confirm your email address" id=emailIcon class=userIcons style="display: none;" onClick="confirmEmail();">&#128231;</span></td>
<td><span title="You have orders waiting to be paid for" id="ordersIcon" class=userIcons style="display: none;" onClick="load_domains_list(myAccount);">&#x1F4B3;</span></td>
<td><span title="You have orders waiting to be paid for" id="ordersIcon" class=userIcons style="display: none;" onClick="orders_icon();">&#x1F4B3;</span></td>
<td align=center>
<span id="basketIcon" style="display: none;" class="popup">
<span class=userIcons title="You have items waiting to checkout" ${style} onClick='togglePopUp("basketPopup",30000);'>&#128722;</span>
Expand Down
75 changes: 56 additions & 19 deletions htdocs/paypal.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function paypal_single_payment(description, amount)
let e = document.getElementById("payment-whole");
e.innerHTML = x;

initPayPalButton(description, amount, reply.token);
initPayPalButton(description, format_amount(amount,true), reply.token);
},{ json:{ "provider":"paypal"}})
}

Expand All @@ -49,29 +49,64 @@ function test_single_paypal() // this is for debugging



function initPayPalButton(description, amount, custom_id) {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'horizontal',
label: 'paypal',

},
function make_paypal_order(description, amount, custom_id)
{
let this_value = {
"currency_code": gbl.config.currency.iso,
"value": amount
};

createOrder: function(data, actions) {
return actions.order.create({
let ret_js = {
purchase_units: [
{
"description": description,
"custom_id": custom_id,
"amount":{
"currency_code": gbl.config.currency.iso,
"value": amount
}
"amount": { ...this_value, ...{ "breakdown": { "item_total": this_value } } }
}
]
});
] };

if ((ctx.orders)&&(ctx.orders.length > 0)) {
let item_list = [];
for(let order of ctx.orders) {
let dom = domain_of(order.domain_id);
let yrs = `${order.num_years} yrs`;
if (order.num_years==1) yrs=`${order.num_years} yr`;
item_list.push({
"name": `${order.order_type} ${dom.display_name} for ${yrs}`,
"quantity": 1,
"unit_amount": {
"currency_code": gbl.config.currency.iso,
"value": format_amount(order.price_paid,true)
}
});
}
ret_js.purchase_units[0].items = item_list;
return ret_js;
}

ret_js.purchase_units[0].items = [ {
"name": description,
"quantity": 1,
"unit_amount": this_value
} ];

return ret_js;
}


function initPayPalButton(description, amount, custom_id) {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'horizontal',
label: 'paypal',
},

createOrder: function(data, actions) {
post_data = make_paypal_order(description, amount, custom_id);
console.log(post_data);
return actions.order.create(post_data);
},

onApprove: function(data, actions) {
Expand All @@ -84,7 +119,9 @@ function initPayPalButton(description, amount, custom_id) {
});
},

onError: function(err) { errMsg(err,"payment-whole"); }
onError: function(err) {
console.log(err);
}

}).render('#payment-button');
}
2 changes: 1 addition & 1 deletion python/librar/hashstr.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ def make_session_key(session_code, user_agent):


if __name__ == "__main__":
print(make_hash())
print(make_hash(chars_needed=30))
1 change: 1 addition & 0 deletions python/librar/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"backend_retry_timeout": 300,
"backend_retry_attempts": 3,
"renew_limit": 10,
"max_checks": 5,
"max_basket_size": 10,
"trans_per_page": 25,
"orders_expire_hrs": int(6.5 * 24),
Expand Down
Loading

0 comments on commit 0b52633

Please sign in to comment.