Skip to content

Instantly share code, notes, and snippets.

@imprakharshukla
Created March 27, 2020 06:35
Show Gist options
  • Save imprakharshukla/e322998cd6ef266e0e3c25879caa75bb to your computer and use it in GitHub Desktop.
Save imprakharshukla/e322998cd6ef266e0e3c25879caa75bb to your computer and use it in GitHub Desktop.
const functions = require('firebase-functions');
const cors = require('cors')({ origin: true });
exports.purch_moddedFetch = functions.https.onRequest((request, response) => {
cors(request, response, async () => {
const id = request.query.id;
const uid = request.query.uid;
console.log("ID is " + id);
console.log("UID is " + uid);
var stripe = require('stripe')('sk_test_xxxx');
if (id === "bundle") {
stripe.checkout.sessions.create(
{
success_url: 'https://andropaym.firebaseapp.com/success.html',
cancel_url: 'https://andropaym.firebaseapp.com/fail.html',
metadata: { uid: uid, payID: getPayID() },
payment_method_types: ['card'],
line_items: [
{
name: "Modded OS Bundle",
description: 'Carefully modified Linux Distro Bundle for Android.',
amount: 37500,
currency: 'inr',
quantity: 1,
},
],
},
function (err, session) {
console.log("Session ID is " + session)
response.send(session);
}
);
}
else {
stripe.checkout.sessions.create(
{
success_url: 'https://andropaym.firebaseapp.com/success.html',
cancel_url: 'https://andropaym.firebaseapp.com/fail.html',
metadata: { uid: uid, payID: getPayID() },
payment_method_types: ['card'],
line_items: [
{
name: getDistro(id),
description: 'Carefully modified Linux Distro for Android.',
amount: 15000,
currency: 'inr',
quantity: 1,
},
],
},
function (err, session) {
console.log("Session ID is " + session)
response.send(session);
}
);
}
});
});
function getDistro(id) {
let distro;
switch (id) {
case "deb":
distro = "Modded OS Debian";
break;
case "andro":
distro = "Modded OS Ubuntu XFCE";
break;
case "man":
distro = "Modded OS Manjaro XFCE";
break;
case "kde":
distro = "Modded OS Ubuntu KDE";
break;
case "bundle":
distro = "Modded OS Bundle";
break;
}
return distro;
}
function getPayID() {
return 'GPA.' + getRand(9999, 1001) + "-" + getRand(9999, 1001) + "-" + getRand(9999, 1001) + "-" + getRand(99999, 10001);
}
function getRand(max, min) {
return (Math.floor(Math.random() * (max - min) + min)).toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment