-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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/channel aware stripe #2058
Feat/channel aware stripe #2058
Conversation
], | ||
UpdatePromotionResult: ['MissingConditionsError', 'Promotion'], | ||
}, | ||
export interface PossibleTypesResultData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I regenerated types. How to prettify everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a pre-commit hook that applies Prettier to all changed files. Is that not working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, yarn husky install
gives me error Command "husky" not found.
. I see the dependency. But this is something for later. I will try to manually lint or prettier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM, it is working now, not sure why. I did get an Out Of Memory so I had to change the command to NODE_OPTIONS=\"--max-old-space-size=8096\" lint-staged
Thanks for this @martijnvdbrug! I'll review it soon when I get some time to dedicate to this. In the mean time I'll invite @vrosa to see if he has any feedback, as the original author of the Stripe integration. |
By the way, I just pushed a lot of changes to the major branch, including all the TypeORM breaking changes. I'm afraid you'll need to do a bit of extra work to integrate these changes. I made some notes on the main changes in the TypeORM APIs: Ref: https://typeorm.io/changelog#030httpsgithubcomtypeormtypeormpull8616-2022-03-17
|
Thanks for the heads up, I'll have a closer look later this week if that's ok. |
@michaelbromley Not sure why the generated types changed in core. Looks like formatting. How can I make sure formatting is up to date? If I run |
@michaelbromley Is the |
@martijnvdbrug You're right, it was in a broken state after a recent merge from master. Should be working now hopefully! |
@@ -87,7 +87,7 @@ | |||
"hooks": { | |||
"commit-msg": "commitlint -e $HUSKY_GIT_PARAMS", | |||
"post-commit": "git update-index --again", | |||
"pre-commit": "lint-staged", | |||
"pre-commit": "NODE_OPTIONS=\"--max-old-space-size=8096\" lint-staged", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is an Ubuntu specific issue, but the OOM also happens in my own repo's with eslint, and this is how I fixed it. https://stackoverflow.com/questions/53230823/fatal-error-ineffective-mark-compacts-near-heap-limit-allocation-failed-javas
Strange, e2e tests here are also failing with `Error: Cannot find module '@ardatan/aggregate-error'
|
Not sure why, maybe caching? Anyway, I found a few more issues with e2e tests and just pushed some changes to major. |
const paymentIntent = event.data.object as Stripe.PaymentIntent; | ||
const { metadata: { channelToken, orderCode, orderId } = {} } = paymentIntent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Destructuring here is going to throw an error in case paymentIntent
is null
or undefined
. These new lines should be moved to after the if (!paymentIntent)
check, since retrieving the order depends on a valid payment intent in the first place:
const paymentIntent = event.data.object as Stripe.PaymentIntent;
if (!paymentIntent) {
Logger.error(noPaymentIntentErrorMessage, loggerCtx);
response.status(HttpStatus.BAD_REQUEST).send(noPaymentIntentErrorMessage);
return;
}
const { metadata: { channelToken, orderCode, orderId } = {} } = paymentIntent;
// more code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. fixed
const order = await this.orderService.findOneByCode(ctx, orderCode); | ||
if (!order) { | ||
throw Error(`Unable to find order ${orderCode}, unable to settle payment ${paymentIntent.id}!`); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon it makes the most sense to have this check right after an order is retrieved to ensure we're processing an actual message from Stripe before proceeding any further:
if (!order) {
throw Error(`Unable to find order ${orderCode}, unable to settle payment ${paymentIntent.id}!`);
}
try {
event = this.stripeService.constructEventFromPayload(request.rawBody, signature);
}
// more code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also valid feedback. Fixed
@@ -50,39 +72,47 @@ export const stripePaymentMethodHandler = new PaymentMethodHandler({ | |||
}, | |||
|
|||
async createRefund(ctx, input, amount, order, payment, args): Promise<CreateRefundResult> { | |||
const result = await stripeService.createRefund(payment.transactionId, amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest, why did you remove createRefund
from StripeService
and moved the code here? The idea was to encapsulate interactions with the Stripe
object inside the service so the handler doesn't need to know about the Stripe API, e.g. stripe.refunds.create
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why I did it: simplicity, the function was just proxying to the stripe client.
I have changed it back, encapsulation the stripe client inside the service is also a good point.
export class VendureStripeClient extends Stripe { | ||
|
||
constructor( | ||
public apiKey: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a minor thing but from what I could tell apiKey
doesn't need to be public as it's not referenced anywhere unlike webhookSecret
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it can be private.
@vrosa @michaelbromley thanks for the thorough feedback on this PR. I've incorporated all feedback and updated with the latest Major branch again. (Still the same errors in e2e, that seem unrelated to these changes) |
I'd very much appreciate having an update on where this is at the moment - I eagerly need it to launch a new store on the same vendure instance that already serves another store. Thank you for your work on this! 🙏 |
Hi everyone. Apologies for the wait - I had quite a lot on my plate preparing the v2 beta release. @martijnvdbrug thanks for this incredible effort and also @vrosa for your thorough review. This is ready to merge, but if would be good in Martijn can provide a paragraph on the breaking change that I can use in the merge commit, which will subsequently appear in the changelog. Also if you feel it would be helpful, you can provide an expanded explanation which I can then put in the migration guide for v1->v2. |
@michaelbromley Breaking change docs: Updating Stripe from
|
Thanks @martijnvdbrug! This will be in 2.0.0-beta.2, expected next week 🥳 |
This PR implements config for Stripe per channel: A user can set ApiKey and webhooks per channel via the Admin UI.
It would be nice to encrypt the ApiKey based on an env var, before storing it in the DB, but I can't find a way to hook into the saving of handler args.
The PR also includes a Stripe dev-server to test out changes during development:
E2e tests are still missing the webhook mocking, but that's not part of this PR. I've manually verified payment flow with the dev-server and local tunnel:
(admin UI looks nice!)