Skip to content

Commit

Permalink
paypal one shot for top-up done
Browse files Browse the repository at this point in the history
  • Loading branch information
james-stevens committed Feb 21, 2023
1 parent 32a5671 commit 97913e8
Show file tree
Hide file tree
Showing 32 changed files with 331 additions and 108 deletions.
21 changes: 21 additions & 0 deletions emails/admin_webhook_failed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
To: {{policy.admin_email}}
From: {{policy.name_sender}} <{{policy.email_sender}}>
X-Env-From: {{policy.email_return}}
Subject: {{policy.business_name}}: {{pay_module}} failed payment processing

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

Processig of payment from {{pay_module}} failed.
<P>
<table style="margin-left: 100px">
<tr><Td class=promptCell>Processor :</td><td class=dataCell>{{pay_module}}</td></tr>
<tr><Td class=promptCell>Message :</td><td class=dataCell>{{message}}</td></tr>
<tr><Td class=promptCell>Failename :</td><td class=dataCell>{{filename}}</td></tr>
</table>

{% include "end.html" %}
3 changes: 1 addition & 2 deletions emails/domain_transferred.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "start.inc" %}
Subject: You just received a gift of the domain {{domain.display_name}} ({{domain.name}})
Subject: {{policy.business_name}}: You just received a gift of the domain {{domain.display_name}} ({{domain.name}})

<html>
<style type='text/css'>
Expand All @@ -18,4 +18,3 @@


{% include "end.html" %}
</body></html>
1 change: 1 addition & 0 deletions emails/end.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
<font size=+1>Yours</font><br>
&nbsp;&nbsp;&nbsp;{{ policy.name_sender }}<br>
&nbsp;&nbsp;&nbsp;<a href="{{ policy.website_name }}">{{ policy.website_name }}</a><br>
</body></html>
3 changes: 1 addition & 2 deletions emails/gifted_domain.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "start.inc" %}
Subject: You just received a gift of the domain {{domain.display_name}} ({{domain.name}})
Subject: {{policy.business_name}}: You just received a gift of the domain {{domain.display_name}} ({{domain.name}})

<html>
<style type='text/css'>
Expand All @@ -18,4 +18,3 @@


{% include "end.html" %}
</body></html>
2 changes: 1 addition & 1 deletion emails/password_reset.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "start.inc" %}
Subject: Password reset done at {{policy.business_name}}
Subject: {{policy.business_name}}: Password reset done at {{policy.business_name}}

<html>
<style type='text/css'>
Expand Down
27 changes: 27 additions & 0 deletions emails/payment_done.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{% include "start.inc" %}
Subject: {{policy.business_name}}: Successfully processed credit from {{ provider }}

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

Thank you for you payment from {{provider}}. Any pending orders you have will
now be automatically processed.
<P>

<table style="margin-left: 100px">
<tr><Td class=promptCell>Amount Credited :</td><td class=dataCell>{{transaction.amount_fmt}}</td></tr>
<tr><Td class=promptCell>New Account Balance :</td><td class=dataCell>{{user.acct_current_balance_fmt}}</td></tr>

{% if paypal_trans_id is defined and paypal_trans_id %}
<tr><Td class=promptCell>PayPal Transaction Refrence :</td><td class=dataCell>{{paypal_trans_id}}</td></tr>
<tr><Td class=promptCell>PayPal Account EMail :</td><td class=dataCell>{{paypal_email}}</td></tr>
{% endif %}

</table>


{% include "end.html" %}
3 changes: 1 addition & 2 deletions emails/receipt.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "start.inc" %}
Subject: Order processed for {{sale.sales_type}} on {{domain.display_name}} ({{domain.name}})
Subject: {{policy.business_name}}: Order processed for {{sale.sales_type}} on {{domain.display_name}} ({{domain.name}})

<html>
<style type='text/css'>
Expand All @@ -23,4 +23,3 @@


{% include "end.html" %}
</body></html>
2 changes: 1 addition & 1 deletion emails/reminder.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "start.inc" %}
Subject: Expiry of domain {{domain.display_name}} ({{domain.name}})
Subject: {{policy.business_name}}: Expiry of domain {{domain.display_name}} ({{domain.name}})

<html>
<style type='text/css'>
Expand Down
2 changes: 1 addition & 1 deletion emails/reset_request.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "start.inc" %}
Subject: Password reset request at {{policy.business_name}}
Subject: {{policy.business_name}}: Password reset request

<html>
<style type='text/css'>
Expand Down
2 changes: 1 addition & 1 deletion emails/verify_email.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% include "start.inc" %}
Subject: Email Address verification for {{policy.business_name}}
Subject: {{policy.business_name}}: Email Address verification

<html>
<style type='text/css'>
Expand Down
23 changes: 8 additions & 15 deletions htdocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1277,19 +1277,11 @@
let e = document.getElementById("add_payment_type");
if (!e) return;

console.log("add_payment",e.value);

callApi("payments/html",(ok,reply) => {
let p = document.getElementById("add_pay_div");
if ((ok)&&(p)) {
// let x="<table align=center border=0>";
// x += settings_header(`Add Payment Method - ${gbl.config.payment[e.value]}`)+"<tr><td>"+reply+"</td></tr></table>";
// # CODE
console.log(reply);
gbl.paypal = reply;
if (reply.html) p.innerHTML = reply.html;
if (reply.script) { let k = eval(reply.script); }
// let f = document.getElementById("pay.provider_tag");
// if (f) f.focus();
return;
}
def_errMsg("Error getting HTML for payment",reply,"add_pay_div");
Expand All @@ -1316,23 +1308,24 @@
function top_up_account()
{
let f = document.top_up_form;
if (!f.top_up_method.value) {
if ((!f.top_up_method.value)||(!(f.top_up_method.value in payments))||(!payments[f.top_up_method.value].single)) {
errMsg("Please select a payment method","TopUpAcct");
f.top_up_method.focus();
return false;
}

if (!f.top_up_amount.value) {
if ((!f.top_up_amount.value)||(isNaN(f.top_up_amount.value))) {
errMsg("Please enter a top-up amount","TopUpAcct");
f.top_up_amount.focus();
return false;
}

let x = `<center><h3>Top-Up Amount: ${gbl.config.currency.symbol}${f.top_up_amount.value}</h3></center>`;
let raw_amt = from_float(f.top_up_amount.value)
let x = `<center><h3>Top-Up Amount: ${format_amount(raw_amt)}</h3></center>`;
x += "<div id='payment-whole'></div>";
elm.userSpace.innerHTML = x;

payments[f.top_up_method.value].single(`${policy("business_name","Registrar")}: Top-Up`,f.top_up_amount.value);
payments[f.top_up_method.value].single(`${policy("business_name","Registrar")}: Top-Up`,format_amount(raw_amt,true));

return false;
}
Expand All @@ -1343,7 +1336,7 @@
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>Select method:</td>";
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))
Expand Down Expand Up @@ -1402,7 +1395,7 @@
x += "<table width=75% align=center cellspacing=1 cellpadding=0 border=0>";
x += "<tr><th>Payment Method</th><th>Payment Data</th></tr>"
for(let i of reply) {
x += `<tr onClick='remove_payment("${i.provider}","${i.provider_tag}");' class=dataRow title="Click to remove this payment method"><td>${gbl.config.payment[i.provider]}</td>`;
x += `<tr onClick='remove_payment("${i.provider}","${i.provider_tag}");' class=dataRow title="Click to remove this payment record"><td>${i.provider}</td>`;
x += `<td>${i.provider_tag}</td></tr>`;
}
x += "</table>";
Expand Down
7 changes: 7 additions & 0 deletions htdocs/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ const validations = {
rrDS: /^(([123456]?[0-9]{1,4}|[0-9]1,4) ([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]) [1234] [0-9A-F ]{40,100})$/i,
};

const pow10 = { 0:1, 1:10, 2:100, 3:1000, 4:10000, 5:100000, 6:1000000, 7:10000000, 8:100000000, 9:1000000000, 10:10000000000 };

function from_float(amount)
{
return Math.round(parseFloat(amount)*pow10[gbl.config.currency.decimal]);
}


function callApi(sfx,callback,inData)
{
Expand Down
6 changes: 3 additions & 3 deletions htdocs/paypal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function paypal_startup() // {module}_startup() is a mandatory func in a JS paym
add_paypal_script(gbl.config.payment.paypal.client_id,gbl.config.currency.iso);

payments["paypal"] = {
"desc": "PayPal",
"desc": "Pay by PayPal",
"single": paypal_single_payment
};
}
Expand Down Expand Up @@ -78,8 +78,8 @@ function initPayPalButton(description, amount, custom_id) {
return actions.order.capture().then(function(orderData) {
// console.log(orderData);
let e = document.getElementById("payment-whole");
let x = '<center><h3>Thank you for your payment!</h3><br>'
x += "Your payment will be processed<br>when PayPal notifies us they have completed the transfer</center>";
let x = '<center><h3>Thank you for your payment!</h3>'
x += "Your payment will be processed when PayPal notifies us they have completed the transfer</center>";
e.innerHTML = x;
});
},
Expand Down
2 changes: 1 addition & 1 deletion python/backend/.pylintrc
2 changes: 1 addition & 1 deletion python/backend/dom_plugins/.pylintrc
2 changes: 1 addition & 1 deletion python/bin/.pylintrc
1 change: 1 addition & 0 deletions python/cardproc/.pylintrc
1 change: 1 addition & 0 deletions python/cronjob/.pylintrc
2 changes: 1 addition & 1 deletion python/epprest/.pylintrc
2 changes: 1 addition & 1 deletion python/librar/.pylintrc
5 changes: 1 addition & 4 deletions python/librar/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ def admin_trans(injs):
if not ok or not user_db or len(user_db) <= 0:
return False, "Invalid user_id given"

site_currency = policy.policy("currency")
amount *= static.POW10[site_currency["decimal"]]
amount = int(round(amount, 0))

amount = amt_from_float(amount)
ok, trans_id = apply_transaction(user_id, amount, "Admin: " + injs["description"], as_admin=True)
if not ok:
return False, trans_id
Expand Down
38 changes: 28 additions & 10 deletions python/librar/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import inspect
import idna
import sys

from librar.policy import this_policy as policy
from librar import mysql as sql
Expand All @@ -24,6 +25,12 @@ def event_log(other_items, stack_pos=2):


def ashex(line):
if isinstance(line, int):
out_hex = ""
while line > 0:
out_hex = static.HEXLIB[line & 0xf] + out_hex
line = line >> 4
return out_hex if len(out_hex) > 0 else "0"
if isinstance(line, str):
line = line.encode("utf-8")
ret = ""
Expand All @@ -49,6 +56,14 @@ def puny_to_utf8(name, strict_idna_2008=None):
return None


def amt_from_float(amt, currency=None):
if currency is None:
currency = policy.policy("currency")
amt = float(amt)
amt *= static.POW10[currency["decimal"]]
return int(round(float(amt), 0))


def format_currency(number, currency, with_symbol=True):
num = number
pfx = currency["symbol"] if with_symbol else ""
Expand All @@ -72,13 +87,16 @@ def format_currency(number, currency, with_symbol=True):


if __name__ == "__main__":
print(puny_to_utf8("frog.xn--k3h"))
print(puny_to_utf8("frog.xn--k3hw410f"))
print(puny_to_utf8("xn--e28h.xn--dp8h"))
print(puny_to_utf8("xn--strae-oqa.com"))

print(puny_to_utf8("frog.xn--k3h", True))
print(puny_to_utf8("frog.xn--k3hw410f", True))
print(puny_to_utf8("xn--e28h.xn--dp8h", True))
print(puny_to_utf8("xn--strae-oqa.com", True))
print(puny_to_utf8("xn--st-rae-oqa.com", True))
print(amt_from_float(sys.argv[1]))
#print(ashex(int(sys.argv[1])))

# print(puny_to_utf8("frog.xn--k3h"))
# print(puny_to_utf8("frog.xn--k3hw410f"))
# print(puny_to_utf8("xn--e28h.xn--dp8h"))
# print(puny_to_utf8("xn--strae-oqa.com"))

# print(puny_to_utf8("frog.xn--k3h", True))
# print(puny_to_utf8("frog.xn--k3hw410f", True))
# print(puny_to_utf8("xn--e28h.xn--dp8h", True))
# print(puny_to_utf8("xn--strae-oqa.com", True))
# print(puny_to_utf8("xn--st-rae-oqa.com", True))
5 changes: 3 additions & 2 deletions python/librar/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,13 @@ def sql_delete_one(table, where):
return ok is not None


def sql_insert(table, column_vals):
def sql_insert(table, column_vals, ignore=False):
if table in static.AUTO_CREATED_AMENDED_DT:
for col in ["amended_dt", "created_dt"]:
if col not in column_vals:
column_vals[col] = None
return sql_exec(f"insert into {table} set " + data_set(column_vals, ","))
with_ignore = "ignore" if ignore else ""
return sql_exec(f"insert {with_ignore} into {table} set " + data_set(column_vals, ","))


def sql_exists(table, where):
Expand Down
12 changes: 3 additions & 9 deletions python/librar/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,16 +270,10 @@ def apply_price_factor(action, dom, factor, num_years, retain_reg_price):
if dom[action] is None or dom[action] == 0:
our_price *= float(num_years)

site_currency = policy.policy("currency")
our_price *= static.POW10[site_currency["decimal"]]
our_price = round(float(our_price), 0)

currency = policy.policy("currency")
if retain_reg_price:
regs_price *= static.POW10[site_currency["decimal"]]
regs_price = round(float(regs_price), 0)
dom["reg_" + action] = int(regs_price)

dom[action] = int(our_price)
dom["reg_" + action] = amt_from_float(regs_price, currency)
dom[action] = amt_from_float(out_price, currency)


def start_up():
Expand Down
1 change: 1 addition & 0 deletions python/mailer/.pylintrc
5 changes: 4 additions & 1 deletion python/mailer/spool_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
ERROR_BASE = f"{os.environ['BASE']}/storage/perm/mail_error"
TEMPLATE_DIR = f"{os.environ['BASE']}/emails"

REQUIRE_FORMATTING = ["price_paid", "acct_current_balance"]
REQUIRE_FORMATTING = [
"price_paid", "price_charged", "acct_current_balance", "amount", "pre_balance", "post_balance",
"acct_current_balance", "acct_previous_balance", "acct_overdraw_limit", "acct_warn_low_balance", "for_sale_amount"
]


def event_log(prefix, records):
Expand Down
1 change: 1 addition & 0 deletions python/payments/.pylintrc
Loading

0 comments on commit 97913e8

Please sign in to comment.