Skip to content

Commit

Permalink
Update phone field handling in payment processing to not be passed as…
Browse files Browse the repository at this point in the history
… empty string and set to 'auto'
  • Loading branch information
ricardo committed Feb 25, 2025
1 parent 586dbdd commit e09db26
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const getStripeElementOptions = () => {
billingDetails: {
name: 'never',
email: 'never',
phone: 'never',
// The phone field is optional, so it needs to be "auto" to not throw errors
// when passing the phone parameter to create a payment method.
phone: 'auto',
address: {
country: 'never',
line1: 'never',
Expand Down Expand Up @@ -194,7 +196,7 @@ const PaymentProcessor = ( {
billing_details: {
name: `${ billingAddress.first_name } ${ billingAddress.last_name }`.trim(),
email: billingAddress.email,
phone: billingAddress.phone,
phone: billingAddress.phone || null, // Phone is optional, but an empty string is not allowed by Stripe.
address: {
city: billingAddress.city,
country: billingAddress.country,
Expand Down
4 changes: 3 additions & 1 deletion client/classic/upe/payment-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ function createStripePaymentMethod(
).trim()
: undefined,
email: document.querySelector( '#billing_email' )?.value,
phone: document.querySelector( '#billing_phone' )?.value,
phone:
// Phone is optional, but an empty string is not allowed by Stripe.
document.querySelector( '#billing_phone' )?.value || null,
address: {
city: document.querySelector( '#billing_city' )?.value,
country: document.querySelector( '#billing_country' )
Expand Down
6 changes: 3 additions & 3 deletions client/stripe-utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,9 @@ export const getHiddenBillingFields = ( enabledBillingFields ) => {
email: enabledBillingFields.includes( 'billing_email' )
? 'never'
: 'auto',
phone: enabledBillingFields.includes( 'billing_phone' )
? 'never'
: 'auto',
// The phone field is optional, so it needs to be "auto" to not throw errors
// when passing the phone parameter to create a payment method.
phone: 'auto',
address: {
country: enabledBillingFields.includes( 'billing_country' )
? 'never'
Expand Down

0 comments on commit e09db26

Please sign in to comment.