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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3388801-2.patch | 568 bytes | abramm |
Issue fork commerce_stripe-3388801
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
Comment #2
abrammComment #3
abrammComment #7
vmarchukCommitted!