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: prevent Stripe Payment Element from rendering when amount is zero #7515

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ interface StripeGateway extends Gateway {
}

/**
* @unreleased added fields conditional when donation amount is zero
* @since 3.13.0 Use only stripeKey to load the Stripe script (when stripeConnectedAccountId is missing) to prevent errors when the account is connected through API keys
* @since 3.12.1 updated afterCreatePayment response type to include billing details address
* @since 3.0.0
Expand Down Expand Up @@ -212,6 +213,10 @@ const stripePaymentElementGateway: StripeGateway = {
appearance: appearanceOptions,
};

if (donationAmount <= 0) {
return <>{__('Donation amount must be greater than zero to proceed.', 'give')}</>;
}
Comment on lines +216 to +218
Copy link
Contributor

Choose a reason for hiding this comment

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

@jonwaldstein Should this be resolved upstream? Might this affect other gateways as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a good question and something I have considered and even spiked

However, In order to accomplish this upstream the options I see are:

  1. Assume all gateways will not render fields when amount is 0
  2. The gateway API has a concept of accepts $0 and each gateway implements (test gateway, offline, etc would potentially return true)

These options further solidify our rejection of $0 donations which we're still working out in our product. So at this point, I think it's okay for the gateways to handle this themselves (which most are doing) - at least until we come to a solid conclusion and direction for our product around the subject.

Copy link
Contributor

@JasonTheAdams JasonTheAdams Oct 31, 2024

Choose a reason for hiding this comment

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

I'm not sure if this helps, but I know that we're planning at some point to allow $0 donations for things like events. I think, at that time, we're actually more likely to do something like hide the gateways (similar to WooCommerce). In the meantime, I think we can simply enforce the current assumption that donations must be at least $1 — or whatever the actual minimum donation value is.

I think it's fine to go this route for now, knowing we may change it later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah hiding the gateways was an option on my $0 spike. That was something I built for the marketing team to allow $0 donations. I'd like to pull out some of what I did over there for core.

I do also like the idea of using the minimum amount value too 🤔

However, the scope of this PR is so small and would solve the immediate weirdness.

I'd be happy to open a separate one that ports over the gateway filtering to play around with all gateways which of course will increase the scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Started scaffolding the other PR #7599

Copy link
Contributor

Choose a reason for hiding this comment

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

Up to you whether you want to merge this PR to fix the immediate issue and proceed or not. This would ultimately become a tiny amount of technical debt.


return (
<Elements stripe={stripePromise} options={stripeElementOptions}>
<StripeFields gateway={stripePaymentElementGateway} />
Expand Down
Loading