Skip to content

Commit

Permalink
NowPayment crypto payments mostly works
Browse files Browse the repository at this point in the history
  • Loading branch information
james-stevens committed Mar 30, 2023
1 parent 9129c3a commit 1d14a74
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions python/payments/libpay.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def config():
return all_config


def process_webhook(webhook_data, sent_data):
def process_webhook(headers, webhook_data, sent_data):
if "name" not in webhook_data:
return False, "Webhook data has no 'name' property"

Expand All @@ -61,7 +61,7 @@ def process_webhook(webhook_data, sent_data):
if (func := pay_handler.run(pay_module, "webhook")) is None:
return False, f"Webhook for'{pay_module}' module is not set up"

ok, reply = func(webhook_data, sent_data, file_name)
ok, reply = func(headers, webhook_data, sent_data, file_name)
if ok is None and reply is None:
os.remove(file_name)
return True, True
Expand Down
26 changes: 13 additions & 13 deletions python/payments/plugins/paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def paypal_config():
return None

return_conf = {"desc": "Pay by PayPal"}
payapl_conf = pay_conf[THIS_MODULE]
paypal_mode = payapl_conf["mode"] if "mode" in payapl_conf else "live"
if paypal_mode == "test":
my_conf = pay_conf[THIS_MODULE]
my_mode = my_conf["mode"] if "mode" in my_conf else "live"
if my_mode == "test":
return_conf["desc"] = "Pay by PayPal SandBox"
if paypal_mode in payapl_conf and "client_id" in payapl_conf[paypal_mode]:
return_conf["client_id"] = payapl_conf[paypal_mode]["client_id"]
elif "client_id" in payapl_conf:
return_conf["client_id"] = payapl_conf["client_id"]
if my_mode in my_conf and "client_id" in my_conf[my_mode]:
return_conf["client_id"] = my_conf[my_mode]["client_id"]
elif "client_id" in my_conf:
return_conf["client_id"] = my_conf["client_id"]
else:
return None
return return_conf
Expand All @@ -41,15 +41,15 @@ def paypal_startup():
if not isinstance(pay_conf, dict) or THIS_MODULE not in pay_conf:
return None

payapl_conf = pay_conf[THIS_MODULE]
paypal_mode = payapl_conf["mode"] if "mode" in payapl_conf else "live"
my_conf = pay_conf[THIS_MODULE]
my_mode = my_conf["mode"] if "mode" in my_conf else "live"

if paypal_mode in payapl_conf and misc.has_data(payapl_conf[paypal_mode], ["webhook", "client_id"]):
mode_conf = payapl_conf[paypal_mode]
if my_mode in my_conf and misc.has_data(my_conf[my_mode], ["webhook", "client_id"]):
mode_conf = my_conf[my_mode]
pay_handler.pay_webhooks[mode_conf["webhook"]] = {
"name": THIS_MODULE,
"client_id": mode_conf["client_id"],
"mode": paypal_mode
"mode": my_mode
}
return True

Expand Down Expand Up @@ -219,7 +219,7 @@ def process_webhook(self):
return True, True


def paypal_process_webhook(webhook_data, sent_data, filename):
def paypal_process_webhook(headers, webhook_data, sent_data, filename):
hook = PayPalWebHook(webhook_data, sent_data, filename)
if not hook.interesting_webhook():
return None, None
Expand Down
3 changes: 2 additions & 1 deletion python/webui/run_webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def before_request():

allowable_referrer = policy.policy("allowable_referrer")
if allowable_referrer is not None and isinstance(allowable_referrer, (dict, list)):
log(f"REFER={flask.request.referrer}")
if flask.request.referrer in allowable_referrer:
return None
elif flask.request.referrer == policy.policy("website_name"):
Expand Down Expand Up @@ -171,7 +172,7 @@ def catch_webhook(webhook):
elif flask.request.method == "GET":
sent_data = flask.request.args

ok, reply = libpay.process_webhook(webhook_data, sent_data)
ok, reply = libpay.process_webhook(req.headers, webhook_data, sent_data)
if not ok:
return req.abort(reply)
return req.response(reply)
Expand Down

0 comments on commit 1d14a74

Please sign in to comment.