Commit 0c443342 authored by Aral Balkan's avatar Aral Balkan

Progress on socket communication

parent 35325391
......@@ -20,9 +20,27 @@ window.addEventListener('load', _ => {
$('#update').addEventListener('submit', event => {
event.preventDefault()
console.log('Moo')
socket.send(JSON.stringify({
action: 'update',
subscriptionId,
amount: $('#patronageAmount').value
}))
})
socket.send(`Update amount to: ${$('#patronageAmount').value}`)
$('#pause').addEventListener('submit', event => {
event.preventDefault()
socket.send(JSON.stringify({
action: 'pause',
subscriptionId
}))
})
$('#cancel').addEventListener('submit', event => {
event.preventDefault()
socket.send(JSON.stringify({
action: 'cancel',
subscriptionId
}))
})
})
\ No newline at end of file
})
......@@ -4,7 +4,6 @@ const moment = require('moment')
const stripe = require('stripe')('sk_test_GT9DfvDjhljTdIe3rKyEHtyU00RVQ0FCNP')
stripe.setTelemetryEnabled(false)
console.log(process.cwd())
const htmlTemplate = fs.readFileSync('.dynamic/client/patron.html')
const clientSideJavaScript = fs.readFileSync('.dynamic/client/patron.js')
......@@ -27,19 +26,16 @@ module.exports = async (request, response, next) => {
const sessionId = request.params.id
// TODO: Document this edge case in the Site.js docs.
if (sessionId === '.websocket') {
// This is a web socket request, leave it be.
next()
return
}
console.log('>>>> SESSION ID = <<<<', sessionId)
const session = await stripe.checkout.sessions.retrieve(sessionId)
const subscription = await stripe.subscriptions.retrieve(session.subscription)
console.log('subscription', subscription)
const subscriptionId = subscription.id
const subscriptionStatus = subscription.status
......
......@@ -5,6 +5,6 @@ module.exports = app => {
app.get('/patron/:id', httpsGetPatron)
app.ws('/patron', wssPatron)
app.ws('/patron/', wssPatron)
}
module.exports = (webSocket, request) => {
console.log('Socket route ready')
webSocket.on('message', (data) => {
console.log(`Received: ${data}`)
console.log('Received:', JSON.parse(data))
})
}
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