Commit 7617d104 authored by Aral Balkan's avatar Aral Balkan

Initial add

parents
Pipeline #872 canceled with stages
const stripe = require('stripe')('sk_test_GT9DfvDjhljTdIe3rKyEHtyU00RVQ0FCNP')
stripe.setTelemetryEnabled(false)
module.exports = async (request, response) => {
const sessionId = request.query.session_id
const session = await stripe.checkout.sessions.retrieve(sessionId)
const subscription = await stripe.subscriptions.retrieve(session.subscription)
const subscriptionId = subscription.id
const subscriptionStatus = subscription.status
const patronSince = Date(subscription.billing_cycle_anchor)
const currentPeriodStart = Date(subscription.current_period_start)
const currentPeriodEnd = Date(subscription.current_period_end)
const patronageAmount = subscription.quantity
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Your Patronage</title>
<style>
html {
color: black;
background-color: white;
}
</style>
</head>
<body>
<h1>Your patronage</h1>
<ul>
<li>Patron since: ${patronSince}</li>
<li>Amount: €${patronageAmount}/month</li>
<li>Status: ${subscriptionStatus}</li>
</ul>
<p>Current period started ${currentPeriodStart} and will end on ${currentPeriodEnd}.</p>
<h2>Update your patronage</h2>
<p>This will update your patronage amount.</p>
<form action='/patronage?action=update&id=${subscriptionId}'>
<label for='amount'>Amount (€/month):<label>
<input type='text' value='${patronageAmount}'>
<input type='submit' value='Update my patronage' />
</form>
<h2>Cancel your patronage</h2>
<p>This will stop your monthly patronage effective immediately.</p>
<form action='/patronage?action=cancel&id=${subscriptionId}'>
<input type='submit' value='Cancel my patronage' />
</form>
</body>
</html>`
response.type('html').status(200).end(html)
}
node_modules
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Cancel</title>
<style>
html {
color: black;
background-color: white;
}
</style>
</head>
<body>
<h1>Cancel!</h1>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Stripe client test</title>
<style>
html {
color: black;
background-color: white;
}
</style>
</head>
<body>
<button id='checkout'>Checkout!</button>
<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe('pk_test_mLQRpGuO7qq3XMfSgwmt4n8U00FSZOIY1h')
document.querySelector('#checkout').addEventListener('click', (event) => {
stripe.redirectToCheckout({
items: [
{plan: 'plan_FSsO2vwva5oEOP', quantity: 100}
],
successUrl: 'https://aral.hypha.dev/success?session_id={CHECKOUT_SESSION_ID}',
cancelUrl: 'https://aral.hypha.dev/cancel',
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
alert(result.error.message)
})
})
</script>
</body>
</html>
\ No newline at end of file
{
"name": "stripe-test",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"lodash.isplainobject": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
"integrity": "sha1-fFJqUtibRcRcxpC4gWO+BJf1UMs="
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
},
"safe-buffer": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
"integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg=="
},
"stripe": {
"version": "7.4.0",
"resolved": "https://registry.npmjs.org/stripe/-/stripe-7.4.0.tgz",
"integrity": "sha512-eurSZJw45MvnV7PjmFHMgJMkCihHgqGHr11OHpFdMh+5CCyYvbVlA5uP5VoVQakhYjSLCObs0dbXtGYhIAMKvw==",
"requires": {
"lodash.isplainobject": "^4.0.6",
"qs": "^6.6.0",
"safe-buffer": "^5.1.1",
"uuid": "^3.3.2"
}
},
"uuid": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
"integrity": "sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA=="
}
}
}
{
"name": "stripe-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"stripe": "^7.4.0"
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Success</title>
<style>
html {
color: black;
background-color: white;
}
</style>
</head>
<body>
<h1>Success!</h1>
<p id='message'></p>
<script>
const urlParams = new URLSearchParams(window.location.search)
const sessionId = urlParams.get('session_id')
const adminPageUrl = `https://aral.hypha.dev/fund-us/?session_id=${sessionId}`
document.querySelector('#message').innerHTML = `
Please bookmark this address: <a href='${adminPageUrl}'>Your patronage page</a>.
It is the page from which you can make changes to your patronage.
`
</script>
</body>
</html>
\ No newline at end of file
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