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

Return to the checkout form when the payment intent is created #7753

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Genevieve-K
Copy link
Contributor

When the payment intent cannot be create due to a Stripe error (Ex: Your card's security code is incorrect.), there is an Exception. Some functions as handlePaymentIntentStatus() cannot access to status/id, and a new exception is created. There is no point in going any further, and we can return directly to the checkout form as in class-give-stripe-payment-method.php.

Errors in log:

[19-Feb-2025 13:03:38 UTC] PHP Warning:  Attempt to read property "id" on bool in /wp/wp-content/plugins/give/src/PaymentGateways/Gateways/Stripe/ValueObjects/PaymentIntent.php on line 44
[19-Feb-2025 13:03:38 UTC] PHP Warning:  Attempt to read property "status" on bool in /wp/wp-content/plugins/give/src/PaymentGateways/Gateways/Stripe/ValueObjects/PaymentIntent.php on line 53

Message for the donor from handlePaymentIntentStatus():
image

A question: if this error occurs in a recurring donation, the error is simply: Your card's security code is incorrect. , There was an issue with your donation transaction:...

When the payment intent cannot be create due to a Stripe error (Ex:  Your card's security code is incorrect.), there is an Exception. 
Some functions as handlePaymentIntentStatus() cannot access to status/id, and a new exception is created. There is no point in going any further, and we can return to the checkout form as in class-give-stripe-payment-method.php.
@Genevieve-K
Copy link
Contributor Author

@jonwaldstein I understood that you agree with this PR. Can you confirm?

@jonwaldstein
Copy link
Contributor

@Genevieve-K thanks for this! I think this is a nice simple solution that should work 😄

I think your analysis of the nested exception is accurate (knowing this code is considered legacy old and specific to our v2 forms now).

The proper way this Give_Stripe_Payment_Intent::create logic should be reused in our Gateway API is to simply throw an exception with a message for reasoning and let the gateway api respond back to the form. Instead, we are catching the exception inside the gateway class, which continues the logic while setting errors in session.

For future reference: here is where we are catching all gateway exceptions for v2 forms. We would need to update the exception message to be dynamic and let gateways throw exceptions instead of catching them. This is how our v3 forms work with gateways, so all they need to do is throw an exception to be caught later 😄

@jonwaldstein jonwaldstein self-requested a review February 24, 2025 18:58
@Genevieve-K
Copy link
Contributor Author

@jonwaldstein Thank you. We added a cart to GiveWP. So we separate the donation form and the checkout form. A donor can give several gifts before paying. It's difficult to use the v3 forms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants