Skip to content

Commit

Permalink
order attribution values
Browse files Browse the repository at this point in the history
  • Loading branch information
frosso committed May 6, 2024
1 parent 83989e1 commit b42101d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* global jQuery */

/**
* External dependencies
*/
import { addFilter } from '@wordpress/hooks';

addFilter(
'wcpay.payment-request.cart-place-order-extension-data',
'automattic/wcpay/payment-request',
( extensionData ) => {
const orderAttributionValues = jQuery(
'#wcpay-express-checkout__order-attribution-inputs input'
);

if ( ! orderAttributionValues.length ) {
return extensionData;
}

const orderAttributionData = {};
orderAttributionValues.each( function () {
const name = jQuery( this )
.attr( 'name' )
.replace( 'wc_order_attribution_', '' );
const value = jQuery( this ).val();

if ( name && value ) {
orderAttributionData[ name ] = value;
}
} );

return {
...extensionData,
'woocommerce/order-attribution': orderAttributionData,
};
}
);
1 change: 1 addition & 0 deletions client/tokenized-payment-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import PaymentRequestCartApi from './cart-api';
import WooPaymentsPaymentRequest from './payment-request';
import paymentRequestButtonUi from './button-ui';
import './compatibility/wc-deposits';
import './compatibility/wc-order-attribution';
import './compatibility/wc-product-variations';

import '../checkout/express-checkout-buttons.scss';
Expand Down
19 changes: 15 additions & 4 deletions client/tokenized-payment-request/payment-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { doAction, addAction, removeAction } from '@wordpress/hooks';
import {
doAction,
addAction,
removeAction,
applyFilters,
} from '@wordpress/hooks';

/**
* Internal dependencies
Expand Down Expand Up @@ -281,9 +286,15 @@ export default class WooPaymentsPaymentRequest {
paymentRequest.on( 'paymentmethod', async ( event ) => {
// TODO: this works for PDPs - need to handle checkout scenarios for pay-for-order, cart, checkout.
try {
const response = await _self.paymentRequestCartApi.placeOrder(
transformStripePaymentMethodForStoreApi( event )
);
const response = await _self.paymentRequestCartApi.placeOrder( {
// adding extension data as a separate action,
// so that we make it harder for external plugins to modify or intercept checkout data.
...transformStripePaymentMethodForStoreApi( event ),
extensions: applyFilters(
'wcpay.payment-request.cart-place-order-extension-data',
{}
),
} );

const confirmationRequest = _self.wcpayApi.confirmIntent(
response.payment_result.redirect_url
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function display_express_checkout_buttons() {
}
$this->payment_request_button_handler->display_payment_request_button_html();
?>
<wc-order-attribution-inputs id="wcpay-express-checkout__order-attribution-inputs"></wc-order-attribution-inputs>
</div >
<?php
$this->display_express_checkout_separator_if_necessary( $separator_starts_hidden );
Expand Down

0 comments on commit b42101d

Please sign in to comment.