Missing Phone number, missing Billing Surname

Created on 25 November 2024, 5 months ago
Updated 2 February 2025, 3 months ago

Problem/Motivation

In the commerce_stripe_payment_request_button module for Drupal 10, there are critical issues where:

The billing family name (surname) is sometimes missing from the customer's billing profile after completing a payment using the payment request button (e.g., Apple Pay, Google Pay, Amazon Pay).
The customer's phone number is sometimes missing from the billing or shipping information.

These missing details lead to incomplete billing information, causing significant issues such as:

Failed order synchronizations: Orders cannot be sent to external systems (e.g., Order Management Systems) without complete information.
Errors during order processing: The system throws errors when required fields are missing, preventing orders from being processed correctly.

Error Messages Observed:

Missing Phone Number:
Error in order comments:

Client error: `POST {url}/api/v3/order/new` resulted in a `422 Unprocessable Content` response: {"errors":[{"status":422,"title":"Error","description":"trim(): Argument #1 ($string) must be of type string, null given ..."}]}

Observed with Amazon Pay as the payment method.

Missing Surname:

Error in order comments:

Client error: `POST {url}/api/v3/order/new` resulted in a `422 Unprocessable Content` response: {"errors":[{"status":422,"title":"Error","description":"Billing address surname cannot be empty."}]}

Steps to reproduce

Note: Reproducing the issue might require specific conditions, as the errors seem to occur under particular circumstances, especially with Amazon Pay.

Setup:
Install Drupal 10 with Commerce and the commerce_stripe_payment_request_button module.
Configure the module with Stripe credentials and enable payment request buttons, including Amazon Pay.
Ensure that the module is configured to request phone numbers and surnames where applicable.

Test Purchase:
Option A: Use an Amazon Pay account that lacks a phone number or surname in its profile.
Option B: Simulate a payment where the customer chooses not to provide a phone number or surname (if possible).
Add a product to the cart and proceed to checkout using the payment request button, selecting Amazon Pay as the payment method.
Complete the payment process.

Observe the Issue:
After order completion, check the order in the Drupal Commerce backend.
Verify whether the billing profile associated with the order is missing the surname and/or phone number.

Attempt to Synchronize the Order:
If applicable, attempt to synchronize the order with external systems (e.g., Order Management Systems).
Observe any error messages indicating missing required fields.

Important: If you receive errors during testing, similar to the ones provided, note them for inclusion in the issue report.

Proposed resolution

For Missing Surname:

Issue: The code incorrectly accesses the associative array returned by processCustomerName(), using numeric indices instead of the correct keys.
Solution:
Update the code to use the correct associative array keys 'given_name' and 'family_name' when accessing customer names.
Replace all instances of $names[0] and $names[1] with $names['given_name'] and $names['family_name'].

For Missing Phone Number:

Issue: Conditional checks or incorrect data access methods prevent the phone number from being saved.
Solution:
Review and adjust the code to ensure that the phone number is retrieved correctly from the payment data, especially for Amazon Pay.
Remove unnecessary conditions that prevent the phone number from being assigned to the customer profile.
Ensure that the code handles cases where the phone number might not be provided and adds appropriate fallbacks or prompts.

Remaining tasks

User interface changes

None.

All changes are in the backend code.
No modifications to the user interface are required.

API changes

None.

The module's API remains the same.
No new functions or breaking changes are introduced.

Data model changes

None.

The existing data model is sufficient.
Changes ensure that existing fields are populated correctly.

🐛 Bug report
Status

Needs review

Version

3.8

Component

Code

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024