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

feat(api): add charge-stripe endpoint #54545

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

Conversation

ahmaxed
Copy link
Member

@ahmaxed ahmaxed commented Apr 26, 2024

  • feat: add add-donation schema to schemas
  • feat(API): add charge-stipe endpoint

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 #51294

@github-actions github-actions bot added the platform: api Server application that needs familiarity with Express, Loopback, MongoDB etc. label Apr 26, 2024
@ahmaxed ahmaxed changed the title feat: add add-donation schema to schemas feat(API): add charge-stipe endpoint Apr 26, 2024
if (user) req.user = user;
}
} catch {
return send401(reply, TOKEN_INVALID);
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if I need to return an error or not here since we are just checking if user is authorized and pass the user object.

})
}
}
schema: schemas.addDonation
Copy link
Member Author

Choose a reason for hiding this comment

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

Just a clean up.

Comment on lines +249 to +257
const { id: customerId } = await stripe.customers.create({
email,
name
});

// TODO(Post-MVP) stripe has moved to a paymentintent flow, the create call should be updated to reflect this
const paymentMethod = await stripe.paymentMethods.attach(token.id, {
customer: customerId
});
Copy link
Member Author

Choose a reason for hiding this comment

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

In the current api, card has been passed directly when creating the customer. The current api works but the card definition has been removed from the ar types. As a result, I create the customer and then attach the payment method to it.
I will update current api to the new pattern as well.

Comment on lines +300 to +302
return reply.send({
type: 'success',
isDonating: true
Copy link
Member Author

@ahmaxed ahmaxed May 2, 2024

Choose a reason for hiding this comment

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

The current api returns the whole subscription, but that is not used in the client.
I returned isDonating for consistency.

Comment on lines +234 to +237
if (
!isEmail(email) ||
!donationSubscriptionConfig.plans[duration].includes(amount)
) {
Copy link
Member Author

@ahmaxed ahmaxed May 2, 2024

Choose a reason for hiding this comment

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

Improved the validation slightly to check existing for plan.

@ahmaxed ahmaxed marked this pull request as ready for review May 2, 2024 07:18
@ahmaxed ahmaxed requested a review from a team as a code owner May 2, 2024 07:18
@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 2, 2024
@ShaunSHamilton ShaunSHamilton changed the title feat(API): add charge-stipe endpoint feat(api): add charge-stripe endpoint May 3, 2024
email,
name
});

Copy link
Member

Choose a reason for hiding this comment

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

We should figure out if this might benefit from being done before creating the customer.

Suggested change
const { id: paymentMethodId } = await stripe.paymentMethods.create({
type: 'card',
card: { token: token.id }
});

@ahmaxed ahmaxed added status: blocked Is waiting on followup from either the Opening Poster of the issue or PR, or a maintainer. and removed status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. labels May 6, 2024
@ahmaxed
Copy link
Member Author

ahmaxed commented May 6, 2024

blocked by #54668

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. status: blocked Is waiting on followup from either the Opening Poster of the issue or PR, or a maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

POST /donate/charge-stripe
2 participants