Skip to content

Commit

Permalink
Clean Up Codebase and Remove Obsolete "wallets" Feature Flags and Imp…
Browse files Browse the repository at this point in the history
…lementations (#10058)
  • Loading branch information
gpressutto5 authored Jan 6, 2025
1 parent 5460f00 commit bbe2c67
Show file tree
Hide file tree
Showing 34 changed files with 121 additions and 3,692 deletions.
4 changes: 4 additions & 0 deletions changelog/remove-tokenized-cart-ece-flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: update

Clean Up Codebase and Remove Obsolete "wallets" Feature Flags and Implementations
115 changes: 1 addition & 114 deletions client/checkout/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
* Internal dependencies
*/
import { getConfig, getUPEConfig } from 'utils/checkout';
import {
getExpressCheckoutConfig,
buildAjaxURL,
getExpressCheckoutAjaxURL,
} from 'utils/express-checkout';
import { getExpressCheckoutConfig, buildAjaxURL } from 'utils/express-checkout';
import { getAppearance } from 'checkout/upe-styles';
import { getAppearanceType } from '../utils';

Expand Down Expand Up @@ -326,115 +322,6 @@ export default class WCPayAPI {
} );
}

/**
* Updates cart with selected shipping option.
*
* @param {Object} shippingOption Shipping option.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECEUpdateShippingDetails( shippingOption ) {
return this.request(
getExpressCheckoutAjaxURL( 'ece_update_shipping_method' ),
{
security: getExpressCheckoutConfig( 'nonce' )?.update_shipping,
shipping_method: [ shippingOption.id ],
is_product_page:
getExpressCheckoutConfig( 'button_context' ) === 'product',
}
);
}

/**
* Get cart items and total amount.
*
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECEGetCartDetails() {
return this.request(
getExpressCheckoutAjaxURL( 'ece_get_cart_details' ),
{
security: getExpressCheckoutConfig( 'nonce' )?.get_cart_details,
}
);
}

/**
* Add product to cart from variable product page.
*
* @param {Object} productData Product data.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECEAddToCart( productData ) {
return this.request( getExpressCheckoutAjaxURL( 'add_to_cart' ), {
security: getExpressCheckoutConfig( 'nonce' )?.add_to_cart,
...productData,
} );
}

/**
* Get selected product data from variable product page.
*
* @param {Object} productData Product data.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECEGetSelectedProductData( productData ) {
return this.request(
getExpressCheckoutAjaxURL( 'ece_get_selected_product_data' ),
{
security: getExpressCheckoutConfig( 'nonce' )
?.get_selected_product_data,
...productData,
}
);
}

/**
* Submits shipping address to get available shipping options
* from Express Checkout ECE payment method.
*
* @param {Object} shippingAddress Shipping details.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECECalculateShippingOptions( shippingAddress ) {
return this.request(
getExpressCheckoutAjaxURL( 'ece_get_shipping_options' ),
{
security: getExpressCheckoutConfig( 'nonce' )?.shipping,
is_product_page:
getExpressCheckoutConfig( 'button_context' ) === 'product',
...shippingAddress,
}
);
}

/**
* Creates order based on Express Checkout ECE payment method.
*
* @param {Object} paymentData Order data.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECECreateOrder( paymentData ) {
return this.request( getExpressCheckoutAjaxURL( 'ece_create_order' ), {
_wpnonce: getExpressCheckoutConfig( 'nonce' )?.checkout,
...paymentData,
} );
}

/**
* Pays for an order based on the Express Checkout payment method.
*
* @param {integer} order The order ID.
* @param {Object} paymentData Order data.
* @return {Promise} Promise for the request to the server.
*/
expressCheckoutECEPayForOrder( order, paymentData ) {
return this.request( getExpressCheckoutAjaxURL( 'ece_pay_for_order' ), {
_wpnonce: getExpressCheckoutConfig( 'nonce' )?.pay_for_order,
order,
...paymentData,
} );
}

initWooPay( userEmail, woopayUserSession ) {
if ( ! this.isWooPayRequesting ) {
this.isWooPayRequesting = true;
Expand Down
20 changes: 1 addition & 19 deletions client/checkout/api/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
*/
import WCPayAPI from '..';
import request from 'wcpay/checkout/utils/request';
import {
buildAjaxURL,
getExpressCheckoutAjaxURL,
getExpressCheckoutConfig,
} from 'wcpay/utils/express-checkout';
import { buildAjaxURL } from 'wcpay/utils/express-checkout';
import { getConfig } from 'wcpay/utils/checkout';

jest.mock( 'wcpay/checkout/utils/request', () =>
Expand Down Expand Up @@ -145,20 +141,6 @@ describe( 'WCPayAPI', () => {
expect( api.isWooPayRequesting ).toBe( false );
} );

test( 'express checkout pay for order is initialized correctly', async () => {
getExpressCheckoutAjaxURL.mockReturnValue( 'https://example.org/' );
getExpressCheckoutConfig.mockReturnValue( { pay_for_order: '1234' } );

const api = new WCPayAPI( {}, request );
await api.expressCheckoutECEPayForOrder( '12', { foo: 'bar' } );

expect( request ).toHaveBeenLastCalledWith( 'https://example.org/', {
_wpnonce: '1234',
order: '12',
foo: 'bar',
} );
} );

test( 'WooPay should not support global theme styles', async () => {
buildAjaxURL.mockReturnValue( 'https://example.org/' );
getConfig.mockImplementation( ( key ) => {
Expand Down
21 changes: 6 additions & 15 deletions client/checkout/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import { SavedTokenHandler } from './saved-token-handler';
import PaymentMethodLabel from './payment-method-label';
import request from '../utils/request';
import enqueueFraudScripts from 'fraud-scripts';
import {
expressCheckoutElementApplePay,
expressCheckoutElementGooglePay,
} from '../../express-checkout/blocks';
import {
tokenizedExpressCheckoutElementApplePay,
tokenizedExpressCheckoutElementGooglePay,
Expand Down Expand Up @@ -161,17 +157,12 @@ if ( getUPEConfig( 'isWooPayEnabled' ) ) {
}

if ( getUPEConfig( 'isPaymentRequestEnabled' ) ) {
if ( getUPEConfig( 'isTokenizedCartEceEnabled' ) ) {
registerExpressPaymentMethod(
tokenizedExpressCheckoutElementApplePay( api )
);
registerExpressPaymentMethod(
tokenizedExpressCheckoutElementGooglePay( api )
);
} else {
registerExpressPaymentMethod( expressCheckoutElementApplePay( api ) );
registerExpressPaymentMethod( expressCheckoutElementGooglePay( api ) );
}
registerExpressPaymentMethod(
tokenizedExpressCheckoutElementApplePay( api )
);
registerExpressPaymentMethod(
tokenizedExpressCheckoutElementGooglePay( api )
);
}
window.addEventListener( 'load', () => {
enqueueFraudScripts( getUPEConfig( 'fraudServices' ) );
Expand Down

This file was deleted.

Loading

0 comments on commit bbe2c67

Please sign in to comment.