How to use stripe.checkout.sessions.create method in qawolf

Best JavaScript code snippet using qawolf

checkout.test.js

Source:checkout.test.js Github

copy

Full Screen

1import stripeModule from 'stripe';2import nconf from 'nconf';3import common from '../../../../../../website/common';4import * as subscriptions from '../../../../../../website/server/libs/payments/stripe/subscriptions';5import * as oneTimePayments from '../../../../../../website/server/libs/payments/stripe/oneTimePayments';6import {7 createCheckoutSession,8 createEditCardCheckoutSession,9} from '../../../../../../website/server/libs/payments/stripe/checkout';10import {11 generateGroup,12} from '../../../../../helpers/api-unit.helper';13import { model as User } from '../../../../../../website/server/models/user';14import { model as Group } from '../../../../../../website/server/models/group';15import * as gems from '../../../../../../website/server/libs/payments/gems';16const { i18n } = common;17describe('Stripe - Checkout', () => {18 const stripe = stripeModule('test');19 const BASE_URL = nconf.get('BASE_URL');20 const redirectUrls = {21 success_url: `${BASE_URL}/redirect/stripe-success-checkout`,22 cancel_url: `${BASE_URL}/redirect/stripe-error-checkout`,23 };24 describe('createCheckoutSession', () => {25 let user;26 const sessionId = 'session-id';27 beforeEach(() => {28 user = new User();29 sandbox.stub(stripe.checkout.sessions, 'create').returns(sessionId);30 sandbox.stub(gems, 'validateGiftMessage');31 });32 it('gems', async () => {33 const amount = 999;34 const gemsBlockKey = '21gems';35 sandbox.stub(oneTimePayments, 'getOneTimePaymentInfo').returns({36 amount,37 gemsBlock: common.content.gems[gemsBlockKey],38 });39 const res = await createCheckoutSession({ user, gemsBlock: gemsBlockKey }, stripe);40 expect(res).to.equal(sessionId);41 const metadata = {42 type: 'gems',43 userId: user._id,44 gift: undefined,45 sub: undefined,46 gemsBlock: gemsBlockKey,47 };48 expect(gems.validateGiftMessage).to.not.be.called;49 expect(oneTimePayments.getOneTimePaymentInfo).to.be.calledOnce;50 expect(oneTimePayments.getOneTimePaymentInfo).to.be.calledWith(gemsBlockKey, undefined, user);51 expect(stripe.checkout.sessions.create).to.be.calledOnce;52 expect(stripe.checkout.sessions.create).to.be.calledWith({53 payment_method_types: ['card'],54 metadata,55 line_items: [{56 price_data: {57 product_data: {58 name: common.i18n.t('nGems', { nGems: 21 }),59 },60 unit_amount: amount,61 currency: 'usd',62 },63 quantity: 1,64 }],65 mode: 'payment',66 ...redirectUrls,67 });68 });69 it('gems gift', async () => {70 const receivingUser = new User();71 await receivingUser.save();72 const gift = {73 type: 'gems',74 uuid: receivingUser._id,75 gems: {76 amount: 4,77 },78 };79 const amount = 100;80 sandbox.stub(oneTimePayments, 'getOneTimePaymentInfo').returns({81 amount,82 gemsBlock: null,83 });84 const res = await createCheckoutSession({ user, gift }, stripe);85 expect(res).to.equal(sessionId);86 const metadata = {87 type: 'gift-gems',88 userId: user._id,89 gift: JSON.stringify(gift),90 sub: undefined,91 gemsBlock: undefined,92 };93 expect(gems.validateGiftMessage).to.be.calledOnce;94 expect(gems.validateGiftMessage).to.be.calledWith(gift, user);95 expect(oneTimePayments.getOneTimePaymentInfo).to.be.calledOnce;96 expect(oneTimePayments.getOneTimePaymentInfo).to.be.calledWith(undefined, gift, user);97 expect(stripe.checkout.sessions.create).to.be.calledOnce;98 expect(stripe.checkout.sessions.create).to.be.calledWith({99 payment_method_types: ['card'],100 metadata,101 line_items: [{102 price_data: {103 product_data: {104 name: common.i18n.t('nGemsGift', { nGems: 4 }),105 },106 unit_amount: amount,107 currency: 'usd',108 },109 quantity: 1,110 }],111 mode: 'payment',112 ...redirectUrls,113 });114 });115 it('subscription gift', async () => {116 const receivingUser = new User();117 await receivingUser.save();118 const subKey = 'basic_3mo';119 const gift = {120 type: 'subscription',121 uuid: receivingUser._id,122 subscription: {123 key: subKey,124 },125 };126 const amount = 1500;127 sandbox.stub(oneTimePayments, 'getOneTimePaymentInfo').returns({128 amount,129 gemsBlock: null,130 subscription: common.content.subscriptionBlocks[subKey],131 });132 const res = await createCheckoutSession({ user, gift }, stripe);133 expect(res).to.equal(sessionId);134 const metadata = {135 type: 'gift-sub',136 userId: user._id,137 gift: JSON.stringify(gift),138 sub: undefined,139 gemsBlock: undefined,140 };141 expect(oneTimePayments.getOneTimePaymentInfo).to.be.calledOnce;142 expect(oneTimePayments.getOneTimePaymentInfo).to.be.calledWith(undefined, gift, user);143 expect(stripe.checkout.sessions.create).to.be.calledOnce;144 expect(stripe.checkout.sessions.create).to.be.calledWith({145 payment_method_types: ['card'],146 metadata,147 line_items: [{148 price_data: {149 product_data: {150 name: common.i18n.t('nMonthsSubscriptionGift', { nMonths: 3 }),151 },152 unit_amount: amount,153 currency: 'usd',154 },155 quantity: 1,156 }],157 mode: 'payment',158 ...redirectUrls,159 });160 });161 it('subscription', async () => {162 const subKey = 'basic_3mo';163 const coupon = null;164 sandbox.stub(subscriptions, 'checkSubData').returns(undefined);165 const sub = common.content.subscriptionBlocks[subKey];166 const res = await createCheckoutSession({ user, sub, coupon }, stripe);167 expect(res).to.equal(sessionId);168 const metadata = {169 type: 'subscription',170 userId: user._id,171 gift: undefined,172 sub: JSON.stringify(sub),173 };174 expect(subscriptions.checkSubData).to.be.calledOnce;175 expect(subscriptions.checkSubData).to.be.calledWith(sub, false, coupon);176 expect(stripe.checkout.sessions.create).to.be.calledOnce;177 expect(stripe.checkout.sessions.create).to.be.calledWith({178 payment_method_types: ['card'],179 metadata,180 line_items: [{181 price: sub.key,182 quantity: 1,183 // @TODO proper copy184 }],185 mode: 'subscription',186 ...redirectUrls,187 });188 });189 it('throws if group does not exists', async () => {190 const groupId = 'invalid';191 sandbox.stub(Group.prototype, 'getMemberCount').resolves(4);192 const subKey = 'group_monthly';193 const coupon = null;194 const sub = common.content.subscriptionBlocks[subKey];195 await expect(createCheckoutSession({196 user, sub, coupon, groupId,197 }, stripe))198 .to.eventually.be.rejected.and.to.eql({199 httpCode: 404,200 name: 'NotFound',201 message: i18n.t('groupNotFound'),202 });203 });204 it('group plan', async () => {205 const group = generateGroup({206 name: 'test group',207 type: 'guild',208 privacy: 'public',209 leader: user._id,210 });211 const groupId = group._id;212 await group.save();213 sandbox.stub(Group.prototype, 'getMemberCount').resolves(4);214 // Add user to group215 user.guilds.push(groupId);216 await user.save();217 const subKey = 'group_monthly';218 const coupon = null;219 sandbox.stub(subscriptions, 'checkSubData').returns(undefined);220 const sub = common.content.subscriptionBlocks[subKey];221 const res = await createCheckoutSession({222 user, sub, coupon, groupId,223 }, stripe);224 expect(res).to.equal(sessionId);225 const metadata = {226 type: 'subscription',227 userId: user._id,228 gift: undefined,229 sub: JSON.stringify(sub),230 groupId,231 };232 expect(Group.prototype.getMemberCount).to.be.calledOnce;233 expect(subscriptions.checkSubData).to.be.calledOnce;234 expect(subscriptions.checkSubData).to.be.calledWith(sub, true, coupon);235 expect(stripe.checkout.sessions.create).to.be.calledOnce;236 expect(stripe.checkout.sessions.create).to.be.calledWith({237 payment_method_types: ['card'],238 metadata,239 line_items: [{240 price: sub.key,241 quantity: 6,242 // @TODO proper copy243 }],244 mode: 'subscription',245 ...redirectUrls,246 });247 });248 // no gift, sub or gem payment249 it('throws if type is invalid', async () => {250 await expect(createCheckoutSession({ user }, stripe))251 .to.eventually.be.rejected;252 });253 });254 describe('createEditCardCheckoutSession', () => {255 let user;256 const sessionId = 'session-id';257 const customerId = 'customerId';258 const subscriptionId = 'subscription-id';259 let subscriptionsListStub;260 beforeEach(() => {261 user = new User();262 sandbox.stub(stripe.checkout.sessions, 'create').returns(sessionId);263 subscriptionsListStub = sandbox.stub(stripe.subscriptions, 'list');264 subscriptionsListStub.resolves({ data: [{ id: subscriptionId }] });265 });266 it('throws if no valid data is supplied', async () => {267 await expect(createEditCardCheckoutSession({}, stripe))268 .to.eventually.be.rejected;269 });270 it('throws if customer does not exists', async () => {271 await expect(createEditCardCheckoutSession({ user }, stripe))272 .to.eventually.be.rejected.and.to.eql({273 httpCode: 401,274 name: 'NotAuthorized',275 message: i18n.t('missingSubscription'),276 });277 });278 it('throws if subscription does not exists', async () => {279 user.purchased.plan.customerId = customerId;280 subscriptionsListStub.resolves({ data: [] });281 await expect(createEditCardCheckoutSession({ user }, stripe))282 .to.eventually.be.rejected.and.to.eql({283 httpCode: 401,284 name: 'NotAuthorized',285 message: i18n.t('missingSubscription'),286 });287 });288 it('change card for user subscription', async () => {289 user.purchased.plan.customerId = customerId;290 const metadata = {291 userId: user._id,292 type: 'edit-card-user',293 };294 const res = await createEditCardCheckoutSession({ user }, stripe);295 expect(res).to.equal(sessionId);296 expect(subscriptionsListStub).to.be.calledOnce;297 expect(subscriptionsListStub).to.be.calledWith({ customer: customerId });298 expect(stripe.checkout.sessions.create).to.be.calledOnce;299 expect(stripe.checkout.sessions.create).to.be.calledWith({300 mode: 'setup',301 payment_method_types: ['card'],302 metadata,303 customer: customerId,304 setup_intent_data: {305 metadata: {306 customer_id: customerId,307 subscription_id: subscriptionId,308 },309 },310 ...redirectUrls,311 });312 });313 it('throws if group does not exists', async () => {314 const groupId = 'invalid';315 await expect(createEditCardCheckoutSession({ user, groupId }, stripe))316 .to.eventually.be.rejected.and.to.eql({317 httpCode: 404,318 name: 'NotFound',319 message: i18n.t('groupNotFound'),320 });321 });322 describe('with group', () => {323 let group; let groupId;324 beforeEach(async () => {325 group = generateGroup({326 name: 'test group',327 type: 'guild',328 privacy: 'public',329 leader: user._id,330 });331 groupId = group._id;332 await group.save();333 });334 it('throws if user is not allowed to change group plan', async () => {335 const anotherUser = new User();336 anotherUser.guilds.push(groupId);337 await anotherUser.save();338 await expect(createEditCardCheckoutSession({ user: anotherUser, groupId }, stripe))339 .to.eventually.be.rejected.and.to.eql({340 httpCode: 401,341 name: 'NotAuthorized',342 message: i18n.t('onlyGroupLeaderCanManageSubscription'),343 });344 });345 it('throws if customer does not exists (group)', async () => {346 await expect(createEditCardCheckoutSession({ user, groupId }, stripe))347 .to.eventually.be.rejected.and.to.eql({348 httpCode: 401,349 name: 'NotAuthorized',350 message: i18n.t('missingSubscription'),351 });352 });353 it('throws if subscription does not exists (group)', async () => {354 group.purchased.plan.customerId = customerId;355 subscriptionsListStub.resolves({ data: [] });356 await expect(createEditCardCheckoutSession({ user, groupId }, stripe))357 .to.eventually.be.rejected.and.to.eql({358 httpCode: 401,359 name: 'NotAuthorized',360 message: i18n.t('missingSubscription'),361 });362 });363 it('change card for group plans - leader', async () => {364 group.purchased.plan.customerId = customerId;365 await group.save();366 const metadata = {367 userId: user._id,368 type: 'edit-card-group',369 groupId,370 };371 const res = await createEditCardCheckoutSession({ user, groupId }, stripe);372 expect(res).to.equal(sessionId);373 expect(subscriptionsListStub).to.be.calledOnce;374 expect(subscriptionsListStub).to.be.calledWith({ customer: customerId });375 expect(stripe.checkout.sessions.create).to.be.calledOnce;376 expect(stripe.checkout.sessions.create).to.be.calledWith({377 mode: 'setup',378 payment_method_types: ['card'],379 metadata,380 customer: customerId,381 setup_intent_data: {382 metadata: {383 customer_id: customerId,384 subscription_id: subscriptionId,385 },386 },387 ...redirectUrls,388 });389 });390 it('change card for group plans - plan owner', async () => {391 const anotherUser = new User();392 anotherUser.guilds.push(groupId);393 await anotherUser.save();394 group.purchased.plan.customerId = customerId;395 group.purchased.plan.owner = anotherUser._id;396 await group.save();397 const metadata = {398 userId: anotherUser._id,399 type: 'edit-card-group',400 groupId,401 };402 const res = await createEditCardCheckoutSession({ user: anotherUser, groupId }, stripe);403 expect(res).to.equal(sessionId);404 expect(subscriptionsListStub).to.be.calledOnce;405 expect(subscriptionsListStub).to.be.calledWith({ customer: customerId });406 expect(stripe.checkout.sessions.create).to.be.calledOnce;407 expect(stripe.checkout.sessions.create).to.be.calledWith({408 mode: 'setup',409 payment_method_types: ['card'],410 metadata,411 customer: customerId,412 setup_intent_data: {413 metadata: {414 customer_id: customerId,415 subscription_id: subscriptionId,416 },417 },418 ...redirectUrls,419 });420 });421 });422 });...

Full Screen

Full Screen

stripe.ts

Source:stripe.ts Github

copy

Full Screen

...34 switch (tier) {35 case "researcher":36 freeTrial37 ? coupon && coupon.id38 ? (session = await stripe.checkout.sessions.create({39 payment_method_types: ["card"],40 client_reference_id: `${user.id}`,41 subscription_data: {42 trial_period_days: 7,43 },44 line_items: [45 {46 price: process.env.STRIPE_RESEARCH_MONTH_KEY,47 quantity: 1,48 },49 ],50 mode: "subscription",51 discounts: [52 {53 coupon: coupon.id,54 },55 ],56 metadata: {57 trial: true,58 },59 success_url:60 process.env.NODE_ENV === "development"61 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"62 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",63 cancel_url:64 process.env.NODE_ENV === "development"65 ? "http://localhost:3000/begin"66 : "https://www.untanglify.com/begin",67 }))68 : (session = await stripe.checkout.sessions.create({69 payment_method_types: ["card"],70 client_reference_id: `${user.id}`,71 subscription_data: {72 trial_period_days: 7,73 },74 line_items: [75 {76 price: process.env.STRIPE_RESEARCH_MONTH_KEY,77 quantity: 1,78 },79 ],80 mode: "subscription",81 metadata: {82 trial: true,83 },84 success_url:85 process.env.NODE_ENV === "development"86 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"87 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",88 cancel_url:89 process.env.NODE_ENV === "development"90 ? "http://localhost:3000/begin"91 : "https://www.untanglify.com/begin",92 }))93 : coupon && coupon.id94 ? (session = await stripe.checkout.sessions.create({95 payment_method_types: ["card"],96 client_reference_id: `${user.id}`,97 line_items: [98 {99 price: process.env.STRIPE_RESEARCH_MONTH_KEY,100 quantity: 1,101 },102 ],103 mode: "subscription",104 discounts: [105 {106 coupon: coupon.id,107 },108 ],109 metadata: {110 trial: true,111 },112 success_url:113 process.env.NODE_ENV === "development"114 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"115 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",116 cancel_url:117 process.env.NODE_ENV === "development"118 ? "http://localhost:3000/begin"119 : "https://www.untanglify.com/begin",120 }))121 : (session = await stripe.checkout.sessions.create({122 payment_method_types: ["card"],123 client_reference_id: `${user.id}`,124 line_items: [125 {126 price: process.env.STRIPE_RESEARCH_MONTH_KEY,127 quantity: 1,128 },129 ],130 mode: "subscription",131 metadata: {132 trial: true,133 },134 success_url:135 process.env.NODE_ENV === "development"136 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"137 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",138 cancel_url:139 process.env.NODE_ENV === "development"140 ? "http://localhost:3000/begin"141 : "https://www.untanglify.com/begin",142 }));143 return session.url;144 case "student":145 freeTrial146 ? coupon && coupon.id147 ? (session = await stripe.checkout.sessions.create({148 payment_method_types: ["card"],149 client_reference_id: `${user.id}`,150 subscription_data: {151 trial_period_days: 7,152 },153 line_items: [154 {155 price: process.env.STRIPE_STUDENT_MONTH_KEY,156 quantity: 1,157 },158 ],159 metadata: {160 trial: true,161 },162 mode: "subscription",163 discounts: [164 {165 coupon: coupon.id,166 },167 ],168 success_url:169 process.env.NODE_ENV === "development"170 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"171 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",172 cancel_url:173 process.env.NODE_ENV === "development"174 ? "http://localhost:3000/begin"175 : "https://www.untanglify.com/begin",176 }))177 : (session = await stripe.checkout.sessions.create({178 payment_method_types: ["card"],179 client_reference_id: `${user.id}`,180 subscription_data: {181 trial_period_days: 7,182 },183 line_items: [184 {185 price: process.env.STRIPE_STUDENT_MONTH_KEY,186 quantity: 1,187 },188 ],189 metadata: {190 trial: true,191 },192 mode: "subscription",193 success_url:194 process.env.NODE_ENV === "development"195 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"196 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",197 cancel_url:198 process.env.NODE_ENV === "development"199 ? "http://localhost:3000/begin"200 : "https://www.untanglify.com/begin",201 }))202 : coupon && coupon.id203 ? (session = await stripe.checkout.sessions.create({204 payment_method_types: ["card"],205 client_reference_id: `${user.id}`,206 line_items: [207 {208 price: process.env.STRIPE_STUDENT_MONTH_KEY,209 quantity: 1,210 },211 ],212 metadata: {213 trial: true,214 },215 mode: "subscription",216 discounts: [217 {218 coupon: coupon.id,219 },220 ],221 success_url:222 process.env.NODE_ENV === "development"223 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"224 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",225 cancel_url:226 process.env.NODE_ENV === "development"227 ? "http://localhost:3000/begin"228 : "https://www.untanglify.com/begin",229 }))230 : (session = await stripe.checkout.sessions.create({231 payment_method_types: ["card"],232 client_reference_id: `${user.id}`,233 line_items: [234 {235 price: process.env.STRIPE_STUDENT_MONTH_KEY,236 quantity: 1,237 },238 ],239 metadata: {240 trial: true,241 },242 mode: "subscription",243 success_url:244 process.env.NODE_ENV === "development"245 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"246 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",247 cancel_url:248 process.env.NODE_ENV === "development"249 ? "http://localhost:3000/begin"250 : "https://www.untanglify.com/begin",251 }));252 return session.url;253 default:254 break;255 }256 break;257 case "yearly":258 switch (tier) {259 case "researcher":260 coupon && coupon.id261 ? (session = await stripe.checkout.sessions.create({262 payment_method_types: ["card"],263 client_reference_id: `${user.id}`,264 line_items: [265 {266 price: process.env.STRIPE_RESEARCH_YEAR_KEY,267 quantity: 1,268 },269 ],270 mode: "subscription",271 discounts: [272 {273 coupon: coupon.id,274 },275 ],276 success_url:277 process.env.NODE_ENV === "development"278 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"279 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",280 cancel_url:281 process.env.NODE_ENV === "development"282 ? "http://localhost:3000/begin"283 : "https://www.untanglify.com/begin",284 }))285 : (session = await stripe.checkout.sessions.create({286 payment_method_types: ["card"],287 client_reference_id: `${user.id}`,288 line_items: [289 {290 price: process.env.STRIPE_RESEARCH_YEAR_KEY,291 quantity: 1,292 },293 ],294 mode: "subscription",295 success_url:296 process.env.NODE_ENV === "development"297 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"298 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",299 cancel_url:300 process.env.NODE_ENV === "development"301 ? "http://localhost:3000/begin"302 : "https://www.untanglify.com/begin",303 }));304 return session.url;305 case "student":306 coupon && coupon.id307 ? (session = await stripe.checkout.sessions.create({308 payment_method_types: ["card"],309 client_reference_id: `${user.id}`,310 line_items: [311 {312 price: process.env.STRIPE_STUDENT_YEAR_KEY,313 quantity: 1,314 },315 ],316 mode: "subscription",317 discounts: [318 {319 coupon: coupon.id,320 },321 ],322 success_url:323 process.env.NODE_ENV === "development"324 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"325 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",326 cancel_url:327 process.env.NODE_ENV === "development"328 ? "http://localhost:3000/begin"329 : "https://www.untanglify.com/begin",330 }))331 : (session = await stripe.checkout.sessions.create({332 payment_method_types: ["card"],333 client_reference_id: `${user.id}`,334 line_items: [335 {336 price: process.env.STRIPE_STUDENT_YEAR_KEY,337 quantity: 1,338 },339 ],340 mode: "subscription",341 success_url:342 process.env.NODE_ENV === "development"343 ? "http://localhost:3000/users/onboarding?session_id={CHECKOUT_SESSION_ID}"344 : "https://www.untanglify.com/users/onboarding?session_id={CHECKOUT_SESSION_ID}",345 cancel_url:...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

2const stripe = require('stripe')(stripeKey);3module.exports = async function (context, req) {4 if (req.body && req.body.customer_id) {5 if (req.body.customer_currency === 'MXN') {6 const session = await stripe.checkout.sessions.create({7 payment_method_types: ['card'],8 subscription_data: {9 trial_from_plan: req.body.trial,10 },11 line_items: [{12 price: "price_1HQfbYEaFEmd6wlWEa2tdA9j",13 quantity: 1,14 }],15 customer: req.body.customer_id,16 mode: 'subscription',17 allow_promotion_codes: true,18 success_url: req.body.success_url,19 cancel_url: req.body.cancel_url20 });21 context.res = {22 status: 200,23 body: session24 };25 }26 if (req.body.customer_currency === 'USD') {27 const session = await stripe.checkout.sessions.create({28 payment_method_types: ['card'],29 subscription_data: {30 trial_from_plan: req.body.trial,31 },32 line_items: [{33 price: "price_1HQfbxEaFEmd6wlWv4F7Uwv9",34 quantity: 1,35 }],36 customer: req.body.customer_id,37 mode: 'subscription',38 allow_promotion_codes: true,39 success_url: req.body.success_url,40 cancel_url: req.body.cancel_url41 });42 context.res = {43 status: 200,44 body: session45 };46 }47 if (req.body.customer_currency === 'ARS') {48 const session = await stripe.checkout.sessions.create({49 payment_method_types: ['card'],50 subscription_data: {51 trial_from_plan: req.body.trial,52 },53 line_items: [{54 price: "price_1HQfeiEaFEmd6wlWNqvIf2mm",55 quantity: 1,56 }],57 customer: req.body.customer_id,58 mode: 'subscription',59 allow_promotion_codes: true,60 success_url: req.body.success_url,61 cancel_url: req.body.cancel_url62 });63 context.res = {64 status: 200,65 body: session66 };67 }68 if (req.body.customer_currency === 'BOB') {69 const session = await stripe.checkout.sessions.create({70 payment_method_types: ['card'],71 subscription_data: {72 trial_from_plan: req.body.trial,73 },74 line_items: [{75 price: "price_1HRMc6EaFEmd6wlWZqWOHDlK",76 quantity: 1,77 }],78 customer: req.body.customer_id,79 mode: 'subscription',80 allow_promotion_codes: true,81 success_url: req.body.success_url,82 cancel_url: req.body.cancel_url83 });84 context.res = {85 status: 200,86 body: session87 };88 }89 if (req.body.customer_currency === 'CLP') {90 const session = await stripe.checkout.sessions.create({91 payment_method_types: ['card'],92 subscription_data: {93 trial_from_plan: req.body.trial,94 },95 line_items: [{96 price: "price_1HRMg2EaFEmd6wlWbToTzgGA",97 quantity: 1,98 }],99 customer: req.body.customer_id,100 mode: 'subscription',101 allow_promotion_codes: true,102 success_url: req.body.success_url,103 cancel_url: req.body.cancel_url104 });105 context.res = {106 status: 200,107 body: session108 };109 }110 if (req.body.customer_currency === 'COP') {111 const session = await stripe.checkout.sessions.create({112 payment_method_types: ['card'],113 subscription_data: {114 trial_from_plan: req.body.trial,115 },116 line_items: [{117 price: "price_1HRMNeEaFEmd6wlWuIkIEGko",118 quantity: 1,119 }],120 customer: req.body.customer_id,121 mode: 'subscription',122 allow_promotion_codes: true,123 success_url: req.body.success_url,124 cancel_url: req.body.cancel_url125 });126 context.res = {127 status: 200,128 body: session129 };130 }131 if (req.body.customer_currency === 'CRC') {132 const session = await stripe.checkout.sessions.create({133 payment_method_types: ['card'],134 subscription_data: {135 trial_from_plan: req.body.trial,136 },137 line_items: [{138 price: "price_1HRMmBEaFEmd6wlWqCV6xo2J",139 quantity: 1,140 }],141 customer: req.body.customer_id,142 mode: 'subscription',143 allow_promotion_codes: true,144 success_url: req.body.success_url,145 cancel_url: req.body.cancel_url146 });147 context.res = {148 status: 200,149 body: session150 };151 }152 if (req.body.customer_currency === 'GTQ') {153 const session = await stripe.checkout.sessions.create({154 payment_method_types: ['card'],155 subscription_data: {156 trial_from_plan: req.body.trial,157 },158 line_items: [{159 price: "price_1HRMmqEaFEmd6wlWJHxuD7iM",160 quantity: 1,161 }],162 customer: req.body.customer_id,163 mode: 'subscription',164 allow_promotion_codes: true,165 success_url: req.body.success_url,166 cancel_url: req.body.cancel_url167 });168 context.res = {169 status: 200,170 body: session171 };172 }173 if (req.body.customer_currency === 'HTG') {174 const session = await stripe.checkout.sessions.create({175 payment_method_types: ['card'],176 subscription_data: {177 trial_from_plan: req.body.trial,178 },179 line_items: [{180 price: "price_1HRMsSEaFEmd6wlWb10JAMar",181 quantity: 1,182 }],183 customer: req.body.customer_id,184 mode: 'subscription',185 allow_promotion_codes: true,186 success_url: req.body.success_url,187 cancel_url: req.body.cancel_url188 });189 context.res = {190 status: 200,191 body: session192 };193 }194 if (req.body.customer_currency === 'HNL') {195 const session = await stripe.checkout.sessions.create({196 payment_method_types: ['card'],197 subscription_data: {198 trial_from_plan: req.body.trial,199 },200 line_items: [{201 price: "price_1HRMtJEaFEmd6wlW6h638H3U",202 quantity: 1,203 }],204 customer: req.body.customer_id,205 mode: 'subscription',206 allow_promotion_codes: true,207 success_url: req.body.success_url,208 cancel_url: req.body.cancel_url209 });210 context.res = {211 status: 200,212 body: session213 };214 }215 if (req.body.customer_currency === 'NIO') {216 const session = await stripe.checkout.sessions.create({217 payment_method_types: ['card'],218 subscription_data: {219 trial_from_plan: req.body.trial,220 },221 line_items: [{222 price: "price_1HRMtvEaFEmd6wlWCuEIXckk",223 quantity: 1,224 }],225 customer: req.body.customer_id,226 mode: 'subscription',227 allow_promotion_codes: true,228 success_url: req.body.success_url,229 cancel_url: req.body.cancel_url230 });231 context.res = {232 status: 200,233 body: session234 };235 }236 if (req.body.customer_currency === 'PYG') {237 const session = await stripe.checkout.sessions.create({238 payment_method_types: ['card'],239 subscription_data: {240 trial_from_plan: req.body.trial,241 },242 line_items: [{243 price: "price_1HRMupEaFEmd6wlWxNOKrxyJ",244 quantity: 1,245 }],246 customer: req.body.customer_id,247 mode: 'subscription',248 allow_promotion_codes: true,249 success_url: req.body.success_url,250 cancel_url: req.body.cancel_url251 });252 context.res = {253 status: 200,254 body: session255 };256 }257 if (req.body.customer_currency === 'PEN') {258 const session = await stripe.checkout.sessions.create({259 payment_method_types: ['card'],260 subscription_data: {261 trial_from_plan: req.body.trial,262 },263 line_items: [{264 price: "price_1HRMvLEaFEmd6wlWxrKohg5S",265 quantity: 1,266 }],267 customer: req.body.customer_id,268 mode: 'subscription',269 allow_promotion_codes: true,270 success_url: req.body.success_url,271 cancel_url: req.body.cancel_url272 });273 context.res = {274 status: 200,275 body: session276 };277 }278 if (req.body.customer_currency === 'DOP') {279 const session = await stripe.checkout.sessions.create({280 payment_method_types: ['card'],281 subscription_data: {282 trial_from_plan: req.body.trial,283 },284 line_items: [{285 price: "price_1HRMvwEaFEmd6wlWwcSv32B1",286 quantity: 1,287 }],288 customer: req.body.customer_id,289 mode: 'subscription',290 allow_promotion_codes: true,291 success_url: req.body.success_url,292 cancel_url: req.body.cancel_url293 });294 context.res = {295 status: 200,296 body: session297 };298 }299 if (req.body.customer_currency === 'UYU') {300 const session = await stripe.checkout.sessions.create({301 payment_method_types: ['card'],302 subscription_data: {303 trial_from_plan: req.body.trial,304 },305 line_items: [{306 price: "price_1HRMwSEaFEmd6wlWzvAOPib1",307 quantity: 1,308 }],309 customer: req.body.customer_id,310 mode: 'subscription',311 allow_promotion_codes: true,312 success_url: req.body.success_url,313 cancel_url: req.body.cancel_url314 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const qawolf = require("qawolf");2const stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7dc");3const context = {};4const browser = await qawolf.launch();5context.browser = browser;6await qawolf.register(context);7try {8 const page = await browser.newPage();9 await page.click("text=Buy now");10 await page.click("text=Buy now");11 const session = await stripe.checkout.sessions.create({12 {13 price_data: {14 product_data: {15 },16 },17 },18 });19 await page.goto(session.url);20 await page.click("input[name='cardnumber']");21 await page.fill("input[name='cardnumber']", "4242424242424242");22 await page.fill("input[name='exp-date']", "04/24");23 await page.fill("input[name='cvc']", "242");24 await page.fill("input[name='postal']", "42424");25 await page.click("text=Pay $20.00");26 await page.waitForTimeout(1000);27} catch (error) {28 await qawolf.stopVideos(context);29 throw error;30}31await qawolf.stopVideos(context);32const qawolf = require("qawolf");33const stripe = require("stripe")("sk_test_4eC39HqLyjWDarjtT1zdp7dc");34const context = {};35const browser = await qawolf.launch();36context.browser = browser;37await qawolf.register(context);38try {39 const page = await browser.newPage();40 await page.click("text=Buy now");41 await page.click("text=Buy now

Full Screen

Using AI Code Generation

copy

Full Screen

1const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');2describe('stripe checkout session', () => {3 it('create stripe checkout session', async () => {4 const session = await stripe.checkout.sessions.create({5 {6 price_data: {7 product_data: {8 },9 },10 },11 });12 console.log(session.id);13 });14 it('retrieve stripe checkout session', async () => {15 const session = await stripe.checkout.sessions.retrieve(16 );17 console.log(session.id);18 });19 it('list stripe checkout sessions', async () => {20 const sessions = await stripe.checkout.sessions.list({21 });22 console.log(sessions.data[0].id);23 });24});25const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc');26describe('stripe checkout session', () => {27 it('create stripe checkout session', async () => {28 const session = await stripe.checkout.sessions.create({29 {30 price_data: {31 product_data: {32 },33 },34 },

Full Screen

Using AI Code Generation

copy

Full Screen

1const stripe = require("stripe")("sk_test_****");2const { browser, context, page } = require('qawolf');3const faker = require('faker');4describe('test', () => {5 beforeAll(async () => {6 await browser.launch();7 });8 afterAll(async () => {9 await browser.close();10 });11 it('test', async () => {12 await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const stripe = require('stripe')('sk_test_51H6hOoDgjZ6zgH6jJ3gB3q3qy0G5Yj2Xc5N5k5eBZp1rN5z5RlRg7VlE4pJ4hY9Xgq3J7Vn3nJHc7VQ2Kj6T7oQe00BhTJ9bHs');2const uuid = require('uuid/v4');3exports.makePayment = (req, res) => {4 const { products, token } = req.body;5 console.log("PRODUCTS", products);6 let amount = 0;7 products.map(p => {8 amount = amount + p.price;9 });10 const idempotencyKey = uuid();11 return stripe.customers.create({12 })13 .then(customer => {14 stripe.charges.create({15 shipping: {16 address: {17 }18 }19 }, { idempotencyKey })20 .then(result => res.status(200).json(result))21 .catch(err => console.log(err));22 })23}24const stripe = require('stripe')('sk_test_51H6hOoDgjZ6zgH6jJ3gB3q3qy0G5Yj2Xc5N5k5eBZp1rN5z5RlRg7VlE4pJ4hY9Xgq3J7Vn3nJHc7VQ2Kj6T7oQe00BhTJ9bHs');25const uuid = require('uuid/v4');26exports.makePayment = (req, res) => {27 const { products, token } = req.body;28 console.log("PRODUCTS", products);29 let amount = 0;

Full Screen

Using AI Code Generation

copy

Full Screen

1const stripe = require('stripe')('sk_test_51H8Jw0C1sOzT1kY2ZDd7PcJ9e9tjKdV8hWj3wq3Cn2QaLcVY8W1pIbNzR9XKj7y8tWn0wJwI1x1kzTmDd2QoJmGg00XeJ2aE0g');2const session = await stripe.checkout.sessions.create({3 {4 price_data: {5 product_data: {6 },7 },8 },9});10console.log(session);11const stripe = require('stripe')('sk_test_51H8Jw0C1sOzT1kY2ZDd7PcJ9e9tjKdV8hWj3wq3Cn2QaLcVY8W1pIbNzR9XKj7y8tWn0wJwI1x1kzTmDd2QoJmGg00XeJ2aE0g');12const session = await stripe.checkout.sessions.create({13 {14 price_data: {15 product_data: {16 },17 },18 },19});20console.log(session);

Full Screen

Using AI Code Generation

copy

Full Screen

1const stripe = require("stripe")("sk_test_51HvIYcKZ8d1r1X9Q2oN7VjR8t4y7V4b2x0vq3Yl1jDpSgX9e9fHjD5b0m0m5w5Ox1KjzV0Y2aZdPmX9F9v5KjWfP00n5g5K5a5");2async function createCheckoutSession() {3 const session = await stripe.checkout.sessions.create({4 {5 price_data: {6 product_data: {7 },8 },9 },10 });11 console.log(session.id);12}13createCheckoutSession();14const stripe = require("stripe")("sk_test_51HvIYcKZ8d1r1X9Q2oN7VjR8t4y7V4b2x0vq3Yl1jDpSgX9e9fHjD5b0m0m5w5Ox1KjzV0Y2aZdPmX9F9v5KjWfP00n5g5K5a5");15async function listCheckoutSessions() {16 const sessions = await stripe.checkout.sessions.list({17 });18 console.log(sessions);19}20listCheckoutSessions();21const stripe = require("stripe")("sk_test_51HvIYcKZ8d1r1X9Q2oN7VjR8t4y7V4b2x0vq3Yl1jDpSgX9e9fHjD5b0m0m5w5Ox1KjzV0Y2aZdPmX9F9

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run qawolf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful