Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update stripe wallets to use payment intent #54668

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

ahmaxed
Copy link
Member

@ahmaxed ahmaxed commented May 6, 2024

Checklist:

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the main branch of freeCodeCamp.
  • I have tested these changes either locally on my machine, or GitPod.

Closes #XXXXX

@github-actions github-actions bot added platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: i18n language translation/internationalization. Often combined with language type label labels May 6, 2024
@github-actions github-actions bot added the platform: api Server application that needs familiarity with Express, Loopback, MongoDB etc. label May 15, 2024
@ahmaxed ahmaxed force-pushed the feat/update-charge-stripe branch from da0270b to db66ab6 Compare May 20, 2024 12:29
@ahmaxed ahmaxed marked this pull request as ready for review May 28, 2024 07:35
@ahmaxed ahmaxed requested a review from a team as a code owner May 28, 2024 07:35
@ahmaxed ahmaxed added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label May 28, 2024
Comment on lines 144 to 148
};

export const allStripeProductIdsArray = Object.values(stripeProductIds)
.flatMap(env => Object.values(env))
.flatMap(duration => Object.values(duration));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};
export const allStripeProductIdsArray = Object.values(stripeProductIds)
.flatMap(env => Object.values(env))
.flatMap(duration => Object.values(duration));
} as const;
export const allStripeProductIdsArray = [
...Object.values(stripeProductIds['live']['month']),
...Object.values(stripeProductIds['staging']['month'])
];

Bit more readable, imo. Also, it's stricter type-wise (it has the literals, not the just string)

Comment on lines 127 to 144
export const stripeProductIds = {
live: {
month: {
500: 'prod_Cc9bIxB2NvjpLy',
1000: 'prod_BuiSxWk7jGSFlJ',
2000: 'prod_IElpZVK7kOn6Fe',
4000: 'prod_IElq1foW39g3Cx'
}
},
staging: {
month: {
500: 'prod_GD1GGbJsqQaupl',
1000: 'prod_GD1IzNEXfSCGgy',
2000: 'prod_IEkNp8M03xvsuB',
4000: 'prod_IEkPebxS63mVbs'
}
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const stripeProductIds = {
live: {
month: {
500: 'prod_Cc9bIxB2NvjpLy',
1000: 'prod_BuiSxWk7jGSFlJ',
2000: 'prod_IElpZVK7kOn6Fe',
4000: 'prod_IElq1foW39g3Cx'
}
},
staging: {
month: {
500: 'prod_GD1GGbJsqQaupl',
1000: 'prod_GD1IzNEXfSCGgy',
2000: 'prod_IEkNp8M03xvsuB',
4000: 'prod_IEkPebxS63mVbs'
}
}
};
const stripeProductIds = {
live: {
month: {
500: 'prod_Cc9bIxB2NvjpLy',
1000: 'prod_BuiSxWk7jGSFlJ',
2000: 'prod_IElpZVK7kOn6Fe',
4000: 'prod_IElq1foW39g3Cx'
}
},
staging: {
month: {
500: 'prod_GD1GGbJsqQaupl',
1000: 'prod_GD1IzNEXfSCGgy',
2000: 'prod_IEkNp8M03xvsuB',
4000: 'prod_IEkPebxS63mVbs'
}
}
};

What is this for? It's not imported anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahmaxed, all of the product ids match what we have on Stripe, and are the correct donation amounts and duration.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Kris.

if (paymentIntent.status === 'requires_action') {
const { error } = await stripe.confirmCardPayment(clientSecret);
if (error) {
console.log('confirmationError');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log('confirmationError');

Comment on lines 146 to 147
if (paymentMethod) {
displayError(t('donate.refresh-needed'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear why having a payment method should result in an error being displayed. I would have assumed the opposite, so perhaps this needs a different name or a comment to clarify.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the payment comes after clicking. If it comes before it means something has gone wrong.
I just mapped the use of token to paymentMethod. That error case might have been resolved.
I will give it another look

postPayment,
onDonationStateChange,
handlePaymentButtonLoad
}: WalletsButtonProps) => {
const [token, setToken] = useState<Token | null>(null);
const [paymentMethod, setpaymentMethod] = useState<PaymentMethod | null>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [paymentMethod, setpaymentMethod] = useState<PaymentMethod | null>(
const [paymentMethod, setPaymentMethod] = useState<PaymentMethod | null>(

Nit.

paymentProvider: PaymentProvider.Stripe,
token,
pr.on('paymentmethod', async event => {
setpaymentMethod(event.paymentMethod);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setpaymentMethod(event.paymentMethod);
setPaymentMethod(event.paymentMethod);

Nit.

const subscription = await stripe.subscriptions.retrieve(subscriptionId);
const isSubscriptionActive = subscription.status === 'active';
const productId = subscription.items.data[0].plan.product;
const isSubscribedInMinutes = isWithinFiveMinutes(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why "within"? Surely we want to know that current_period_start was in the last five minutes, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main purpose for this to check if it has happened recently. 5 minutes is only an arbitrary number.
Do you suggest calling it inLastFiveMinutes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable. To be honest, it was the fact that isWithinFiveMinutes checked the absolute time difference that got me wondering. That seemed very weird!

api-server/src/server/boot/donate.js Outdated Show resolved Hide resolved
api-server/src/server/boot/donate.js Outdated Show resolved Hide resolved
shared/config/donation-settings.ts Outdated Show resolved Hide resolved
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
@ShaunSHamilton ShaunSHamilton changed the title Update the Stripe wallets to use payment intent. fix: update stripe wallets to use payment intent May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: api Server application that needs familiarity with Express, Loopback, MongoDB etc. platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: i18n language translation/internationalization. Often combined with language type label status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants