-
Notifications
You must be signed in to change notification settings - Fork 58
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 pre-auth behavior #232
Fix pre-auth behavior #232
Conversation
Actually sorry for the spam... there's still a flaw in this, for PaymentIntents we shouldn't check authorization until confirm. (So we need to not return a 402 on a PaymentIntent creation if confirm=false.) Not sure if this PR makes that any worse, gotta think about it. Will consider and fix. |
5456e33
to
9ca640b
Compare
Actually this was working fine, what a pleasant surprise! :) I added a more elaborate test to verify it. This should be good to review now |
b64e112
to
d00c513
Compare
@adrienverge this one's ready for review if you want! We're using it at Via now (in an internal fork I want to get rid of :) ). |
Sure! We'll look at it as soon as we have some time to review. Good it to merge local edits upstream 👍 and by the way, do you plan to propose other ones? If it's the case, it's easier for us to test them all at once. |
@adrienverge I do propose other ones. They are kind of based on each other in a way that Github isn't good at supporting. I could send one big one after this if that is useful. The remaining stuff is a series of increasingly small things. Also I have some things you might find suspicious: testing undocumented and/or deprecated Stripe behavior... I'll probably separate those out to avoid controversy on the more mainstream changes. :) |
Hello @bpcreech, OK understood. Your contributions are welcome, especially since they are clean and useful :) For next ones: as you wish. GitHub can show PRs with multiple commits inside them pretty nicely. You can also open a PR mentioning that it's based on another one, and we'll only look at the last commit. About this one, it looks good, but our test suite detected a problem. I digged to identify the problem, and it seems that your current implementation changes behavior for card 4000000000000341 (a card that you can associate to a customer but is supposed to fail upon payment, see documentation). With such a card, both Stripe and current Localstripe seem to accept creating a subscription ( Here are minimal reproducers.
In my opinion, failing with a HTTP 402 would make sense. I think this is how Stripe behaves for simple payments like |
This adds a small suite of tests related to the discussion at #232 (comment) It seems that Stripe works this way (I've tested it today), so let's make sure Localstripe does it too, by adding a non-regression test.
ah good to know! we don't use subscriptions at Via so I didn't catch that
|
This adds a small suite of tests related to the discussion at #232 (comment) It seems that Stripe works this way (I've tested it today), so let's make sure Localstripe does it too, by adding a non-regression test.
e268682
to
cfa1e13
Compare
okay, @adrienverge this should be ready for re-review now! I modified it so that all the paths to Charge creation have to explicitly request raise-on-failure by way of an As part of that I split up |
cfa1e13
to
6c99bee
Compare
adrienverge#232 is failing with a "This environment is externally managed" error from pip because it's trying to install to the system Python. For some reason this doesn't happen on a fork, e.g., #2. I assume this is due to a Github probably runner change; I'm not sure whether intentional. Anyway we can just be explicit; pip should just use a user install during the test run.
adrienverge#232 is failing with a "This environment is externally managed" error from pip because it's trying to install to the system Python. For some reason this doesn't happen on a fork, e.g., #2. I assume this is due to a Github probably runner change; I'm not sure whether intentional. Anyway we can fix this by using a venv, which is best practice anyway.
40bc732
to
61e8730
Compare
adrienverge#232 is failing with a "This environment is externally managed" error from pip because it's trying to install to the system Python. For some reason this doesn't happen on a fork, e.g., #2. I assume this is due to a Github probably runner change; I'm not sure whether intentional. Anyway we can fix this by using a venv, which is best practice anyway.
327e6c8
to
e6a4305
Compare
adrienverge#232 is failing with a "This environment is externally managed" error from pip because it's trying to install to the system Python. For some reason this doesn't happen on a fork, e.g., #2. I assume this is due to a Github probably runner change; I'm not sure whether intentional. Anyway we can fix this by using a venv, which is best practice anyway.
Also added a small CI fix: it looks like the Github actions runner is now set to require a venv (which for some reason I can't repro on my own fork) |
@bpcreech thanks for seeing and investigating the issue. I wasn't entirely convinced with the venv solution and I was curious so I investigated further and proposed another solution: #234 I ran your PR on our test suite and no issue was detected this time, that's great. I will take more time tomorrow to read the code and spot issues if any. In the meantime, if you want, you can rebase on master, the CI will be fixed (or later, no hurry) |
e6a4305
to
894cb7c
Compare
no problem, rebased! |
894cb7c
to
17269d9
Compare
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.
Hi!
The code looks clean and smart.
It's a bit too hard for me to understand every cases. I tried but it's too much time, so I trust you to have been carreful on the details (other people uses Localstripe, if you break their integration they will not be happy 😅 )
I let Adrien tells if it looks OK to him too or not, on my side good to go 👍
34fc901
to
725be4e
Compare
Before this change we were erroneously marking pre-auth'd charges as status=pending, when they're actually status=succeeded. We were (accidentally) working around this incorrect behavior in pre-auth'd PaymentIntents. To get this right we have to actually split the _trigger_payment method into two: a check for payment authorization (which we do on construction even for Charges created with capture=false), and a separate routine to actually capture the charge (which we do on construction for non-pre-auth'd charges, and on _api_capture for pre-auth'd charges). We also split the PaymentIntent._api_confirm method into two for more control of error handling. We then adjust the PaymentIntent wrapper to fit. This also fixes a tiny mistake in the Charge refund test; it was asserting the wrong variable.
71d30b9
to
86f16ed
Compare
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.
Before this change we were erroneously marking pre-auth'd charges as status=pending, when they're actually status=succeeded. We were (accidentally) working around this incorrect behavior in pre-auth'd PaymentIntents.
To get this right we have to actually split the _trigger_payment method into two: a check for payment authorization (which we do on construction even for Charges created with capture=false), and a separate routine to actually capture the charge (which we do on construction for non-pre-auth'd charges, and on _api_capture for pre-auth'd charges). We also split the PaymentIntent._api_confirm method into two for more control of error handling. We then adjust the PaymentIntent wrapper to fit.
This also fixes a tiny mistake in the Charge refund test; it was asserting the wrong variable.
This also fixes a minor CI problem by using a venv. (I can't reproduce this in my local fork, implying this is a runner change rolling out now... not sure if it's intentional or not, but using a venv seems like a good idea regardless.)