Skip to content

Express Pay buttons expect extension field names to be prefix with addon- which isn't always the case. #7907

Closed
@peterwilsoncc

Description

Describe the bug

The JavaScript for the Express Pay button puchases on the product page expects fields added by other extensions to use the prefix addon-

// Add addons data to the POST body
const formData = $( 'form.cart' ).serializeArray();
$.each( formData, ( i, field ) => {
if ( /^addon-/.test( field.name ) ) {
if ( /\[\]$/.test( field.name ) ) {
const fieldName = field.name.substring(
0,
field.name.length - 2
);
if ( data[ fieldName ] ) {
data[ fieldName ].push( field.value );
} else {
data[ fieldName ] = [ field.value ];
}
} else {
data[ field.name ] = field.value;
}
}
} );

This isn't always the case, as many extensions (possibly most) use the prefix wc_extensionname for custom fields on the front end. This is certainly the case with deposits and bookings.

Deposits uses the field wc_deposit_option for selecting whether to pay a deposit or the full amount. Bookings uses a number of fields: wc_bookings_field_start_date_month, wc_bookings_field_start_date_day, wc_bookings_field_start_date_year, min_date, max_date and timezone_offset for daily blocks, others exist for part day blocks.

As a default, I think it would be good to include fields that begin with wc_ in the form values submitted to the express pay buttons. A JavaScript filter could also be made available to allow extensions to add other fields to be included when the express pay buttons add items to carts.

This issue came out of testing deposits compatibility with this extension, see woocommerce-deposits#569.

The result of this assumption for Deposits is that the user always gets charged the full amount when using express pay buttons on the product page. This is regardless of their selection.

To Reproduce

  1. Activate Payments and Deposits
  2. Create a product with a deposit: make the deposit optional, ie allow purchesers to chose whether to pay in full or pay a deposit
  3. Enable Express Pay buttons
  4. Visit the product create above
  5. Select "Pay deposit"
  6. Click an express pay button (eg, Google Pay)
  7. The full amount will be charged to the user.

Actual behavior

Incomplete form data is used on the product page.

Screenshots

Screen Shot 2023-12-14 at 10 50 40 am

Screen Shot 2023-12-14 at 10 51 14 am

Expected behavior

Full form data be used when adding items to cart for express pay buttons

(In case of Deposits, that selecting deposit results in charging the deposit only)

Desktop (please complete the following information):

  • OS: macOS
  • Browser Chrome
  • Version 120

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context

woocommerce-deposits#569.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

category: coreWC Payments core related issues, where it’s obvious.component: WooPayWooPay related issuescomponent: payment request buttonApple Pay, Google Pay, etcpriority: highThe issue/PR is high priority—it affects lots of customers substantially, but not critically.type: bugThe issue is a confirmed bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions