Skip to content

Commit

Permalink
log payment url
Browse files Browse the repository at this point in the history
  • Loading branch information
apsantiso committed Jun 14, 2024
1 parent a3b9319 commit af72fd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/app/routes/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class AuthController {
bridgeUser: userData.bridgeUser,
sharedWorkspace: userData.sharedWorkspace,
appSumoDetails: null,
/* hasReferralsProgram: await this.service.UsersReferrals.hasReferralsProgram(
/* hasReferralsProgram: await this.service.UsersReferrals.hasReferralsProgram(
userData,
userData.bridgeUser,
userData.userId,
Expand Down
37 changes: 19 additions & 18 deletions src/app/services/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const RenewalPeriod = {
Lifetime: 'lifetime',
};

function getMonthCount(intervalCount, timeInterval) {
function getMonthCount (intervalCount, timeInterval) {
const byTimeIntervalCalculator = {
month: () => intervalCount,
year: () => intervalCount * 12,
Expand All @@ -22,14 +22,14 @@ function getMonthCount(intervalCount, timeInterval) {
return byTimeIntervalCalculator[timeInterval]();
}

function getMonthlyAmount(totalPrice, intervalCount, timeInterval) {
function getMonthlyAmount (totalPrice, intervalCount, timeInterval) {
const monthCount = getMonthCount(intervalCount, timeInterval);
const monthlyPrice = totalPrice / monthCount;

return monthlyPrice;
}

function getRenewalPeriod(intervalCount, interval) {
function getRenewalPeriod (intervalCount, interval) {
let renewalPeriod = RenewalPeriod.Monthly;

if (interval === 'month' && intervalCount === 6) {
Expand All @@ -46,22 +46,23 @@ module.exports = () => {
return isTest ? StripeTest : StripeProduction;
};

const userExistsInPayments = async (user) => {
const userExistsInPayments = async user => {
const paymentsUrl = process.env.PAYMENTS_SERVER_URL;
console.log({ paymentsUrl });

Check warning on line 51 in src/app/services/stripe.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Unexpected console statement

Check warning on line 51 in src/app/services/stripe.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement
const token = SignNewToken(user, process.env.JWT_SECRET, true);

try {
await axios.get(`${paymentsUrl}/users/exists`, {
headers: {
'Authorization': `Bearer ${token}`
}
Authorization: `Bearer ${token}`,
},
});

} catch (err) {
if (err.response?.status !== 404) {
throw err;
}

console.log(err);

Check warning on line 65 in src/app/services/stripe.js

View workflow job for this annotation

GitHub Actions / run-tests (16.x)

Unexpected console statement

Check warning on line 65 in src/app/services/stripe.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement
return false;
}
};
Expand All @@ -75,7 +76,7 @@ module.exports = () => {
reject(err.message);
} else {
const plansMin = plans.data
.map((p) => ({
.map(p => ({
id: p.id,
price: p.amount,
name: p.nickname,
Expand All @@ -97,8 +98,8 @@ module.exports = () => {
reject(err.message);
} else {
const prices = response.data
.filter((p) => !!p.metadata.show)
.map((p) => ({
.filter(p => !!p.metadata.show)
.map(p => ({
id: p.id,
name: p.nickname,
amount: p.unit_amount,
Expand Down Expand Up @@ -130,8 +131,8 @@ module.exports = () => {
const response = await stripe.products.list({ limit: 100 });

const stripeProducts = response.data
.filter((p) => (p.metadata.is_drive === '1' || p.metadata.is_teams === '1') && p.metadata.show === '1')
.map((p) => ({
.filter(p => (p.metadata.is_drive === '1' || p.metadata.is_teams === '1') && p.metadata.show === '1')
.map(p => ({
id: p.id,
name: p.name,
metadata: {
Expand All @@ -150,7 +151,7 @@ module.exports = () => {
const prices = await getProductPrices(stripeProduct.id, isTest);

products.push(
...prices.map((price) => ({
...prices.map(price => ({
...stripeProduct,
price: {
...price,
Expand Down Expand Up @@ -195,7 +196,7 @@ module.exports = () => {
return result.url;
};

const getUserSubscriptionPlans = async (email) => {
const getUserSubscriptionPlans = async email => {
const isTest = !isProduction();
const stripe = await getStripe(isTest);
const customers = await findCustomersByEmail(email, isTest);
Expand All @@ -213,7 +214,7 @@ module.exports = () => {
allCustomerSubscriptions.data.sort((a, b) => b.created - a.created);

plans.push(
...allCustomerSubscriptions.data.map((subscription) => ({
...allCustomerSubscriptions.data.map(subscription => ({
status: subscription.status,
planId: subscription.plan.id,
productId: subscription.plan.product.id,
Expand All @@ -239,10 +240,10 @@ module.exports = () => {
return plans;
};

const findSessionById = async (sessionId) => {
const findSessionById = async sessionId => {
const stripe = await getStripe(sessionId.match(/^cs_test/));
const session = await stripe.checkout.sessions.retrieve(sessionId, {
expand: ['total_details.breakdown.discounts.discount']
expand: ['total_details.breakdown.discounts.discount'],
});

return session;
Expand All @@ -257,6 +258,6 @@ module.exports = () => {
getBilling,
getUserSubscriptionPlans,
findSessionById,
userExistsInPayments
userExistsInPayments,
};
};

0 comments on commit af72fd9

Please sign in to comment.