Skip to content

Commit

Permalink
misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nano2dev committed Mar 24, 2024
1 parent 309c033 commit 7d05310
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 17 deletions.
22 changes: 12 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -460,21 +460,23 @@ <h1 class="smaller">NanoPay.js</h1>
setTimeout(() => {

NanoPay.open({
checkout: 'ccc68c11',
debug: 'ccc68c11',
// alias: true, // required
address: '@development', // required
// address: '@development', // required
// amount: 30, // required
// notify: '[email protected]',
// contact: true,
// // random: false,
strings: {
email_placeholder: 'Required *',
shipping_placeholder: 'Required *',
},
line_items: [
{ name: "Shirt (X-Small)", price: 0.122 },
{ name: "Mens Shoes (9.5)", price: 0 }
],
shipping: 0.011,
// strings: {
// email_placeholder: 'Required *',
// shipping_placeholder: 'Required *',
// },
// breakdown: [
// { name: "Shirt (X-Small)", price: 0.122 },
// { name: "Mens Shoes (9.5)", price: 0 }
// ],
// shipping: 0.011,
// currency: 'USD',
success: (block) => {
document.getElementById('success').innerText = 'Success'
Expand Down
49 changes: 42 additions & 7 deletions latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@
var get_name = config.claim || config.lease || config.name || config.get_name || config.username
var disclaimer = config.disclaimer
var expiration = config.timeout || config.expiration || config.time || config.time
var service_fee = config.fee || config.service_fee

var wallets = {
nault: { image: 'https://pay.nano.to/img/nault.png', name: 'Nault' },
Expand All @@ -334,6 +335,7 @@
line_items: config.strings && config.strings.line_items ? config.strings.line_items : (config.line_items && config.line_items.length > 1 ? 'Items' : 'Item'),
email: config.strings && config.strings.email ? config.strings.email : 'Email',
shipping: config.strings && config.strings.shipping ? config.strings.shipping : 'Shipping',
service_fee: config.strings && config.strings.shipping ? config.strings.shipping : 'Service Fee',
tax: config.strings && config.strings.tax ? config.strings.tax : 'Sales Tax',
subtotal: config.strings && config.strings.subtotal ? config.strings.subtotal : 'Subtotal',
button: config.strings && config.strings.button ? config.strings.button : 'Pay with Nano',
Expand All @@ -359,7 +361,10 @@

show_loading(true)

if (!wallets[wallet]) return alert("NanoPay: Invalid wallet option. Supported: natrium, nault, nautilus, cake.")
if (!wallets[wallet]) {
show_loading(false)
return alert("NanoPay: Invalid wallet option. Supported: natrium, nault, nautilus, cake.")
}

if (config.contact === "false") config.contact = false

Expand Down Expand Up @@ -397,7 +402,10 @@
config.disclaimer = 'Username taken. Only original owner can add time.'
}

if (rpc_checkout.error) return alert("NanoPay: " + rpc_checkout.message || rpc_checkout.error)
if (rpc_checkout.error) {
show_loading(false)
return alert("NanoPay: " + rpc_checkout.message || rpc_checkout.error)
}

var default_plan = 1
rpc_checkout.amount = rpc_checkout.plans[default_plan].value
Expand All @@ -415,7 +423,10 @@
address: config.address
}))

if (rpc_checkout.error) return alert("NanoPay: " + rpc_checkout.message || rpc_checkout.error)
if (rpc_checkout.error) {
show_loading(false)
return alert("NanoPay: " + rpc_checkout.message || rpc_checkout.error)
}

window.NanoPay.config.require_alias = true

Expand All @@ -425,10 +436,16 @@

} else {

if (!address) return alert("NanoPay: Address or Username required.")
if (!address) {
show_loading(false)
return alert("NanoPay: Address or Username required.")
}

if (line_items) {
if (!Array.isArray(line_items) || line_items && !line_items.find(a => a && a.price)) return alert("NanoPay: Invalid line_items. Example: [ { name: 'T-Shirt', price: 5 } ] ")
if (!Array.isArray(line_items) || line_items && !line_items.find(a => a && a.price)) {
show_loading(false)
return alert("NanoPay: Invalid line_items. Example: [ { name: 'T-Shirt', price: 5 } ] ")
}
description = original_config.description || 'TOTAL'
}

Expand All @@ -449,7 +466,9 @@
}

if (amount && !rpc_checkout.amount_raw) {
return alert("NanoPay: " + rpc_checkout.message || 'Checkout Error. Please contact [email protected] with error code #112')
alert("NanoPay: " + rpc_checkout.message || 'Checkout Error. Please contact [email protected] with error code #112')
show_loading(false)
return
}

if (!config.plans && !config.line_items && !get_alias && !get_alias) {
Expand Down Expand Up @@ -489,7 +508,7 @@
#nano-pay-details { box-sizing: border-box; display: flex;justify-content: start;width: 100%;padding: 15px 14px;border-bottom: 1px solid ${ window.NanoPay.dark_mode ? '#ffffff08' : '#0000000f' };position: relative;align-items: start; }
#nano-pay-details-spacer { text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.5; min-width: 90px; }
#nano-pay-details-labels { font-family: sans-serif; text-transform: uppercase;opacity: 0.5;font-size: 95%;line-height: 17px;letter-spacing: 0.8px; }
#nano-pay-details-labels { font-family: sans-serif; opacity: 0.5;font-size: 95%;line-height: 17px;letter-spacing: 0.8px; }
#nano-pay-details-labels > div, #nano-pay-details-values > div { margin: 3px 0; }
#nano-pay-details-values { text-transform: uppercase;opacity: 1;font-size: 90%;line-height: 17px;letter-spacing: 0.8px; margin-left: auto; }
Expand Down Expand Up @@ -612,6 +631,22 @@
<div id="nano-pay-amount-value">${rpc_checkout.amount} ${symbol}</div>
</div>
</div>
<div id="nano-pay-details" style="${ rpc_checkout.service_fee || rpc_checkout.service_fee === 0 ? '' : 'display: none' }">
<div style="display: ${Number(config.shipping) || config.shipping === true || config.shipping === "true" ? 'block' : 'none'}" id="nano-pay-details-spacer"></div>
<div id="nano-pay-details-labels">
<div style="display: ${rpc_checkout.subtotal ? 'block' : 'none'}">${strings.description || 'Amount'}</div>
<div>${strings.service_fee}</div>
<br>
<div id="nano-pay-description">Total Amount</div>
</div>
<div id="nano-pay-details-values">
<div style="display: ${rpc_checkout.subtotal ? 'block' : 'none'}; text-align: right">${rpc_checkout.subtotal} ${symbol}</div>
<div style="text-align: right">${rpc_checkout.service_fee} ${symbol}</div>
<br>
<div id="nano-pay-amount-value">${rpc_checkout.amount} ${symbol}</div>
</div>
</div>
<div id="nano-pay-disclaimer" style="display: ${config.disclaimer ? 'flex' : 'none'}">
<div>${config.disclaimer}</div>
Expand Down

0 comments on commit 7d05310

Please sign in to comment.