Problem/Motivation

The following JS error is thrown at checkout if Payment Element gateway is used but billing information collection is disabled:

Uncaught IntegrationError: Invalid value for elements.create('payment'): defaultValues should be an object. You specified: .

This is happening because the defaultValues is initialized as empty array and is only populated if billing information collection is enabled.
From StripeReview.php:

   $pane_form['#attached']['drupalSettings']['commerceStripe'] = [
   ...
        'paymentElementOptions' => [
          'layout' => !empty($config['style']) ? $config['style']['layout'] : 'tabs',
          'defaultValues' => [],
        ],
      ];
      $profiles = $this->order->collectProfiles();
      if (isset($profiles['billing']) && !$profiles['billing']->get('address')->isEmpty()) {
        $billing_address = $profiles['billing']->get('address')->first()->toArray();
        $pane_form['#attached']['drupalSettings']['commerceStripe']['paymentElementOptions']['defaultValues']['billingDetails'] = [
     ...
          ],
        ];
      }

The empty array get serialized to [] (JS array) in JSON while Stripe expects it to be an object.

Steps to reproduce

1. Create a new Payment Element payment gateway.
2. Disable collection of billing info.
3. Proceed to checkout, walk through to the step where Stripe Review pane is added.
Expected: the payment form is displayed.
Actual: the form is not displayed and JS error may be seen in browser console.

Proposed resolution

Just remove the line setting empty defaultValues, this parameter is not required.

Remaining tasks

Test and commit the patch.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#2 3388801-2.patch568 bytesabramm
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

abramm created an issue. See original summary.

abramm’s picture

StatusFileSize
new568 bytes
abramm’s picture

Assigned: abramm » Unassigned
Status: Active » Needs review

vmarchuk made their first commit to this issue’s fork.

  • vmarchuk committed d049d9a3 on 8.x-1.x
    Issue #3388801: Stripe Payment Element JS error thrown if billing...
vmarchuk’s picture

Status: Needs review » Fixed

Committed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.