Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Small Technology Foundation web site
spikes
patronage
Commits
a2f53081
Verified
Commit
a2f53081
authored
Aug 03, 2019
by
Aral Balkan
Browse files
Add resume patronage feature
parent
d5b5198c
Changes
4
Hide whitespace changes
Inline
Side-by-side
.dynamic/client/patron.html
View file @
a2f53081
...
...
@@ -81,7 +81,7 @@
const
planId
=
'
${planId}
'
const
itemId
=
'
${itemId}
'
const
currentAmount
=
$
{
patronageAmount
}
const
isPaused
=
'
${isPaused}
'
const
isPaused
=
$
{
isPaused
}
console
.
log
(
'
isPaused
'
,
isPaused
)
...
...
.dynamic/client/patron.js
View file @
a2f53081
...
...
@@ -23,6 +23,7 @@ window.addEventListener('load', _ => {
}
switch
(
response
.
for
)
{
case
'
update
'
:
$
(
'
#updateButton
'
).
value
=
'
Update my patronage
'
$
(
'
#updateButton
'
).
disabled
=
false
...
...
@@ -46,8 +47,19 @@ window.addEventListener('load', _ => {
'
success
'
)
break
}
case
'
resume
'
:
$
(
'
#resume-your-patronage
'
).
hidden
=
true
$
(
'
#resumeButton
'
).
value
=
'
Resume my patronage
'
$
(
'
#resumeButton
'
).
disabled
=
false
$
(
'
#pause-your-patronage
'
).
hidden
=
false
Modal
.
fire
(
'
Patronage resumed
'
,
`Your patronage has been resumed effective immediately. You can pause it again at any time. Thank you for supporting us.`
,
'
success
'
)
break
}
}
//
...
...
@@ -85,6 +97,16 @@ window.addEventListener('load', _ => {
$
(
'
#updateButton
'
).
disabled
=
true
}
if
(
commandName
===
'
pause
'
)
{
$
(
'
#pauseButton
'
).
value
=
'
Pausing…
'
$
(
'
#pauseButton
'
).
disabled
=
true
}
if
(
commandName
===
'
resume
'
)
{
$
(
'
#resumeButton
'
).
value
=
'
Resuming…
'
$
(
'
#resumeButton
'
).
disabled
=
true
}
let
proceed
=
true
if
(
commandName
===
'
cancel
'
)
proceed
=
await
confirmCancellation
()
...
...
@@ -96,6 +118,6 @@ window.addEventListener('load', _ => {
handleCommand
(
'
update
'
)
handleCommand
(
'
pause
'
)
handleCommand
(
'
resume
'
)
handleCommand
(
'
cancel
'
)
})
.dynamic/https/get/patron.js
View file @
a2f53081
...
...
@@ -63,7 +63,7 @@ module.exports = async (request, response, next) => {
const
patronageAmount
=
subscription
.
quantity
const
isPaused
=
subscription
.
discount
!==
undefined
const
isPaused
=
subscription
.
discount
!==
null
// Newly-created?
let
newPatronMessage
=
''
...
...
.dynamic/wss/patron.js
View file @
a2f53081
...
...
@@ -10,38 +10,64 @@ module.exports = (webSocket, request) => {
let
result
switch
(
command
.
action
)
{
case
'
update
'
:
// Update the patronage amount, starting with the next payment (not prorated).
try
{
result
=
await
stripe
.
subscriptions
.
update
(
command
.
subscriptionId
,
{
prorate
:
false
,
items
:
[{
id
:
command
.
itemId
,
plan
:
command
.
planId
,
quantity
:
command
.
amount
}]
})
result
=
await
stripe
.
subscriptions
.
update
(
command
.
subscriptionId
,
{
prorate
:
false
,
items
:
[
{
id
:
command
.
itemId
,
plan
:
command
.
planId
,
quantity
:
command
.
amount
}
]
}
)
}
catch
(
error
)
{
webSocket
.
send
(
JSON
.
stringify
({
for
:
command
.
action
,
error
}))
}
webSocket
.
send
(
JSON
.
stringify
({
for
:
command
.
action
,
amount
:
result
.
quantity
}))
break
;
break
;
case
'
pause
'
:
// Pausing a subscription is not a native concept within the Stripe API. Instead, we implement
// one of the recommended strategies for obtaining that outcome by applying a 100% discount coupon.
try
{
result
=
await
stripe
.
subscriptions
.
update
(
command
.
subscriptionId
,
{
prorate
:
false
,
coupon
:
'
VKQ30S0b
'
})
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
;
break
;
case
'
resume
'
:
// A paused subscription (see above) is resumed by deleting the 100% subscription discount.
try
{
result
=
await
stripe
.
subscriptions
.
deleteDiscount
(
command
.
subscriptionId
)
}
catch
(
error
)
{
webSocket
.
send
(
JSON
.
stringify
({
for
:
command
.
action
,
error
}))
}
webSocket
.
send
(
JSON
.
stringify
({
for
:
command
.
action
}))
break
;
case
'
cancel
'
:
console
.
log
(
'
CANCEL
'
)
break
;
break
;
default
:
console
.
log
(
`Unknown command received:
${
command
.
action
}
`
)
const
error
=
new
Error
(
`Unknown command received:
${
command
.
action
}
`
)
console
.
log
(
error
)
webSocket
.
send
(
JSON
.
stringify
({
for
:
command
.
action
,
error
}))
}
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment