Skip to content

Commit

Permalink
testing metadata fields
Browse files Browse the repository at this point in the history
  • Loading branch information
merissali committed Feb 27, 2022
1 parent 7fde974 commit 81f216d
Showing 1 changed file with 25 additions and 33 deletions.
58 changes: 25 additions & 33 deletions services/memberships/handler.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import helpers from '../../lib/handlerHelpers';
import db from '../../lib/db';
const stripe = require('stripe')(
'sk_test_51KOxOlBAxwbCreS7JRQtvZCnCgLmn8tjK7WPHDGjpw0s4vfVHLwbcrZZvQLmd5cY7zKRIsfj3pnEDDHTy3G81Tuf00v9ygIBrC'
import helpers from "../../lib/handlerHelpers";
import db from "../../lib/db";
const stripe = require("stripe")(
"sk_test_51KOxOlBAxwbCreS7JRQtvZCnCgLmn8tjK7WPHDGjpw0s4vfVHLwbcrZZvQLmd5cY7zKRIsfj3pnEDDHTy3G81Tuf00v9ygIBrC"
);
// development endpoint secret - switch to live secret key in production
const endpointSecret = 'whsec_TYSFr29HQ4bIPu649lgkxOrlPjrDOe2l';
const { MEMBERSHIPS_TABLE } = require('../../constants/tables');
const endpointSecret = "whsec_TYSFr29HQ4bIPu649lgkxOrlPjrDOe2l";
const { MEMBERSHIPS_TABLE } = require("../../constants/tables");
export const getAll = async (event, ctx, callback) => {

try {

// scan the table
const memberships = await db.scan(MEMBERSHIPS_TABLE);

Expand All @@ -21,46 +19,34 @@ export const getAll = async (event, ctx, callback) => {
// return the response object
callback(null, response);
return null;

} catch (err) {

callback(null, err);
return null;

}

};

export const webhook = async (event, ctx, callback) => {

const sig = event.headers['Stripe-Signature'];
const sig = event.headers["Stripe-Signature"];
let eventData;
console.log(event.body);

// Stripe returns an error if verification fails
try {

eventData = stripe.webhooks.constructEvent(event.body, sig, endpointSecret);

} catch (err) {

return helpers.createResponse(400, {
message: `Webhook Error: ${err.message}`,
});

}

// Handle the checkout.session.completed event
if (eventData.type == 'checkout.session.completed') {

if (eventData.type == "checkout.session.completed") {
console.log(eventData.data);

}

let response = helpers.createResponse(200, {});
callback(null, response);
return null;

};

export const config = {
Expand All @@ -70,33 +56,40 @@ export const config = {
};

export const payment = async (event, ctx, callback) => {
const {
target: { value },
} = event;

const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
payment_method_types: ["card"],
line_items: [
{
price_data: {
currency: 'CAD',
currency: "CAD",
product_data: {
name: 'BizTech Membership',
images: ['https://imgur.com/TRiZYtG.png'],
name: "BizTech Membership",
images: ["https://imgur.com/TRiZYtG.png"],
},
unit_amount: 500,
},
quantity: 1,
},
],
metadata: {
test_order_id: '12345',
test_order_id: "12345",
test_order_id2: 12345,
test_first_name: 'John',
test_last_name: 'Cena',
test_first_name: "John",
test_last_name: "Cena",
test_test: "test",
id: ctx.id,
id2: ctx.body.id,
education0: ctx.education,
education1: ctx.body.education,
education: event.education,
email: event.body.email,
email2: value.email,
email3: value.body.email,
test: value,
// faculty: event.faculty,
// first_name: event.body.first_name,
// heard_from: event.body.heard_from,
Expand All @@ -112,12 +105,11 @@ export const payment = async (event, ctx, callback) => {
// international: event.body.international,
// prev_member: event.body.prev_member,
},
mode: 'payment',
success_url: 'https://app.ubcbiztech.com/signup/success',
cancel_url: 'https://facebook.com',
mode: "payment",
success_url: "https://app.ubcbiztech.com/signup/success",
cancel_url: "https://facebook.com",
});
let response = helpers.createResponse(200, session.url);
callback(null, response);
return null;

};

0 comments on commit 81f216d

Please sign in to comment.