Skip to content

Commit 81f216d

Browse files
committed
testing metadata fields
1 parent 7fde974 commit 81f216d

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

services/memberships/handler.js

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
import helpers from '../../lib/handlerHelpers';
2-
import db from '../../lib/db';
3-
const stripe = require('stripe')(
4-
'sk_test_51KOxOlBAxwbCreS7JRQtvZCnCgLmn8tjK7WPHDGjpw0s4vfVHLwbcrZZvQLmd5cY7zKRIsfj3pnEDDHTy3G81Tuf00v9ygIBrC'
1+
import helpers from "../../lib/handlerHelpers";
2+
import db from "../../lib/db";
3+
const stripe = require("stripe")(
4+
"sk_test_51KOxOlBAxwbCreS7JRQtvZCnCgLmn8tjK7WPHDGjpw0s4vfVHLwbcrZZvQLmd5cY7zKRIsfj3pnEDDHTy3G81Tuf00v9ygIBrC"
55
);
66
// development endpoint secret - switch to live secret key in production
7-
const endpointSecret = 'whsec_TYSFr29HQ4bIPu649lgkxOrlPjrDOe2l';
8-
const { MEMBERSHIPS_TABLE } = require('../../constants/tables');
7+
const endpointSecret = "whsec_TYSFr29HQ4bIPu649lgkxOrlPjrDOe2l";
8+
const { MEMBERSHIPS_TABLE } = require("../../constants/tables");
99
export const getAll = async (event, ctx, callback) => {
10-
1110
try {
12-
1311
// scan the table
1412
const memberships = await db.scan(MEMBERSHIPS_TABLE);
1513

@@ -21,46 +19,34 @@ export const getAll = async (event, ctx, callback) => {
2119
// return the response object
2220
callback(null, response);
2321
return null;
24-
2522
} catch (err) {
26-
2723
callback(null, err);
2824
return null;
29-
3025
}
31-
3226
};
3327

3428
export const webhook = async (event, ctx, callback) => {
35-
36-
const sig = event.headers['Stripe-Signature'];
29+
const sig = event.headers["Stripe-Signature"];
3730
let eventData;
3831
console.log(event.body);
3932

4033
// Stripe returns an error if verification fails
4134
try {
42-
4335
eventData = stripe.webhooks.constructEvent(event.body, sig, endpointSecret);
44-
4536
} catch (err) {
46-
4737
return helpers.createResponse(400, {
4838
message: `Webhook Error: ${err.message}`,
4939
});
50-
5140
}
5241

5342
// Handle the checkout.session.completed event
54-
if (eventData.type == 'checkout.session.completed') {
55-
43+
if (eventData.type == "checkout.session.completed") {
5644
console.log(eventData.data);
57-
5845
}
5946

6047
let response = helpers.createResponse(200, {});
6148
callback(null, response);
6249
return null;
63-
6450
};
6551

6652
export const config = {
@@ -70,33 +56,40 @@ export const config = {
7056
};
7157

7258
export const payment = async (event, ctx, callback) => {
59+
const {
60+
target: { value },
61+
} = event;
7362

7463
const session = await stripe.checkout.sessions.create({
75-
payment_method_types: ['card'],
64+
payment_method_types: ["card"],
7665
line_items: [
7766
{
7867
price_data: {
79-
currency: 'CAD',
68+
currency: "CAD",
8069
product_data: {
81-
name: 'BizTech Membership',
82-
images: ['https://imgur.com/TRiZYtG.png'],
70+
name: "BizTech Membership",
71+
images: ["https://imgur.com/TRiZYtG.png"],
8372
},
8473
unit_amount: 500,
8574
},
8675
quantity: 1,
8776
},
8877
],
8978
metadata: {
90-
test_order_id: '12345',
79+
test_order_id: "12345",
9180
test_order_id2: 12345,
92-
test_first_name: 'John',
93-
test_last_name: 'Cena',
81+
test_first_name: "John",
82+
test_last_name: "Cena",
83+
test_test: "test",
9484
id: ctx.id,
9585
id2: ctx.body.id,
9686
education0: ctx.education,
9787
education1: ctx.body.education,
9888
education: event.education,
9989
email: event.body.email,
90+
email2: value.email,
91+
email3: value.body.email,
92+
test: value,
10093
// faculty: event.faculty,
10194
// first_name: event.body.first_name,
10295
// heard_from: event.body.heard_from,
@@ -112,12 +105,11 @@ export const payment = async (event, ctx, callback) => {
112105
// international: event.body.international,
113106
// prev_member: event.body.prev_member,
114107
},
115-
mode: 'payment',
116-
success_url: 'https://app.ubcbiztech.com/signup/success',
117-
cancel_url: 'https://facebook.com',
108+
mode: "payment",
109+
success_url: "https://app.ubcbiztech.com/signup/success",
110+
cancel_url: "https://facebook.com",
118111
});
119112
let response = helpers.createResponse(200, session.url);
120113
callback(null, response);
121114
return null;
122-
123115
};

0 commit comments

Comments
 (0)