Skip to content

Commit 7fb67c2

Browse files
committed
improved checkout
1 parent ce75321 commit 7fb67c2

5 files changed

Lines changed: 36 additions & 31 deletions

File tree

Synergism.css

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ body button:active:not(:disabled):not(.disable-hover-color) {
553553

554554
#exitOffline,
555555
#exitFastForward,
556-
#closeCart,
557556
#checkout {
558557
width: 18em;
559558
min-height: auto;
@@ -567,7 +566,6 @@ body button:active:not(:disabled):not(.disable-hover-color) {
567566
}
568567

569568
#exitOffline:hover,
570-
#closeCart:hover,
571569
#checkout:not(:disabled):hover {
572570
background-color: var(--purplehover-color);
573571
}
@@ -5034,7 +5032,13 @@ form input:hover {
50345032
margin: 0 auto;
50355033
}
50365034

5037-
#closeCart,
5035+
#checkout-buttons {
5036+
display: flex;
5037+
justify-content: center;
5038+
flex-direction: column;
5039+
margin: 0 auto;
5040+
}
5041+
50385042
#checkout {
50395043
margin: 2px auto 4px;
50405044
}

index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4564,9 +4564,10 @@ <h1 id="pCoinUpgradeName">Welcome to the PseudoShop!</h1>
45644564
</label>
45654565
</section>
45664566

4567-
<button id="checkout" type="submit">Checkout</button>
4568-
<div id="checkout-paypal"></div>
4569-
<button id="closeCart" type="button">Close</button>
4567+
<div id="checkout-buttons">
4568+
<button id="checkout" type="submit" i18n="tabs.pseudocoins.checkoutStripe"></button>
4569+
<div id="checkout-paypal"></div>
4570+
</div>
45704571
</div>
45714572
</div>
45724573
<div id="merchContainer">

src/purchases/CheckoutTab.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { loadScript } from '@paypal/paypal-js'
22
import { prod } from '../Config'
3-
import { changeSubTab, Tabs } from '../Tabs'
43
import { Alert, Notification } from '../UpdateHTML'
54
import { memoize } from '../Utility'
65
import { products, subscriptionProducts } from './CartTab'
@@ -10,28 +9,17 @@ import { updatePseudoCoins } from './UpgradesSubtab'
109
const tab = document.querySelector<HTMLElement>('#pseudoCoins > #cartContainer')!
1110
const form = tab.querySelector('div.cartList')!
1211

13-
const checkout = form.querySelector('button#checkout')
14-
const closeCart = form.querySelector('button#closeCart')
12+
const checkout = form.querySelector<HTMLElement>('button#checkout')
1513
const radioTOSAgree = form.querySelector<HTMLInputElement>('section > input[type="radio"]')!
1614
const totalCost = form.querySelector('p#totalCost')
1715
const itemList = form.querySelector('#itemList')!
1816

19-
let tosAgreed = false
2017
const formatter = Intl.NumberFormat('en-US', {
2118
style: 'currency',
2219
currency: 'USD'
2320
})
2421

2522
export const initializeCheckoutTab = memoize(() => {
26-
closeCart?.addEventListener('click', () => {
27-
changeSubTab(Tabs.Purchase, { page: 0 })
28-
})
29-
30-
radioTOSAgree.addEventListener('click', () => {
31-
tosAgreed = !tosAgreed
32-
radioTOSAgree.checked = tosAgreed
33-
})
34-
3523
itemList.insertAdjacentHTML(
3624
'afterend',
3725
products.map((product) => (`
@@ -46,8 +34,8 @@ export const initializeCheckoutTab = memoize(() => {
4634
`)).join('')
4735
)
4836

49-
checkout?.addEventListener('click', (e) => {
50-
if (!tosAgreed) {
37+
function submitCheckout (e: MouseEvent) {
38+
if (!radioTOSAgree.checked) {
5139
e.preventDefault()
5240
Notification('You must accept the terms of service first!')
5341
return
@@ -59,13 +47,22 @@ export const initializeCheckoutTab = memoize(() => {
5947
fd.set(product.id, `${product.quantity}`)
6048
}
6149

62-
fd.set('tosAgree', tosAgreed ? 'on' : 'off')
50+
fd.set('tosAgree', radioTOSAgree.checked ? 'on' : 'off')
51+
52+
checkout?.setAttribute('disabled', '')
6353

64-
checkout.setAttribute('disabled', '')
54+
let url: string
6555

66-
const url = !prod
67-
? 'https://synergism.cc/stripe/test/create-checkout-session'
68-
: 'https://synergism.cc/stripe/create-checkout-session'
56+
const clickedId = (e.target as HTMLElement).id
57+
58+
if (clickedId === 'checkout') {
59+
url = !prod
60+
? 'https://synergism.cc/stripe/test/create-checkout-session'
61+
: 'https://synergism.cc/stripe/create-checkout-session'
62+
} else {
63+
Notification(`You clicked on ${clickedId}.`)
64+
return
65+
}
6966

7067
fetch(url, {
7168
method: 'POST',
@@ -79,9 +76,11 @@ export const initializeCheckoutTab = memoize(() => {
7976
}
8077
})
8178
.finally(() => {
82-
checkout.removeAttribute('disabled')
79+
checkout?.removeAttribute('disabled')
8380
})
84-
})
81+
}
82+
83+
checkout?.addEventListener('click', submitCheckout)
8584

8685
initializePayPal('#checkout-paypal')
8786
})
@@ -188,7 +187,7 @@ async function initializePayPal (selector: string | HTMLElement) {
188187
fd.set(product.id, `${product.quantity}`)
189188
}
190189

191-
fd.set('tosAgree', tosAgreed ? 'on' : 'off')
190+
fd.set('tosAgree', radioTOSAgree.checked ? 'on' : 'off')
192191
const url = 'https://synergism.cc/paypal/orders/create'
193192

194193
const response = await fetch(url, {

src/purchases/SubscriptionsSubtab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export const createIndividualSubscriptionHTML = (product: SubscriptionProduct, e
144144
<button data-id="${product.id}" data-name="${product.name}" data-upgrade class="pseudoCoinButton">
145145
Upgrade for ${formatter.format((product.price - existingCosts) / 100)} USD / mo
146146
</button>
147-
<div class="checkout-paypal" data-id="${product.id}"></div>
147+
<!--<div class="checkout-paypal" data-id="${product.id}"></div>-->
148148
</div>
149149
</section>
150150
`

translations/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4152,7 +4152,8 @@
41524152
"subscriptions": "Subscriptions",
41534153
"upgrades": "Buy Upgrades",
41544154
"merch": "Purchase Merch",
4155-
"consumables": "Consumables & Events"
4155+
"consumables": "Consumables & Events",
4156+
"checkoutStripe": "Checkout with Stripe"
41564157
}
41574158
},
41584159
"offlineProgress": {

0 commit comments

Comments
 (0)