Version Description
- 2021.05.13 =
- New - Add support for WooCommerce Checkout blocks. PR#604
- New - Add support for Square stores located in Ireland. PR#609
- Fix - Improve manual sync performance and reduce stream timeout responses from Square on stores with large catalogs. PR#612
Download this release
Release Info
Developer | automattic |
Plugin | WooCommerce Square |
Version | 2.5.0 |
Comparing to | |
See all releases |
Code changes from version 2.4.1 to 2.5.0
- assets/blocks/credit-card/checkout-handler.js +63 -0
- assets/blocks/credit-card/component-card-fields.js +69 -0
- assets/blocks/credit-card/component-credit-card.js +57 -0
- assets/blocks/credit-card/component-saved-token.js +47 -0
- assets/blocks/credit-card/constants.js +2 -0
- assets/blocks/credit-card/index.js +54 -0
- assets/blocks/credit-card/use-after-processing-checkout.js +80 -0
- assets/blocks/credit-card/use-payment-form.js +275 -0
- assets/blocks/credit-card/use-payment-processing.js +98 -0
- assets/blocks/index.js +12 -0
- assets/blocks/square-utils/index.js +1 -0
- assets/blocks/square-utils/type-defs.js +66 -0
- assets/blocks/square-utils/utils.js +127 -0
- assets/css/frontend/wc-square-cart-checkout-blocks.min.css +2 -0
- assets/css/frontend/wc-square-cart-checkout-blocks.min.css.map +1 -0
- assets/css/frontend/wc-square-cart-checkout-blocks.scss +117 -0
- assets/js/frontend/wc-square-digital-wallet.js +73 -1
- assets/js/frontend/wc-square-digital-wallet.min.js +1 -1
- assets/js/frontend/wc-square-digital-wallet.min.js.map +1 -1
- build/index.asset.php +1 -0
- build/index.js +1 -0
- i18n/languages/woocommerce-square.pot +42 -31
- includes/Gateway.php +2 -2
- includes/Gateway/Blocks_Handler.php +318 -0
- includes/Gateway/Digital_Wallet.php +1 -0
- includes/Plugin.php +2 -1
- includes/Sync/Manual_Synchronization.php +1 -4
- readme.txt +6 -1
- woocommerce-square.php +16 -2
assets/blocks/credit-card/checkout-handler.js
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { useContext } from '@wordpress/element';
|
5 |
+
import { Context } from 'react-square-payment-form';
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Internal dependencies
|
9 |
+
*/
|
10 |
+
import { usePaymentProcessing } from './use-payment-processing';
|
11 |
+
import { useAfterProcessingCheckout } from './use-after-processing-checkout';
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @typedef {import('../square-utils/type-defs').SquarePaymentFormHandler} SquarePaymentFormHandler
|
15 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').EventRegistrationProps} EventRegistrationProps
|
16 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').BillingDataProps} BillingDataProps
|
17 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').EmitResponseProps} EmitResponseProps
|
18 |
+
*/
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Handles checkout processing
|
22 |
+
*
|
23 |
+
* @param {Object} props Incoming props
|
24 |
+
* @param {SquarePaymentFormHandler} props.checkoutFormHandler Checkout form handler
|
25 |
+
* @param {EventRegistrationProps} props.eventRegistration Event registration functions.
|
26 |
+
* @param {EmitResponseProps} props.emitResponse Helpers for observer response objects.
|
27 |
+
*/
|
28 |
+
export const CheckoutHandler = ( {
|
29 |
+
checkoutFormHandler,
|
30 |
+
eventRegistration,
|
31 |
+
emitResponse,
|
32 |
+
} ) => {
|
33 |
+
const square = useContext( Context );
|
34 |
+
|
35 |
+
const {
|
36 |
+
onPaymentProcessing,
|
37 |
+
onCheckoutAfterProcessingWithError,
|
38 |
+
onCheckoutAfterProcessingWithSuccess,
|
39 |
+
} = eventRegistration;
|
40 |
+
|
41 |
+
const {
|
42 |
+
getPaymentMethodData,
|
43 |
+
createNonce,
|
44 |
+
verifyBuyer,
|
45 |
+
} = checkoutFormHandler;
|
46 |
+
|
47 |
+
usePaymentProcessing(
|
48 |
+
onPaymentProcessing,
|
49 |
+
emitResponse,
|
50 |
+
square,
|
51 |
+
getPaymentMethodData,
|
52 |
+
createNonce,
|
53 |
+
verifyBuyer
|
54 |
+
);
|
55 |
+
|
56 |
+
useAfterProcessingCheckout(
|
57 |
+
onCheckoutAfterProcessingWithError,
|
58 |
+
onCheckoutAfterProcessingWithSuccess,
|
59 |
+
emitResponse
|
60 |
+
);
|
61 |
+
|
62 |
+
return null;
|
63 |
+
};
|
assets/blocks/credit-card/component-card-fields.js
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { __ } from '@wordpress/i18n';
|
5 |
+
import {
|
6 |
+
CreditCardNumberInput,
|
7 |
+
CreditCardExpirationDateInput,
|
8 |
+
CreditCardPostalCodeInput,
|
9 |
+
CreditCardCVVInput,
|
10 |
+
} from 'react-square-payment-form';
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Renders checkout card fields
|
14 |
+
*
|
15 |
+
* @param {string} cardType Card Type
|
16 |
+
*/
|
17 |
+
export const ComponentCardFields = ( { cardType } ) => {
|
18 |
+
return (
|
19 |
+
<fieldset id="wc-square-credit-card-credit-card-form">
|
20 |
+
<span className="sq-label">
|
21 |
+
{ __( 'Card Number', 'woocommerce-square' ) }
|
22 |
+
</span>
|
23 |
+
<div
|
24 |
+
id="wc-square-credit-card-account-number-hosted"
|
25 |
+
className={ `wc-square-credit-card-hosted-field ${
|
26 |
+
cardType ? `card-type-${ cardType }` : ''
|
27 |
+
}` }
|
28 |
+
>
|
29 |
+
<CreditCardNumberInput label={ '' } />
|
30 |
+
</div>
|
31 |
+
|
32 |
+
<div className="sq-form-third">
|
33 |
+
<span className="sq-label">
|
34 |
+
{ __( 'Expiration (MM/YY)', 'woocommerce-square' ) }
|
35 |
+
</span>
|
36 |
+
<div
|
37 |
+
id="wc-square-credit-card-expiry-hosted"
|
38 |
+
className="wc-square-credit-card-hosted-field"
|
39 |
+
>
|
40 |
+
<CreditCardExpirationDateInput label={ '' } />
|
41 |
+
</div>
|
42 |
+
</div>
|
43 |
+
|
44 |
+
<div className="sq-form-third">
|
45 |
+
<span className="sq-label">
|
46 |
+
{ __( 'Card Security Code', 'woocommerce-square' ) }
|
47 |
+
</span>
|
48 |
+
<div
|
49 |
+
id="wc-square-credit-card-csc-hosted"
|
50 |
+
className="wc-square-credit-card-hosted-field"
|
51 |
+
>
|
52 |
+
<CreditCardCVVInput label={ '' } />
|
53 |
+
</div>
|
54 |
+
</div>
|
55 |
+
|
56 |
+
<div className="sq-form-third">
|
57 |
+
<span className="sq-label">
|
58 |
+
{ __( 'Postal code', 'woocommerce-square' ) }
|
59 |
+
</span>
|
60 |
+
<div
|
61 |
+
id="wc-square-credit-card-postal-code-hosted"
|
62 |
+
className="wc-square-credit-card-hosted-field"
|
63 |
+
>
|
64 |
+
<CreditCardPostalCodeInput label={ '' } />
|
65 |
+
</div>
|
66 |
+
</div>
|
67 |
+
</fieldset>
|
68 |
+
);
|
69 |
+
};
|
assets/blocks/credit-card/component-credit-card.js
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { __ } from '@wordpress/i18n';
|
5 |
+
import { SquarePaymentForm } from 'react-square-payment-form';
|
6 |
+
|
7 |
+
/**
|
8 |
+
* Internal dependencies
|
9 |
+
*/
|
10 |
+
import { CheckoutHandler } from './checkout-handler';
|
11 |
+
import { usePaymentForm } from './use-payment-form';
|
12 |
+
import { getSquareServerData } from '../square-utils';
|
13 |
+
import { ComponentCardFields } from './component-card-fields';
|
14 |
+
|
15 |
+
/**
|
16 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps
|
17 |
+
*/
|
18 |
+
|
19 |
+
/**
|
20 |
+
* Square's credit card component
|
21 |
+
*
|
22 |
+
* @param {RegisteredPaymentMethodProps} props Incoming props
|
23 |
+
*/
|
24 |
+
export const ComponentCreditCard = ( {
|
25 |
+
billing,
|
26 |
+
eventRegistration,
|
27 |
+
emitResponse,
|
28 |
+
shouldSavePayment,
|
29 |
+
} ) => {
|
30 |
+
const form = usePaymentForm( billing, shouldSavePayment );
|
31 |
+
|
32 |
+
return (
|
33 |
+
<SquarePaymentForm
|
34 |
+
formId={ 'square-credit-card' }
|
35 |
+
sandbox={ getSquareServerData().isSandbox }
|
36 |
+
applicationId={ getSquareServerData().applicationId }
|
37 |
+
locationId={ getSquareServerData().locationId }
|
38 |
+
inputStyles={ getSquareServerData().inputStyles }
|
39 |
+
placeholderCreditCard={ '•••• •••• •••• ••••' }
|
40 |
+
placeholderExpiration={ __( 'MM / YY', 'woocommerce-square' ) }
|
41 |
+
placeholderCVV={ __( 'CSC', 'woocommerce-square' ) }
|
42 |
+
postalCode={ form.getPostalCode }
|
43 |
+
cardNonceResponseReceived={ form.cardNonceResponseReceived }
|
44 |
+
inputEventReceived={ form.handleInputReceived }
|
45 |
+
paymentFormLoaded={ () => form.setLoaded( true ) }
|
46 |
+
>
|
47 |
+
<ComponentCardFields cardType={ form.cardType } />
|
48 |
+
{ form.isLoaded && (
|
49 |
+
<CheckoutHandler
|
50 |
+
checkoutFormHandler={ form }
|
51 |
+
eventRegistration={ eventRegistration }
|
52 |
+
emitResponse={ emitResponse }
|
53 |
+
/>
|
54 |
+
) }
|
55 |
+
</SquarePaymentForm>
|
56 |
+
);
|
57 |
+
};
|
assets/blocks/credit-card/component-saved-token.js
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { SquarePaymentForm } from 'react-square-payment-form';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Internal dependencies
|
8 |
+
*/
|
9 |
+
import { CheckoutHandler } from './checkout-handler';
|
10 |
+
import { usePaymentForm } from './use-payment-form';
|
11 |
+
import { getSquareServerData } from '../square-utils';
|
12 |
+
|
13 |
+
/**
|
14 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps
|
15 |
+
*/
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Square's saved credit card component
|
19 |
+
*
|
20 |
+
* @param {RegisteredPaymentMethodProps} props Incoming props
|
21 |
+
*/
|
22 |
+
export const ComponentSavedToken = ( {
|
23 |
+
billing,
|
24 |
+
eventRegistration,
|
25 |
+
emitResponse,
|
26 |
+
token,
|
27 |
+
} ) => {
|
28 |
+
const form = usePaymentForm( billing, false, token );
|
29 |
+
|
30 |
+
return (
|
31 |
+
<SquarePaymentForm
|
32 |
+
formId={ 'square-credit-card-saved-card' }
|
33 |
+
sandbox={ getSquareServerData().isSandbox }
|
34 |
+
applicationId={ getSquareServerData().applicationId }
|
35 |
+
locationId={ getSquareServerData().locationId }
|
36 |
+
paymentFormLoaded={ () => form.setLoaded( true ) }
|
37 |
+
>
|
38 |
+
{ form.isLoaded && (
|
39 |
+
<CheckoutHandler
|
40 |
+
checkoutFormHandler={ form }
|
41 |
+
eventRegistration={ eventRegistration }
|
42 |
+
emitResponse={ emitResponse }
|
43 |
+
/>
|
44 |
+
) }
|
45 |
+
</SquarePaymentForm>
|
46 |
+
);
|
47 |
+
};
|
assets/blocks/credit-card/constants.js
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
export const PAYMENT_METHOD_NAME = 'square-credit-card';
|
2 |
+
export const PAYMENT_METHOD_ID = 'square_credit_card';
|
assets/blocks/credit-card/index.js
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Internal dependencies
|
3 |
+
*/
|
4 |
+
import { ComponentCreditCard } from './component-credit-card';
|
5 |
+
import { ComponentSavedToken } from './component-saved-token';
|
6 |
+
import { PAYMENT_METHOD_NAME, PAYMENT_METHOD_ID } from './constants';
|
7 |
+
import { getSquareServerData } from '../square-utils';
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').RegisteredPaymentMethodProps} RegisteredPaymentMethodProps
|
11 |
+
*/
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Label component
|
15 |
+
*
|
16 |
+
* @param {RegisteredPaymentMethodProps} props
|
17 |
+
*/
|
18 |
+
const SquareLabel = ( props ) => {
|
19 |
+
const { PaymentMethodLabel } = props.components;
|
20 |
+
return <PaymentMethodLabel text={ getSquareServerData().title } />;
|
21 |
+
};
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Payment method content component
|
25 |
+
*
|
26 |
+
* @param {Object} props Incoming props for component (including props from Payments API)
|
27 |
+
* @param {ComponentCreditCard|ComponentSavedToken} props.RenderedComponent Component to render
|
28 |
+
*/
|
29 |
+
const SquareComponent = ( { RenderedComponent, ...props } ) => {
|
30 |
+
return <RenderedComponent { ...props } />;
|
31 |
+
};
|
32 |
+
|
33 |
+
const squareCreditCardMethod = {
|
34 |
+
name: PAYMENT_METHOD_NAME,
|
35 |
+
label: <SquareLabel />,
|
36 |
+
content: <SquareComponent RenderedComponent={ ComponentCreditCard } />,
|
37 |
+
edit: <SquareComponent RenderedComponent={ ComponentCreditCard } />,
|
38 |
+
savedTokenComponent: (
|
39 |
+
<SquareComponent RenderedComponent={ ComponentSavedToken } />
|
40 |
+
),
|
41 |
+
paymentMethodId: PAYMENT_METHOD_ID,
|
42 |
+
ariaLabel: 'Square',
|
43 |
+
canMakePayment: () =>
|
44 |
+
getSquareServerData().applicationId && getSquareServerData().locationId
|
45 |
+
? true
|
46 |
+
: false,
|
47 |
+
supports: {
|
48 |
+
features: getSquareServerData().supports,
|
49 |
+
showSavedCards: getSquareServerData().showSavedCards,
|
50 |
+
showSaveOption: getSquareServerData().showSaveOption,
|
51 |
+
},
|
52 |
+
};
|
53 |
+
|
54 |
+
export default squareCreditCardMethod;
|
assets/blocks/credit-card/use-after-processing-checkout.js
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { useEffect } from '@wordpress/element';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @typedef {import('../square-utils/type-defs').SquarePaymentFormHandler} SquarePaymentFormHandler
|
8 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').EmitResponseProps} EmitResponseProps
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Handle after checkout processing events.
|
13 |
+
*
|
14 |
+
* Once the checkout has been submitted and server-side processing has completed, check
|
15 |
+
* if there's any client-side errors that need to be returned.
|
16 |
+
*
|
17 |
+
* Once checkout process is completed, reset the SquarePaymentFormHandler state.
|
18 |
+
*
|
19 |
+
* @param {Function} onCheckoutAfterProcessingWithError Callback for registering observers for after the checkout has been processed and has an error
|
20 |
+
* @param {Function} onCheckoutAfterProcessingWithSuccess Callback for registering observers for after the checkout has been processed and is successful
|
21 |
+
* @param {EmitResponseProps} emitResponse Helpers for observer response objects
|
22 |
+
*/
|
23 |
+
export const useAfterProcessingCheckout = (
|
24 |
+
onCheckoutAfterProcessingWithError,
|
25 |
+
onCheckoutAfterProcessingWithSuccess,
|
26 |
+
emitResponse
|
27 |
+
) => {
|
28 |
+
useEffect( () => {
|
29 |
+
/**
|
30 |
+
* Before finishing the checkout with the 'success' status, check that there
|
31 |
+
* are no checkout errors and return them if so.
|
32 |
+
*
|
33 |
+
* This function is attached onCheckoutAfterProcessingWithError and onCheckoutAfterProcessingWithSuccess hooks.
|
34 |
+
*
|
35 |
+
* @param {Object} checkoutResponse
|
36 |
+
*
|
37 |
+
* @return {Object} If checkout errors, return an error response object with message, otherwise return true.
|
38 |
+
*/
|
39 |
+
const onCheckoutComplete = ( checkoutResponse ) => {
|
40 |
+
let response = { type: emitResponse.responseTypes.SUCCESS };
|
41 |
+
|
42 |
+
const {
|
43 |
+
paymentStatus,
|
44 |
+
paymentDetails,
|
45 |
+
} = checkoutResponse.processingResponse;
|
46 |
+
|
47 |
+
if (
|
48 |
+
paymentStatus === emitResponse.responseTypes.ERROR &&
|
49 |
+
paymentDetails.checkoutNotices
|
50 |
+
) {
|
51 |
+
response = {
|
52 |
+
type: emitResponse.responseTypes.ERROR,
|
53 |
+
message: JSON.parse( paymentDetails.checkoutNotices ),
|
54 |
+
messageContext: emitResponse.noticeContexts.PAYMENTS,
|
55 |
+
retry: true,
|
56 |
+
};
|
57 |
+
}
|
58 |
+
|
59 |
+
return response;
|
60 |
+
};
|
61 |
+
|
62 |
+
const unsubscribeCheckoutCompleteError = onCheckoutAfterProcessingWithError(
|
63 |
+
onCheckoutComplete
|
64 |
+
);
|
65 |
+
const unsubscribeCheckoutCompleteSuccess = onCheckoutAfterProcessingWithSuccess(
|
66 |
+
onCheckoutComplete
|
67 |
+
);
|
68 |
+
|
69 |
+
return () => {
|
70 |
+
unsubscribeCheckoutCompleteError();
|
71 |
+
unsubscribeCheckoutCompleteSuccess();
|
72 |
+
};
|
73 |
+
}, [
|
74 |
+
onCheckoutAfterProcessingWithError,
|
75 |
+
onCheckoutAfterProcessingWithSuccess,
|
76 |
+
emitResponse.noticeContexts.PAYMENTS,
|
77 |
+
emitResponse.responseTypes.ERROR,
|
78 |
+
emitResponse.responseTypes.SUCCESS,
|
79 |
+
] );
|
80 |
+
};
|
assets/blocks/credit-card/use-payment-form.js
ADDED
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { useState, useCallback, useMemo, useRef } from '@wordpress/element';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Internal dependencies
|
8 |
+
*/
|
9 |
+
import {
|
10 |
+
getSquareServerData,
|
11 |
+
handleErrors,
|
12 |
+
log,
|
13 |
+
logData,
|
14 |
+
} from '../square-utils';
|
15 |
+
import { PAYMENT_METHOD_NAME } from './constants';
|
16 |
+
|
17 |
+
/**
|
18 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').BillingDataProps} BillingDataProps
|
19 |
+
* @typedef {import('../square-utils/type-defs').SquarePaymentFormHandler} SquarePaymentFormHandler
|
20 |
+
* @typedef {import('../square-utils/type-defs').SquareContext} SquareContext
|
21 |
+
*/
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Payment Form Handler
|
25 |
+
*
|
26 |
+
* @param {BillingDataProps} billing Checkout billing data.
|
27 |
+
* @param {boolean} shouldSavePayment True if customer has checked box to save card. Defaults to false
|
28 |
+
* @param {string} token Saved card/token ID passed from server.
|
29 |
+
*
|
30 |
+
* @return {SquarePaymentFormHandler} An object with properties that interact with the Square Payment Form
|
31 |
+
*/
|
32 |
+
export const usePaymentForm = (
|
33 |
+
billing,
|
34 |
+
shouldSavePayment = false,
|
35 |
+
token = null
|
36 |
+
) => {
|
37 |
+
const [ isLoaded, setLoaded ] = useState( false );
|
38 |
+
const [ cardType, setCardType ] = useState( '' );
|
39 |
+
const resolveCreateNonce = useRef( null );
|
40 |
+
const resolveVerifyBuyer = useRef( null );
|
41 |
+
|
42 |
+
const verificationDetails = useMemo( () => {
|
43 |
+
const intent = shouldSavePayment && ! token ? 'STORE' : 'CHARGE';
|
44 |
+
const newVerificationDetails = {
|
45 |
+
billingContact: {
|
46 |
+
familyName: billing.billingData.last_name || '',
|
47 |
+
givenName: billing.billingData.first_name || '',
|
48 |
+
email: billing.billingData.email || '',
|
49 |
+
country: billing.billingData.country || '',
|
50 |
+
region: billing.billingData.state || '',
|
51 |
+
city: billing.billingData.city || '',
|
52 |
+
postalCode: billing.billingData.postcode || '',
|
53 |
+
phone: billing.billingData.phone || '',
|
54 |
+
addressLines: [
|
55 |
+
billing.billingData.address_1 || '',
|
56 |
+
billing.billingData.address_2 || '',
|
57 |
+
],
|
58 |
+
},
|
59 |
+
intent,
|
60 |
+
};
|
61 |
+
|
62 |
+
if ( intent === 'CHARGE' ) {
|
63 |
+
newVerificationDetails.amount = (
|
64 |
+
billing.cartTotal.value / 100
|
65 |
+
).toString();
|
66 |
+
newVerificationDetails.currencyCode = billing.currency.code;
|
67 |
+
}
|
68 |
+
return newVerificationDetails;
|
69 |
+
}, [
|
70 |
+
billing.billingData,
|
71 |
+
billing.cartTotal.value,
|
72 |
+
billing.currency.code,
|
73 |
+
shouldSavePayment,
|
74 |
+
token,
|
75 |
+
] );
|
76 |
+
|
77 |
+
const getPaymentMethodData = useCallback(
|
78 |
+
( { cardData, nonce, verificationToken, notices, logs } ) => {
|
79 |
+
const data = {
|
80 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-card-type` ]: cardType || '',
|
81 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-last-four` ]:
|
82 |
+
cardData?.last_4 || '',
|
83 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-exp-month` ]:
|
84 |
+
cardData?.exp_month?.toString() || '',
|
85 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-exp-year` ]:
|
86 |
+
cardData?.exp_year?.toString() || '',
|
87 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-payment-postcode` ]:
|
88 |
+
cardData?.billing_postal_code || '',
|
89 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-payment-nonce` ]: nonce || '',
|
90 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-payment-token` ]: token || '',
|
91 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-buyer-verification-token` ]:
|
92 |
+
verificationToken || '',
|
93 |
+
[ `wc-${ PAYMENT_METHOD_NAME }-tokenize-payment-method` ]:
|
94 |
+
shouldSavePayment || false,
|
95 |
+
'log-data': logs.length > 0 ? JSON.stringify( logs ) : '',
|
96 |
+
'checkout-notices':
|
97 |
+
notices.length > 0 ? JSON.stringify( notices ) : '',
|
98 |
+
};
|
99 |
+
|
100 |
+
return data;
|
101 |
+
},
|
102 |
+
[ cardType, shouldSavePayment, token ]
|
103 |
+
);
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Handles the response from SqPaymentForm.onCreateNonce() and resolves promise
|
107 |
+
*
|
108 |
+
* @param {Array} errors Errors thrown by Square when attempting to create a payment nonce with given card details on checkout
|
109 |
+
* @param {string} nonce Payment nonce created by Square
|
110 |
+
* @param {Object} cardData Validated card data used to create payment nonce
|
111 |
+
*/
|
112 |
+
const cardNonceResponseReceived = ( errors, nonce, cardData ) => {
|
113 |
+
const response = {
|
114 |
+
notices: [],
|
115 |
+
logs: [],
|
116 |
+
};
|
117 |
+
|
118 |
+
if ( errors ) {
|
119 |
+
handleErrors( errors, response );
|
120 |
+
} else if ( ! nonce ) {
|
121 |
+
logData( 'Nonce is missing from the Square response', response );
|
122 |
+
log( 'Nonce is missing from the Square response', 'error' );
|
123 |
+
handleErrors( [], response );
|
124 |
+
} else {
|
125 |
+
logData( cardData, response );
|
126 |
+
log( 'Card data received' );
|
127 |
+
log( cardData );
|
128 |
+
|
129 |
+
response.cardData = cardData;
|
130 |
+
response.nonce = nonce;
|
131 |
+
}
|
132 |
+
|
133 |
+
if ( resolveCreateNonce.current ) {
|
134 |
+
resolveCreateNonce.current( response );
|
135 |
+
}
|
136 |
+
};
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Generates a payment nonce
|
140 |
+
*
|
141 |
+
* @param {SquareContext} square Instance of SqPaymentForm to call onCreateNonce
|
142 |
+
*
|
143 |
+
* @return {Promise} Returns promise which will be resolved in cardNonceResponseReceived callback
|
144 |
+
*/
|
145 |
+
const createNonce = useCallback(
|
146 |
+
( square ) => {
|
147 |
+
if ( ! token ) {
|
148 |
+
const promise = new Promise(
|
149 |
+
( resolve ) => ( resolveCreateNonce.current = resolve )
|
150 |
+
);
|
151 |
+
square.onCreateNonce();
|
152 |
+
return promise;
|
153 |
+
}
|
154 |
+
|
155 |
+
return Promise.resolve( { token } );
|
156 |
+
},
|
157 |
+
[ token ]
|
158 |
+
);
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Generates a verification buyer token
|
162 |
+
*
|
163 |
+
* @param {SquareContext} square Instance of SqPaymentForm to call onVerifyBuyer
|
164 |
+
* @param {string} paymentToken Payment Token to verify
|
165 |
+
*
|
166 |
+
* @return {Promise} Returns promise which will be resolved in handleVerifyBuyerResponse callback
|
167 |
+
*/
|
168 |
+
const verifyBuyer = useCallback(
|
169 |
+
( square, paymentToken ) => {
|
170 |
+
const promise = new Promise(
|
171 |
+
( resolve ) => ( resolveVerifyBuyer.current = resolve )
|
172 |
+
);
|
173 |
+
|
174 |
+
square.onVerifyBuyer(
|
175 |
+
paymentToken,
|
176 |
+
verificationDetails,
|
177 |
+
handleVerifyBuyerResponse
|
178 |
+
);
|
179 |
+
return promise;
|
180 |
+
},
|
181 |
+
[ verificationDetails, handleVerifyBuyerResponse ]
|
182 |
+
);
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Handles the response from SqPaymentForm.onVerifyBuyer() and resolves promise
|
186 |
+
*
|
187 |
+
* @param {Array} errors Errors thrown by Square when verifying buyer credentials
|
188 |
+
* @param {Object} verificationResult Verify buyer result from Square
|
189 |
+
*/
|
190 |
+
const handleVerifyBuyerResponse = useCallback(
|
191 |
+
( errors, verificationResult ) => {
|
192 |
+
const response = {
|
193 |
+
notices: [],
|
194 |
+
logs: [],
|
195 |
+
};
|
196 |
+
|
197 |
+
if ( errors ) {
|
198 |
+
for ( const error of errors ) {
|
199 |
+
if ( ! error.field ) {
|
200 |
+
error.field = 'none';
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
handleErrors( errors, response );
|
205 |
+
}
|
206 |
+
|
207 |
+
// no errors, but also no verification token.
|
208 |
+
if ( ! verificationResult || ! verificationResult.token ) {
|
209 |
+
logData(
|
210 |
+
'Verification token is missing from the Square response',
|
211 |
+
response
|
212 |
+
);
|
213 |
+
log(
|
214 |
+
'Verification token is missing from the Square response',
|
215 |
+
'error'
|
216 |
+
);
|
217 |
+
handleErrors( [], response );
|
218 |
+
} else {
|
219 |
+
response.verificationToken = verificationResult.token;
|
220 |
+
}
|
221 |
+
|
222 |
+
if ( resolveVerifyBuyer.current ) {
|
223 |
+
resolveVerifyBuyer.current( response );
|
224 |
+
}
|
225 |
+
},
|
226 |
+
[ resolveVerifyBuyer ]
|
227 |
+
);
|
228 |
+
|
229 |
+
/**
|
230 |
+
* When customers interact with the SqPaymentForm iframe elements, determine
|
231 |
+
* whether the cardBrandChanged event has occurred and set card type
|
232 |
+
*
|
233 |
+
* @param {Object} event Input event object
|
234 |
+
*/
|
235 |
+
const handleInputReceived = useCallback( ( event ) => {
|
236 |
+
// change card icon
|
237 |
+
if ( event.eventType === 'cardBrandChanged' ) {
|
238 |
+
const brand = event.cardBrand;
|
239 |
+
let newCardType = 'plain';
|
240 |
+
|
241 |
+
if ( brand === null || brand === 'unknown' ) {
|
242 |
+
newCardType = '';
|
243 |
+
}
|
244 |
+
|
245 |
+
if ( getSquareServerData().availableCardTypes[ brand ] !== null ) {
|
246 |
+
newCardType = getSquareServerData().availableCardTypes[ brand ];
|
247 |
+
}
|
248 |
+
|
249 |
+
log( `Card brand changed to ${ brand }` );
|
250 |
+
setCardType( newCardType );
|
251 |
+
}
|
252 |
+
}, [] );
|
253 |
+
|
254 |
+
/**
|
255 |
+
* Returns the postcode value from BillingDataProps or an empty string
|
256 |
+
*
|
257 |
+
* @return {string} Postal Code value or an empty string
|
258 |
+
*/
|
259 |
+
const getPostalCode = useCallback( () => {
|
260 |
+
const postalCode = billing.billingData.postcode || '';
|
261 |
+
return postalCode;
|
262 |
+
}, [ billing.billingData.postcode ] );
|
263 |
+
|
264 |
+
return {
|
265 |
+
cardNonceResponseReceived,
|
266 |
+
handleInputReceived,
|
267 |
+
isLoaded,
|
268 |
+
setLoaded,
|
269 |
+
getPostalCode,
|
270 |
+
cardType,
|
271 |
+
createNonce,
|
272 |
+
verifyBuyer,
|
273 |
+
getPaymentMethodData,
|
274 |
+
};
|
275 |
+
};
|
assets/blocks/credit-card/use-payment-processing.js
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { useEffect, useRef } from '@wordpress/element';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Internal dependencies
|
8 |
+
*/
|
9 |
+
import { getSquareServerData } from '../square-utils';
|
10 |
+
|
11 |
+
/**
|
12 |
+
* @typedef {import('../square-utils/type-defs').SquarePaymentFormHandler} SquarePaymentFormHandler
|
13 |
+
* @typedef {import('@woocommerce/type-defs/registered-payment-method-props').EmitResponseProps} EmitResponseProps
|
14 |
+
* @typedef {import('../square-utils/type-defs').SquareContext} SquareContext
|
15 |
+
*/
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Sets up payment details and POST data to be processed on server-side on checkout submission.
|
19 |
+
*
|
20 |
+
* If the checkout has a nonce, token or data to be logged to WooCommerce Status logs, this function
|
21 |
+
* sends a SUCCESS request to the server with this data inside paymentMethodData.
|
22 |
+
*
|
23 |
+
* If the checkout has errors, we send `has-checkout-errors` to the server-side so that the status
|
24 |
+
* of the request can be set to 'ERROR' before gateway validation is done.
|
25 |
+
*
|
26 |
+
* @param {Function} onPaymentProcessing Callback for registering observers on the payment processing event
|
27 |
+
* @param {EmitResponseProps} emitResponse Helpers for observer response objects
|
28 |
+
* @param {SquareContext} squareContext Square payment form context variable
|
29 |
+
* @param {Function} getPaymentMethodData CreateNonce function
|
30 |
+
* @param {Function} createNonce CreateNonce function
|
31 |
+
* @param {Function} verifyBuyer VerifyBuyer function
|
32 |
+
*/
|
33 |
+
export const usePaymentProcessing = (
|
34 |
+
onPaymentProcessing,
|
35 |
+
emitResponse,
|
36 |
+
squareContext,
|
37 |
+
getPaymentMethodData,
|
38 |
+
createNonce,
|
39 |
+
verifyBuyer
|
40 |
+
) => {
|
41 |
+
const square = useRef( squareContext );
|
42 |
+
|
43 |
+
useEffect( () => {
|
44 |
+
square.current = squareContext;
|
45 |
+
}, [ squareContext ] );
|
46 |
+
|
47 |
+
useEffect( () => {
|
48 |
+
const processCheckout = async () => {
|
49 |
+
const response = { type: emitResponse.responseTypes.SUCCESS };
|
50 |
+
const defaults = {
|
51 |
+
nonce: '',
|
52 |
+
notices: [],
|
53 |
+
logs: [],
|
54 |
+
};
|
55 |
+
|
56 |
+
const createNonceResponse = await createNonce( square.current );
|
57 |
+
const paymentData = { ...defaults, ...createNonceResponse };
|
58 |
+
const paymentToken = paymentData.token || paymentData.nonce;
|
59 |
+
|
60 |
+
if ( getSquareServerData().is3dsEnabled && paymentToken ) {
|
61 |
+
const verifyBuyerResponse = await verifyBuyer(
|
62 |
+
square.current,
|
63 |
+
paymentToken
|
64 |
+
);
|
65 |
+
|
66 |
+
paymentData.verificationToken =
|
67 |
+
verifyBuyerResponse.verificationToken || '';
|
68 |
+
paymentData.logs = paymentData.logs.concat(
|
69 |
+
verifyBuyerResponse.log || []
|
70 |
+
);
|
71 |
+
paymentData.errors = paymentData.notices.concat(
|
72 |
+
verifyBuyerResponse.errors || []
|
73 |
+
);
|
74 |
+
}
|
75 |
+
|
76 |
+
if ( paymentToken || paymentData.logs.length > 0 ) {
|
77 |
+
response.meta = {
|
78 |
+
paymentMethodData: getPaymentMethodData( paymentData ),
|
79 |
+
};
|
80 |
+
} else if ( paymentData.notices.length > 0 ) {
|
81 |
+
response.type = emitResponse.responseTypes.ERROR;
|
82 |
+
response.message = paymentData.notices;
|
83 |
+
}
|
84 |
+
|
85 |
+
return response;
|
86 |
+
};
|
87 |
+
|
88 |
+
const unsubscribe = onPaymentProcessing( processCheckout );
|
89 |
+
return unsubscribe;
|
90 |
+
}, [
|
91 |
+
onPaymentProcessing,
|
92 |
+
emitResponse.responseTypes.SUCCESS,
|
93 |
+
emitResponse.responseTypes.ERROR,
|
94 |
+
createNonce,
|
95 |
+
verifyBuyer,
|
96 |
+
getPaymentMethodData,
|
97 |
+
] );
|
98 |
+
};
|
assets/blocks/index.js
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* Internal dependencies
|
8 |
+
*/
|
9 |
+
import squareCreditCardMethod from './credit-card';
|
10 |
+
|
11 |
+
// Register Square Credit Card.
|
12 |
+
registerPaymentMethod( squareCreditCardMethod );
|
assets/blocks/square-utils/index.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
export * from './utils';
|
assets/blocks/square-utils/type-defs.js
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* @typedef {Object} SquareServerData
|
3 |
+
*
|
4 |
+
* @property {string} title The payment method title (used for payment method label)
|
5 |
+
* @property {string} applicationId The connected Square account's application ID
|
6 |
+
* @property {string} locationId The Square store location ID
|
7 |
+
* @property {boolean} isSandbox Is Square set to sandbox mode
|
8 |
+
* @property {boolean} is3dsEnabled Is 3D secure enabled for the connected Square accountThe type of button.
|
9 |
+
* @property {Array} inputStyles Input styles for the SqPaymentForm iframe elementsThe theme for the button.
|
10 |
+
* @property {Object} availableCardTypes List of available card types
|
11 |
+
* @property {string} loggingEnabled Is logging enabled
|
12 |
+
* @property {string} generalError General error message for unhandled errors
|
13 |
+
* @property {boolean} showSavedCards Is tokenization/saved cards enabled
|
14 |
+
* @property {boolean} showSaveOption Is tokenization/saved cards enabled
|
15 |
+
* @property {Object} supports List of features supported by Square
|
16 |
+
*/
|
17 |
+
|
18 |
+
/**
|
19 |
+
* Client-side Square logs to be logged to WooCommerce logs on checkout submission
|
20 |
+
*
|
21 |
+
* @typedef {Object} SquareLogData
|
22 |
+
*
|
23 |
+
* @property {Array} errors Critical client-side errors to be logged
|
24 |
+
* @property {Array} messages Non-critical errors to be logged
|
25 |
+
*/
|
26 |
+
|
27 |
+
/**
|
28 |
+
* Square Billing Contact
|
29 |
+
*
|
30 |
+
* @typedef {Object} SquareBillingContact
|
31 |
+
*
|
32 |
+
* @property {string} familyName The billing last name
|
33 |
+
* @property {string} givenName The billing first name
|
34 |
+
* @property {string} email The billing email
|
35 |
+
* @property {string} country The billing contact country
|
36 |
+
* @property {string} region The billing state/region
|
37 |
+
* @property {string} city The billing city
|
38 |
+
* @property {string} postalCode The postal/zip code
|
39 |
+
* @property {string} phone The billing email
|
40 |
+
* @property {Array} [addressLines] An array of address line items.
|
41 |
+
*/
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Square Context object
|
45 |
+
*
|
46 |
+
* @typedef {Object} SquareContext
|
47 |
+
*
|
48 |
+
* @property {Function} onCreateNonce Triggers the SqPaymentCustomer billing data
|
49 |
+
* @property {Function} onVerifyBuyer Triggers the SqPaymentForm.verifyBuyer() function
|
50 |
+
*/
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Square Payment Form Handler
|
54 |
+
*
|
55 |
+
* @typedef {Object} SquarePaymentFormHandler
|
56 |
+
*
|
57 |
+
* @property {Function} cardNonceResponseReceived Function for handling response from sqPaymentForm.onCreateNonce
|
58 |
+
* @property {Function} handleInputReceived Handle inputs received on sqPaymentForm
|
59 |
+
* @property {boolean} isLoaded Used to determine if sqPaymentForm has finished loading
|
60 |
+
* @property {Function} setLoaded Function to set isLoaded state
|
61 |
+
* @property {Function} getPostalCode Function to return billingContact postalcode value
|
62 |
+
* @property {Function} cardBrandClass Function to return billingContact postalcode value
|
63 |
+
* @property {Function} createNonce Function to return billingContact postalcode value
|
64 |
+
* @property {Function} verifyBuyer Function to return billingContact postalcode value
|
65 |
+
* @property {Function} getPaymentMethodData Function to return billingContact postalcode value
|
66 |
+
*/
|
assets/blocks/square-utils/utils.js
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* External dependencies
|
3 |
+
*/
|
4 |
+
import { getSetting } from '@woocommerce/settings';
|
5 |
+
|
6 |
+
/**
|
7 |
+
* @typedef {import('./type-defs').SquareServerData} SquareServerData
|
8 |
+
*/
|
9 |
+
|
10 |
+
let cachedSquareData = null;
|
11 |
+
|
12 |
+
/**
|
13 |
+
* Square settings that comes from the server
|
14 |
+
*
|
15 |
+
* @return {SquareServerData} Square server data.
|
16 |
+
*/
|
17 |
+
const getSquareServerData = () => {
|
18 |
+
if ( cachedSquareData !== null ) {
|
19 |
+
return cachedSquareData;
|
20 |
+
}
|
21 |
+
|
22 |
+
const squareData = getSetting( 'square_credit_card_data', null );
|
23 |
+
|
24 |
+
if ( ! squareData ) {
|
25 |
+
throw new Error( 'Square initialization data is not available' );
|
26 |
+
}
|
27 |
+
|
28 |
+
cachedSquareData = {
|
29 |
+
title: squareData.title || '',
|
30 |
+
applicationId: squareData.application_id || '',
|
31 |
+
locationId: squareData.location_id || '',
|
32 |
+
isSandbox: squareData.is_sandbox || false,
|
33 |
+
is3dsEnabled: squareData.is_3ds_enabled || false,
|
34 |
+
inputStyles: squareData.input_styles || [],
|
35 |
+
availableCardTypes: squareData.available_card_types || {},
|
36 |
+
loggingEnabled: squareData.logging_enabled || false,
|
37 |
+
generalError: squareData.general_error || '',
|
38 |
+
showSavedCards: squareData.show_saved_cards || false,
|
39 |
+
showSaveOption: squareData.show_save_option || false,
|
40 |
+
supports: squareData.supports || {},
|
41 |
+
};
|
42 |
+
|
43 |
+
return cachedSquareData;
|
44 |
+
};
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Handles errors received from Square requests
|
48 |
+
*
|
49 |
+
* @param {Array} errors
|
50 |
+
* @param {Object} response
|
51 |
+
*/
|
52 |
+
const handleErrors = ( errors, response = { logs: [], notices: [] } ) => {
|
53 |
+
let errorFound = false;
|
54 |
+
|
55 |
+
if ( errors ) {
|
56 |
+
const fieldOrder = [
|
57 |
+
'none',
|
58 |
+
'cardNumber',
|
59 |
+
'expirationDate',
|
60 |
+
'cvv',
|
61 |
+
'postalCode',
|
62 |
+
];
|
63 |
+
|
64 |
+
if ( errors.length >= 1 ) {
|
65 |
+
// sort based on the field order without the brackets around a.field and b.field.
|
66 |
+
// the precedence is different and gives different results.
|
67 |
+
errors.sort( ( a, b ) => {
|
68 |
+
return (
|
69 |
+
fieldOrder.indexOf( a.field ) -
|
70 |
+
fieldOrder.indexOf( b.field )
|
71 |
+
);
|
72 |
+
} );
|
73 |
+
}
|
74 |
+
|
75 |
+
for ( const error of errors ) {
|
76 |
+
if (
|
77 |
+
error.type === 'UNSUPPORTED_CARD_BRAND' ||
|
78 |
+
error.type === 'VALIDATION_ERROR'
|
79 |
+
) {
|
80 |
+
// To avoid confusion between CSC used in the frontend and CVV that is used in the error message.
|
81 |
+
response.notices.push( error.message.replace( /CVV/, 'CSC' ) );
|
82 |
+
errorFound = true;
|
83 |
+
} else {
|
84 |
+
logData( error, response );
|
85 |
+
}
|
86 |
+
}
|
87 |
+
}
|
88 |
+
|
89 |
+
// if no specific messages are set, display a general error.
|
90 |
+
if ( ! errorFound ) {
|
91 |
+
response.notices.push( getSquareServerData().generalError );
|
92 |
+
}
|
93 |
+
};
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Log to the console if logging is enabled
|
97 |
+
*
|
98 |
+
* @param {*} data Data to log to console
|
99 |
+
* @param {string} type Type of log, 'error' will log as an error
|
100 |
+
*/
|
101 |
+
const log = ( data, type = 'notice' ) => {
|
102 |
+
if ( ! getSquareServerData().loggingEnabled ) {
|
103 |
+
return;
|
104 |
+
}
|
105 |
+
|
106 |
+
if ( type === 'error' ) {
|
107 |
+
console.error( data );
|
108 |
+
} else {
|
109 |
+
console.log( data );
|
110 |
+
}
|
111 |
+
};
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Logs data to Square Credit Card logs found in WooCommerce > Status > Logs if logging is enabled
|
115 |
+
*
|
116 |
+
* @param {*} data Data to log
|
117 |
+
* @param {Object} response Checkout response object to attach log data to
|
118 |
+
*/
|
119 |
+
const logData = ( data, response ) => {
|
120 |
+
if ( ! getSquareServerData().loggingEnabled || ! response ) {
|
121 |
+
return;
|
122 |
+
}
|
123 |
+
|
124 |
+
response.logs.push( data );
|
125 |
+
};
|
126 |
+
|
127 |
+
export { getSquareServerData, handleErrors, log, logData };
|
assets/css/frontend/wc-square-cart-checkout-blocks.min.css
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
1 |
+
.wc-block-checkout__payment-method div#square-credit-card .sq-payment-form{color:#373f4a;font-family:inherit;font-weight:400;position:relative;width:380px}.wc-block-checkout__payment-method div#square-credit-card #wc-square-credit-card-credit-card-form{margin:0 0 1em;padding:0;border:0;background-color:transparent}.wc-block-checkout__payment-method div#square-credit-card .sq-label{font-size:.8em;font-weight:500;line-height:24px;letter-spacing:.5;text-transform:uppercase;display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.wc-block-checkout__payment-method div#square-credit-card .wc-square-credit-card-hosted-field{display:inline-block}.wc-block-checkout__payment-method div#square-credit-card .sq-input{padding:10px;border:1px solid #e0e2e3;-webkit-transition:border-color .2s ease-in-out,background .2s ease-in-out;-moz-transition:border-color .2s ease-in-out,background .2s ease-in-out;-ms-transition:border-color .2s ease-in-out,background .2s ease-in-out;transition:border-color .2s ease-in-out,background .2s ease-in-out;outline-offset:-2px;box-sizing:border-box;border-radius:4px}.wc-block-checkout__payment-method div#square-credit-card .sq-input,.wc-block-checkout__payment-method div#square-credit-card .wc-square-credit-card-hosted-field{width:100%;height:3em}.wc-block-checkout__payment-method div#square-credit-card #square-credit-card-sq-card-number{padding-right:55px;background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-cc-plain.svg);background-repeat:no-repeat;background-position:99%;background-size:50px 31px}@media only screen and (max-width:320px){.wc-block-checkout__payment-method div#square-credit-card #square-credit-card-sq-card-number{background-image:none}}.wc-block-checkout__payment-method div#square-credit-card .card-type-visa #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-visa.svg)}.wc-block-checkout__payment-method div#square-credit-card .card-type-mastercard #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-mastercard.svg)}.wc-block-checkout__payment-method div#square-credit-card .card-type-amex #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-amex.svg)}.wc-block-checkout__payment-method div#square-credit-card .card-type-diners-club #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-dinersclub.svg)}.wc-block-checkout__payment-method div#square-credit-card .card-type-maestro #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-maestro.svg)}.wc-block-checkout__payment-method div#square-credit-card .card-type-jcb #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-jcb.svg)}.wc-block-checkout__payment-method div#square-credit-card .card-type-discover #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-discover.svg)}.wc-block-checkout__payment-method div#square-credit-card .card-type-invalid #square-credit-card-sq-card-number{background-image:url(../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images/card-cc-invalid.svg)}.wc-block-checkout__payment-method div#square-credit-card .sq-input--focus{border:1px solid #4a90e2;background-color:rgba(74,144,226,.02)}.wc-block-checkout__payment-method div#square-credit-card .sq-input--error{border:1px solid #e02f2f;background-color:rgba(244,47,47,.02)}.wc-block-checkout__payment-method div#square-credit-card .sq-form-third{float:left;width:calc((100% - 32px)/ 3);padding:0;margin:0 16px 16px 0}.wc-block-checkout__payment-method div#square-credit-card .sq-form-third:last-of-type{margin-right:0}
|
2 |
+
/*# sourceMappingURL=wc-square-cart-checkout-blocks.min.css.map */
|
assets/css/frontend/wc-square-cart-checkout-blocks.min.css.map
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
{"version":3,"sources":["wc-square-cart-checkout-blocks.scss"],"names":[],"mappings":"AAGC,2EACC,MAAO,QACP,YAAa,QACb,YAAa,IACb,SAAU,SACV,MAAO,MAGR,kGACC,OAAQ,EAAA,EAAA,IACR,QAAS,EACT,OAAQ,EACR,iBAAkB,YAGnB,oEACC,UAAW,KACX,YAAa,IACb,YAAa,KACb,eAAgB,GAChB,eAAgB,UAChB,QAAS,MACT,SAAU,OACV,cAAe,SACf,YAAa,OAGd,8FACC,QAAS,aAGV,oEACC,QAAS,KACT,OAAQ,IAAA,MAAA,QACR,mBAAoB,aAAA,IAAA,WAAA,CAAA,WAAA,IAAA,YACpB,gBAAiB,aAAA,IAAA,WAAA,CAAA,WAAA,IAAA,YACjB,eAAgB,aAAA,IAAA,WAAA,CAAA,WAAA,IAAA,YAChB,WAAY,aAAA,IAAA,WAAA,CAAA,WAAA,IAAA,YACZ,eAAgB,KAChB,WAAY,WACZ,cAAe,IAGhB,oEACA,8FACC,MAAO,KACP,OAAQ,IAGT,6FACC,cAAe,KACf,iBAAkB,8GAClB,kBAAmB,UACnB,oBAAqB,IACrB,gBAAiB,KAAA,KAEuB,yCAPzC,6FAQE,iBAAkB,MAIJ,6GACf,iBAAkB,0GAGG,mHACrB,iBAAkB,gHAGH,6GACf,iBAAkB,0GAGI,oHACtB,iBAAkB,gHAGA,gHAClB,iBAAkB,6GAGJ,4GACd,iBAAkB,yGAGC,iHACnB,iBAAkB,8GAGA,gHAClB,iBAAkB,gHAGnB,2EACC,OAAQ,IAAA,MAAA,QACR,iBAAkB,qBAGnB,2EACC,OAAQ,IAAA,MAAA,QACR,iBAAkB,oBAGnB,yEACC,MAAO,KACP,MAAO,uBACP,QAAS,EACT,OAAQ,EAAA,KAAA,KAAA,EAGK,sFACb,aAAc"}
|
assets/css/frontend/wc-square-cart-checkout-blocks.scss
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
$image_path: '../../../vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/assets/images';
|
2 |
+
|
3 |
+
.wc-block-checkout__payment-method div#square-credit-card {
|
4 |
+
.sq-payment-form {
|
5 |
+
color: #373F4A;
|
6 |
+
font-family: inherit;
|
7 |
+
font-weight: normal;
|
8 |
+
position: relative;
|
9 |
+
width: 380px;
|
10 |
+
}
|
11 |
+
|
12 |
+
#wc-square-credit-card-credit-card-form {
|
13 |
+
margin: 0 0 1em;
|
14 |
+
padding: 0;
|
15 |
+
border: 0;
|
16 |
+
background-color: transparent;
|
17 |
+
}
|
18 |
+
|
19 |
+
.sq-label {
|
20 |
+
font-size: 0.8em;
|
21 |
+
font-weight: 500;
|
22 |
+
line-height: 24px;
|
23 |
+
letter-spacing: 0.5;
|
24 |
+
text-transform: uppercase;
|
25 |
+
display: block;
|
26 |
+
overflow: hidden;
|
27 |
+
text-overflow: ellipsis;
|
28 |
+
white-space: nowrap;
|
29 |
+
}
|
30 |
+
|
31 |
+
.wc-square-credit-card-hosted-field {
|
32 |
+
display: inline-block;
|
33 |
+
}
|
34 |
+
|
35 |
+
.sq-input {
|
36 |
+
padding: 10px;
|
37 |
+
border: 1px solid #E0E2E3;
|
38 |
+
-webkit-transition: border-color .2s ease-in-out, background .2s ease-in-out;
|
39 |
+
-moz-transition: border-color .2s ease-in-out, background .2s ease-in-out;
|
40 |
+
-ms-transition: border-color .2s ease-in-out, background .2s ease-in-out;
|
41 |
+
transition: border-color .2s ease-in-out, background .2s ease-in-out;
|
42 |
+
outline-offset: -2px;
|
43 |
+
box-sizing: border-box;
|
44 |
+
border-radius: 4px;
|
45 |
+
}
|
46 |
+
|
47 |
+
.sq-input,
|
48 |
+
.wc-square-credit-card-hosted-field {
|
49 |
+
width: 100%;
|
50 |
+
height: 3em;
|
51 |
+
}
|
52 |
+
|
53 |
+
#square-credit-card-sq-card-number {
|
54 |
+
padding-right: 55px;
|
55 |
+
background-image: url('#{$image_path}/card-cc-plain.svg');
|
56 |
+
background-repeat: no-repeat;
|
57 |
+
background-position: 99%;
|
58 |
+
background-size: 50px 31px;
|
59 |
+
|
60 |
+
@media only screen and (max-width : 320px) {
|
61 |
+
background-image: none;
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
.card-type-visa #square-credit-card-sq-card-number {
|
66 |
+
background-image: url('#{$image_path}/card-visa.svg');
|
67 |
+
}
|
68 |
+
|
69 |
+
.card-type-mastercard #square-credit-card-sq-card-number {
|
70 |
+
background-image: url('#{$image_path}/card-mastercard.svg');
|
71 |
+
}
|
72 |
+
|
73 |
+
.card-type-amex #square-credit-card-sq-card-number {
|
74 |
+
background-image: url('#{$image_path}/card-amex.svg');
|
75 |
+
}
|
76 |
+
|
77 |
+
.card-type-diners-club #square-credit-card-sq-card-number {
|
78 |
+
background-image: url('#{$image_path}/card-dinersclub.svg');
|
79 |
+
}
|
80 |
+
|
81 |
+
.card-type-maestro #square-credit-card-sq-card-number {
|
82 |
+
background-image: url('#{$image_path}/card-maestro.svg');
|
83 |
+
}
|
84 |
+
|
85 |
+
.card-type-jcb #square-credit-card-sq-card-number {
|
86 |
+
background-image: url('#{$image_path}/card-jcb.svg');
|
87 |
+
}
|
88 |
+
|
89 |
+
.card-type-discover #square-credit-card-sq-card-number {
|
90 |
+
background-image: url('#{$image_path}/card-discover.svg');
|
91 |
+
}
|
92 |
+
|
93 |
+
.card-type-invalid #square-credit-card-sq-card-number {
|
94 |
+
background-image: url('#{$image_path}/card-cc-invalid.svg');
|
95 |
+
}
|
96 |
+
|
97 |
+
.sq-input--focus {
|
98 |
+
border: 1px solid #4A90E2;
|
99 |
+
background-color: rgba(74,144,226,0.02);
|
100 |
+
}
|
101 |
+
|
102 |
+
.sq-input--error {
|
103 |
+
border: 1px solid #E02F2F;
|
104 |
+
background-color: rgba(244,47,47,0.02);
|
105 |
+
}
|
106 |
+
|
107 |
+
.sq-form-third {
|
108 |
+
float: left;
|
109 |
+
width: calc((100% - 32px) / 3);
|
110 |
+
padding: 0;
|
111 |
+
margin: 0 16px 16px 0;
|
112 |
+
}
|
113 |
+
|
114 |
+
.sq-form-third:last-of-type {
|
115 |
+
margin-right: 0;
|
116 |
+
}
|
117 |
+
}
|
assets/js/frontend/wc-square-digital-wallet.js
CHANGED
@@ -21,6 +21,7 @@ jQuery( document ).ready( ( $ ) => {
|
|
21 |
constructor( args ) {
|
22 |
this.args = args;
|
23 |
this.payment_request = args.payment_request;
|
|
|
24 |
this.wallet = '#wc-square-digital-wallet';
|
25 |
this.buttons = '.wc-square-wallet-buttons';
|
26 |
|
@@ -45,6 +46,7 @@ jQuery( document ).ready( ( $ ) => {
|
|
45 |
this.get_payment_request().then(
|
46 |
( response ) => {
|
47 |
this.payment_request = JSON.parse( response );
|
|
|
48 |
this.load_square_form();
|
49 |
this.unblock_ui();
|
50 |
},
|
@@ -334,6 +336,43 @@ jQuery( document ).ready( ( $ ) => {
|
|
334 |
data.billing_phone = billingContact.phone;
|
335 |
}
|
336 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
// AJAX process checkout.
|
338 |
this.process_digital_wallet_checkout( data ).then(
|
339 |
( response ) => {
|
@@ -346,6 +385,39 @@ jQuery( document ).ready( ( $ ) => {
|
|
346 |
);
|
347 |
}
|
348 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
/*
|
350 |
* Recalculate totals
|
351 |
*
|
@@ -355,6 +427,7 @@ jQuery( document ).ready( ( $ ) => {
|
|
355 |
return new Promise( ( resolve, reject ) => {
|
356 |
return $.post( this.get_ajax_url( 'recalculate_totals' ), data, ( response ) => {
|
357 |
if ( response.success ) {
|
|
|
358 |
return resolve( response.data );
|
359 |
}
|
360 |
return reject( response.data );
|
@@ -522,4 +595,3 @@ jQuery( document ).ready( ( $ ) => {
|
|
522 |
|
523 |
window.WC_Square_Digital_Wallet_Handler = WC_Square_Digital_Wallet_Handler;
|
524 |
} );
|
525 |
-
|
21 |
constructor( args ) {
|
22 |
this.args = args;
|
23 |
this.payment_request = args.payment_request;
|
24 |
+
this.total_amount = args.payment_request.total.amount;
|
25 |
this.wallet = '#wc-square-digital-wallet';
|
26 |
this.buttons = '.wc-square-wallet-buttons';
|
27 |
|
46 |
this.get_payment_request().then(
|
47 |
( response ) => {
|
48 |
this.payment_request = JSON.parse( response );
|
49 |
+
this.total_amount = this.payment_request.total.amount;
|
50 |
this.load_square_form();
|
51 |
this.unblock_ui();
|
52 |
},
|
336 |
data.billing_phone = billingContact.phone;
|
337 |
}
|
338 |
|
339 |
+
// if SCA is enabled, verify the buyer and add verification token to data.
|
340 |
+
if ( this.args.is_3d_secure_enabled ) {
|
341 |
+
this.log( '3DS verification enabled. Verifying buyer' );
|
342 |
+
|
343 |
+
var self = this;
|
344 |
+
|
345 |
+
this.payment_form.verifyBuyer(
|
346 |
+
nonce,
|
347 |
+
self.get_verification_details( billingContact, shippingContact ),
|
348 |
+
function(err, verificationResult) {
|
349 |
+
if (err == null) {
|
350 |
+
// SCA verification complete. Do checkout.
|
351 |
+
self.log( '3DS verification successful' );
|
352 |
+
data['wc-square-credit-card-buyer-verification-token'] = verificationResult.token;
|
353 |
+
self.do_checkout( data );
|
354 |
+
} else {
|
355 |
+
// SCA verification failed. Render errors.
|
356 |
+
self.log( '3DS verification failed' );
|
357 |
+
self.log(err);
|
358 |
+
self.render_errors( [err.message] );
|
359 |
+
}
|
360 |
+
}
|
361 |
+
);
|
362 |
+
} else {
|
363 |
+
// SCA not enabled. Do checkout.
|
364 |
+
this.do_checkout( data );
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
/**
|
369 |
+
* Do Digital Wallet Checkout
|
370 |
+
*
|
371 |
+
* @since 2.4.2
|
372 |
+
*
|
373 |
+
* @param {Object} args
|
374 |
+
*/
|
375 |
+
do_checkout( data ) {
|
376 |
// AJAX process checkout.
|
377 |
this.process_digital_wallet_checkout( data ).then(
|
378 |
( response ) => {
|
385 |
);
|
386 |
}
|
387 |
|
388 |
+
/**
|
389 |
+
* Gets a verification details object to be used in verifyBuyer()
|
390 |
+
*
|
391 |
+
* @since 2.4.2
|
392 |
+
*
|
393 |
+
* @param {Object} billingContact
|
394 |
+
* @param {Object} shippingContact
|
395 |
+
*
|
396 |
+
* @return {Object} Verification details object.
|
397 |
+
*/
|
398 |
+
get_verification_details( billingContact, shippingContact ) {
|
399 |
+
const verification_details = {
|
400 |
+
intent: 'CHARGE',
|
401 |
+
amount: this.total_amount,
|
402 |
+
currencyCode: this.payment_request.currencyCode,
|
403 |
+
billingContact: {
|
404 |
+
familyName: billingContact.familyName ? billingContact.familyName : '',
|
405 |
+
givenName: billingContact.givenName ? billingContact.givenName : '',
|
406 |
+
email: shippingContact.email ? shippingContact.email : '',
|
407 |
+
country: billingContact.country ? billingContact.country.toUpperCase() : '',
|
408 |
+
region: billingContact.region ? billingContact.region : '',
|
409 |
+
city: billingContact.city ? billingContact.city : '',
|
410 |
+
postalCode: billingContact.postalCode ? billingContact.postalCode : '',
|
411 |
+
phone: shippingContact.phone ? shippingContact.phone : '',
|
412 |
+
addressLines: billingContact.addressLines ? billingContact.addressLines : '',
|
413 |
+
},
|
414 |
+
}
|
415 |
+
|
416 |
+
this.log( verification_details );
|
417 |
+
|
418 |
+
return verification_details;
|
419 |
+
}
|
420 |
+
|
421 |
/*
|
422 |
* Recalculate totals
|
423 |
*
|
427 |
return new Promise( ( resolve, reject ) => {
|
428 |
return $.post( this.get_ajax_url( 'recalculate_totals' ), data, ( response ) => {
|
429 |
if ( response.success ) {
|
430 |
+
this.total_amount = response.data.total.amount;
|
431 |
return resolve( response.data );
|
432 |
}
|
433 |
return reject( response.data );
|
595 |
|
596 |
window.WC_Square_Digital_Wallet_Handler = WC_Square_Digital_Wallet_Handler;
|
597 |
} );
|
|
assets/js/frontend/wc-square-digital-wallet.min.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1 |
-
"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}jQuery(document).ready(function($){var WC_Square_Digital_Wallet_Handler=function(){function WC_Square_Digital_Wallet_Handler(args){_classCallCheck(this,WC_Square_Digital_Wallet_Handler);this.args=args;this.payment_request=args.payment_request;this.wallet="#wc-square-digital-wallet";this.buttons=".wc-square-wallet-buttons";if($(this.wallet).length===0){return}$(this.wallet).hide();$(this.buttons).hide();this.build_digital_wallet();this.attach_page_events()}_createClass(WC_Square_Digital_Wallet_Handler,[{key:"build_digital_wallet",value:function build_digital_wallet(){var _this=this;this.block_ui();this.get_payment_request().then(function(response){_this.payment_request=JSON.parse(response);_this.load_square_form();_this.unblock_ui()},function(message){_this.log("[Square] Could not build payment request. "+message,"error");$(_this.wallet).hide()})}},{key:"attach_page_events",value:function attach_page_events(){var _this2=this;if(this.args.context==="product"){var addToCartButton=$(".single_add_to_cart_button");$("#wc-square-apple-pay, #wc-square-google-pay").on("click",function(e){if(addToCartButton.is(".disabled")){e.stopImmediatePropagation();if(addToCartButton.is(".wc-variation-is-unavailable")){window.alert(wc_add_to_cart_variation_params.i18n_unavailable_text)}else if(addToCartButton.is(".wc-variation-selection-needed")){window.alert(wc_add_to_cart_variation_params.i18n_make_a_selection_text)}return}_this2.add_to_cart()});$(document.body).on("woocommerce_variation_has_changed",function(){return _this2.build_digital_wallet()});$(".quantity").on("input",".qty",function(){return _this2.build_digital_wallet()})}if(this.args.context==="cart"){$(document.body).on("updated_cart_totals",function(){return _this2.build_digital_wallet()})}if(this.args.context==="checkout"){$(document.body).on("updated_checkout",function(){return _this2.build_digital_wallet()})}}},{key:"load_square_form",value:function load_square_form(){if(this.payment_form){this.log("[Square] Destroying digital wallet payment form");this.payment_form.destroy()}this.log("[Square] Building digital wallet payment form");this.payment_form=new SqPaymentForm(this.get_form_params());this.payment_form.build()}},{key:"get_form_params",value:function get_form_params(){var _this3=this;var params={applicationId:this.args.application_id,locationId:this.args.location_id,autobuild:false,applePay:{elementId:"wc-square-apple-pay"},googlePay:{elementId:"wc-square-google-pay"},callbacks:{paymentFormLoaded:function paymentFormLoaded(){return _this3.unblock_ui()},createPaymentRequest:function createPaymentRequest(){return _this3.create_payment_request()},methodsSupported:function methodsSupported(methods,unsupportedReason){return _this3.methods_supported(methods,unsupportedReason)},shippingContactChanged:function shippingContactChanged(shippingContact,done){return _this3.handle_shipping_address_changed(shippingContact,done)},shippingOptionChanged:function shippingOptionChanged(shippingOption,done){return _this3.handle_shipping_option_changed(shippingOption,done)},cardNonceResponseReceived:function cardNonceResponseReceived(errors,nonce,cardData,billingContact,shippingContact,shippingOption){_this3.handle_card_nonce_response(errors,nonce,cardData,billingContact,shippingContact,shippingOption)}}};if(this.payment_request.requestShippingAddress===false){delete params.callbacks.shippingOptionChanged}if(this.args.hide_button_options.includes("google")){delete params.googlePay}if(this.args.hide_button_options.includes("apple")){delete params.applePay}return params}},{key:"create_payment_request",value:function create_payment_request(){return this.payment_request}},{key:"methods_supported",value:function methods_supported(methods,unsupportedReason){if(methods.applePay===true||methods.googlePay===true){if(methods.applePay===true){$("#wc-square-apple-pay").show()}if(methods.googlePay===true){$("#wc-square-google-pay").show()}$(this.wallet).show()}else{this.log(unsupportedReason)}}},{key:"get_payment_request",value:function get_payment_request(){var _this4=this;return new Promise(function(resolve,reject){var data={context:_this4.args.context,security:_this4.args.payment_request_nonce};if(_this4.args.context==="product"){var product_data=_this4.get_product_data();$.extend(data,product_data)}$.post(_this4.get_ajax_url("get_payment_request"),data,function(response){if(response.success){return resolve(response.data)}return reject(response.data)})})}},{key:"handle_shipping_address_changed",value:function handle_shipping_address_changed(shippingContact,done){var data={context:this.args.context,shipping_contact:shippingContact.data,security:this.args.recalculate_totals_nonce};this.recalculate_totals(data).then(function(response){return done(response)},function(){return done({error:"Bad Request"})})}},{key:"handle_shipping_option_changed",value:function handle_shipping_option_changed(shippingOption,done){var data={context:this.args.context,shipping_option:shippingOption.data.id,security:this.args.recalculate_totals_nonce};this.recalculate_totals(data).then(function(response){return done(response)},function(){return done({error:"Bad Request"})})}},{key:"handle_card_nonce_response",value:function handle_card_nonce_response(errors,nonce,cardData,billingContact,shippingContact,shippingOption){var _this5=this;if(errors){return this.render_errors(errors)}if(!nonce){return this.render_errors(this.args.general_error)}this.block_ui();var data={action:"",_wpnonce:this.args.process_checkout_nonce,billing_first_name:billingContact.givenName?billingContact.givenName:"",billing_last_name:billingContact.familyName?billingContact.familyName:"",billing_company:"",billing_email:shippingContact.email?shippingContact.email:"",billing_phone:shippingContact.phone?shippingContact.phone:"",billing_country:billingContact.country?billingContact.country.toUpperCase():"",billing_address_1:billingContact.addressLines&&billingContact.addressLines[0]?billingContact.addressLines[0]:"",billing_address_2:billingContact.addressLines&&billingContact.addressLines[1]?billingContact.addressLines[1]:"",billing_city:billingContact.city?billingContact.city:"",billing_state:billingContact.region?billingContact.region:"",billing_postcode:billingContact.postalCode?billingContact.postalCode:"",shipping_first_name:shippingContact.givenName?shippingContact.givenName:"",shipping_last_name:shippingContact.familyName?shippingContact.familyName:"",shipping_company:"",shipping_country:shippingContact.country?shippingContact.country.toUpperCase():"",shipping_address_1:shippingContact.addressLines&&shippingContact.addressLines[0]?shippingContact.addressLines[0]:"",shipping_address_2:shippingContact.addressLines&&shippingContact.addressLines[1]?shippingContact.addressLines[1]:"",shipping_city:shippingContact.city?shippingContact.city:"",shipping_state:shippingContact.region?shippingContact.region:"",shipping_postcode:shippingContact.postalCode?shippingContact.postalCode:"",shipping_method:[!shippingOption?null:shippingOption.id],order_comments:"",payment_method:"square_credit_card",ship_to_different_address:1,terms:1,"wc-square-credit-card-payment-nonce":nonce,"wc-square-credit-card-last-four":cardData.last_4?cardData.last_4:null,"wc-square-credit-card-exp-month":cardData.exp_month?cardData.exp_month:null,"wc-square-credit-card-exp-year":cardData.exp_year?cardData.exp_year:null,"wc-square-credit-card-payment-postcode":cardData.billing_postal_code?cardData.billing_postal_code:null,"wc-square-digital-wallet-type":cardData.digital_wallet_type};if(cardData.digital_wallet_type==="GOOGLE_PAY"){if(billingContact.givenName){data.billing_first_name=billingContact.givenName.split(" ").slice(0,1).join(" ");data.billing_last_name=billingContact.givenName.split(" ").slice(1).join(" ")}if(shippingContact.givenName){data.shipping_last_name=shippingContact.givenName.split(" ").slice(0,1).join(" ");data.shipping_last_name=shippingContact.givenName.split(" ").slice(1).join(" ")}}if(!data.billing_phone&&billingContact.phone){data.billing_phone=billingContact.phone}this.process_digital_wallet_checkout(data).then(function(response){window.location=response.redirect},function(response){_this5.log(response,"error");_this5.render_errors_html(response.messages)})}},{key:"recalculate_totals",value:function recalculate_totals(data){var _this6=this;return new Promise(function(resolve,reject){return $.post(_this6.get_ajax_url("recalculate_totals"),data,function(response){if(response.success){return resolve(response.data)}return reject(response.data)})})}},{key:"get_product_data",value:function get_product_data(){var product_id=$(".single_add_to_cart_button").val();var attributes={};if($(".single_variation_wrap").length){product_id=$(".single_variation_wrap").find("input[name=\"product_id\"]").val();if($(".variations_form").length){$(".variations_form").find(".variations select").each(function(index,select){var attribute_name=$(select).data("attribute_name")||$(select).attr("name");var value=$(select).val()||"";return attributes[attribute_name]=value})}}return{product_id:product_id,quantity:$(".quantity .qty").val(),attributes:attributes}}},{key:"add_to_cart",value:function add_to_cart(){var _this7=this;var data={security:this.args.add_to_cart_nonce};var product_data=this.get_product_data();$.extend(data,product_data);$.post(this.get_ajax_url("add_to_cart"),data,function(response){if(response.error){return window.alert(response.data)}var data=JSON.parse(response.data);_this7.payment_request=data.payment_request;_this7.args.payment_request_nonce=data.payment_request_nonce;_this7.args.add_to_cart_nonce=data.add_to_cart_nonce;_this7.args.recalculate_totals_nonce=data.recalculate_totals_nonce;_this7.args.process_checkout_nonce=data.process_checkout_nonce})}},{key:"process_digital_wallet_checkout",value:function process_digital_wallet_checkout(data){var _this8=this;return new Promise(function(resolve,reject){$.post(_this8.get_ajax_url("process_checkout"),data,function(response){if(response.result==="success"){return resolve(response)}return reject(response)})})}},{key:"get_ajax_url",value:function get_ajax_url(request){return this.args.ajax_url.replace("%%endpoint%%","square_digital_wallet_"+request)}},{key:"render_errors_html",value:function render_errors_html(errors_html){$(".woocommerce-error, .woocommerce-message").remove();var element=this.args.context==="product"?$(".product"):$(".shop_table.cart").closest("form");element.before(errors_html);this.unblock_ui();$("html, body").animate({scrollTop:element.offset().top-100},1000)}},{key:"render_errors",value:function render_errors(errors){var error_message_html="<ul class=\"woocommerce-error\"><li>"+errors.join("</li><li>")+"</li></ul>";this.render_errors_html(error_message_html)}},{key:"block_ui",value:function block_ui(){$(this.buttons).block({message:null,overlayCSS:{background:"#fff",opacity:0.6}})}},{key:"unblock_ui",value:function unblock_ui(){$(this.buttons).unblock()}},{key:"log",value:function log(message){var type=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"notice";if(!this.args.logging_enabled){return}if(type==="error"){return console.error(message)}return console.log(message)}}]);return WC_Square_Digital_Wallet_Handler}();window.WC_Square_Digital_Wallet_Handler=WC_Square_Digital_Wallet_Handler});
|
2 |
//# sourceMappingURL=wc-square-digital-wallet.min.js.map
|
1 |
+
"use strict";function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}jQuery(document).ready(function($){var WC_Square_Digital_Wallet_Handler=function(){function WC_Square_Digital_Wallet_Handler(args){_classCallCheck(this,WC_Square_Digital_Wallet_Handler);this.args=args;this.payment_request=args.payment_request;this.total_amount=args.payment_request.total.amount;this.wallet="#wc-square-digital-wallet";this.buttons=".wc-square-wallet-buttons";if($(this.wallet).length===0){return}$(this.wallet).hide();$(this.buttons).hide();this.build_digital_wallet();this.attach_page_events()}_createClass(WC_Square_Digital_Wallet_Handler,[{key:"build_digital_wallet",value:function build_digital_wallet(){var _this=this;this.block_ui();this.get_payment_request().then(function(response){_this.payment_request=JSON.parse(response);_this.total_amount=_this.payment_request.total.amount;_this.load_square_form();_this.unblock_ui()},function(message){_this.log("[Square] Could not build payment request. "+message,"error");$(_this.wallet).hide()})}},{key:"attach_page_events",value:function attach_page_events(){var _this2=this;if(this.args.context==="product"){var addToCartButton=$(".single_add_to_cart_button");$("#wc-square-apple-pay, #wc-square-google-pay").on("click",function(e){if(addToCartButton.is(".disabled")){e.stopImmediatePropagation();if(addToCartButton.is(".wc-variation-is-unavailable")){window.alert(wc_add_to_cart_variation_params.i18n_unavailable_text)}else if(addToCartButton.is(".wc-variation-selection-needed")){window.alert(wc_add_to_cart_variation_params.i18n_make_a_selection_text)}return}_this2.add_to_cart()});$(document.body).on("woocommerce_variation_has_changed",function(){return _this2.build_digital_wallet()});$(".quantity").on("input",".qty",function(){return _this2.build_digital_wallet()})}if(this.args.context==="cart"){$(document.body).on("updated_cart_totals",function(){return _this2.build_digital_wallet()})}if(this.args.context==="checkout"){$(document.body).on("updated_checkout",function(){return _this2.build_digital_wallet()})}}},{key:"load_square_form",value:function load_square_form(){if(this.payment_form){this.log("[Square] Destroying digital wallet payment form");this.payment_form.destroy()}this.log("[Square] Building digital wallet payment form");this.payment_form=new SqPaymentForm(this.get_form_params());this.payment_form.build()}},{key:"get_form_params",value:function get_form_params(){var _this3=this;var params={applicationId:this.args.application_id,locationId:this.args.location_id,autobuild:false,applePay:{elementId:"wc-square-apple-pay"},googlePay:{elementId:"wc-square-google-pay"},callbacks:{paymentFormLoaded:function paymentFormLoaded(){return _this3.unblock_ui()},createPaymentRequest:function createPaymentRequest(){return _this3.create_payment_request()},methodsSupported:function methodsSupported(methods,unsupportedReason){return _this3.methods_supported(methods,unsupportedReason)},shippingContactChanged:function shippingContactChanged(shippingContact,done){return _this3.handle_shipping_address_changed(shippingContact,done)},shippingOptionChanged:function shippingOptionChanged(shippingOption,done){return _this3.handle_shipping_option_changed(shippingOption,done)},cardNonceResponseReceived:function cardNonceResponseReceived(errors,nonce,cardData,billingContact,shippingContact,shippingOption){_this3.handle_card_nonce_response(errors,nonce,cardData,billingContact,shippingContact,shippingOption)}}};if(this.payment_request.requestShippingAddress===false){delete params.callbacks.shippingOptionChanged}if(this.args.hide_button_options.includes("google")){delete params.googlePay}if(this.args.hide_button_options.includes("apple")){delete params.applePay}return params}},{key:"create_payment_request",value:function create_payment_request(){return this.payment_request}},{key:"methods_supported",value:function methods_supported(methods,unsupportedReason){if(methods.applePay===true||methods.googlePay===true){if(methods.applePay===true){$("#wc-square-apple-pay").show()}if(methods.googlePay===true){$("#wc-square-google-pay").show()}$(this.wallet).show()}else{this.log(unsupportedReason)}}},{key:"get_payment_request",value:function get_payment_request(){var _this4=this;return new Promise(function(resolve,reject){var data={context:_this4.args.context,security:_this4.args.payment_request_nonce};if(_this4.args.context==="product"){var product_data=_this4.get_product_data();$.extend(data,product_data)}$.post(_this4.get_ajax_url("get_payment_request"),data,function(response){if(response.success){return resolve(response.data)}return reject(response.data)})})}},{key:"handle_shipping_address_changed",value:function handle_shipping_address_changed(shippingContact,done){var data={context:this.args.context,shipping_contact:shippingContact.data,security:this.args.recalculate_totals_nonce};this.recalculate_totals(data).then(function(response){return done(response)},function(){return done({error:"Bad Request"})})}},{key:"handle_shipping_option_changed",value:function handle_shipping_option_changed(shippingOption,done){var data={context:this.args.context,shipping_option:shippingOption.data.id,security:this.args.recalculate_totals_nonce};this.recalculate_totals(data).then(function(response){return done(response)},function(){return done({error:"Bad Request"})})}},{key:"handle_card_nonce_response",value:function handle_card_nonce_response(errors,nonce,cardData,billingContact,shippingContact,shippingOption){if(errors){return this.render_errors(errors)}if(!nonce){return this.render_errors(this.args.general_error)}this.block_ui();var data={action:"",_wpnonce:this.args.process_checkout_nonce,billing_first_name:billingContact.givenName?billingContact.givenName:"",billing_last_name:billingContact.familyName?billingContact.familyName:"",billing_company:"",billing_email:shippingContact.email?shippingContact.email:"",billing_phone:shippingContact.phone?shippingContact.phone:"",billing_country:billingContact.country?billingContact.country.toUpperCase():"",billing_address_1:billingContact.addressLines&&billingContact.addressLines[0]?billingContact.addressLines[0]:"",billing_address_2:billingContact.addressLines&&billingContact.addressLines[1]?billingContact.addressLines[1]:"",billing_city:billingContact.city?billingContact.city:"",billing_state:billingContact.region?billingContact.region:"",billing_postcode:billingContact.postalCode?billingContact.postalCode:"",shipping_first_name:shippingContact.givenName?shippingContact.givenName:"",shipping_last_name:shippingContact.familyName?shippingContact.familyName:"",shipping_company:"",shipping_country:shippingContact.country?shippingContact.country.toUpperCase():"",shipping_address_1:shippingContact.addressLines&&shippingContact.addressLines[0]?shippingContact.addressLines[0]:"",shipping_address_2:shippingContact.addressLines&&shippingContact.addressLines[1]?shippingContact.addressLines[1]:"",shipping_city:shippingContact.city?shippingContact.city:"",shipping_state:shippingContact.region?shippingContact.region:"",shipping_postcode:shippingContact.postalCode?shippingContact.postalCode:"",shipping_method:[!shippingOption?null:shippingOption.id],order_comments:"",payment_method:"square_credit_card",ship_to_different_address:1,terms:1,"wc-square-credit-card-payment-nonce":nonce,"wc-square-credit-card-last-four":cardData.last_4?cardData.last_4:null,"wc-square-credit-card-exp-month":cardData.exp_month?cardData.exp_month:null,"wc-square-credit-card-exp-year":cardData.exp_year?cardData.exp_year:null,"wc-square-credit-card-payment-postcode":cardData.billing_postal_code?cardData.billing_postal_code:null,"wc-square-digital-wallet-type":cardData.digital_wallet_type};if(cardData.digital_wallet_type==="GOOGLE_PAY"){if(billingContact.givenName){data.billing_first_name=billingContact.givenName.split(" ").slice(0,1).join(" ");data.billing_last_name=billingContact.givenName.split(" ").slice(1).join(" ")}if(shippingContact.givenName){data.shipping_last_name=shippingContact.givenName.split(" ").slice(0,1).join(" ");data.shipping_last_name=shippingContact.givenName.split(" ").slice(1).join(" ")}}if(!data.billing_phone&&billingContact.phone){data.billing_phone=billingContact.phone}if(this.args.is_3d_secure_enabled){this.log("3DS verification enabled. Verifying buyer");var self=this;this.payment_form.verifyBuyer(nonce,self.get_verification_details(billingContact,shippingContact),function(err,verificationResult){if(err==null){self.log("3DS verification successful");data["wc-square-credit-card-buyer-verification-token"]=verificationResult.token;self.do_checkout(data)}else{self.log("3DS verification failed");self.log(err);self.render_errors([err.message])}})}else{this.do_checkout(data)}}},{key:"do_checkout",value:function do_checkout(data){var _this5=this;this.process_digital_wallet_checkout(data).then(function(response){window.location=response.redirect},function(response){_this5.log(response,"error");_this5.render_errors_html(response.messages)})}},{key:"get_verification_details",value:function get_verification_details(billingContact,shippingContact){var verification_details={intent:"CHARGE",amount:this.total_amount,currencyCode:this.payment_request.currencyCode,billingContact:{familyName:billingContact.familyName?billingContact.familyName:"",givenName:billingContact.givenName?billingContact.givenName:"",email:shippingContact.email?shippingContact.email:"",country:billingContact.country?billingContact.country.toUpperCase():"",region:billingContact.region?billingContact.region:"",city:billingContact.city?billingContact.city:"",postalCode:billingContact.postalCode?billingContact.postalCode:"",phone:shippingContact.phone?shippingContact.phone:"",addressLines:billingContact.addressLines?billingContact.addressLines:""}};this.log(verification_details);return verification_details}},{key:"recalculate_totals",value:function recalculate_totals(data){var _this6=this;return new Promise(function(resolve,reject){return $.post(_this6.get_ajax_url("recalculate_totals"),data,function(response){if(response.success){_this6.total_amount=response.data.total.amount;return resolve(response.data)}return reject(response.data)})})}},{key:"get_product_data",value:function get_product_data(){var product_id=$(".single_add_to_cart_button").val();var attributes={};if($(".single_variation_wrap").length){product_id=$(".single_variation_wrap").find("input[name=\"product_id\"]").val();if($(".variations_form").length){$(".variations_form").find(".variations select").each(function(index,select){var attribute_name=$(select).data("attribute_name")||$(select).attr("name");var value=$(select).val()||"";return attributes[attribute_name]=value})}}return{product_id:product_id,quantity:$(".quantity .qty").val(),attributes:attributes}}},{key:"add_to_cart",value:function add_to_cart(){var _this7=this;var data={security:this.args.add_to_cart_nonce};var product_data=this.get_product_data();$.extend(data,product_data);$.post(this.get_ajax_url("add_to_cart"),data,function(response){if(response.error){return window.alert(response.data)}var data=JSON.parse(response.data);_this7.payment_request=data.payment_request;_this7.args.payment_request_nonce=data.payment_request_nonce;_this7.args.add_to_cart_nonce=data.add_to_cart_nonce;_this7.args.recalculate_totals_nonce=data.recalculate_totals_nonce;_this7.args.process_checkout_nonce=data.process_checkout_nonce})}},{key:"process_digital_wallet_checkout",value:function process_digital_wallet_checkout(data){var _this8=this;return new Promise(function(resolve,reject){$.post(_this8.get_ajax_url("process_checkout"),data,function(response){if(response.result==="success"){return resolve(response)}return reject(response)})})}},{key:"get_ajax_url",value:function get_ajax_url(request){return this.args.ajax_url.replace("%%endpoint%%","square_digital_wallet_"+request)}},{key:"render_errors_html",value:function render_errors_html(errors_html){$(".woocommerce-error, .woocommerce-message").remove();var element=this.args.context==="product"?$(".product"):$(".shop_table.cart").closest("form");element.before(errors_html);this.unblock_ui();$("html, body").animate({scrollTop:element.offset().top-100},1000)}},{key:"render_errors",value:function render_errors(errors){var error_message_html="<ul class=\"woocommerce-error\"><li>"+errors.join("</li><li>")+"</li></ul>";this.render_errors_html(error_message_html)}},{key:"block_ui",value:function block_ui(){$(this.buttons).block({message:null,overlayCSS:{background:"#fff",opacity:0.6}})}},{key:"unblock_ui",value:function unblock_ui(){$(this.buttons).unblock()}},{key:"log",value:function log(message){var type=arguments.length>1&&arguments[1]!==undefined?arguments[1]:"notice";if(!this.args.logging_enabled){return}if(type==="error"){return console.error(message)}return console.log(message)}}]);return WC_Square_Digital_Wallet_Handler}();window.WC_Square_Digital_Wallet_Handler=WC_Square_Digital_Wallet_Handler});
|
2 |
//# sourceMappingURL=wc-square-digital-wallet.min.js.map
|
assets/js/frontend/wc-square-digital-wallet.min.js.map
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"version":3,"sources":["wc-square-digital-wallet.js"],"names":["jQuery","document","ready","$","WC_Square_Digital_Wallet_Handler","args","payment_request","wallet","buttons","length","hide","build_digital_wallet","attach_page_events","block_ui","get_payment_request","then","response","JSON","parse","load_square_form","unblock_ui","message","log","context","addToCartButton","on","e","is","stopImmediatePropagation","window","alert","wc_add_to_cart_variation_params","i18n_unavailable_text","i18n_make_a_selection_text","add_to_cart","body","payment_form","destroy","SqPaymentForm","get_form_params","build","params","applicationId","application_id","locationId","location_id","autobuild","applePay","elementId","googlePay","callbacks","paymentFormLoaded","createPaymentRequest","create_payment_request","methodsSupported","methods","unsupportedReason","methods_supported","shippingContactChanged","shippingContact","done","handle_shipping_address_changed","shippingOptionChanged","shippingOption","handle_shipping_option_changed","cardNonceResponseReceived","errors","nonce","cardData","billingContact","handle_card_nonce_response","requestShippingAddress","hide_button_options","includes","show","Promise","resolve","reject","data","security","payment_request_nonce","product_data","get_product_data","extend","post","get_ajax_url","success","shipping_contact","recalculate_totals_nonce","recalculate_totals","error","shipping_option","id","render_errors","general_error","action","_wpnonce","process_checkout_nonce","billing_first_name","givenName","billing_last_name","familyName","billing_company","billing_email","email","billing_phone","phone","billing_country","country","toUpperCase","billing_address_1","addressLines","billing_address_2","billing_city","city","billing_state","region","billing_postcode","postalCode","shipping_first_name","shipping_last_name","shipping_company","shipping_country","shipping_address_1","shipping_address_2","shipping_city","shipping_state","shipping_postcode","shipping_method","order_comments","payment_method","ship_to_different_address","terms","last_4","exp_month","exp_year","billing_postal_code","digital_wallet_type","split","slice","join","process_digital_wallet_checkout","location","redirect","render_errors_html","messages","product_id","val","attributes","find","each","index","select","attribute_name","attr","value","quantity","add_to_cart_nonce","result","request","ajax_url","replace","errors_html","remove","element","closest","before","animate","scrollTop","offset","top","error_message_html","block","overlayCSS","background","opacity","unblock","type","logging_enabled","console"],"mappings":"ioBAOAA,MAAM,CAAEC,QAAF,CAAN,CAAmBC,KAAnB,CAA0B,SAAEC,CAAF,CAAS,IAM5BC,CAAAA,gC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jB,CAAC,CAAE,YAAF,CAAD,CAAkBoK,OAAlB,CAA2B,CAC1BC,SAAS,CAAEJ,OAAO,CAACK,MAAR,GAAiBC,GAAjB,CAAuB,GADR,CAA3B,CAEG,IAFH,CAGA,CA5cgC,6BAmdjC,uBAAexG,MAAf,CAAwB,CACvB,GAAMyG,CAAAA,kBAAkB,CAAG,uCAAuCzG,MAAM,CAAC0E,IAAP,CAAa,WAAb,CAAvC,CAAoE,YAA/F,CACA,KAAKI,kBAAL,CAAyB2B,kBAAzB,CACA,CAtdgC,wBA6djC,mBAAW,CACVxK,CAAC,CAAE,KAAKK,OAAP,CAAD,CAAkBoK,KAAlB,CAAyB,CACxBvJ,OAAO,CAAE,IADe,CAExBwJ,UAAU,CAAE,CACXC,UAAU,CAAE,MADD,CAEXC,OAAO,CAAE,GAFE,CAFY,CAAzB,CAOA,CAregC,0BA4ejC,qBAAa,CACZ5K,CAAC,CAAE,KAAKK,OAAP,CAAD,CAAkBwK,OAAlB,EACA,CA9egC,mBAqfjC,aAAK3J,OAAL,CAAgC,IAAlB4J,CAAAA,IAAkB,2DAAX,QAAW,CAE/B,GAAK,CAAE,KAAK5K,IAAL,CAAU6K,eAAjB,CAAmC,CAClC,MACA,CAED,GAAKD,IAAI,GAAK,OAAd,CAAwB,CACvB,MAAOE,CAAAA,OAAO,CAACzF,KAAR,CAAerE,OAAf,CACP,CAED,MAAO8J,CAAAA,OAAO,CAAC7J,GAAR,CAAaD,OAAb,CACP,CAhgBgC,+CAmgBlCQ,MAAM,CAACzB,gCAAP,CAA0CA,gCAC1C,CApgBD","sourcesContent":["/* global wc_add_to_cart_variation_params, SqPaymentForm */\n\n/**\n * Square Credit Card Digital Wallet Handler class.\n *\n * @since 2.3\n */\njQuery( document ).ready( ( $ ) => {\n\t/**\n\t * Square Credit Card Digital Wallet Handler class.\n\t *\n\t * @since 2.3\n\t */\n\tclass WC_Square_Digital_Wallet_Handler {\n\t\t/**\n\t\t * Setup handler\n\t\t *\n\t\t * @param {Array} args\n\t\t * @since 2.3\n\t\t */\n\t\tconstructor( args ) {\n\t\t\tthis.args = args;\n\t\t\tthis.payment_request = args.payment_request;\n\t\t\tthis.wallet = '#wc-square-digital-wallet';\n\t\t\tthis.buttons = '.wc-square-wallet-buttons';\n\n\t\t\tif ( $( this.wallet ).length === 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t$( this.wallet ).hide();\n\t\t\t$( this.buttons ).hide();\n\n\t\t\tthis.build_digital_wallet();\n\t\t\tthis.attach_page_events();\n\t\t}\n\n\t\t/**\n\t\t * Fetch a new payment request object and reload the SqPaymentForm\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tbuild_digital_wallet() {\n\t\t\tthis.block_ui();\n\t\t\tthis.get_payment_request().then(\n\t\t\t\t( response ) => {\n\t\t\t\t\tthis.payment_request = JSON.parse( response );\n\t\t\t\t\tthis.load_square_form();\n\t\t\t\t\tthis.unblock_ui();\n\t\t\t\t},\n\t\t\t\t( message ) => {\n\t\t\t\t\tthis.log( '[Square] Could not build payment request. ' + message, 'error' );\n\t\t\t\t\t$( this.wallet ).hide();\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Add page event listeners\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tattach_page_events() {\n\t\t\tif ( this.args.context === 'product' ) {\n\t\t\t\tconst addToCartButton = $( '.single_add_to_cart_button' );\n\n\t\t\t\t$( '#wc-square-apple-pay, #wc-square-google-pay' ).on( 'click', ( e ) => {\n\t\t\t\t\tif ( addToCartButton.is( '.disabled' ) ) {\n\t\t\t\t\t\te.stopImmediatePropagation();\n\n\t\t\t\t\t\tif ( addToCartButton.is( '.wc-variation-is-unavailable' ) ) {\n\t\t\t\t\t\t\twindow.alert( wc_add_to_cart_variation_params.i18n_unavailable_text );\n\t\t\t\t\t\t} else if ( addToCartButton.is( '.wc-variation-selection-needed' ) ) {\n\t\t\t\t\t\t\twindow.alert( wc_add_to_cart_variation_params.i18n_make_a_selection_text );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.add_to_cart();\n\t\t\t\t} );\n\n\t\t\t\t$( document.body ).on( 'woocommerce_variation_has_changed', () => this.build_digital_wallet() );\n\n\t\t\t\t$( '.quantity' ).on( 'input', '.qty', () => this.build_digital_wallet() );\n\t\t\t}\n\n\t\t\tif ( this.args.context === 'cart' ) {\n\t\t\t\t$( document.body ).on( 'updated_cart_totals', () => this.build_digital_wallet() );\n\t\t\t}\n\n\t\t\tif ( this.args.context === 'checkout' ) {\n\t\t\t\t$( document.body ).on( 'updated_checkout', () => this.build_digital_wallet() );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Load the digital wallet payment form\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tload_square_form() {\n\t\t\tif ( this.payment_form ) {\n\t\t\t\tthis.log( '[Square] Destroying digital wallet payment form' );\n\t\t\t\tthis.payment_form.destroy();\n\t\t\t}\n\n\t\t\tthis.log( '[Square] Building digital wallet payment form' );\n\t\t\tthis.payment_form = new SqPaymentForm( this.get_form_params() );\n\t\t\tthis.payment_form.build();\n\t\t}\n\n\t\t/**\n\t\t * Gets the Square payment form params.\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_form_params() {\n\t\t\tconst params = {\n\t\t\t\tapplicationId: this.args.application_id,\n\t\t\t\tlocationId: this.args.location_id,\n\t\t\t\tautobuild: false,\n\t\t\t\tapplePay: {\n\t\t\t\t\telementId: 'wc-square-apple-pay',\n\t\t\t\t},\n\t\t\t\tgooglePay: {\n\t\t\t\t\telementId: 'wc-square-google-pay',\n\t\t\t\t},\n\t\t\t\tcallbacks: {\n\t\t\t\t\tpaymentFormLoaded: () => this.unblock_ui(),\n\t\t\t\t\tcreatePaymentRequest: () => this.create_payment_request(),\n\t\t\t\t\tmethodsSupported: ( methods, unsupportedReason ) => this.methods_supported( methods, unsupportedReason ),\n\t\t\t\t\tshippingContactChanged: ( shippingContact, done ) => this.handle_shipping_address_changed( shippingContact, done ),\n\t\t\t\t\tshippingOptionChanged: ( shippingOption, done ) => this.handle_shipping_option_changed( shippingOption, done ),\n\t\t\t\t\tcardNonceResponseReceived: ( errors, nonce, cardData, billingContact, shippingContact, shippingOption ) => {\n\t\t\t\t\t\tthis.handle_card_nonce_response( errors, nonce, cardData, billingContact, shippingContact, shippingOption );\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\n\t\t\t// Fix console errors for Google Pay when there are no shipping options set. See note in Square documentation under shippingOptions: https://developer.squareup.com/docs/api/paymentform#paymentrequestfields.\n\t\t\tif ( this.payment_request.requestShippingAddress === false ) {\n\t\t\t\tdelete params.callbacks.shippingOptionChanged;\n\t\t\t}\n\n\t\t\t// Remove support for Google Pay and/or Apple Pay if chosen in settings.\n\t\t\tif ( this.args.hide_button_options.includes( 'google' ) ) {\n\t\t\t\tdelete params.googlePay;\n\t\t\t}\n\n\t\t\tif ( this.args.hide_button_options.includes( 'apple' ) ) {\n\t\t\t\tdelete params.applePay;\n\t\t\t}\n\n\t\t\treturn params;\n\t\t}\n\n\t\t/**\n\t\t * Sets the a payment request object for the Square Payment Form\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tcreate_payment_request() {\n\t\t\treturn this.payment_request;\n\t\t}\n\n\t\t/**\n\t\t * Check which methods are supported and show/hide the correct buttons on frontend\n\t\t * Reference: https://developer.squareup.com/docs/api/paymentform#methodssupported\n\t\t *\n\t\t * @param {Object} methods\n\t\t * @param {string} unsupportedReason\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tmethods_supported( methods, unsupportedReason ) {\n\t\t\tif ( methods.applePay === true || methods.googlePay === true ) {\n\t\t\t\tif ( methods.applePay === true ) {\n\t\t\t\t\t$( '#wc-square-apple-pay' ).show();\n\t\t\t\t}\n\n\t\t\t\tif ( methods.googlePay === true ) {\n\t\t\t\t\t$( '#wc-square-google-pay' ).show();\n\t\t\t\t}\n\n\t\t\t\t$( this.wallet ).show();\n\t\t\t} else {\n\t\t\t\tthis.log( unsupportedReason );\n\t\t\t}\n\t\t}\n\n\t\t/*\n\t\t * Get the payment request on a product page\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_payment_request() {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tconst data = {\n\t\t\t\t\tcontext: this.args.context,\n\t\t\t\t\tsecurity: this.args.payment_request_nonce,\n\t\t\t\t};\n\n\t\t\t\tif ( this.args.context === 'product' ) {\n\t\t\t\t\tconst product_data = this.get_product_data();\n\t\t\t\t\t$.extend( data, product_data );\n\t\t\t\t}\n\t\t\t\t// retrieve a payment request object.\n\t\t\t\t$.post( this.get_ajax_url( 'get_payment_request' ), data, ( response ) => {\n\t\t\t\t\tif ( response.success ) {\n\t\t\t\t\t\treturn resolve( response.data );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn reject( response.data );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Handle all shipping address recalculations in the Apple/Google Pay window\n\t\t *\n\t\t * Reference: https://developer.squareup.com/docs/api/paymentform#shippingcontactchanged\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\thandle_shipping_address_changed( shippingContact, done ) {\n\t\t\tconst data = {\n\t\t\t\tcontext: this.args.context,\n\t\t\t\tshipping_contact: shippingContact.data,\n\t\t\t\tsecurity: this.args.recalculate_totals_nonce,\n\t\t\t};\n\n\t\t\t// send ajax request get_shipping_options.\n\t\t\tthis.recalculate_totals( data ).then( ( response ) => {\n\t\t\t\treturn done( response );\n\t\t\t}, () => {\n\t\t\t\treturn done( {\n\t\t\t\t\terror: 'Bad Request',\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Handle all shipping method changes in the Apple/Google Pay window\n\t\t *\n\t\t * Reference: https://developer.squareup.com/docs/api/paymentform#shippingoptionchanged\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\thandle_shipping_option_changed( shippingOption, done ) {\n\t\t\tconst data = {\n\t\t\t\tcontext: this.args.context,\n\t\t\t\tshipping_option: shippingOption.data.id,\n\t\t\t\tsecurity: this.args.recalculate_totals_nonce,\n\t\t\t};\n\n\t\t\tthis.recalculate_totals( data ).then( ( response ) => {\n\t\t\t\treturn done( response );\n\t\t\t}, () => {\n\t\t\t\treturn done( {\n\t\t\t\t\terror: 'Bad Request',\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Handle the payment response.\n\t\t *\n\t\t * On success, set the checkout billing/shipping data and submit the checkout.\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\thandle_card_nonce_response( errors, nonce, cardData, billingContact, shippingContact, shippingOption ) {\n\t\t\tif ( errors ) {\n\t\t\t\treturn this.render_errors( errors );\n\t\t\t}\n\n\t\t\tif ( ! nonce ) {\n\t\t\t\treturn this.render_errors( this.args.general_error );\n\t\t\t}\n\n\t\t\tthis.block_ui();\n\n\t\t\tconst data = {\n\t\t\t\taction: '',\n\t\t\t\t_wpnonce: this.args.process_checkout_nonce,\n\t\t\t\tbilling_first_name: billingContact.givenName ? billingContact.givenName : '',\n\t\t\t\tbilling_last_name: billingContact.familyName ? billingContact.familyName : '',\n\t\t\t\tbilling_company: '',\n\t\t\t\tbilling_email: shippingContact.email ? shippingContact.email : '',\n\t\t\t\tbilling_phone: shippingContact.phone ? shippingContact.phone : '',\n\t\t\t\tbilling_country: billingContact.country ? billingContact.country.toUpperCase() : '',\n\t\t\t\tbilling_address_1: billingContact.addressLines && billingContact.addressLines[ 0 ] ? billingContact.addressLines[ 0 ] : '',\n\t\t\t\tbilling_address_2: billingContact.addressLines && billingContact.addressLines[ 1 ] ? billingContact.addressLines[ 1 ] : '',\n\t\t\t\tbilling_city: billingContact.city ? billingContact.city : '',\n\t\t\t\tbilling_state: billingContact.region ? billingContact.region : '',\n\t\t\t\tbilling_postcode: billingContact.postalCode ? billingContact.postalCode : '',\n\t\t\t\tshipping_first_name: shippingContact.givenName ? shippingContact.givenName : '',\n\t\t\t\tshipping_last_name: shippingContact.familyName ? shippingContact.familyName : '',\n\t\t\t\tshipping_company: '',\n\t\t\t\tshipping_country: shippingContact.country ? shippingContact.country.toUpperCase() : '',\n\t\t\t\tshipping_address_1: shippingContact.addressLines && shippingContact.addressLines[ 0 ] ? shippingContact.addressLines[ 0 ] : '',\n\t\t\t\tshipping_address_2: shippingContact.addressLines && shippingContact.addressLines[ 1 ] ? shippingContact.addressLines[ 1 ] : '',\n\t\t\t\tshipping_city: shippingContact.city ? shippingContact.city : '',\n\t\t\t\tshipping_state: shippingContact.region ? shippingContact.region : '',\n\t\t\t\tshipping_postcode: shippingContact.postalCode ? shippingContact.postalCode : '',\n\t\t\t\tshipping_method: [ ! shippingOption ? null : shippingOption.id ],\n\t\t\t\torder_comments: '',\n\t\t\t\tpayment_method: 'square_credit_card',\n\t\t\t\tship_to_different_address: 1,\n\t\t\t\tterms: 1,\n\t\t\t\t'wc-square-credit-card-payment-nonce': nonce,\n\t\t\t\t'wc-square-credit-card-last-four': cardData.last_4 ? cardData.last_4 : null,\n\t\t\t\t'wc-square-credit-card-exp-month': cardData.exp_month ? cardData.exp_month : null,\n\t\t\t\t'wc-square-credit-card-exp-year': cardData.exp_year ? cardData.exp_year : null,\n\t\t\t\t'wc-square-credit-card-payment-postcode': cardData.billing_postal_code ? cardData.billing_postal_code : null,\n\t\t\t\t'wc-square-digital-wallet-type': cardData.digital_wallet_type,\n\t\t\t};\n\n\t\t\t// handle slightly different mapping for Google Pay (Google returns full name as a single string).\n\t\t\tif ( cardData.digital_wallet_type === 'GOOGLE_PAY' ) {\n\t\t\t\tif ( billingContact.givenName ) {\n\t\t\t\t\tdata.billing_first_name = billingContact.givenName.split( ' ' ).slice( 0, 1 ).join( ' ' );\n\t\t\t\t\tdata.billing_last_name = billingContact.givenName.split( ' ' ).slice( 1 ).join( ' ' );\n\t\t\t\t}\n\n\t\t\t\tif ( shippingContact.givenName ) {\n\t\t\t\t\tdata.shipping_last_name = shippingContact.givenName.split( ' ' ).slice( 0, 1 ).join( ' ' );\n\t\t\t\t\tdata.shipping_last_name = shippingContact.givenName.split( ' ' ).slice( 1 ).join( ' ' );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if the billing_phone was not found on shippingContact, use the value on billingContact if that exists.\n\t\t\tif ( ! data.billing_phone && billingContact.phone ) {\n\t\t\t\tdata.billing_phone = billingContact.phone;\n\t\t\t}\n\n\t\t\t// AJAX process checkout.\n\t\t\tthis.process_digital_wallet_checkout( data ).then(\n\t\t\t\t( response ) => {\n\t\t\t\t\twindow.location = response.redirect;\n\t\t\t\t},\n\t\t\t\t( response ) => {\n\t\t\t\t\tthis.log( response, 'error' );\n\t\t\t\t\tthis.render_errors_html( response.messages );\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t/*\n\t\t * Recalculate totals\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\trecalculate_totals( data ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\treturn $.post( this.get_ajax_url( 'recalculate_totals' ), data, ( response ) => {\n\t\t\t\t\tif ( response.success ) {\n\t\t\t\t\t\treturn resolve( response.data );\n\t\t\t\t\t}\n\t\t\t\t\treturn reject( response.data );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Get the product data for building the payment request on the product page\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_product_data() {\n\t\t\tlet product_id = $( '.single_add_to_cart_button' ).val();\n\n\t\t\tconst attributes = {};\n\n\t\t\t// Check if product is a variable product.\n\t\t\tif ( $( '.single_variation_wrap' ).length ) {\n\t\t\t\tproduct_id = $( '.single_variation_wrap' ).find( 'input[name=\"product_id\"]' ).val();\n\t\t\t\tif ( $( '.variations_form' ).length ) {\n\t\t\t\t\t$( '.variations_form' ).find( '.variations select' ).each( ( index, select ) => {\n\t\t\t\t\t\tconst attribute_name = $( select ).data( 'attribute_name' ) || $( select ).attr( 'name' );\n\t\t\t\t\t\tconst value = $( select ).val() || '';\n\t\t\t\t\t\treturn attributes[ attribute_name ] = value;\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tproduct_id,\n\t\t\t\tquantity: $( '.quantity .qty' ).val(),\n\t\t\t\tattributes,\n\t\t\t};\n\t\t}\n\n\t\t/*\n\t\t * Add the product to the cart\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tadd_to_cart() {\n\t\t\tconst data = {\n\t\t\t\tsecurity: this.args.add_to_cart_nonce,\n\t\t\t};\n\t\t\tconst product_data = this.get_product_data();\n\t\t\t$.extend( data, product_data );\n\n\t\t\t// retrieve a payment request object.\n\t\t\t$.post( this.get_ajax_url( 'add_to_cart' ), data, ( response ) => {\n\t\t\t\tif ( response.error ) {\n\t\t\t\t\treturn window.alert( response.data );\n\t\t\t\t}\n\n\t\t\t\tconst data = JSON.parse( response.data );\n\t\t\t\tthis.payment_request = data.payment_request;\n\t\t\t\tthis.args.payment_request_nonce = data.payment_request_nonce;\n\t\t\t\tthis.args.add_to_cart_nonce = data.add_to_cart_nonce;\n\t\t\t\tthis.args.recalculate_totals_nonce = data.recalculate_totals_nonce;\n\t\t\t\tthis.args.process_checkout_nonce = data.process_checkout_nonce;\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Process the digital wallet checkout\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tprocess_digital_wallet_checkout( data ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\t$.post( this.get_ajax_url( 'process_checkout' ), data, ( response ) => {\n\t\t\t\t\tif ( response.result === 'success' ) {\n\t\t\t\t\t\treturn resolve( response );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn reject( response );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Helper function to return the ajax URL for the given request/action\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_ajax_url( request ) {\n\t\t\treturn this.args.ajax_url.replace( '%%endpoint%%', 'square_digital_wallet_' + request );\n\t\t}\n\n\t\t/*\n\t\t * Renders errors given the error message HTML\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\trender_errors_html( errors_html ) {\n\t\t\t// hide and remove any previous errors.\n\t\t\t$( '.woocommerce-error, .woocommerce-message' ).remove();\n\n\t\t\tconst element = this.args.context === 'product' ? $( '.product' ) : $( '.shop_table.cart' ).closest( 'form' );\n\n\t\t\t// add errors\n\t\t\telement.before( errors_html );\n\n\t\t\t// unblock UI\n\t\t\tthis.unblock_ui();\n\n\t\t\t// scroll to top\n\t\t\t$( 'html, body' ).animate( {\n\t\t\t\tscrollTop: element.offset().top - 100,\n\t\t\t}, 1000 );\n\t\t}\n\n\t\t/*\n\t\t * Renders errors\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\trender_errors( errors ) {\n\t\t\tconst error_message_html = '<ul class=\"woocommerce-error\"><li>' + errors.join( '</li><li>' ) + '</li></ul>';\n\t\t\tthis.render_errors_html( error_message_html );\n\t\t}\n\n\t\t/*\n\t\t * Block the Apple Pay and Google Pay buttons from being clicked which processing certain actions\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tblock_ui() {\n\t\t\t$( this.buttons ).block( {\n\t\t\t\tmessage: null,\n\t\t\t\toverlayCSS: {\n\t\t\t\t\tbackground: '#fff',\n\t\t\t\t\topacity: 0.6,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Unblock the wallet buttons\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tunblock_ui() {\n\t\t\t$( this.buttons ).unblock();\n\t\t}\n\n\t\t/*\n\t\t * Logs messages to the console when logging is turned on in the settings\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tlog( message, type = 'notice' ) {\n\t\t\t// if logging is disabled, bail.\n\t\t\tif ( ! this.args.logging_enabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( type === 'error' ) {\n\t\t\t\treturn console.error( message );\n\t\t\t}\n\n\t\t\treturn console.log( message );\n\t\t}\n\t}\n\n\twindow.WC_Square_Digital_Wallet_Handler = WC_Square_Digital_Wallet_Handler;\n} );\n\n"],"file":"wc-square-digital-wallet.min.js"}
|
1 |
+
{"version":3,"sources":["wc-square-digital-wallet.js"],"names":["jQuery","document","ready","$","WC_Square_Digital_Wallet_Handler","args","payment_request","total_amount","total","amount","wallet","buttons","length","hide","build_digital_wallet","attach_page_events","block_ui","get_payment_request","then","response","JSON","parse","load_square_form","unblock_ui","message","log","context","addToCartButton","on","e","is","stopImmediatePropagation","window","alert","wc_add_to_cart_variation_params","i18n_unavailable_text","i18n_make_a_selection_text","add_to_cart","body","payment_form","destroy","SqPaymentForm","get_form_params","build","params","applicationId","application_id","locationId","location_id","autobuild","applePay","elementId","googlePay","callbacks","paymentFormLoaded","createPaymentRequest","create_payment_request","methodsSupported","methods","unsupportedReason","methods_supported","shippingContactChanged","shippingContact","done","handle_shipping_address_changed","shippingOptionChanged","shippingOption","handle_shipping_option_changed","cardNonceResponseReceived","errors","nonce","cardData","billingContact","handle_card_nonce_response","requestShippingAddress","hide_button_options","includes","show","Promise","resolve","reject","data","security","payment_request_nonce","product_data","get_product_data","extend","post","get_ajax_url","success","shipping_contact","recalculate_totals_nonce","recalculate_totals","error","shipping_option","id","render_errors","general_error","action","_wpnonce","process_checkout_nonce","billing_first_name","givenName","billing_last_name","familyName","billing_company","billing_email","email","billing_phone","phone","billing_country","country","toUpperCase","billing_address_1","addressLines","billing_address_2","billing_city","city","billing_state","region","billing_postcode","postalCode","shipping_first_name","shipping_last_name","shipping_company","shipping_country","shipping_address_1","shipping_address_2","shipping_city","shipping_state","shipping_postcode","shipping_method","order_comments","payment_method","ship_to_different_address","terms","last_4","exp_month","exp_year","billing_postal_code","digital_wallet_type","split","slice","join","is_3d_secure_enabled","self","verifyBuyer","get_verification_details","err","verificationResult","token","do_checkout","process_digital_wallet_checkout","location","redirect","render_errors_html","messages","verification_details","intent","currencyCode","product_id","val","attributes","find","each","index","select","attribute_name","attr","value","quantity","add_to_cart_nonce","result","request","ajax_url","replace","errors_html","remove","element","closest","before","animate","scrollTop","offset","top","error_message_html","block","overlayCSS","background","opacity","unblock","type","logging_enabled","console"],"mappings":"ioBAOAA,MAAM,CAAEC,QAAF,CAAN,CAAmBC,KAAnB,CAA0B,SAAEC,CAAF,CAAS,IAM5BC,CAAAA,gCAN4B,YAajC,0CAAaC,IAAb,CAAoB,wDACnB,KAAKA,IAAL,CAAYA,IAAZ,CACA,KAAKC,eAAL,CAAuBD,IAAI,CAACC,eAA5B,CACA,KAAKC,YAAL,CAAoBF,IAAI,CAACC,eAAL,CAAqBE,KAArB,CAA2BC,MAA/C,CACA,KAAKC,MAAL,CAAc,2BAAd,CACA,KAAKC,OAAL,CAAe,2BAAf,CAEA,GAAKR,CAAC,CAAE,KAAKO,MAAP,CAAD,CAAiBE,MAAjB,GAA4B,CAAjC,CAAqC,CACpC,MACA,CAEDT,CAAC,CAAE,KAAKO,MAAP,CAAD,CAAiBG,IAAjB,GACAV,CAAC,CAAE,KAAKQ,OAAP,CAAD,CAAkBE,IAAlB,GAEA,KAAKC,oBAAL,GACA,KAAKC,kBAAL,EACA,CA7BgC,iFAoCjC,+BAAuB,gBACtB,KAAKC,QAAL,GACA,KAAKC,mBAAL,GAA2BC,IAA3B,CACC,SAAEC,QAAF,CAAgB,CACf,KAAI,CAACb,eAAL,CAAuBc,IAAI,CAACC,KAAL,CAAYF,QAAZ,CAAvB,CACA,KAAI,CAACZ,YAAL,CAAoB,KAAI,CAACD,eAAL,CAAqBE,KAArB,CAA2BC,MAA/C,CACA,KAAI,CAACa,gBAAL,GACA,KAAI,CAACC,UAAL,EACA,CANF,CAOC,SAAEC,OAAF,CAAe,CACd,KAAI,CAACC,GAAL,CAAU,6CAA+CD,OAAzD,CAAkE,OAAlE,EACArB,CAAC,CAAE,KAAI,CAACO,MAAP,CAAD,CAAiBG,IAAjB,E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AjB,CAAuB,GADR,CAA3B,CAEG,IAFH,CAGA,CArhBgC,6BA4hBjC,uBAAenH,MAAf,CAAwB,CACvB,GAAMoH,CAAAA,kBAAkB,CAAG,uCAAuCpH,MAAM,CAAC0E,IAAP,CAAa,WAAb,CAAvC,CAAoE,YAA/F,CACA,KAAKY,kBAAL,CAAyB8B,kBAAzB,CACA,CA/hBgC,wBAsiBjC,mBAAW,CACVtL,CAAC,CAAE,KAAKQ,OAAP,CAAD,CAAkB+K,KAAlB,CAAyB,CACxBlK,OAAO,CAAE,IADe,CAExBmK,UAAU,CAAE,CACXC,UAAU,CAAE,MADD,CAEXC,OAAO,CAAE,GAFE,CAFY,CAAzB,CAOA,CA9iBgC,0BAqjBjC,qBAAa,CACZ1L,CAAC,CAAE,KAAKQ,OAAP,CAAD,CAAkBmL,OAAlB,EACA,CAvjBgC,mBA8jBjC,aAAKtK,OAAL,CAAgC,IAAlBuK,CAAAA,IAAkB,2DAAX,QAAW,CAE/B,GAAK,CAAE,KAAK1L,IAAL,CAAU2L,eAAjB,CAAmC,CAClC,MACA,CAED,GAAKD,IAAI,GAAK,OAAd,CAAwB,CACvB,MAAOE,CAAAA,OAAO,CAACpG,KAAR,CAAerE,OAAf,CACP,CAED,MAAOyK,CAAAA,OAAO,CAACxK,GAAR,CAAaD,OAAb,CACP,CAzkBgC,+CA4kBlCQ,MAAM,CAAC5B,gCAAP,CAA0CA,gCAC1C,CA7kBD","sourcesContent":["/* global wc_add_to_cart_variation_params, SqPaymentForm */\n\n/**\n * Square Credit Card Digital Wallet Handler class.\n *\n * @since 2.3\n */\njQuery( document ).ready( ( $ ) => {\n\t/**\n\t * Square Credit Card Digital Wallet Handler class.\n\t *\n\t * @since 2.3\n\t */\n\tclass WC_Square_Digital_Wallet_Handler {\n\t\t/**\n\t\t * Setup handler\n\t\t *\n\t\t * @param {Array} args\n\t\t * @since 2.3\n\t\t */\n\t\tconstructor( args ) {\n\t\t\tthis.args = args;\n\t\t\tthis.payment_request = args.payment_request;\n\t\t\tthis.total_amount = args.payment_request.total.amount;\n\t\t\tthis.wallet = '#wc-square-digital-wallet';\n\t\t\tthis.buttons = '.wc-square-wallet-buttons';\n\n\t\t\tif ( $( this.wallet ).length === 0 ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t$( this.wallet ).hide();\n\t\t\t$( this.buttons ).hide();\n\n\t\t\tthis.build_digital_wallet();\n\t\t\tthis.attach_page_events();\n\t\t}\n\n\t\t/**\n\t\t * Fetch a new payment request object and reload the SqPaymentForm\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tbuild_digital_wallet() {\n\t\t\tthis.block_ui();\n\t\t\tthis.get_payment_request().then(\n\t\t\t\t( response ) => {\n\t\t\t\t\tthis.payment_request = JSON.parse( response );\n\t\t\t\t\tthis.total_amount = this.payment_request.total.amount;\n\t\t\t\t\tthis.load_square_form();\n\t\t\t\t\tthis.unblock_ui();\n\t\t\t\t},\n\t\t\t\t( message ) => {\n\t\t\t\t\tthis.log( '[Square] Could not build payment request. ' + message, 'error' );\n\t\t\t\t\t$( this.wallet ).hide();\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Add page event listeners\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tattach_page_events() {\n\t\t\tif ( this.args.context === 'product' ) {\n\t\t\t\tconst addToCartButton = $( '.single_add_to_cart_button' );\n\n\t\t\t\t$( '#wc-square-apple-pay, #wc-square-google-pay' ).on( 'click', ( e ) => {\n\t\t\t\t\tif ( addToCartButton.is( '.disabled' ) ) {\n\t\t\t\t\t\te.stopImmediatePropagation();\n\n\t\t\t\t\t\tif ( addToCartButton.is( '.wc-variation-is-unavailable' ) ) {\n\t\t\t\t\t\t\twindow.alert( wc_add_to_cart_variation_params.i18n_unavailable_text );\n\t\t\t\t\t\t} else if ( addToCartButton.is( '.wc-variation-selection-needed' ) ) {\n\t\t\t\t\t\t\twindow.alert( wc_add_to_cart_variation_params.i18n_make_a_selection_text );\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.add_to_cart();\n\t\t\t\t} );\n\n\t\t\t\t$( document.body ).on( 'woocommerce_variation_has_changed', () => this.build_digital_wallet() );\n\n\t\t\t\t$( '.quantity' ).on( 'input', '.qty', () => this.build_digital_wallet() );\n\t\t\t}\n\n\t\t\tif ( this.args.context === 'cart' ) {\n\t\t\t\t$( document.body ).on( 'updated_cart_totals', () => this.build_digital_wallet() );\n\t\t\t}\n\n\t\t\tif ( this.args.context === 'checkout' ) {\n\t\t\t\t$( document.body ).on( 'updated_checkout', () => this.build_digital_wallet() );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Load the digital wallet payment form\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tload_square_form() {\n\t\t\tif ( this.payment_form ) {\n\t\t\t\tthis.log( '[Square] Destroying digital wallet payment form' );\n\t\t\t\tthis.payment_form.destroy();\n\t\t\t}\n\n\t\t\tthis.log( '[Square] Building digital wallet payment form' );\n\t\t\tthis.payment_form = new SqPaymentForm( this.get_form_params() );\n\t\t\tthis.payment_form.build();\n\t\t}\n\n\t\t/**\n\t\t * Gets the Square payment form params.\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_form_params() {\n\t\t\tconst params = {\n\t\t\t\tapplicationId: this.args.application_id,\n\t\t\t\tlocationId: this.args.location_id,\n\t\t\t\tautobuild: false,\n\t\t\t\tapplePay: {\n\t\t\t\t\telementId: 'wc-square-apple-pay',\n\t\t\t\t},\n\t\t\t\tgooglePay: {\n\t\t\t\t\telementId: 'wc-square-google-pay',\n\t\t\t\t},\n\t\t\t\tcallbacks: {\n\t\t\t\t\tpaymentFormLoaded: () => this.unblock_ui(),\n\t\t\t\t\tcreatePaymentRequest: () => this.create_payment_request(),\n\t\t\t\t\tmethodsSupported: ( methods, unsupportedReason ) => this.methods_supported( methods, unsupportedReason ),\n\t\t\t\t\tshippingContactChanged: ( shippingContact, done ) => this.handle_shipping_address_changed( shippingContact, done ),\n\t\t\t\t\tshippingOptionChanged: ( shippingOption, done ) => this.handle_shipping_option_changed( shippingOption, done ),\n\t\t\t\t\tcardNonceResponseReceived: ( errors, nonce, cardData, billingContact, shippingContact, shippingOption ) => {\n\t\t\t\t\t\tthis.handle_card_nonce_response( errors, nonce, cardData, billingContact, shippingContact, shippingOption );\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\n\t\t\t// Fix console errors for Google Pay when there are no shipping options set. See note in Square documentation under shippingOptions: https://developer.squareup.com/docs/api/paymentform#paymentrequestfields.\n\t\t\tif ( this.payment_request.requestShippingAddress === false ) {\n\t\t\t\tdelete params.callbacks.shippingOptionChanged;\n\t\t\t}\n\n\t\t\t// Remove support for Google Pay and/or Apple Pay if chosen in settings.\n\t\t\tif ( this.args.hide_button_options.includes( 'google' ) ) {\n\t\t\t\tdelete params.googlePay;\n\t\t\t}\n\n\t\t\tif ( this.args.hide_button_options.includes( 'apple' ) ) {\n\t\t\t\tdelete params.applePay;\n\t\t\t}\n\n\t\t\treturn params;\n\t\t}\n\n\t\t/**\n\t\t * Sets the a payment request object for the Square Payment Form\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tcreate_payment_request() {\n\t\t\treturn this.payment_request;\n\t\t}\n\n\t\t/**\n\t\t * Check which methods are supported and show/hide the correct buttons on frontend\n\t\t * Reference: https://developer.squareup.com/docs/api/paymentform#methodssupported\n\t\t *\n\t\t * @param {Object} methods\n\t\t * @param {string} unsupportedReason\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tmethods_supported( methods, unsupportedReason ) {\n\t\t\tif ( methods.applePay === true || methods.googlePay === true ) {\n\t\t\t\tif ( methods.applePay === true ) {\n\t\t\t\t\t$( '#wc-square-apple-pay' ).show();\n\t\t\t\t}\n\n\t\t\t\tif ( methods.googlePay === true ) {\n\t\t\t\t\t$( '#wc-square-google-pay' ).show();\n\t\t\t\t}\n\n\t\t\t\t$( this.wallet ).show();\n\t\t\t} else {\n\t\t\t\tthis.log( unsupportedReason );\n\t\t\t}\n\t\t}\n\n\t\t/*\n\t\t * Get the payment request on a product page\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_payment_request() {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tconst data = {\n\t\t\t\t\tcontext: this.args.context,\n\t\t\t\t\tsecurity: this.args.payment_request_nonce,\n\t\t\t\t};\n\n\t\t\t\tif ( this.args.context === 'product' ) {\n\t\t\t\t\tconst product_data = this.get_product_data();\n\t\t\t\t\t$.extend( data, product_data );\n\t\t\t\t}\n\t\t\t\t// retrieve a payment request object.\n\t\t\t\t$.post( this.get_ajax_url( 'get_payment_request' ), data, ( response ) => {\n\t\t\t\t\tif ( response.success ) {\n\t\t\t\t\t\treturn resolve( response.data );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn reject( response.data );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Handle all shipping address recalculations in the Apple/Google Pay window\n\t\t *\n\t\t * Reference: https://developer.squareup.com/docs/api/paymentform#shippingcontactchanged\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\thandle_shipping_address_changed( shippingContact, done ) {\n\t\t\tconst data = {\n\t\t\t\tcontext: this.args.context,\n\t\t\t\tshipping_contact: shippingContact.data,\n\t\t\t\tsecurity: this.args.recalculate_totals_nonce,\n\t\t\t};\n\n\t\t\t// send ajax request get_shipping_options.\n\t\t\tthis.recalculate_totals( data ).then( ( response ) => {\n\t\t\t\treturn done( response );\n\t\t\t}, () => {\n\t\t\t\treturn done( {\n\t\t\t\t\terror: 'Bad Request',\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Handle all shipping method changes in the Apple/Google Pay window\n\t\t *\n\t\t * Reference: https://developer.squareup.com/docs/api/paymentform#shippingoptionchanged\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\thandle_shipping_option_changed( shippingOption, done ) {\n\t\t\tconst data = {\n\t\t\t\tcontext: this.args.context,\n\t\t\t\tshipping_option: shippingOption.data.id,\n\t\t\t\tsecurity: this.args.recalculate_totals_nonce,\n\t\t\t};\n\n\t\t\tthis.recalculate_totals( data ).then( ( response ) => {\n\t\t\t\treturn done( response );\n\t\t\t}, () => {\n\t\t\t\treturn done( {\n\t\t\t\t\terror: 'Bad Request',\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Handle the payment response.\n\t\t *\n\t\t * On success, set the checkout billing/shipping data and submit the checkout.\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\thandle_card_nonce_response( errors, nonce, cardData, billingContact, shippingContact, shippingOption ) {\n\t\t\tif ( errors ) {\n\t\t\t\treturn this.render_errors( errors );\n\t\t\t}\n\n\t\t\tif ( ! nonce ) {\n\t\t\t\treturn this.render_errors( this.args.general_error );\n\t\t\t}\n\n\t\t\tthis.block_ui();\n\n\t\t\tconst data = {\n\t\t\t\taction: '',\n\t\t\t\t_wpnonce: this.args.process_checkout_nonce,\n\t\t\t\tbilling_first_name: billingContact.givenName ? billingContact.givenName : '',\n\t\t\t\tbilling_last_name: billingContact.familyName ? billingContact.familyName : '',\n\t\t\t\tbilling_company: '',\n\t\t\t\tbilling_email: shippingContact.email ? shippingContact.email : '',\n\t\t\t\tbilling_phone: shippingContact.phone ? shippingContact.phone : '',\n\t\t\t\tbilling_country: billingContact.country ? billingContact.country.toUpperCase() : '',\n\t\t\t\tbilling_address_1: billingContact.addressLines && billingContact.addressLines[ 0 ] ? billingContact.addressLines[ 0 ] : '',\n\t\t\t\tbilling_address_2: billingContact.addressLines && billingContact.addressLines[ 1 ] ? billingContact.addressLines[ 1 ] : '',\n\t\t\t\tbilling_city: billingContact.city ? billingContact.city : '',\n\t\t\t\tbilling_state: billingContact.region ? billingContact.region : '',\n\t\t\t\tbilling_postcode: billingContact.postalCode ? billingContact.postalCode : '',\n\t\t\t\tshipping_first_name: shippingContact.givenName ? shippingContact.givenName : '',\n\t\t\t\tshipping_last_name: shippingContact.familyName ? shippingContact.familyName : '',\n\t\t\t\tshipping_company: '',\n\t\t\t\tshipping_country: shippingContact.country ? shippingContact.country.toUpperCase() : '',\n\t\t\t\tshipping_address_1: shippingContact.addressLines && shippingContact.addressLines[ 0 ] ? shippingContact.addressLines[ 0 ] : '',\n\t\t\t\tshipping_address_2: shippingContact.addressLines && shippingContact.addressLines[ 1 ] ? shippingContact.addressLines[ 1 ] : '',\n\t\t\t\tshipping_city: shippingContact.city ? shippingContact.city : '',\n\t\t\t\tshipping_state: shippingContact.region ? shippingContact.region : '',\n\t\t\t\tshipping_postcode: shippingContact.postalCode ? shippingContact.postalCode : '',\n\t\t\t\tshipping_method: [ ! shippingOption ? null : shippingOption.id ],\n\t\t\t\torder_comments: '',\n\t\t\t\tpayment_method: 'square_credit_card',\n\t\t\t\tship_to_different_address: 1,\n\t\t\t\tterms: 1,\n\t\t\t\t'wc-square-credit-card-payment-nonce': nonce,\n\t\t\t\t'wc-square-credit-card-last-four': cardData.last_4 ? cardData.last_4 : null,\n\t\t\t\t'wc-square-credit-card-exp-month': cardData.exp_month ? cardData.exp_month : null,\n\t\t\t\t'wc-square-credit-card-exp-year': cardData.exp_year ? cardData.exp_year : null,\n\t\t\t\t'wc-square-credit-card-payment-postcode': cardData.billing_postal_code ? cardData.billing_postal_code : null,\n\t\t\t\t'wc-square-digital-wallet-type': cardData.digital_wallet_type,\n\t\t\t};\n\n\t\t\t// handle slightly different mapping for Google Pay (Google returns full name as a single string).\n\t\t\tif ( cardData.digital_wallet_type === 'GOOGLE_PAY' ) {\n\t\t\t\tif ( billingContact.givenName ) {\n\t\t\t\t\tdata.billing_first_name = billingContact.givenName.split( ' ' ).slice( 0, 1 ).join( ' ' );\n\t\t\t\t\tdata.billing_last_name = billingContact.givenName.split( ' ' ).slice( 1 ).join( ' ' );\n\t\t\t\t}\n\n\t\t\t\tif ( shippingContact.givenName ) {\n\t\t\t\t\tdata.shipping_last_name = shippingContact.givenName.split( ' ' ).slice( 0, 1 ).join( ' ' );\n\t\t\t\t\tdata.shipping_last_name = shippingContact.givenName.split( ' ' ).slice( 1 ).join( ' ' );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if the billing_phone was not found on shippingContact, use the value on billingContact if that exists.\n\t\t\tif ( ! data.billing_phone && billingContact.phone ) {\n\t\t\t\tdata.billing_phone = billingContact.phone;\n\t\t\t}\n\n\t\t\t// if SCA is enabled, verify the buyer and add verification token to data.\n\t\t\tif ( this.args.is_3d_secure_enabled ) {\n\t\t\t\tthis.log( '3DS verification enabled. Verifying buyer' );\n\n\t\t\t\tvar self = this;\n\n\t\t\t\tthis.payment_form.verifyBuyer(\n\t\t\t\t\tnonce,\n\t\t\t\t\tself.get_verification_details( billingContact, shippingContact ),\n\t\t\t\t\tfunction(err, verificationResult) {\n\t\t\t\t\t\tif (err == null) {\n\t\t\t\t\t\t\t// SCA verification complete. Do checkout.\n\t\t\t\t\t\t\tself.log( '3DS verification successful' );\n\t\t\t\t\t\t\tdata['wc-square-credit-card-buyer-verification-token'] = verificationResult.token;\n\t\t\t\t\t\t\tself.do_checkout( data );\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t// SCA verification failed. Render errors.\n\t\t\t\t\t\t\tself.log( '3DS verification failed' );\n\t\t\t\t\t\t\tself.log(err);\n\t\t\t\t\t\t\tself.render_errors( [err.message] );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\t// SCA not enabled. Do checkout.\n\t\t\t\tthis.do_checkout( data );\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * Do Digital Wallet Checkout\n\t\t *\n\t\t * @since 2.4.2\n\t\t *\n\t\t * @param {Object} args\n\t\t */\n\t\tdo_checkout( data ) {\n\t\t\t// AJAX process checkout.\n\t\t\tthis.process_digital_wallet_checkout( data ).then(\n\t\t\t\t( response ) => {\n\t\t\t\t\twindow.location = response.redirect;\n\t\t\t\t},\n\t\t\t\t( response ) => {\n\t\t\t\t\tthis.log( response, 'error' );\n\t\t\t\t\tthis.render_errors_html( response.messages );\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Gets a verification details object to be used in verifyBuyer()\n\t\t *\n\t\t * @since 2.4.2\n\t\t *\n\t\t * @param {Object} billingContact\n\t\t * @param {Object} shippingContact\n\t\t *\n\t\t * @return {Object} Verification details object.\n\t\t */\n\t\tget_verification_details( billingContact, shippingContact ) {\n\t\t\tconst verification_details = {\n\t\t\t\tintent: 'CHARGE',\n\t\t\t\tamount: this.total_amount,\n\t\t\t\tcurrencyCode: this.payment_request.currencyCode,\n\t\t\t\tbillingContact: {\n\t\t\t\t\tfamilyName: billingContact.familyName ? billingContact.familyName : '',\n\t\t\t\t\tgivenName: billingContact.givenName ? billingContact.givenName : '',\n\t\t\t\t\temail: shippingContact.email ? shippingContact.email : '',\n\t\t\t\t\tcountry: billingContact.country ? billingContact.country.toUpperCase() : '',\n\t\t\t\t\tregion: billingContact.region ? billingContact.region : '',\n\t\t\t\t\tcity: billingContact.city ? billingContact.city : '',\n\t\t\t\t\tpostalCode: billingContact.postalCode ? billingContact.postalCode : '',\n\t\t\t\t\tphone: shippingContact.phone ? shippingContact.phone : '',\n\t\t\t\t\taddressLines: billingContact.addressLines ? billingContact.addressLines : '',\n\t\t\t\t},\n\t\t\t}\n\n\t\t\tthis.log( verification_details );\n\n\t\t\treturn verification_details;\n\t\t}\n\n\t\t/*\n\t\t * Recalculate totals\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\trecalculate_totals( data ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\treturn $.post( this.get_ajax_url( 'recalculate_totals' ), data, ( response ) => {\n\t\t\t\t\tif ( response.success ) {\n\t\t\t\t\t\tthis.total_amount = response.data.total.amount;\n\t\t\t\t\t\treturn resolve( response.data );\n\t\t\t\t\t}\n\t\t\t\t\treturn reject( response.data );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Get the product data for building the payment request on the product page\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_product_data() {\n\t\t\tlet product_id = $( '.single_add_to_cart_button' ).val();\n\n\t\t\tconst attributes = {};\n\n\t\t\t// Check if product is a variable product.\n\t\t\tif ( $( '.single_variation_wrap' ).length ) {\n\t\t\t\tproduct_id = $( '.single_variation_wrap' ).find( 'input[name=\"product_id\"]' ).val();\n\t\t\t\tif ( $( '.variations_form' ).length ) {\n\t\t\t\t\t$( '.variations_form' ).find( '.variations select' ).each( ( index, select ) => {\n\t\t\t\t\t\tconst attribute_name = $( select ).data( 'attribute_name' ) || $( select ).attr( 'name' );\n\t\t\t\t\t\tconst value = $( select ).val() || '';\n\t\t\t\t\t\treturn attributes[ attribute_name ] = value;\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tproduct_id,\n\t\t\t\tquantity: $( '.quantity .qty' ).val(),\n\t\t\t\tattributes,\n\t\t\t};\n\t\t}\n\n\t\t/*\n\t\t * Add the product to the cart\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tadd_to_cart() {\n\t\t\tconst data = {\n\t\t\t\tsecurity: this.args.add_to_cart_nonce,\n\t\t\t};\n\t\t\tconst product_data = this.get_product_data();\n\t\t\t$.extend( data, product_data );\n\n\t\t\t// retrieve a payment request object.\n\t\t\t$.post( this.get_ajax_url( 'add_to_cart' ), data, ( response ) => {\n\t\t\t\tif ( response.error ) {\n\t\t\t\t\treturn window.alert( response.data );\n\t\t\t\t}\n\n\t\t\t\tconst data = JSON.parse( response.data );\n\t\t\t\tthis.payment_request = data.payment_request;\n\t\t\t\tthis.args.payment_request_nonce = data.payment_request_nonce;\n\t\t\t\tthis.args.add_to_cart_nonce = data.add_to_cart_nonce;\n\t\t\t\tthis.args.recalculate_totals_nonce = data.recalculate_totals_nonce;\n\t\t\t\tthis.args.process_checkout_nonce = data.process_checkout_nonce;\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Process the digital wallet checkout\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tprocess_digital_wallet_checkout( data ) {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\t$.post( this.get_ajax_url( 'process_checkout' ), data, ( response ) => {\n\t\t\t\t\tif ( response.result === 'success' ) {\n\t\t\t\t\t\treturn resolve( response );\n\t\t\t\t\t}\n\n\t\t\t\t\treturn reject( response );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Helper function to return the ajax URL for the given request/action\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tget_ajax_url( request ) {\n\t\t\treturn this.args.ajax_url.replace( '%%endpoint%%', 'square_digital_wallet_' + request );\n\t\t}\n\n\t\t/*\n\t\t * Renders errors given the error message HTML\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\trender_errors_html( errors_html ) {\n\t\t\t// hide and remove any previous errors.\n\t\t\t$( '.woocommerce-error, .woocommerce-message' ).remove();\n\n\t\t\tconst element = this.args.context === 'product' ? $( '.product' ) : $( '.shop_table.cart' ).closest( 'form' );\n\n\t\t\t// add errors\n\t\t\telement.before( errors_html );\n\n\t\t\t// unblock UI\n\t\t\tthis.unblock_ui();\n\n\t\t\t// scroll to top\n\t\t\t$( 'html, body' ).animate( {\n\t\t\t\tscrollTop: element.offset().top - 100,\n\t\t\t}, 1000 );\n\t\t}\n\n\t\t/*\n\t\t * Renders errors\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\trender_errors( errors ) {\n\t\t\tconst error_message_html = '<ul class=\"woocommerce-error\"><li>' + errors.join( '</li><li>' ) + '</li></ul>';\n\t\t\tthis.render_errors_html( error_message_html );\n\t\t}\n\n\t\t/*\n\t\t * Block the Apple Pay and Google Pay buttons from being clicked which processing certain actions\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tblock_ui() {\n\t\t\t$( this.buttons ).block( {\n\t\t\t\tmessage: null,\n\t\t\t\toverlayCSS: {\n\t\t\t\t\tbackground: '#fff',\n\t\t\t\t\topacity: 0.6,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\n\t\t/*\n\t\t * Unblock the wallet buttons\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tunblock_ui() {\n\t\t\t$( this.buttons ).unblock();\n\t\t}\n\n\t\t/*\n\t\t * Logs messages to the console when logging is turned on in the settings\n\t\t *\n\t\t * @since 2.3\n\t\t */\n\t\tlog( message, type = 'notice' ) {\n\t\t\t// if logging is disabled, bail.\n\t\t\tif ( ! this.args.logging_enabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( type === 'error' ) {\n\t\t\t\treturn console.error( message );\n\t\t\t}\n\n\t\t\treturn console.log( message );\n\t\t}\n\t}\n\n\twindow.WC_Square_Digital_Wallet_Handler = WC_Square_Digital_Wallet_Handler;\n} );\n"],"file":"wc-square-digital-wallet.min.js"}
|
build/index.asset.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php return array('dependencies' => array('react', 'wc-blocks-registry', 'wc-settings', 'wp-element', 'wp-i18n', 'wp-polyfill'), 'version' => '0b5b2202560893ec45752e4f994681b3');
|
build/index.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
!function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=30)}([function(e,t){e.exports=window.wp.element},function(e,t){e.exports=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=window.React},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};Object.defineProperty(t,"__esModule",{value:!0});var a=n(r(2));t.Context=a.createContext({applePayState:"loading",formId:"",googlePayState:"loading",masterpassState:"loading",onCreateNonce:function(){},onVerifyBuyer:function(e,t,r){}}),t.default=t.Context},function(e,t,r){"use strict";function n(e){for(var r in e)t.hasOwnProperty(r)||(t[r]=e[r])}Object.defineProperty(t,"__esModule",{value:!0});var a=r(8);n(r(15)),n(r(3)),n(r(16)),n(r(17)),n(r(18)),n(r(19)),n(r(20)),n(r(21)),n(r(22)),n(r(23)),n(r(24)),n(r(8)),t.default=a.SquarePaymentForm},function(e,t){e.exports=window.wp.i18n},function(e,t){e.exports=window.regeneratorRuntime},function(e,t,r){var n=r(25),a=r(26),o=r(27),i=r(29);e.exports=function(e,t){return n(e)||a(e,t)||o(e,t)||i()},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(14)),l=a(r(3));t.SquarePaymentForm=function(e){var t=o.useState("loading"),r=t[0],n=t[1],a=o.useState("loading"),c=a[0],u=a[1],s=o.useState("loading"),d=s[0],f=s[1],p=o.useState(""),m=p[0],v=p[1],y=o.useState(!1),b=y[0],g=y[1],h=o.useState(void 0),_=h[0],O=h[1],C=o.useState(!1),S=C[0],E=C[1],j=i.default((function(t,r,n,a,o,i){!t&&e.createVerificationDetails?_&&_.verifyBuyer(r,e.createVerificationDetails(),(function(t,l){e.cardNonceResponseReceived(t?[t]:null,r,n,l?l.token:void 0,a,o,i)})):e.cardNonceResponseReceived(t,r,n,"",a,o,i)}));function x(t){var r=Object.keys(t);r.includes("masterpass")&&f(!0===t.masterpass?"ready":"unavailable"),r.includes("applePay")&&n(!0===t.applePay?"ready":"unavailable"),r.includes("googlePay")&&u(!0===t.googlePay?"ready":"unavailable"),e.methodsSupported&&e.methodsSupported(t)}var w=function(){E(!0),e.paymentFormLoaded&&e.paymentFormLoaded()};if(o.useEffect((function(){S&&_&&(_.recalculateSize(),e.postalCode&&_.setPostalCode(e.postalCode()),e.focusField&&_.focus(e.focusField()))}),[S,_]),o.useEffect((function(){!function(t,r){if(document.getElementById("sq-payment-form-script")&&"function"==typeof SqPaymentForm)t&&t();else{var n=document.createElement("script");n.id="sq-payment-form-script",e.sandbox?n.src="https://js.squareupsandbox.com/v2/paymentform":n.src="https://js.squareup.com/v2/paymentform",n.onload=function(){t&&t()},n.onerror=function(){r&&r()},document.body.appendChild(n)}}((function(){return g(!0)}),(function(){return v("Unable to load Square payment library")}))}),[]),o.useEffect((function(){return function(){if(!(!b||_||m.length>0))try{var t=new SqPaymentForm(function(e){var t={apiWrapper:e.apiWrapper,applicationId:e.applicationId,autoBuild:!1,callbacks:{cardNonceResponseReceived:e.cardNonceResponseReceived?j:null,createPaymentRequest:e.createPaymentRequest,inputEventReceived:e.inputEventReceived,methodsSupported:x,paymentFormLoaded:w,shippingContactChanged:e.shippingContactChanged,shippingOptionChanged:e.shippingOptionChanged,unsupportedBrowserDetected:e.unsupportedBrowserDetected},locationId:e.locationId};return document.getElementById(e.formId+"-sq-card")?t.card={elementId:e.formId+"-sq-card",inputStyle:e.inputStyles&&e.inputStyles[0]}:document.getElementById(e.formId+"-sq-gift-card")?(t.giftCard={elementId:e.formId+"-sq-gift-card",placeholder:e.placeholderGiftCard||"• • • • • • • • • • • • • • • •"},t.inputClass=e.inputClass||"sq-input",t.inputStyles=e.inputStyles):(t.inputClass=e.inputClass||"sq-input",t.inputStyles=e.inputStyles,document.getElementById(e.formId+"-sq-apple-pay")&&(t.applePay={elementId:e.formId+"-sq-apple-pay"}),document.getElementById(e.formId+"-sq-google-pay")&&(t.googlePay={elementId:e.formId+"-sq-google-pay"}),document.getElementById(e.formId+"-sq-masterpass")&&(t.masterpass={elementId:e.formId+"-sq-masterpass"}),document.getElementById(e.formId+"-sq-card-number")&&(t.cardNumber={elementId:e.formId+"-sq-card-number",placeholder:e.placeholderCreditCard||"• • • • • • • • • • • • • • • •"}),document.getElementById(e.formId+"-sq-cvv")&&(t.cvv={elementId:e.formId+"-sq-cvv",placeholder:e.placeholderCVV||"CVV "}),document.getElementById(e.formId+"-sq-postal-code")?t.postalCode={elementId:e.formId+"-sq-postal-code",placeholder:e.placeholderPostal||"12345"}:t.postalCode=!1,document.getElementById(e.formId+"-sq-expiration-date")&&(t.expirationDate={elementId:e.formId+"-sq-expiration-date",placeholder:e.placeholderExpiration||"MM/YY"})),t}(e));t.build(),O(t)}catch(e){var r=e.message||"Unable to build Square payment form";v(r)}}(),function(){_&&(_.destroy(),O(void 0))}}),[b]),o.useEffect((function(){if(_&&"ready"===d){var t=document.getElementById(e.formId+"-sq-masterpass");if(t){var r=_.masterpassImageUrl();t.style.display="inline-block",t.style.backgroundImage="url("+r+")"}}}),[_,d]),m)return o.default.createElement("div",{className:"sq-payment-form"},o.default.createElement("div",{className:"sq-error-message"},m));var P={applePayState:r,formId:e.formId,googlePayState:c,masterpassState:d,onCreateNonce:function(){_&&_.requestCardNonce()},onVerifyBuyer:function(e,t,r){_&&_.verifyBuyer(e,t,r)}};return o.default.createElement(l.default.Provider,{value:P},o.default.createElement("div",{id:e.formId,className:"sq-payment-form"},e.children))},t.SquarePaymentForm.defaultProps={apiWrapper:"reactjs/0.7.2",formId:"sq-payment-form",inputStyles:[{_mozOsxFontSmoothing:"grayscale",_webkitFontSmoothing:"antialiased",backgroundColor:"transparent",color:"#373F4A",fontFamily:"Helvetica Neue",fontSize:"16px",lineHeight:"24px",padding:"16px",placeholderColor:"#CCC"}],sandbox:!1}},function(e,t){e.exports=window.wc.wcBlocksRegistry},function(e,t,r){var n=r(13);e.exports=function(e,t){if(null==e)return{};var r,a,o=n(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(a=0;a<i.length;a++)r=i[a],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){function r(e,t,r,n,a,o,i){try{var l=e[o](i),c=l.value}catch(e){return void r(e)}l.done?t(c):Promise.resolve(c).then(n,a)}e.exports=function(e){return function(){var t=this,n=arguments;return new Promise((function(a,o){var i=e.apply(t,n);function l(e){r(i,a,o,l,c,"next",e)}function c(e){r(i,a,o,l,c,"throw",e)}l(void 0)}))}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=window.wc.wcSettings},function(e,t){e.exports=function(e,t){if(null==e)return{};var r,n,a={},o=Object.keys(e);for(n=0;n<o.length;n++)r=o[n],t.indexOf(r)>=0||(a[r]=e[r]);return a},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var n=r(2);t.default=function(e){var t=n.useRef(e);return n.useLayoutEffect((function(){t.current=e}),[e]),n.useCallback((function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return t.current.apply(t,e)}),[])}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.ApplePayButton=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,o.default.createElement("button",{id:t.formId+"-sq-apple-pay",className:"sq-apple-pay",style:{display:"ready"===t.applePayState?"block":"none"}}),"loading"===t.applePayState&&e.loadingView,"unavailable"===t.applePayState&&e.unavailableView)}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.CreditCardCVVInput=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,e.label&&o.default.createElement("span",{className:"sq-label"},e.label),o.default.createElement("div",{id:t.formId+"-sq-cvv"}))},t.CreditCardCVVInput.defaultProps={label:"CVV"}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.CreditCardExpirationDateInput=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,e.label&&o.default.createElement("span",{className:"sq-label"},e.label),o.default.createElement("div",{id:t.formId+"-sq-expiration-date"}))},t.CreditCardExpirationDateInput.defaultProps={label:"Expiration"}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.CreditCardNumberInput=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,e.label&&o.default.createElement("span",{className:"sq-label"},e.label),o.default.createElement("div",{id:t.formId+"-sq-card-number"}))},t.CreditCardNumberInput.defaultProps={label:"Credit Card"}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.CreditCardPostalCodeInput=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,e.label&&o.default.createElement("span",{className:"sq-label"},e.label),o.default.createElement("div",{id:t.formId+"-sq-postal-code"}))},t.CreditCardPostalCodeInput.defaultProps={label:"Postal"}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.CreditCardSubmitButton=function(e){var t=o.useContext(i.default);return o.default.createElement("button",{className:"sq-creditcard",onClick:t.onCreateNonce},e.children?e.children:"Pay")}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.GiftCardInput=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,e.label&&o.default.createElement("span",{className:"sq-label"},e.label),o.default.createElement("div",{id:t.formId+"-sq-gift-card"}))},t.GiftCardInput.defaultProps={label:"Gift Card"}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.GooglePayButton=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,o.default.createElement("button",{id:t.formId+"-sq-google-pay",className:"sq-google-pay",style:{display:"ready"===t.googlePayState?"block":"none"}}),"loading"===t.googlePayState&&e.loadingView,"unavailable"===t.googlePayState&&e.unavailableView)}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.MasterpassButton=function(e){var t=o.useContext(i.default);return o.default.createElement("div",null,o.default.createElement("button",{id:t.formId+"-sq-masterpass",className:"sq-masterpass",style:{display:"ready"===t.masterpassState?"block":"none"}}),"loading"===t.masterpassState&&e.loadingView,"unavailable"===t.masterpassState&&e.unavailableView)}},function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t},a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});var o=n(r(2)),i=a(r(3));t.SimpleCard=function(){var e=o.useContext(i.default);return o.default.createElement("div",{id:e.formId+"-sq-card"})}},function(e,t){e.exports=function(e){if(Array.isArray(e))return e},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var r=[],_n=!0,n=!1,a=void 0;try{for(var o,i=e[Symbol.iterator]();!(_n=(o=i.next()).done)&&(r.push(o.value),!t||r.length!==t);_n=!0);}catch(e){n=!0,a=e}finally{try{_n||null==i.return||i.return()}finally{if(n)throw a}}return r}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){var n=r(28);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.default=e.exports,e.exports.__esModule=!0},function(e,t,r){"use strict";r.r(t);var n=r(9),a=r(10),o=r.n(a),i=r(0),l=r(5),c=r(4),u=r(1),s=r.n(u),d=r(11),f=r.n(d),p=r(6),m=r.n(p),v=r(12);function y(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return b(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?b(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,l=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return i=e.done,e},e:function(e){l=!0,o=e},f:function(){try{i||null==r.return||r.return()}finally{if(l)throw o}}}}function b(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var g=null,h=function(){if(null!==g)return g;var e=Object(v.getSetting)("square_credit_card_data",null);if(!e)throw new Error("Square initialization data is not available");return g={title:e.title||"",applicationId:e.application_id||"",locationId:e.location_id||"",isSandbox:e.is_sandbox||!1,is3dsEnabled:e.is_3ds_enabled||!1,inputStyles:e.input_styles||[],availableCardTypes:e.available_card_types||{},loggingEnabled:e.logging_enabled||!1,generalError:e.general_error||"",showSavedCards:e.show_saved_cards||!1,showSaveOption:e.show_save_option||!1,supports:e.supports||{}}},_=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{logs:[],notices:[]},r=!1;if(e){var n=["none","cardNumber","expirationDate","cvv","postalCode"];e.length>=1&&e.sort((function(e,t){return n.indexOf(e.field)-n.indexOf(t.field)}));var a,o=y(e);try{for(o.s();!(a=o.n()).done;){var i=a.value;"UNSUPPORTED_CARD_BRAND"===i.type||"VALIDATION_ERROR"===i.type?(t.notices.push(i.message.replace(/CVV/,"CSC")),r=!0):C(i,t)}}catch(e){o.e(e)}finally{o.f()}}r||t.notices.push(h().generalError)},O=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"notice";h().loggingEnabled&&("error"===t?console.error(e):console.log(e))},C=function(e,t){h().loggingEnabled&&t&&t.logs.push(e)};function S(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function E(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?S(Object(r),!0).forEach((function(t){s()(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):S(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var j=function(e){var t=e.checkoutFormHandler,r=e.eventRegistration,n=e.emitResponse,a=Object(i.useContext)(c.Context),o=r.onPaymentProcessing,l=r.onCheckoutAfterProcessingWithError,u=r.onCheckoutAfterProcessingWithSuccess;return function(e,t,r,n,a,o){var l=Object(i.useRef)(r);Object(i.useEffect)((function(){l.current=r}),[r]),Object(i.useEffect)((function(){return e(function(){var e=f()(m.a.mark((function e(){var r,i,c,u,s,d;return m.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={type:t.responseTypes.SUCCESS},i={nonce:"",notices:[],logs:[]},e.next=4,a(l.current);case 4:if(c=e.sent,u=E(E({},i),c),s=u.token||u.nonce,!h().is3dsEnabled||!s){e.next=14;break}return e.next=10,o(l.current,s);case 10:d=e.sent,u.verificationToken=d.verificationToken||"",u.logs=u.logs.concat(d.log||[]),u.errors=u.notices.concat(d.errors||[]);case 14:return s||u.logs.length>0?r.meta={paymentMethodData:n(u)}:u.notices.length>0&&(r.type=t.responseTypes.ERROR,r.message=u.notices),e.abrupt("return",r);case 16:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}())}),[e,t.responseTypes.SUCCESS,t.responseTypes.ERROR,a,o,n])}(o,n,a,t.getPaymentMethodData,t.createNonce,t.verifyBuyer),function(e,t,r){Object(i.useEffect)((function(){var n=function(e){var t={type:r.responseTypes.SUCCESS},n=e.processingResponse,a=n.paymentStatus,o=n.paymentDetails;return a===r.responseTypes.ERROR&&o.checkoutNotices&&(t={type:r.responseTypes.ERROR,message:JSON.parse(o.checkoutNotices),messageContext:r.noticeContexts.PAYMENTS,retry:!0}),t},a=e(n),o=t(n);return function(){a(),o()}}),[e,t,r.noticeContexts.PAYMENTS,r.responseTypes.ERROR,r.responseTypes.SUCCESS])}(l,u,n),null},x=r(7),w=r.n(x);function P(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return I(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?I(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,l=!1;return{s:function(){r=e[Symbol.iterator]()},n:function(){var e=r.next();return i=e.done,e},e:function(e){l=!0,o=e},f:function(){try{i||null==r.return||r.return()}finally{if(l)throw o}}}}function I(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var q=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=Object(i.useState)(!1),a=w()(n,2),o=a[0],l=a[1],c=Object(i.useState)(""),u=w()(c,2),d=u[0],f=u[1],p=Object(i.useRef)(null),m=Object(i.useRef)(null),v=Object(i.useMemo)((function(){var n=t&&!r?"STORE":"CHARGE",a={billingContact:{familyName:e.billingData.last_name||"",givenName:e.billingData.first_name||"",email:e.billingData.email||"",country:e.billingData.country||"",region:e.billingData.state||"",city:e.billingData.city||"",postalCode:e.billingData.postcode||"",phone:e.billingData.phone||"",addressLines:[e.billingData.address_1||"",e.billingData.address_2||""]},intent:n};return"CHARGE"===n&&(a.amount=(e.cartTotal.value/100).toString(),a.currencyCode=e.currency.code),a}),[e.billingData,e.cartTotal.value,e.currency.code,t,r]),y=Object(i.useCallback)((function(e){var n,a,o,i=e.cardData,l=e.nonce,c=e.verificationToken,u=e.notices,f=e.logs;return o={},s()(o,"wc-".concat("square-credit-card","-card-type"),d||""),s()(o,"wc-".concat("square-credit-card","-last-four"),(null==i?void 0:i.last_4)||""),s()(o,"wc-".concat("square-credit-card","-exp-month"),(null==i||null===(n=i.exp_month)||void 0===n?void 0:n.toString())||""),s()(o,"wc-".concat("square-credit-card","-exp-year"),(null==i||null===(a=i.exp_year)||void 0===a?void 0:a.toString())||""),s()(o,"wc-".concat("square-credit-card","-payment-postcode"),(null==i?void 0:i.billing_postal_code)||""),s()(o,"wc-".concat("square-credit-card","-payment-nonce"),l||""),s()(o,"wc-".concat("square-credit-card","-payment-token"),r||""),s()(o,"wc-".concat("square-credit-card","-buyer-verification-token"),c||""),s()(o,"wc-".concat("square-credit-card","-tokenize-payment-method"),t||!1),s()(o,"log-data",f.length>0?JSON.stringify(f):""),s()(o,"checkout-notices",u.length>0?JSON.stringify(u):""),o}),[d,t,r]),b=function(e,t,r){var n={notices:[],logs:[]};e?_(e,n):t?(C(r,n),O("Card data received"),O(r),n.cardData=r,n.nonce=t):(C("Nonce is missing from the Square response",n),O("Nonce is missing from the Square response","error"),_([],n)),p.current&&p.current(n)},g=Object(i.useCallback)((function(e){if(!r){var t=new Promise((function(e){return p.current=e}));return e.onCreateNonce(),t}return Promise.resolve({token:r})}),[r]),S=Object(i.useCallback)((function(e,t){var r=new Promise((function(e){return m.current=e}));return e.onVerifyBuyer(t,v,E),r}),[v,E]),E=Object(i.useCallback)((function(e,t){var r={notices:[],logs:[]};if(e){var n,a=P(e);try{for(a.s();!(n=a.n()).done;){var o=n.value;o.field||(o.field="none")}}catch(e){a.e(e)}finally{a.f()}_(e,r)}t&&t.token?r.verificationToken=t.token:(C("Verification token is missing from the Square response",r),O("Verification token is missing from the Square response","error"),_([],r)),m.current&&m.current(r)}),[m]),j=Object(i.useCallback)((function(e){if("cardBrandChanged"===e.eventType){var t=e.cardBrand,r="plain";null!==t&&"unknown"!==t||(r=""),null!==h().availableCardTypes[t]&&(r=h().availableCardTypes[t]),O("Card brand changed to ".concat(t)),f(r)}}),[]),x=Object(i.useCallback)((function(){return e.billingData.postcode||""}),[e.billingData.postcode]);return{cardNonceResponseReceived:b,handleInputReceived:j,isLoaded:o,setLoaded:l,getPostalCode:x,cardType:d,createNonce:g,verifyBuyer:S,getPaymentMethodData:y}},M=function(e){var t=e.cardType;return Object(i.createElement)("fieldset",{id:"wc-square-credit-card-credit-card-form"},Object(i.createElement)("span",{className:"sq-label"},Object(l.__)("Card Number","woocommerce-square")),Object(i.createElement)("div",{id:"wc-square-credit-card-account-number-hosted",className:"wc-square-credit-card-hosted-field ".concat(t?"card-type-".concat(t):"")},Object(i.createElement)(c.CreditCardNumberInput,{label:""})),Object(i.createElement)("div",{className:"sq-form-third"},Object(i.createElement)("span",{className:"sq-label"},Object(l.__)("Expiration (MM/YY)","woocommerce-square")),Object(i.createElement)("div",{id:"wc-square-credit-card-expiry-hosted",className:"wc-square-credit-card-hosted-field"},Object(i.createElement)(c.CreditCardExpirationDateInput,{label:""}))),Object(i.createElement)("div",{className:"sq-form-third"},Object(i.createElement)("span",{className:"sq-label"},Object(l.__)("Card Security Code","woocommerce-square")),Object(i.createElement)("div",{id:"wc-square-credit-card-csc-hosted",className:"wc-square-credit-card-hosted-field"},Object(i.createElement)(c.CreditCardCVVInput,{label:""}))),Object(i.createElement)("div",{className:"sq-form-third"},Object(i.createElement)("span",{className:"sq-label"},Object(l.__)("Postal code","woocommerce-square")),Object(i.createElement)("div",{id:"wc-square-credit-card-postal-code-hosted",className:"wc-square-credit-card-hosted-field"},Object(i.createElement)(c.CreditCardPostalCodeInput,{label:""}))))},R=function(e){var t=e.billing,r=e.eventRegistration,n=e.emitResponse,a=e.shouldSavePayment,o=q(t,a);return Object(i.createElement)(c.SquarePaymentForm,{formId:"square-credit-card",sandbox:h().isSandbox,applicationId:h().applicationId,locationId:h().locationId,inputStyles:h().inputStyles,placeholderCreditCard:"•••• •••• •••• ••••",placeholderExpiration:Object(l.__)("MM / YY","woocommerce-square"),placeholderCVV:Object(l.__)("CSC","woocommerce-square"),postalCode:o.getPostalCode,cardNonceResponseReceived:o.cardNonceResponseReceived,inputEventReceived:o.handleInputReceived,paymentFormLoaded:function(){return o.setLoaded(!0)}},Object(i.createElement)(M,{cardType:o.cardType}),o.isLoaded&&Object(i.createElement)(j,{checkoutFormHandler:o,eventRegistration:r,emitResponse:n}))},N=function(e){var t=e.RenderedComponent,r=o()(e,["RenderedComponent"]);return Object(i.createElement)(t,r)},k={name:"square-credit-card",label:Object(i.createElement)((function(e){var t=e.components.PaymentMethodLabel;return Object(i.createElement)(t,{text:h().title})}),null),content:Object(i.createElement)(N,{RenderedComponent:R}),edit:Object(i.createElement)(N,{RenderedComponent:R}),savedTokenComponent:Object(i.createElement)(N,{RenderedComponent:function(e){var t=e.billing,r=e.eventRegistration,n=e.emitResponse,a=e.token,o=q(t,!1,a);return Object(i.createElement)(c.SquarePaymentForm,{formId:"square-credit-card-saved-card",sandbox:h().isSandbox,applicationId:h().applicationId,locationId:h().locationId,paymentFormLoaded:function(){return o.setLoaded(!0)}},o.isLoaded&&Object(i.createElement)(j,{checkoutFormHandler:o,eventRegistration:r,emitResponse:n}))}}),paymentMethodId:"square_credit_card",ariaLabel:"Square",canMakePayment:function(){return!(!h().applicationId||!h().locationId)},supports:{features:h().supports,showSavedCards:h().showSavedCards,showSaveOption:h().showSaveOption}};Object(n.registerPaymentMethod)(k)}]);
|
i18n/languages/woocommerce-square.pot
CHANGED
@@ -2,10 +2,10 @@
|
|
2 |
# This file is distributed under the GNU General Public License v3.0.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version: WooCommerce Square 2.
|
6 |
"Report-Msgid-Bugs-To: "
|
7 |
"https://wordpress.org/support/plugin/woocommerce-square\n"
|
8 |
-
"POT-Creation-Date: 2021-
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=utf-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -434,7 +434,7 @@ msgid "The sync job has failed. Check sync records, or %s."
|
|
434 |
msgstr ""
|
435 |
|
436 |
#: includes/Gateway/API/Requests/Orders.php:88
|
437 |
-
#: includes/Gateway/Digital_Wallet.php:
|
438 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:555
|
439 |
msgid "Discount"
|
440 |
msgstr ""
|
@@ -444,6 +444,29 @@ msgstr ""
|
|
444 |
msgid "Adjustment"
|
445 |
msgstr ""
|
446 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
447 |
#: includes/Gateway/Digital_Wallet.php:110
|
448 |
#. Translators: %1$s: expected location of apple pay verification file, %2$s:
|
449 |
#. opening href tag with link to Square documentation, %3$s: closing href tag
|
@@ -467,60 +490,52 @@ msgstr ""
|
|
467 |
msgid "OR"
|
468 |
msgstr ""
|
469 |
|
470 |
-
#: includes/Gateway/Digital_Wallet.php:
|
471 |
-
#: includes/Gateway/Payment_Form.php:240 includes/Gateway.php:245
|
472 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/Handlers/Abstract_Hosted_Payment_Handler.php:216
|
473 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php:2758
|
474 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php:376
|
475 |
-
msgid "An error occurred, please try again or try an alternate form of payment."
|
476 |
-
msgstr ""
|
477 |
-
|
478 |
-
#: includes/Gateway/Digital_Wallet.php:273
|
479 |
#. translators: product ID
|
480 |
msgid "Product with the ID (%d) cannot be found."
|
481 |
msgstr ""
|
482 |
|
483 |
-
#: includes/Gateway/Digital_Wallet.php:
|
484 |
#. translators: 1: product name 2: quantity in stock
|
485 |
msgid ""
|
486 |
"You cannot add that amount of \"%1$s\"; to the cart because there is not "
|
487 |
"enough stock (%2$s remaining)."
|
488 |
msgstr ""
|
489 |
|
490 |
-
#: includes/Gateway/Digital_Wallet.php:
|
491 |
-
#: includes/Gateway/Digital_Wallet.php:
|
492 |
msgid "Tax"
|
493 |
msgstr ""
|
494 |
|
495 |
-
#: includes/Gateway/Digital_Wallet.php:
|
496 |
msgid "This payment method cannot be used for multiple shipments."
|
497 |
msgstr ""
|
498 |
|
499 |
-
#: includes/Gateway/Digital_Wallet.php:
|
500 |
#: vendor/prospress/action-scheduler/classes/ActionScheduler_Store.php:182
|
501 |
msgid "Pending"
|
502 |
msgstr ""
|
503 |
|
504 |
-
#: includes/Gateway/Digital_Wallet.php:
|
505 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:565
|
506 |
msgid "Shipping"
|
507 |
msgstr ""
|
508 |
|
509 |
-
#: includes/Gateway/Digital_Wallet.php:
|
510 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:575
|
511 |
msgid "Fees"
|
512 |
msgstr ""
|
513 |
|
514 |
-
#: includes/Gateway/Digital_Wallet.php:
|
515 |
#. translators: Context (product, cart, checkout or page)
|
516 |
msgid "Empty payment request data for %s."
|
517 |
msgstr ""
|
518 |
|
519 |
-
#: includes/Gateway/Digital_Wallet.php:
|
520 |
msgid "Empty cart"
|
521 |
msgstr ""
|
522 |
|
523 |
-
#: includes/Gateway/Digital_Wallet.php:
|
524 |
msgid "Unable to verify domain with Apple Pay - missing access token."
|
525 |
msgstr ""
|
526 |
|
@@ -917,7 +932,7 @@ msgid ""
|
|
917 |
"%5$supdated documentation%6$s."
|
918 |
msgstr ""
|
919 |
|
920 |
-
#: includes/Plugin.php:
|
921 |
#. translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s -
|
922 |
#. 2-character country code, %4$s - comma separated list of 2-character country
|
923 |
#. codes
|
@@ -926,7 +941,7 @@ msgid ""
|
|
926 |
"accept transactions from merchants outside of %4$s."
|
927 |
msgstr ""
|
928 |
|
929 |
-
#: includes/Plugin.php:
|
930 |
#. translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s -
|
931 |
#. <a> tag, %4$s - </a> tag
|
932 |
msgid ""
|
@@ -935,7 +950,7 @@ msgid ""
|
|
935 |
"successfully with Square. %3$sRead more here%4$s on how to resolve this."
|
936 |
msgstr ""
|
937 |
|
938 |
-
#: includes/Plugin.php:
|
939 |
#. translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s -
|
940 |
#. <a> tag, %4$s - </a> tag
|
941 |
msgid ""
|
@@ -943,14 +958,14 @@ msgid ""
|
|
943 |
"Square is inactive. Please disconnect and reconnect to resolve."
|
944 |
msgstr ""
|
945 |
|
946 |
-
#: includes/Plugin.php:
|
947 |
msgid ""
|
948 |
"%1$sWooCommerce Square:%2$s Product prices are entered inclusive of tax, "
|
949 |
"but Square does not support syncing tax-inclusive prices. Please make sure "
|
950 |
"your Square tax rates match your WooCommerce tax rates."
|
951 |
msgstr ""
|
952 |
|
953 |
-
#: includes/Plugin.php:
|
954 |
msgid ""
|
955 |
"Heads up! Your store currency is %1$s but your configured Square business "
|
956 |
"location currency is %2$s, so payments cannot be processed. Please "
|
@@ -2900,10 +2915,6 @@ msgstr ""
|
|
2900 |
msgid "Thank you for your order."
|
2901 |
msgstr ""
|
2902 |
|
2903 |
-
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php:1102
|
2904 |
-
msgid "Credit Card"
|
2905 |
-
msgstr ""
|
2906 |
-
|
2907 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php:1104
|
2908 |
msgid "eCheck"
|
2909 |
msgstr ""
|
2 |
# This file is distributed under the GNU General Public License v3.0.
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
+
"Project-Id-Version: WooCommerce Square 2.5.0\n"
|
6 |
"Report-Msgid-Bugs-To: "
|
7 |
"https://wordpress.org/support/plugin/woocommerce-square\n"
|
8 |
+
"POT-Creation-Date: 2021-05-13 04:26:05+00:00\n"
|
9 |
"MIME-Version: 1.0\n"
|
10 |
"Content-Type: text/plain; charset=utf-8\n"
|
11 |
"Content-Transfer-Encoding: 8bit\n"
|
434 |
msgstr ""
|
435 |
|
436 |
#: includes/Gateway/API/Requests/Orders.php:88
|
437 |
+
#: includes/Gateway/Digital_Wallet.php:416
|
438 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:555
|
439 |
msgid "Discount"
|
440 |
msgstr ""
|
444 |
msgid "Adjustment"
|
445 |
msgstr ""
|
446 |
|
447 |
+
#: includes/Gateway/Blocks_Handler.php:137
|
448 |
+
#: includes/Gateway/Digital_Wallet.php:205
|
449 |
+
#: includes/Gateway/Payment_Form.php:240 includes/Gateway.php:245
|
450 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/Handlers/Abstract_Hosted_Payment_Handler.php:216
|
451 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php:2758
|
452 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/integrations/class-sv-wc-payment-gateway-integration-subscriptions.php:376
|
453 |
+
msgid "An error occurred, please try again or try an alternate form of payment."
|
454 |
+
msgstr ""
|
455 |
+
|
456 |
+
#: includes/Gateway/Blocks_Handler.php:152
|
457 |
+
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php:1102
|
458 |
+
msgid "Credit Card"
|
459 |
+
msgstr ""
|
460 |
+
|
461 |
+
#: includes/Gateway/Blocks_Handler.php:298
|
462 |
+
#. translators: %1$s - opening bold HTML tag, %2$s - closing bold HTML tag,
|
463 |
+
#. %3$s - version number
|
464 |
+
msgid ""
|
465 |
+
"%1$sWarning!%2$s Some Square + Checkout Block features do not work with "
|
466 |
+
"your version of WooCommerce Blocks (%3$s). Please update to the latest "
|
467 |
+
"version of WooCommerce Blocks or WooCommerce to fix these issues."
|
468 |
+
msgstr ""
|
469 |
+
|
470 |
#: includes/Gateway/Digital_Wallet.php:110
|
471 |
#. Translators: %1$s: expected location of apple pay verification file, %2$s:
|
472 |
#. opening href tag with link to Square documentation, %3$s: closing href tag
|
490 |
msgid "OR"
|
491 |
msgstr ""
|
492 |
|
493 |
+
#: includes/Gateway/Digital_Wallet.php:274
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
494 |
#. translators: product ID
|
495 |
msgid "Product with the ID (%d) cannot be found."
|
496 |
msgstr ""
|
497 |
|
498 |
+
#: includes/Gateway/Digital_Wallet.php:290
|
499 |
#. translators: 1: product name 2: quantity in stock
|
500 |
msgid ""
|
501 |
"You cannot add that amount of \"%1$s\"; to the cart because there is not "
|
502 |
"enough stock (%2$s remaining)."
|
503 |
msgstr ""
|
504 |
|
505 |
+
#: includes/Gateway/Digital_Wallet.php:312
|
506 |
+
#: includes/Gateway/Digital_Wallet.php:408
|
507 |
msgid "Tax"
|
508 |
msgstr ""
|
509 |
|
510 |
+
#: includes/Gateway/Digital_Wallet.php:347
|
511 |
msgid "This payment method cannot be used for multiple shipments."
|
512 |
msgstr ""
|
513 |
|
514 |
+
#: includes/Gateway/Digital_Wallet.php:358
|
515 |
#: vendor/prospress/action-scheduler/classes/ActionScheduler_Store.php:182
|
516 |
msgid "Pending"
|
517 |
msgstr ""
|
518 |
|
519 |
+
#: includes/Gateway/Digital_Wallet.php:400
|
520 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:565
|
521 |
msgid "Shipping"
|
522 |
msgstr ""
|
523 |
|
524 |
+
#: includes/Gateway/Digital_Wallet.php:424
|
525 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/apple-pay/class-sv-wc-payment-gateway-apple-pay.php:575
|
526 |
msgid "Fees"
|
527 |
msgstr ""
|
528 |
|
529 |
+
#: includes/Gateway/Digital_Wallet.php:459
|
530 |
#. translators: Context (product, cart, checkout or page)
|
531 |
msgid "Empty payment request data for %s."
|
532 |
msgstr ""
|
533 |
|
534 |
+
#: includes/Gateway/Digital_Wallet.php:653
|
535 |
msgid "Empty cart"
|
536 |
msgstr ""
|
537 |
|
538 |
+
#: includes/Gateway/Digital_Wallet.php:787
|
539 |
msgid "Unable to verify domain with Apple Pay - missing access token."
|
540 |
msgstr ""
|
541 |
|
932 |
"%5$supdated documentation%6$s."
|
933 |
msgstr ""
|
934 |
|
935 |
+
#: includes/Plugin.php:456
|
936 |
#. translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s -
|
937 |
#. 2-character country code, %4$s - comma separated list of 2-character country
|
938 |
#. codes
|
941 |
"accept transactions from merchants outside of %4$s."
|
942 |
msgstr ""
|
943 |
|
944 |
+
#: includes/Plugin.php:483
|
945 |
#. translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s -
|
946 |
#. <a> tag, %4$s - </a> tag
|
947 |
msgid ""
|
950 |
"successfully with Square. %3$sRead more here%4$s on how to resolve this."
|
951 |
msgstr ""
|
952 |
|
953 |
+
#: includes/Plugin.php:526
|
954 |
#. translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag, %3$s -
|
955 |
#. <a> tag, %4$s - </a> tag
|
956 |
msgid ""
|
958 |
"Square is inactive. Please disconnect and reconnect to resolve."
|
959 |
msgstr ""
|
960 |
|
961 |
+
#: includes/Plugin.php:558
|
962 |
msgid ""
|
963 |
"%1$sWooCommerce Square:%2$s Product prices are entered inclusive of tax, "
|
964 |
"but Square does not support syncing tax-inclusive prices. Please make sure "
|
965 |
"your Square tax rates match your WooCommerce tax rates."
|
966 |
msgstr ""
|
967 |
|
968 |
+
#: includes/Plugin.php:589
|
969 |
msgid ""
|
970 |
"Heads up! Your store currency is %1$s but your configured Square business "
|
971 |
"location currency is %2$s, so payments cannot be processed. Please "
|
2915 |
msgid "Thank you for your order."
|
2916 |
msgstr ""
|
2917 |
|
|
|
|
|
|
|
|
|
2918 |
#: vendor/skyverge/wc-plugin-framework/woocommerce/payment-gateway/class-sv-wc-payment-gateway.php:1104
|
2919 |
msgid "eCheck"
|
2920 |
msgstr ""
|
includes/Gateway.php
CHANGED
@@ -55,7 +55,7 @@ class Gateway extends Framework\SV_WC_Payment_Gateway_Direct {
|
|
55 |
*
|
56 |
* @var array $sca_supported_currencies Currencies for which SCA(3DS) is supported
|
57 |
*/
|
58 |
-
private $sca_supported_currencies = array( 'GBP' );
|
59 |
|
60 |
/**
|
61 |
* Square Payment Form instance
|
@@ -889,7 +889,7 @@ class Gateway extends Framework\SV_WC_Payment_Gateway_Direct {
|
|
889 |
$is_available = false;
|
890 |
$base_location = wc_get_base_location();
|
891 |
|
892 |
-
if ( wc_site_is_https() && in_array( get_woocommerce_currency(), array( 'USD', 'GBP', 'CAD' ), true ) && ( ! empty( $base_location['country'] ) && in_array( $base_location['country'], array( 'US', 'GB', 'CA' ), true ) ) ) {
|
893 |
$is_available = true;
|
894 |
}
|
895 |
|
55 |
*
|
56 |
* @var array $sca_supported_currencies Currencies for which SCA(3DS) is supported
|
57 |
*/
|
58 |
+
private $sca_supported_currencies = array( 'GBP', 'EUR' );
|
59 |
|
60 |
/**
|
61 |
* Square Payment Form instance
|
889 |
$is_available = false;
|
890 |
$base_location = wc_get_base_location();
|
891 |
|
892 |
+
if ( wc_site_is_https() && in_array( get_woocommerce_currency(), array( 'USD', 'GBP', 'CAD', 'EUR' ), true ) && ( ! empty( $base_location['country'] ) && in_array( $base_location['country'], array( 'US', 'GB', 'CA', 'IE' ), true ) ) ) {
|
893 |
$is_available = true;
|
894 |
}
|
895 |
|
includes/Gateway/Blocks_Handler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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* WooCommerce Square
|
4 |
+
*
|
5 |
+
* This source file is subject to the GNU General Public License v3.0
|
6 |
+
* that is bundled with this package in the file license.txt.
|
7 |
+
* It is also available through the world-wide-web at this URL:
|
8 |
+
* http://www.gnu.org/licenses/gpl-3.0.html
|
9 |
+
* If you did not receive a copy of the license and are unable to
|
10 |
+
* obtain it through the world-wide-web, please send an email
|
11 |
+
* to license@woocommerce.com so we can send you a copy immediately.
|
12 |
+
*
|
13 |
+
* DISCLAIMER
|
14 |
+
*
|
15 |
+
* Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer
|
16 |
+
* versions in the future. If you wish to customize WooCommerce Square for your
|
17 |
+
* needs please refer to https://docs.woocommerce.com/document/woocommerce-square/
|
18 |
+
*/
|
19 |
+
|
20 |
+
namespace WooCommerce\Square\Gateway;
|
21 |
+
|
22 |
+
defined( 'ABSPATH' ) || exit;
|
23 |
+
|
24 |
+
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
|
25 |
+
use Automattic\WooCommerce\Blocks\Payments\PaymentResult;
|
26 |
+
use Automattic\WooCommerce\Blocks\Payments\PaymentContext;
|
27 |
+
use Automattic\WooCommerce\Blocks\Package;
|
28 |
+
use WooCommerce\Square\Plugin;
|
29 |
+
use SkyVerge\WooCommerce\PluginFramework\v5_4_0 as Framework;
|
30 |
+
|
31 |
+
class Blocks_Handler extends AbstractPaymentMethodType {
|
32 |
+
|
33 |
+
/**
|
34 |
+
* @var string $name
|
35 |
+
*/
|
36 |
+
protected $name = 'square_credit_card';
|
37 |
+
|
38 |
+
/**
|
39 |
+
* @var Plugin $plugin
|
40 |
+
*/
|
41 |
+
protected $plugin = null;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var Gateway $gateway
|
45 |
+
*/
|
46 |
+
protected $gateway = null;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Init Square Cart and Checkout Blocks handler class
|
50 |
+
*
|
51 |
+
* @since 2.5
|
52 |
+
*/
|
53 |
+
public function __construct() {
|
54 |
+
$this->plugin = wc_square();
|
55 |
+
|
56 |
+
add_action(
|
57 |
+
'woocommerce_blocks_enqueue_checkout_block_scripts_before',
|
58 |
+
function() {
|
59 |
+
add_filter( 'woocommerce_saved_payment_methods_list', array( $this, 'add_square_saved_payment_methods' ), 10, 2 );
|
60 |
+
}
|
61 |
+
);
|
62 |
+
add_action(
|
63 |
+
'woocommerce_blocks_enqueue_checkout_block_scripts_after',
|
64 |
+
function () {
|
65 |
+
remove_filter( 'woocommerce_saved_payment_methods_list', array( $this, 'add_square_saved_payment_methods' ) );
|
66 |
+
}
|
67 |
+
);
|
68 |
+
|
69 |
+
add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( $this, 'log_js_data' ), 10, 2 );
|
70 |
+
|
71 |
+
add_action( 'admin_notices', array( $this, 'display_compatible_version_notice' ) );
|
72 |
+
}
|
73 |
+
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Initializes the payment method type.
|
77 |
+
*/
|
78 |
+
public function initialize() {
|
79 |
+
$this->settings = get_option( 'woocommerce_square_credit_card_settings', array() );
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Returns if this payment method should be active. If false, the scripts will not be enqueued.
|
84 |
+
*
|
85 |
+
* @return boolean
|
86 |
+
*/
|
87 |
+
public function is_active() {
|
88 |
+
return ! empty( $this->get_gateway() ) ? $this->get_gateway()->is_available() : false;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Register scripts
|
93 |
+
*
|
94 |
+
* @return array
|
95 |
+
*/
|
96 |
+
public function get_payment_method_script_handles() {
|
97 |
+
$asset_path = $this->plugin->get_plugin_path() . '/assets/blocks/build/index.asset.php';
|
98 |
+
$version = Plugin::VERSION;
|
99 |
+
$dependencies = array();
|
100 |
+
|
101 |
+
if ( file_exists( $asset_path ) ) {
|
102 |
+
$asset = require $asset_path;
|
103 |
+
$version = is_array( $asset ) && isset( $asset['version'] ) ? $asset['version'] : $version;
|
104 |
+
$dependencies = is_array( $asset ) && isset( $asset['dependencies'] ) ? $asset['dependencies'] : $dependencies;
|
105 |
+
}
|
106 |
+
|
107 |
+
wp_enqueue_style( 'wc-square-cart-checkout-block', $this->plugin->get_plugin_url() . '/assets/css/frontend/wc-square-cart-checkout-blocks.min.css', array(), Plugin::VERSION );
|
108 |
+
wp_register_script(
|
109 |
+
'wc-square-credit-card-blocks-integration',
|
110 |
+
$this->plugin->get_plugin_url() . '/build/index.js',
|
111 |
+
$dependencies,
|
112 |
+
$version,
|
113 |
+
true
|
114 |
+
);
|
115 |
+
|
116 |
+
wp_set_script_translations( 'wc-square-credit-card-blocks-integration', 'woocommerce-square' );
|
117 |
+
|
118 |
+
return array( 'wc-square-credit-card-blocks-integration' );
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Returns an array of key=>value pairs of data made available to the payment methods script.
|
123 |
+
*
|
124 |
+
* @since 2.5
|
125 |
+
* @return array
|
126 |
+
*/
|
127 |
+
public function get_payment_method_data() {
|
128 |
+
return empty( $this->get_gateway() ) ? array() : array(
|
129 |
+
'title' => $this->get_setting( 'title' ),
|
130 |
+
'application_id' => $this->get_gateway()->get_application_id(),
|
131 |
+
'location_id' => $this->plugin->get_settings_handler()->get_location_id(),
|
132 |
+
'is_sandbox' => $this->plugin->get_settings_handler()->is_sandbox(),
|
133 |
+
'is_3ds_enabled' => $this->get_gateway()->is_3d_secure_enabled(),
|
134 |
+
'input_styles' => $this->get_input_styles(),
|
135 |
+
'available_card_types' => $this->get_available_card_types(),
|
136 |
+
'logging_enabled' => $this->get_gateway()->debug_log(),
|
137 |
+
'general_error' => __( 'An error occurred, please try again or try an alternate form of payment.', 'woocommerce-square' ),
|
138 |
+
'supports' => $this->get_supported_features(),
|
139 |
+
'show_saved_cards' => $this->get_gateway()->tokenization_enabled(),
|
140 |
+
'show_save_option' => $this->get_gateway()->tokenization_enabled(),
|
141 |
+
);
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Helper function to get title of Square gateway to be displayed as Label on checkout block.
|
146 |
+
* Defaults to "Credit Card"
|
147 |
+
*
|
148 |
+
* @since 2.5
|
149 |
+
* @return string
|
150 |
+
*/
|
151 |
+
private function get_title() {
|
152 |
+
return ! empty( $this->get_setting( 'title' ) ) ? $this->get_setting( 'title' ) : esc_html__( 'Credit Card', 'woocommerce-square' );
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Get Square Payment Form iframe input styles
|
157 |
+
*
|
158 |
+
* @since 2.5
|
159 |
+
* @return array
|
160 |
+
*/
|
161 |
+
private function get_input_styles() {
|
162 |
+
$input_styles = array(
|
163 |
+
array(
|
164 |
+
'backgroundColor' => 'transparent',
|
165 |
+
'fontSize' => '1.3em',
|
166 |
+
),
|
167 |
+
);
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Filters the the Square payment form input styles.
|
171 |
+
*
|
172 |
+
* @since 2.5
|
173 |
+
* @param array $styles array of input styles
|
174 |
+
*/
|
175 |
+
return (array) apply_filters( 'wc_square_credit_card_payment_form_input_styles', $input_styles, $this );
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Get a list of available card types
|
180 |
+
*
|
181 |
+
* @since 2.5
|
182 |
+
* @return array
|
183 |
+
*/
|
184 |
+
private function get_available_card_types() {
|
185 |
+
$card_types = array();
|
186 |
+
$square_card_types = array(
|
187 |
+
'visa' => 'visa',
|
188 |
+
'mastercard' => 'masterCard',
|
189 |
+
'amex' => 'americanExpress',
|
190 |
+
'dinersclub' => 'discoverDiners',
|
191 |
+
'jcb' => 'JCB',
|
192 |
+
'discover' => 'discover',
|
193 |
+
);
|
194 |
+
|
195 |
+
$enabled_card_types = is_array( $this->get_gateway()->get_card_types() ) ? $this->get_gateway()->get_card_types() : array();
|
196 |
+
$enabled_card_types = array_map( array( Framework\SV_WC_Payment_Gateway_Helper::class, 'normalize_card_type' ), $enabled_card_types );
|
197 |
+
|
198 |
+
foreach ( $enabled_card_types as $card_type ) {
|
199 |
+
if ( ! empty( $square_card_types[ $card_type ] ) ) {
|
200 |
+
$card_types[ $card_type ] = $square_card_types[ $card_type ];
|
201 |
+
}
|
202 |
+
}
|
203 |
+
|
204 |
+
return array_flip( $card_types );
|
205 |
+
}
|
206 |
+
|
207 |
+
/**
|
208 |
+
* Get a list of features supported by Square
|
209 |
+
*
|
210 |
+
* @since 2.5
|
211 |
+
* @return array
|
212 |
+
*/
|
213 |
+
public function get_supported_features() {
|
214 |
+
$gateway = $this->get_gateway();
|
215 |
+
return ! empty( $gateway ) ? array_filter( $gateway->supports, array( $gateway, 'supports' ) ) : array();
|
216 |
+
}
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Manually adds the customers Square cards to the list of cards returned
|
220 |
+
* by the `woocommerce_saved_payment_methods_list` filter.
|
221 |
+
*
|
222 |
+
* With Square, we don't store customer cards in WC's payment token table so
|
223 |
+
* in order for them to appear on the checkout block we have to manually add them.
|
224 |
+
*
|
225 |
+
* @since 2.5
|
226 |
+
* @param array $saved_methods
|
227 |
+
* @param int $user_id
|
228 |
+
* @return array
|
229 |
+
*/
|
230 |
+
public function add_square_saved_payment_methods( $saved_methods, $user_id ) {
|
231 |
+
$tokens = $this->get_gateway()->get_payment_tokens_handler()->get_tokens( $user_id );
|
232 |
+
|
233 |
+
foreach ( $tokens as $token ) {
|
234 |
+
$saved_method = array(
|
235 |
+
'method' => array(
|
236 |
+
'gateway' => 'square-credit-card', // using the dasherized version of the payment method ID so that the element ID for the saved card is correct
|
237 |
+
'last4' => $token->get_last_four(),
|
238 |
+
'brand' => wc_get_credit_card_type_label( $token->get_card_type() ),
|
239 |
+
),
|
240 |
+
'expires' => $token->get_exp_date(),
|
241 |
+
'is_default' => $token->is_default(),
|
242 |
+
'actions' => array(),
|
243 |
+
'tokenId' => $token->get_id(),
|
244 |
+
);
|
245 |
+
|
246 |
+
$saved_methods['cc'][] = $saved_method;
|
247 |
+
}
|
248 |
+
|
249 |
+
return $saved_methods;
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Hooked on before `process_legacy_payment` and logs any data recording during
|
254 |
+
* the checkout process on client-side.
|
255 |
+
*
|
256 |
+
* If the checkout recorded an error, skip validating the checkout fields by setting the
|
257 |
+
* 'error' status on the PaymentResult.
|
258 |
+
*
|
259 |
+
* @since 2.5
|
260 |
+
* @param PaymentContext $context Holds context for the payment.
|
261 |
+
* @param PaymentResult $result Result of the payment.
|
262 |
+
*/
|
263 |
+
public function log_js_data( PaymentContext $context, PaymentResult &$result ) {
|
264 |
+
if ( 'square_credit_card' === $context->payment_method ) {
|
265 |
+
if ( ! empty( $context->payment_data['log-data'] ) ) {
|
266 |
+
$log_data = json_decode( $context->payment_data['log-data'], true );
|
267 |
+
|
268 |
+
if ( ! empty( $log_data ) ) {
|
269 |
+
foreach ( $log_data as $data ) {
|
270 |
+
$message = sprintf( "[Checkout Block] Square.js Response:\n %s", print_r( wc_clean( $data ), true ) ); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
271 |
+
$this->plugin->log( $message, $this->get_gateway()->get_id() );
|
272 |
+
}
|
273 |
+
}
|
274 |
+
}
|
275 |
+
|
276 |
+
if ( ! empty( $context->payment_data['checkout-notices'] ) ) {
|
277 |
+
$payment_details = $result->payment_details;
|
278 |
+
$payment_details['checkoutNotices'] = $context->payment_data['checkout-notices'];
|
279 |
+
|
280 |
+
$result->set_payment_details( $payment_details );
|
281 |
+
$result->set_status( 'error' );
|
282 |
+
}
|
283 |
+
}
|
284 |
+
}
|
285 |
+
|
286 |
+
/**
|
287 |
+
* Display an admin notice for stores that are running WooCommerce Blocks < 4.8 and also have 3D Secure turned on.
|
288 |
+
*
|
289 |
+
* @since 2.5
|
290 |
+
*/
|
291 |
+
public function display_compatible_version_notice() {
|
292 |
+
$wc_blocks_version = Package::get_version();
|
293 |
+
|
294 |
+
if ( version_compare( $wc_blocks_version, '4.8.0', '<' ) && 'yes' === $this->get_gateway()->get_option( 'enabled', 'no' ) && $this->get_gateway()->is_3d_secure_enabled() ) {
|
295 |
+
?>
|
296 |
+
<div class="notice notice-warning is-dismissible">
|
297 |
+
<?php // translators: %1$s - opening bold HTML tag, %2$s - closing bold HTML tag, %3$s - version number ?>
|
298 |
+
<p><?php echo sprintf( esc_html__( '%1$sWarning!%2$s Some Square + Checkout Block features do not work with your version of WooCommerce Blocks (%3$s). Please update to the latest version of WooCommerce Blocks or WooCommerce to fix these issues.', 'woocommerce-square' ), '<strong>', '</strong>', esc_html( $wc_blocks_version ) ); ?></p>
|
299 |
+
</div>
|
300 |
+
<?php
|
301 |
+
}
|
302 |
+
}
|
303 |
+
|
304 |
+
/**
|
305 |
+
* Helper function to get and store an instance of the Square gateway
|
306 |
+
*
|
307 |
+
* @since 2.5
|
308 |
+
* @return Gateway
|
309 |
+
*/
|
310 |
+
private function get_gateway() {
|
311 |
+
if ( empty( $this->gateway ) ) {
|
312 |
+
$gateways = $this->plugin->get_gateways();
|
313 |
+
$this->gateway = ! empty( $gateways ) ? array_pop( $gateways ) : null;
|
314 |
+
}
|
315 |
+
|
316 |
+
return $this->gateway;
|
317 |
+
}
|
318 |
+
}
|
includes/Gateway/Digital_Wallet.php
CHANGED
@@ -210,6 +210,7 @@ class Digital_Wallet {
|
|
210 |
'process_checkout_nonce' => wp_create_nonce( 'woocommerce-process_checkout' ),
|
211 |
'logging_enabled' => $this->gateway->debug_log(),
|
212 |
'hide_button_options' => $this->get_hidden_button_options(),
|
|
|
213 |
)
|
214 |
);
|
215 |
|
210 |
'process_checkout_nonce' => wp_create_nonce( 'woocommerce-process_checkout' ),
|
211 |
'logging_enabled' => $this->gateway->debug_log(),
|
212 |
'hide_button_options' => $this->get_hidden_button_options(),
|
213 |
+
'is_3d_secure_enabled' => $this->gateway->is_3d_secure_enabled(),
|
214 |
)
|
215 |
);
|
216 |
|
includes/Plugin.php
CHANGED
@@ -42,7 +42,7 @@ class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
|
|
42 |
|
43 |
|
44 |
/** plugin version number */
|
45 |
-
const VERSION = '2.
|
46 |
|
47 |
/** plugin ID */
|
48 |
const PLUGIN_ID = 'square';
|
@@ -443,6 +443,7 @@ class Plugin extends Framework\SV_WC_Payment_Gateway_Plugin {
|
|
443 |
'GB',
|
444 |
'AU',
|
445 |
'JP',
|
|
|
446 |
);
|
447 |
|
448 |
$base_location = wc_get_base_location();
|
42 |
|
43 |
|
44 |
/** plugin version number */
|
45 |
+
const VERSION = '2.5.0';
|
46 |
|
47 |
/** plugin ID */
|
48 |
const PLUGIN_ID = 'square';
|
443 |
'GB',
|
444 |
'AU',
|
445 |
'JP',
|
446 |
+
'IE',
|
447 |
);
|
448 |
|
449 |
$base_location = wc_get_base_location();
|
includes/Sync/Manual_Synchronization.php
CHANGED
@@ -1738,8 +1738,7 @@ class Manual_Synchronization extends Stepped_Job {
|
|
1738 |
* @return int
|
1739 |
*/
|
1740 |
protected function get_max_objects_to_retrieve() {
|
1741 |
-
|
1742 |
-
$max = $this->get_attr( 'max_objects_to_retrieve', 300 );
|
1743 |
|
1744 |
/**
|
1745 |
* Filters the maximum number of objects to retrieve in a single sync job.
|
@@ -1816,6 +1815,4 @@ class Manual_Synchronization extends Stepped_Job {
|
|
1816 |
*/
|
1817 |
return max( 1, (int) apply_filters( 'wc_square_sync_max_objects_total', $max ) );
|
1818 |
}
|
1819 |
-
|
1820 |
-
|
1821 |
}
|
1738 |
* @return int
|
1739 |
*/
|
1740 |
protected function get_max_objects_to_retrieve() {
|
1741 |
+
$max = $this->get_attr( 'max_objects_to_retrieve', 100 );
|
|
|
1742 |
|
1743 |
/**
|
1744 |
* Filters the maximum number of objects to retrieve in a single sync job.
|
1815 |
*/
|
1816 |
return max( 1, (int) apply_filters( 'wc_square_sync_max_objects_total', $max ) );
|
1817 |
}
|
|
|
|
|
1818 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: credit card, square, woocommerce, inventory sync
|
|
4 |
Requires at least: 4.6
|
5 |
Tested up to: 5.7
|
6 |
Requires PHP: 5.6
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv3
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
@@ -71,6 +71,11 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
|
|
71 |
2. The payment gateway settings.
|
72 |
|
73 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
74 |
= 2.4.1 - 2021.03.30 =
|
75 |
* Fix - Variable products are now properly importing from Square on newer versions of WooCommerce. PR#605
|
76 |
|
4 |
Requires at least: 4.6
|
5 |
Tested up to: 5.7
|
6 |
Requires PHP: 5.6
|
7 |
+
Stable tag: 2.5.0
|
8 |
License: GPLv3
|
9 |
License URI: https://www.gnu.org/licenses/gpl-3.0.html
|
10 |
|
71 |
2. The payment gateway settings.
|
72 |
|
73 |
== Changelog ==
|
74 |
+
= 2.5.0 - 2021.05.13 =
|
75 |
+
* New - Add support for WooCommerce Checkout blocks. PR#604
|
76 |
+
* New - Add support for Square stores located in Ireland. PR#609
|
77 |
+
* Fix - Improve manual sync performance and reduce stream timeout responses from Square on stores with large catalogs. PR#612
|
78 |
+
|
79 |
= 2.4.1 - 2021.03.30 =
|
80 |
* Fix - Variable products are now properly importing from Square on newer versions of WooCommerce. PR#605
|
81 |
|
woocommerce-square.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: WooCommerce Square
|
4 |
-
* Version: 2.
|
5 |
* Plugin URI: https://woocommerce.com/products/square/
|
6 |
* Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
|
7 |
* Author: WooCommerce
|
@@ -19,7 +19,7 @@
|
|
19 |
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
|
20 |
*
|
21 |
* WC requires at least: 3.0
|
22 |
-
* WC tested up to: 5.
|
23 |
*/
|
24 |
|
25 |
defined( 'ABSPATH' ) || exit;
|
@@ -75,6 +75,8 @@ class WooCommerce_Square_Loader {
|
|
75 |
if ( $this->is_environment_compatible() ) {
|
76 |
add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
|
77 |
}
|
|
|
|
|
78 |
}
|
79 |
|
80 |
|
@@ -374,6 +376,18 @@ class WooCommerce_Square_Loader {
|
|
374 |
}
|
375 |
|
376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
/**
|
378 |
* Gets the main plugin loader instance.
|
379 |
*
|
1 |
<?php
|
2 |
/**
|
3 |
* Plugin Name: WooCommerce Square
|
4 |
+
* Version: 2.5.0
|
5 |
* Plugin URI: https://woocommerce.com/products/square/
|
6 |
* Description: Adds ability to sync inventory between WooCommerce and Square POS. In addition, you can also make purchases through the Square payment gateway.
|
7 |
* Author: WooCommerce
|
19 |
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
|
20 |
*
|
21 |
* WC requires at least: 3.0
|
22 |
+
* WC tested up to: 5.3
|
23 |
*/
|
24 |
|
25 |
defined( 'ABSPATH' ) || exit;
|
75 |
if ( $this->is_environment_compatible() ) {
|
76 |
add_action( 'plugins_loaded', array( $this, 'init_plugin' ) );
|
77 |
}
|
78 |
+
|
79 |
+
add_action( 'woocommerce_blocks_payment_method_type_registration', array( $this, 'register_payment_method_block_integrations' ), 5, 1 );
|
80 |
}
|
81 |
|
82 |
|
376 |
}
|
377 |
|
378 |
|
379 |
+
/**
|
380 |
+
* Register the Square Credit Card checkout block integration class
|
381 |
+
*
|
382 |
+
* @since 2.5.0
|
383 |
+
*/
|
384 |
+
public function register_payment_method_block_integrations( $payment_method_registry ) {
|
385 |
+
if ( class_exists( '\Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) {
|
386 |
+
$payment_method_registry->register( new WooCommerce\Square\Gateway\Blocks_Handler() );
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
|
391 |
/**
|
392 |
* Gets the main plugin loader instance.
|
393 |
*
|