Commit d5b5198c authored by Aral Balkan's avatar Aral Balkan

Implement pause patronage functionality

parent 516454bb
/* Fix buttons so they appear centered. */
.swal2-actions {
text-align: center;
}
.your-patronage-is-paused-message {
font-size: 1.5em;
text-align: center;
border-radius: 6px;
background-color: #FEE59E;
color: #783806;
padding: 0.25em;
}
\ No newline at end of file
......@@ -18,6 +18,18 @@
<body>
<h1>Your patronage</h1>
<section id='resume-your-patronage' ${isPaused ? '' : 'hidden'}>
<p class='your-patronage-is-paused-message'>Your patronage is paused.</p>
<h2>Resume your patronage</h2>
<p>This will resume your patronage effective immediately. You can pause it again at any point.</p>
<form id='resume'>
<input id='resumeButton' type='submit' value='Resume my patronage' />
</form>
</section>
<p>Status: <span id='status'>offline</span></p>
<div id='received'></div>
......@@ -46,13 +58,15 @@
<input id='updateButton' type='submit' value='Update my patronage' />
</form>
<h2>Pause your patronage</h2>
<section id='pause-your-patronage' ${isPaused ? 'hidden' : ''}>
<h2>Pause your patronage</h2>
<p>This will pause your patronage effective immediately. You can resume it again at any point.</p>
<p>This will pause your patronage effective immediately. You can resume it again at any point.</p>
<form id='pause'>
<input type='submit' value='Pause my patronage' />
</form>
<form id='pause'>
<input id='pauseButton' type='submit' value='Pause my patronage' />
</form>
</section>
<h2>Cancel your patronage</h2>
......@@ -67,6 +81,9 @@
const planId = '${planId}'
const itemId = '${itemId}'
const currentAmount = ${patronageAmount}
const isPaused = '${isPaused}'
console.log('isPaused', isPaused)
${sweetAlert2}
${clientSideJavaScript}
......
......@@ -33,7 +33,19 @@ window.addEventListener('load', _ => {
`Your patronage has been updated to €${response.amount}/month, starting with your next payment. Thank you for supporting us.`,
'success'
)
break;
break
case 'pause':
$('#pause-your-patronage').hidden = true
$('#pauseButton').value = 'Pause my patronage'
$('#pauseButton').disabled = false
$('#resume-your-patronage').hidden = false
Modal.fire(
'Patronage paused',
`Your patronage has been paused effective immediately. You can resume it again at any time. Thank you for supporting us.`,
'success'
)
break
}
}
......
......@@ -38,6 +38,8 @@ module.exports = async (request, response, next) => {
const session = await stripe.checkout.sessions.retrieve(sessionId)
const subscription = await stripe.subscriptions.retrieve(session.subscription)
console.log(subscription)
const subscriptionId = subscription.id
const subscriptionStatus = subscription.status
......@@ -61,6 +63,8 @@ module.exports = async (request, response, next) => {
const patronageAmount = subscription.quantity
const isPaused = subscription.discount !== undefined
// Newly-created?
let newPatronMessage = ''
// TODO: Base the display of this message on whether it is 1+ day after the subscription was created or not.
......
const stripe = require('stripe')('sk_test_GT9DfvDjhljTdIe3rKyEHtyU00RVQ0FCNP')
const pausePatronageCouponId = 'VKQ30S0b'
module.exports = (webSocket, request) => {
webSocket.on('message', async data => {
const command = JSON.parse(data)
let result
switch (command.action) {
case 'update':
let result
// Update the patronage amount, starting with the next payment (not prorated).
try {
result = await stripe.subscriptions.update(command.subscriptionId, {
prorate: false,
......@@ -23,7 +27,15 @@ module.exports = (webSocket, request) => {
webSocket.send(JSON.stringify({for: command.action, amount: result.quantity}))
break;
case 'pause':
console.log('PAUSE')
try {
result = await stripe.subscriptions.update(command.subscriptionId, {
prorate: false,
coupon: 'VKQ30S0b'
})
} catch (error) {
webSocket.send(JSON.stringify({for: command.action, error}))
}
webSocket.send(JSON.stringify({for: command.action, coupon: result.coupon}))
break;
case 'cancel':
console.log('CANCEL')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment