Skip to content

Commit

Permalink
fix bug in basket, make paypal only report orders when they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
james-stevens committed Mar 22, 2023
1 parent da010c5 commit 73e9772
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions htdocs/paypal.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function paypal_amount(amount) {

function make_paypal_order(description, amount, custom_id)
{

let ret_js = {
purchase_units: [
{
Expand Down Expand Up @@ -112,6 +111,7 @@ function make_paypal_order(description, amount, custom_id)
"quantity": 1,
"unit_amount": paypal_amount(amount)
} ];

ret_js.purchase_units[0].amount.breakdown = {
"item_total": paypal_amount(amount)
};
Expand All @@ -138,9 +138,11 @@ function initPayPalButton(description, amount, custom_id) {
return actions.order.capture().then(function(orderData) {
console.log(orderData);
if ((orderData)&&(orderData.purchase_units[0])&&(orderData.purchase_units[0].amount)&&(orderData.purchase_units[0].amount.value)) {
callApi("payments/submitted",(ok,reply)=>{
if (ok) do_orders_icon();
},{ json: { "amount":from_float(orderData.purchase_units[0].amount.value) } });
if ((ctx.orders)&&(ctx.orders.length)) {
callApi("payments/submitted",(ok,reply) => {
if (ok) return do_orders_icon();
},{ json: { "amount":from_float(orderData.purchase_units[0].amount.value) } });
}
}
let e = document.getElementById("payment-whole");
let x = '<center><h3>Thank you for your payment!</h3>'
Expand Down
11 changes: 7 additions & 4 deletions python/webui/basket.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
MANDATORY_BASKET = ["domain", "num_years", "action", "cost"]


def make_blank_domain(name, user_db, status_id):
def make_blank_domain(name, user_db, status_id, num_years):
dom_db = {
"name": name,
"user_id": user_db["user_id"],
Expand All @@ -28,6 +28,8 @@ def make_blank_domain(name, user_db, status_id):
if ok:
dom_db["domain_id"] = dom_id

dom_db["created_dt"] = misc.now()
dom_db["expiry_dt"] = misc.date_add(dom_db["created_dt"], years=num_years)
return ok, dom_db


Expand Down Expand Up @@ -74,7 +76,8 @@ def save_basket(req, whole_basket):

order_db = order["order_db"]
if "domain_id" in order_db and order_db["domain_id"] is None:
ok, dom_db = make_blank_domain(order["domain"], user_db, static.STATUS_WAITING_PAYMENT)
ok, dom_db = make_blank_domain(order["domain"], user_db, static.STATUS_WAITING_PAYMENT,
order_db["num_years"])
if not ok:
return False, f"Failed to reserve domain {order['domain']}"
order_db["domain_id"] = dom_db["domain_id"]
Expand Down Expand Up @@ -142,13 +145,13 @@ def pay_for_basket_item(req, order, user_db):
user_db["acct_current_balance"] -= order_db["price_paid"]

if order_db['order_type'] == "dom/transfer":
ok, dom_db = make_blank_domain(order['domain'], user_db, static.STATUS_TRANS_QUEUED)
ok, dom_db = make_blank_domain(order['domain'], user_db, static.STATUS_TRANS_QUEUED, order_db["num_years"])
if not ok:
return False
order_db["domain_id"] = dom_db["domain_id"]
order["dom_db"] = dom_db
elif order_db['order_type'] == "dom/create":
ok, dom_db = make_blank_domain(order['domain'], user_db, static.STATUS_LIVE)
ok, dom_db = make_blank_domain(order['domain'], user_db, static.STATUS_LIVE, order_db["num_years"])
if not ok:
return False
order_db["domain_id"] = dom_db["domain_id"]
Expand Down

0 comments on commit 73e9772

Please sign in to comment.