Skip to content

Commit

Permalink
Remove Link autofill code
Browse files Browse the repository at this point in the history
  • Loading branch information
annemirasol committed Nov 18, 2024
1 parent 96319ff commit 8ac709a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 313 deletions.
16 changes: 2 additions & 14 deletions client/api/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global Stripe */
import { __ } from '@wordpress/i18n';
import { isLinkEnabled } from 'wcstripe/stripe-utils';
import {
getExpressCheckoutData,
getExpressCheckoutAjaxURL,
Expand Down Expand Up @@ -64,20 +63,9 @@ export default class WCStripeAPI {
* @return {Object} The Stripe Object.
*/
getStripe() {
const {
key,
locale,
isUPEEnabled,
paymentMethodsConfig,
} = this.options;
const { key, locale } = this.options;
if ( ! this.stripe ) {
if ( isUPEEnabled && isLinkEnabled( paymentMethodsConfig ) ) {
this.stripe = this.createStripe( key, locale, [
'link_autofill_modal_beta_1',
] );
} else {
this.stripe = this.createStripe( key, locale );
}
this.stripe = this.createStripe( key, locale );
}
return this.stripe;
}
Expand Down
99 changes: 0 additions & 99 deletions client/blocks/upe/hooks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import confirmCardPayment from './confirm-card-payment.js';
import enableStripeLinkPaymentMethod from 'wcstripe/stripe-link';
import { WC_STORE_CART } from 'wcstripe/blocks/credit-card/constants';
import { isLinkEnabled } from 'wcstripe/stripe-utils';

/**
* Handles the Block Checkout onCheckoutSuccess event.
Expand Down Expand Up @@ -80,103 +78,6 @@ export const usePaymentFailHandler = (
);
};

/**
* Handles rendering the Block Checkout Stripe Link payment method.
*
* @param {*} api The api object.
* @param {*} elements The Stripe elements object.
* @param {*} paymentMethodsConfig The payment methods config object. Used to determine if Stripe Link is enabled.
*/
export const useStripeLink = ( api, elements, paymentMethodsConfig ) => {
const customerData = useCustomerData();
useEffect( () => {
if ( isLinkEnabled( paymentMethodsConfig ) ) {
const shippingAddressFields = {
line1: 'shipping-address_1',
line2: 'shipping-address_2',
city: 'shipping-city',
state: 'components-form-token-input-1',
postal_code: 'shipping-postcode',
country: 'components-form-token-input-0',
first_name: 'shipping-first_name',
last_name: 'shipping-last_name',
};
const billingAddressFields = {
line1: 'billing-address_1',
line2: 'billing-address_2',
city: 'billing-city',
state: 'components-form-token-input-3',
postal_code: 'billing-postcode',
country: 'components-form-token-input-2',
first_name: 'billing-first_name',
last_name: 'billing-last_name',
};

enableStripeLinkPaymentMethod( {
api,
elements,
emailId: 'email',
fill_field_method: ( address, nodeId, key ) => {
const setAddress =
shippingAddressFields[ key ] === nodeId
? customerData.setShippingAddress
: customerData.setBillingAddress;
const customerAddress =
shippingAddressFields[ key ] === nodeId
? customerData.shippingAddress
: customerData.billingAddress;

if ( undefined === customerAddress ) {
return;
}

if ( address.address[ key ] === null ) {
address.address[ key ] = '';
}

if ( key === 'line1' ) {
customerAddress.address_1 = address.address[ key ];
} else if ( key === 'line2' ) {
customerAddress.address_2 = address.address[ key ];
} else if ( key === 'postal_code' ) {
customerAddress.postcode = address.address[ key ];
} else {
customerAddress[ key ] = address.address[ key ];
}

if ( undefined !== customerData.billingAddress ) {
customerAddress.email = getEmail();
}

setAddress( customerAddress );

function getEmail() {
return document.getElementById( 'email' ).value;
}

customerData.billingAddress.email = getEmail();
customerData.setBillingAddress(
customerData.billingAddress
);
},
complete_shipping: () => {
return (
document.getElementById( 'shipping-address_1' ) !== null
);
},
shipping_fields: shippingAddressFields,
billing_fields: billingAddressFields,
complete_billing: () => {
return (
document.getElementById( 'billing-address_1' ) !== null
);
},
} );
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ elements ] );
};

/**
* Returns the customer data and setters for the customer data.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@ import { useEffect, useState } from 'react';
/**
* Internal dependencies
*/
import {
usePaymentCompleteHandler,
usePaymentFailHandler,
useStripeLink,
} from '../hooks';
import { usePaymentCompleteHandler, usePaymentFailHandler } from '../hooks';
import { getBlocksConfiguration } from 'wcstripe/blocks/utils';
import WCStripeAPI from 'wcstripe/api';
import {
Expand Down Expand Up @@ -268,8 +264,6 @@ const PaymentProcessor = ( {
emitResponse
);

useStripeLink( api, elements, paymentMethodsConfig );

const onSelectedPaymentMethodChange = ( { value, complete } ) => {
setSelectedPaymentMethodType( value.type );
setIsPaymentElementComplete( complete );
Expand Down
61 changes: 1 addition & 60 deletions client/classic/upe/deferred-intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import jQuery from 'jquery';
import WCStripeAPI from '../../api';
import {
generateCheckoutEventNames,
getPaymentMethodTypes,
getSelectedUPEGatewayPaymentMethod,
getStripeServerData,
isPaymentMethodRestrictedToLocation,
Expand All @@ -17,7 +16,6 @@ import {
mountStripePaymentElement,
processPayment,
} from './payment-processing';
import enableStripeLinkPaymentMethod from 'wcstripe/stripe-link';

jQuery( function ( $ ) {
// Create an API object, which will be used throughout the checkout.
Expand Down Expand Up @@ -89,69 +87,12 @@ jQuery( function ( $ ) {
for ( const upeElement of $(
'.wc-stripe-upe-element'
).toArray() ) {
const component = await mountStripePaymentElement(
api,
upeElement
);
await mountStripePaymentElement( api, upeElement );
restrictPaymentMethodToLocation( upeElement );
maybeEnableStripeLinkPaymentMethod(
component.elements,
upeElement.dataset.paymentMethodType
);
}
}
}

function maybeEnableStripeLinkPaymentMethod( elements, paymentMethodType ) {
const isCheckout = getStripeServerData()?.isCheckout;
if ( ! isCheckout ) {
return;
}

if ( paymentMethodType !== 'card' ) {
return;
}

const isStripeLinkEnabled = getPaymentMethodTypes(
paymentMethodType
).includes( 'link' );
if ( ! isStripeLinkEnabled ) {
return;
}

enableStripeLinkPaymentMethod( {
api,
elements,
emailId: 'billing_email',
complete_billing: () => {
return document.getElementById( 'billing_address_1' ) !== null;
},
complete_shipping: () => {
return document.getElementById( 'shipping_address_1' ) !== null;
},
shipping_fields: {
line1: 'shipping_address_1',
line2: 'shipping_address_2',
city: 'shipping_city',
state: 'shipping_state',
postal_code: 'shipping_postcode',
country: 'shipping_country',
first_name: 'shipping_first_name',
last_name: 'shipping_last_name',
},
billing_fields: {
line1: 'billing_address_1',
line2: 'billing_address_2',
city: 'billing_city',
state: 'billing_state',
postal_code: 'billing_postcode',
country: 'billing_country',
first_name: 'billing_first_name',
last_name: 'billing_last_name',
},
} );
}

function restrictPaymentMethodToLocation( upeElement ) {
if ( isPaymentMethodRestrictedToLocation( upeElement ) ) {
togglePaymentMethodForCountry( upeElement );
Expand Down
133 changes: 0 additions & 133 deletions client/stripe-link/index.js

This file was deleted.

0 comments on commit 8ac709a

Please sign in to comment.