2020-11-17 10:51:27 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
|
|
|
2020-03-10 13:39:21 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { TYPES, DEFAULT_STATE, STATUS } from './constants';
|
|
|
|
|
|
|
|
const {
|
|
|
|
SET_PRISTINE,
|
2020-04-14 16:52:23 +00:00
|
|
|
SET_IDLE,
|
2020-03-10 13:39:21 +00:00
|
|
|
SET_PROCESSING,
|
2020-04-14 16:52:23 +00:00
|
|
|
SET_BEFORE_PROCESSING,
|
|
|
|
SET_AFTER_PROCESSING,
|
|
|
|
SET_PROCESSING_RESPONSE,
|
2020-03-10 13:39:21 +00:00
|
|
|
SET_REDIRECT_URL,
|
|
|
|
SET_COMPLETE,
|
|
|
|
SET_HAS_ERROR,
|
|
|
|
SET_NO_ERROR,
|
|
|
|
INCREMENT_CALCULATING,
|
|
|
|
DECREMENT_CALCULATING,
|
2020-12-02 14:27:28 +00:00
|
|
|
SET_CUSTOMER_ID,
|
2020-03-30 14:32:23 +00:00
|
|
|
SET_ORDER_ID,
|
2020-07-31 15:17:01 +00:00
|
|
|
SET_ORDER_NOTES,
|
Support "create account" option in checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/2851)
* prototype 'create account' checkbox in checkout block
* expose store config for generating password/username to blocks:
+ use FILTER_VALIDATE_BOOLEAN instead of hard-coded `yes`
* stub out signup form in checkout block
* context / provider to store checkout signup form data
* revert signup form - checkout block will always generate username etc
* persist signup checkbox in checkout state & pass to checkout API
* add `create_account` param to order API, fix name in client POST
* handle creating user account as part of order (first cut)
* ensure the order is associated with the new customer
* only show 'create account' checkbox when appropriate (guest checkout)
* remove unnecessary username/password variables
* refactor account-creation logic into functions:
- clarify inputs and outputs
- use RouteException for error handling
- use woo options directly, avoid dependency on WC_Checkout
* update "email exists" error message to use existing error message text
* handle all known errors from wc_create_new_customer + use core message
* only show "create account" checkbox to shopper when necessary:
- if guest checkout is disabled, user must create account - not optional
* only show "create account" if account creation is optional:
- fixes incorrect logic in previous commit
- add some comments to clarify
* fix create account logic in API when checkout requires account:
- use correct woo setting option name
- reverse logic to match option = allow guest false means registration required
* strip html tags from create account error messages
* temporarily force enable autogenerate user/pass in new account API
* fix rebase errors
* add new allowCreateAccount attribute in checkout block
* show/hide `Create account` checkbox dependent on block attribute:
- previously was dependent on store setting
* new create user API, with set initial password email (first cut):
- use core register_new_user for creating the user
- this triggers core "set new password" email
- generate username using logic lifted from WC core
- rough cut, lots to tidy/polish here
* remove alternative/unused create account function
* set `Customer` role for signups during checkout
* eslint fix - switch case break
* remove comments that mirror code & might go stale
* tidy func comment
* remove unused function
* use store setting `allow signup` for default value of new block option
* refactor order signup logic to service class first cut:
- new CreateAccount service
- hook up via custom action (for now at least)
- paste over existing create account logic (temporary - will be replaced)
* adapt wc_create_new_customer logic in CreateAccount service (WIP)
* set default_password_nag on new account + throw instead of WP_Error
* rename `createAccount` => `shouldCreateAccount` to clarify meaning
* fix checkout block - renamed `shouldCreateAccount` (missed in prev commit)
* prototype sending alternative email template for checkout signup
* add magic link to set password to blocks new account html email
* tidy up new account email templates - set password link, subject/heading
* use same id so merchant setting tweaks apply to our new improved email
* remove logging
* code tidies in CreateAccount service:
- remove unnecessary constructor
- type-hint in should_create_customer_account
- streamline logic in should_create_customer_account - remove
unnecessary `empty` check
- add comments to illuminate different use-cases handled by should_create_customer_account
* don't provide password to new account email templates (no longer used)
* declare dependencies in root namespace
* code tidies on new account email class:
- correct namespace and camelcase name
- declare class in file, don't instantiate; instantiate in client code
(CreateAccount service) when used
- no require/file import, use `use`
* move CustomerNewEmail to folder matching namespace
* use Package->get_path for email template paths:
- CreateAccount service now depends on Package
- CreateAccount passes Package to email class so it can use `get_path`
- note: CustomerNewAccount is not registered with DI container as it
needs to be instantiated after Woo init (for `WC_Email`)
- shift email templates to {plugin}/templates, consistent with WP
convention
* call CreateAccount::from_order_request directly, no custom hook:
- custom hook is not appropriate as we may not want to allow
extensibility in this way - TBD
* add appropriate margin above create account checkbox
* remove unnecessary direct-access protection
* generalise name of error-handling method
* simplify CustomerNewAccount - instantiate directly, when needed
* remove unused new_account_email member - now instantiated on demand
* numerous fixes and updates due to rebase changes
* fix typo in name of CustomerNewAccount php file (missing `n`)
* experiment - link to lost-password form in my-account (prototype branded screen)
* Revert "experiment - link to lost-password form in my-account (prototype branded screen)"
This reverts commit e1dc6dd5e9f0218ede81da92188d813c2d0856d9.
* feature gate CreateAccount service init to dev build only +
+ remove stale comment
* feature gate front end "Create account" checkbox to feature plugin only
* feature gate editor "allow signup" option to dev build only
* feature gate checkout api create account - dev build only
* tweak feature gating PHP logic so it's robust:
- all PHP feature gating is in the service class
- all publicly-available methods return early if feature gate off
- Checkout rest API transparently calls service - no explicit feature
gate at API level
* ensure frontend/editor features are feature gated (isExperimentalBuild is a function)
* feature gate value of checkoutAllowsSignup - can only be true in feature plugin
* fix a / an typo in comment
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* remove commented code
* hello world unit test (doesn't test anything yet)
* add a command for running unit tests when container already up:
- this should probably move to another PR/branch
* basic tests of core logic in CreateAccount service
* import isExperimentalBuild direct:
- import from alias package was causing an issue, likely a dependency cycle
* refactor from_order_request to return new user ID so it's easier to test
* test creating a customer from an order + rest request:
- i.e. a full end-to-end integration test
* delete redundant test and tidy comments
* generalise test to provider format
* refactor create-dup-user err test to use same approach as success test
* add test for when user should not be created
* don't hard-code options in "create" test, remove redundant provider in no-account-requested test
* de-generalise "user already signed up" test
* add test for malformed email
* flesh out & comment successful signup tests
* flesh out "invalid email" tests
* clarify no account requested test comment
* remove phpunit:quick - I don't think it's needed
* add comment explaining this is an integration test
* experiment – disable feature flag, is this why the tests are failing?
* revert test commit - restore feature gate (experimental flag)
* skip all tests if CreateAccount is disabled due to feature flag
* d'oh - expose CreateAccount:is_feature_enabled so can be used in tests
* add jsdoc for checkout-state shouldCreateAccount field
* remove unnecessary comment + fix whitespace/indentation
* simulate logged-out user for createaccount signup tests
* use a single, compound if statement for early return (review nitpick)
* don't hide `checkoutAllowsSignup` store setting behind feature flag:
- the feature flag should be used to enable/disable behaviour
- it's dangerous to adjust store settings/options based on feature flag
* rejig tests so they require woocommerce_blocks_phase==3:
- make feature gate method private to avoid exposing
- remove feature flag check & test skip for other builds
- set blocks phase in travis config
* remove redundant user-logout in test setup - cleaner to just require this
* use WP function bracket style (same line)
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2020-10-01 02:07:16 +00:00
|
|
|
SET_SHOULD_CREATE_ACCOUNT,
|
2020-03-10 13:39:21 +00:00
|
|
|
} = TYPES;
|
|
|
|
|
2020-04-14 16:52:23 +00:00
|
|
|
const {
|
|
|
|
PRISTINE,
|
|
|
|
IDLE,
|
|
|
|
PROCESSING,
|
|
|
|
BEFORE_PROCESSING,
|
|
|
|
AFTER_PROCESSING,
|
|
|
|
COMPLETE,
|
|
|
|
} = STATUS;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares the payment_result data from the server checkout endpoint response.
|
|
|
|
*
|
|
|
|
* @param {Object} data The value of `payment_result` from the checkout
|
|
|
|
* processing endpoint response.
|
2020-04-16 14:39:46 +00:00
|
|
|
* @param {string} data.message If there was a general error message it will appear
|
|
|
|
* on this property.
|
2020-04-14 16:52:23 +00:00
|
|
|
* @param {string} data.payment_status The payment status. One of 'success', 'failure',
|
|
|
|
* 'pending', 'error'.
|
|
|
|
* @param {Array<Object>} data.payment_details An array of Objects with a 'key' property that is a
|
|
|
|
* string and value property that is a string. These are
|
|
|
|
* converted to a flat object where the key becomes the
|
|
|
|
* object property and value the property value.
|
|
|
|
*
|
|
|
|
* @return {Object} A new object with 'paymentStatus', and 'paymentDetails' as the properties.
|
|
|
|
*/
|
|
|
|
export const prepareResponseData = ( data ) => {
|
|
|
|
const responseData = {
|
2020-04-16 14:39:46 +00:00
|
|
|
message: data?.message || '',
|
2020-04-14 16:52:23 +00:00
|
|
|
paymentStatus: data.payment_status,
|
|
|
|
paymentDetails: {},
|
|
|
|
};
|
|
|
|
if ( Array.isArray( data.payment_details ) ) {
|
|
|
|
data.payment_details.forEach( ( { key, value } ) => {
|
2020-11-17 10:51:27 +00:00
|
|
|
responseData.paymentDetails[ key ] = decodeEntities( value );
|
2020-04-14 16:52:23 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
return responseData;
|
|
|
|
};
|
2020-03-10 13:39:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducer for the checkout state
|
|
|
|
*
|
|
|
|
* @param {Object} state Current state.
|
|
|
|
* @param {Object} action Incoming action object.
|
2020-09-20 23:54:08 +00:00
|
|
|
* @param {string} action.url URL passed in.
|
|
|
|
* @param {string} action.type Type of action.
|
2020-12-02 14:27:28 +00:00
|
|
|
* @param {string} action.customerId Customer ID.
|
2020-09-20 23:54:08 +00:00
|
|
|
* @param {string} action.orderId Order ID.
|
|
|
|
* @param {Array} action.orderNotes Order notes.
|
Support "create account" option in checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/2851)
* prototype 'create account' checkbox in checkout block
* expose store config for generating password/username to blocks:
+ use FILTER_VALIDATE_BOOLEAN instead of hard-coded `yes`
* stub out signup form in checkout block
* context / provider to store checkout signup form data
* revert signup form - checkout block will always generate username etc
* persist signup checkbox in checkout state & pass to checkout API
* add `create_account` param to order API, fix name in client POST
* handle creating user account as part of order (first cut)
* ensure the order is associated with the new customer
* only show 'create account' checkbox when appropriate (guest checkout)
* remove unnecessary username/password variables
* refactor account-creation logic into functions:
- clarify inputs and outputs
- use RouteException for error handling
- use woo options directly, avoid dependency on WC_Checkout
* update "email exists" error message to use existing error message text
* handle all known errors from wc_create_new_customer + use core message
* only show "create account" checkbox to shopper when necessary:
- if guest checkout is disabled, user must create account - not optional
* only show "create account" if account creation is optional:
- fixes incorrect logic in previous commit
- add some comments to clarify
* fix create account logic in API when checkout requires account:
- use correct woo setting option name
- reverse logic to match option = allow guest false means registration required
* strip html tags from create account error messages
* temporarily force enable autogenerate user/pass in new account API
* fix rebase errors
* add new allowCreateAccount attribute in checkout block
* show/hide `Create account` checkbox dependent on block attribute:
- previously was dependent on store setting
* new create user API, with set initial password email (first cut):
- use core register_new_user for creating the user
- this triggers core "set new password" email
- generate username using logic lifted from WC core
- rough cut, lots to tidy/polish here
* remove alternative/unused create account function
* set `Customer` role for signups during checkout
* eslint fix - switch case break
* remove comments that mirror code & might go stale
* tidy func comment
* remove unused function
* use store setting `allow signup` for default value of new block option
* refactor order signup logic to service class first cut:
- new CreateAccount service
- hook up via custom action (for now at least)
- paste over existing create account logic (temporary - will be replaced)
* adapt wc_create_new_customer logic in CreateAccount service (WIP)
* set default_password_nag on new account + throw instead of WP_Error
* rename `createAccount` => `shouldCreateAccount` to clarify meaning
* fix checkout block - renamed `shouldCreateAccount` (missed in prev commit)
* prototype sending alternative email template for checkout signup
* add magic link to set password to blocks new account html email
* tidy up new account email templates - set password link, subject/heading
* use same id so merchant setting tweaks apply to our new improved email
* remove logging
* code tidies in CreateAccount service:
- remove unnecessary constructor
- type-hint in should_create_customer_account
- streamline logic in should_create_customer_account - remove
unnecessary `empty` check
- add comments to illuminate different use-cases handled by should_create_customer_account
* don't provide password to new account email templates (no longer used)
* declare dependencies in root namespace
* code tidies on new account email class:
- correct namespace and camelcase name
- declare class in file, don't instantiate; instantiate in client code
(CreateAccount service) when used
- no require/file import, use `use`
* move CustomerNewEmail to folder matching namespace
* use Package->get_path for email template paths:
- CreateAccount service now depends on Package
- CreateAccount passes Package to email class so it can use `get_path`
- note: CustomerNewAccount is not registered with DI container as it
needs to be instantiated after Woo init (for `WC_Email`)
- shift email templates to {plugin}/templates, consistent with WP
convention
* call CreateAccount::from_order_request directly, no custom hook:
- custom hook is not appropriate as we may not want to allow
extensibility in this way - TBD
* add appropriate margin above create account checkbox
* remove unnecessary direct-access protection
* generalise name of error-handling method
* simplify CustomerNewAccount - instantiate directly, when needed
* remove unused new_account_email member - now instantiated on demand
* numerous fixes and updates due to rebase changes
* fix typo in name of CustomerNewAccount php file (missing `n`)
* experiment - link to lost-password form in my-account (prototype branded screen)
* Revert "experiment - link to lost-password form in my-account (prototype branded screen)"
This reverts commit e1dc6dd5e9f0218ede81da92188d813c2d0856d9.
* feature gate CreateAccount service init to dev build only +
+ remove stale comment
* feature gate front end "Create account" checkbox to feature plugin only
* feature gate editor "allow signup" option to dev build only
* feature gate checkout api create account - dev build only
* tweak feature gating PHP logic so it's robust:
- all PHP feature gating is in the service class
- all publicly-available methods return early if feature gate off
- Checkout rest API transparently calls service - no explicit feature
gate at API level
* ensure frontend/editor features are feature gated (isExperimentalBuild is a function)
* feature gate value of checkoutAllowsSignup - can only be true in feature plugin
* fix a / an typo in comment
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* remove commented code
* hello world unit test (doesn't test anything yet)
* add a command for running unit tests when container already up:
- this should probably move to another PR/branch
* basic tests of core logic in CreateAccount service
* import isExperimentalBuild direct:
- import from alias package was causing an issue, likely a dependency cycle
* refactor from_order_request to return new user ID so it's easier to test
* test creating a customer from an order + rest request:
- i.e. a full end-to-end integration test
* delete redundant test and tidy comments
* generalise test to provider format
* refactor create-dup-user err test to use same approach as success test
* add test for when user should not be created
* don't hard-code options in "create" test, remove redundant provider in no-account-requested test
* de-generalise "user already signed up" test
* add test for malformed email
* flesh out & comment successful signup tests
* flesh out "invalid email" tests
* clarify no account requested test comment
* remove phpunit:quick - I don't think it's needed
* add comment explaining this is an integration test
* experiment – disable feature flag, is this why the tests are failing?
* revert test commit - restore feature gate (experimental flag)
* skip all tests if CreateAccount is disabled due to feature flag
* d'oh - expose CreateAccount:is_feature_enabled so can be used in tests
* add jsdoc for checkout-state shouldCreateAccount field
* remove unnecessary comment + fix whitespace/indentation
* simulate logged-out user for createaccount signup tests
* use a single, compound if statement for early return (review nitpick)
* don't hide `checkoutAllowsSignup` store setting behind feature flag:
- the feature flag should be used to enable/disable behaviour
- it's dangerous to adjust store settings/options based on feature flag
* rejig tests so they require woocommerce_blocks_phase==3:
- make feature gate method private to avoid exposing
- remove feature flag check & test skip for other builds
- set blocks phase in travis config
* remove redundant user-logout in test setup - cleaner to just require this
* use WP function bracket style (same line)
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2020-10-01 02:07:16 +00:00
|
|
|
* @param {boolean} action.shouldCreateAccount True if shopper has requested a user account (signup checkbox).
|
2020-09-20 23:54:08 +00:00
|
|
|
* @param {Object} action.data Other action payload.
|
2020-03-10 13:39:21 +00:00
|
|
|
*/
|
2020-04-14 16:52:23 +00:00
|
|
|
export const reducer = (
|
|
|
|
state = DEFAULT_STATE,
|
2020-12-02 14:27:28 +00:00
|
|
|
{ url, type, customerId, orderId, orderNotes, shouldCreateAccount, data }
|
2020-04-14 16:52:23 +00:00
|
|
|
) => {
|
2020-07-31 15:17:01 +00:00
|
|
|
let newState = state;
|
2020-03-10 13:39:21 +00:00
|
|
|
switch ( type ) {
|
|
|
|
case SET_PRISTINE:
|
|
|
|
newState = DEFAULT_STATE;
|
|
|
|
break;
|
2020-04-14 16:52:23 +00:00
|
|
|
case SET_IDLE:
|
|
|
|
newState =
|
2020-07-29 11:00:26 +00:00
|
|
|
state.status !== IDLE
|
2020-04-14 16:52:23 +00:00
|
|
|
? {
|
|
|
|
...state,
|
|
|
|
status: IDLE,
|
|
|
|
}
|
|
|
|
: state;
|
|
|
|
break;
|
2020-03-10 13:39:21 +00:00
|
|
|
case SET_REDIRECT_URL:
|
|
|
|
newState =
|
|
|
|
url !== state.url
|
|
|
|
? {
|
|
|
|
...state,
|
|
|
|
redirectUrl: url,
|
|
|
|
}
|
|
|
|
: state;
|
|
|
|
break;
|
2020-04-14 16:52:23 +00:00
|
|
|
case SET_PROCESSING_RESPONSE:
|
|
|
|
newState = {
|
|
|
|
...state,
|
|
|
|
processingResponse: data,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
2020-03-10 13:39:21 +00:00
|
|
|
case SET_COMPLETE:
|
|
|
|
newState =
|
2020-04-08 15:46:34 +00:00
|
|
|
state.status !== COMPLETE
|
2020-03-10 13:39:21 +00:00
|
|
|
? {
|
|
|
|
...state,
|
2020-04-08 15:46:34 +00:00
|
|
|
status: COMPLETE,
|
2020-04-15 15:43:03 +00:00
|
|
|
redirectUrl: data?.redirectUrl || state.redirectUrl,
|
2020-03-10 13:39:21 +00:00
|
|
|
}
|
|
|
|
: state;
|
|
|
|
break;
|
|
|
|
case SET_PROCESSING:
|
|
|
|
newState =
|
2020-04-08 15:46:34 +00:00
|
|
|
state.status !== PROCESSING
|
2020-03-10 13:39:21 +00:00
|
|
|
? {
|
|
|
|
...state,
|
2020-04-08 15:46:34 +00:00
|
|
|
status: PROCESSING,
|
2020-03-10 13:39:21 +00:00
|
|
|
hasError: false,
|
|
|
|
}
|
|
|
|
: state;
|
|
|
|
// clear any error state.
|
|
|
|
newState =
|
|
|
|
newState.hasError === false
|
|
|
|
? newState
|
|
|
|
: { ...newState, hasError: false };
|
|
|
|
break;
|
2020-04-14 16:52:23 +00:00
|
|
|
case SET_BEFORE_PROCESSING:
|
2020-04-03 11:50:54 +00:00
|
|
|
newState =
|
2020-04-14 16:52:23 +00:00
|
|
|
state.status !== BEFORE_PROCESSING
|
2020-04-03 11:50:54 +00:00
|
|
|
? {
|
|
|
|
...state,
|
2020-04-14 16:52:23 +00:00
|
|
|
status: BEFORE_PROCESSING,
|
2020-04-03 11:50:54 +00:00
|
|
|
hasError: false,
|
|
|
|
}
|
|
|
|
: state;
|
|
|
|
break;
|
2020-04-14 16:52:23 +00:00
|
|
|
case SET_AFTER_PROCESSING:
|
|
|
|
newState =
|
|
|
|
state.status !== AFTER_PROCESSING
|
|
|
|
? {
|
|
|
|
...state,
|
|
|
|
status: AFTER_PROCESSING,
|
|
|
|
}
|
|
|
|
: state;
|
|
|
|
break;
|
2020-03-10 13:39:21 +00:00
|
|
|
case SET_HAS_ERROR:
|
|
|
|
newState = state.hasError
|
|
|
|
? state
|
|
|
|
: {
|
|
|
|
...state,
|
|
|
|
hasError: true,
|
|
|
|
};
|
|
|
|
newState =
|
2020-04-03 11:50:54 +00:00
|
|
|
state.status === PROCESSING ||
|
2020-04-14 16:52:23 +00:00
|
|
|
state.status === BEFORE_PROCESSING
|
2020-03-10 13:39:21 +00:00
|
|
|
? {
|
|
|
|
...newState,
|
|
|
|
status: IDLE,
|
|
|
|
}
|
|
|
|
: newState;
|
|
|
|
break;
|
|
|
|
case SET_NO_ERROR:
|
|
|
|
newState = state.hasError
|
|
|
|
? {
|
|
|
|
...state,
|
|
|
|
hasError: false,
|
|
|
|
}
|
|
|
|
: state;
|
|
|
|
break;
|
|
|
|
case INCREMENT_CALCULATING:
|
|
|
|
newState = {
|
|
|
|
...state,
|
|
|
|
calculatingCount: state.calculatingCount + 1,
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
case DECREMENT_CALCULATING:
|
|
|
|
newState = {
|
|
|
|
...state,
|
|
|
|
calculatingCount: Math.max( 0, state.calculatingCount - 1 ),
|
|
|
|
};
|
|
|
|
break;
|
2020-12-02 14:27:28 +00:00
|
|
|
case SET_CUSTOMER_ID:
|
|
|
|
newState = {
|
|
|
|
...state,
|
|
|
|
customerId,
|
|
|
|
};
|
|
|
|
break;
|
2020-03-30 14:32:23 +00:00
|
|
|
case SET_ORDER_ID:
|
|
|
|
newState = {
|
|
|
|
...state,
|
|
|
|
orderId,
|
|
|
|
};
|
|
|
|
break;
|
Support "create account" option in checkout block (https://github.com/woocommerce/woocommerce-blocks/pull/2851)
* prototype 'create account' checkbox in checkout block
* expose store config for generating password/username to blocks:
+ use FILTER_VALIDATE_BOOLEAN instead of hard-coded `yes`
* stub out signup form in checkout block
* context / provider to store checkout signup form data
* revert signup form - checkout block will always generate username etc
* persist signup checkbox in checkout state & pass to checkout API
* add `create_account` param to order API, fix name in client POST
* handle creating user account as part of order (first cut)
* ensure the order is associated with the new customer
* only show 'create account' checkbox when appropriate (guest checkout)
* remove unnecessary username/password variables
* refactor account-creation logic into functions:
- clarify inputs and outputs
- use RouteException for error handling
- use woo options directly, avoid dependency on WC_Checkout
* update "email exists" error message to use existing error message text
* handle all known errors from wc_create_new_customer + use core message
* only show "create account" checkbox to shopper when necessary:
- if guest checkout is disabled, user must create account - not optional
* only show "create account" if account creation is optional:
- fixes incorrect logic in previous commit
- add some comments to clarify
* fix create account logic in API when checkout requires account:
- use correct woo setting option name
- reverse logic to match option = allow guest false means registration required
* strip html tags from create account error messages
* temporarily force enable autogenerate user/pass in new account API
* fix rebase errors
* add new allowCreateAccount attribute in checkout block
* show/hide `Create account` checkbox dependent on block attribute:
- previously was dependent on store setting
* new create user API, with set initial password email (first cut):
- use core register_new_user for creating the user
- this triggers core "set new password" email
- generate username using logic lifted from WC core
- rough cut, lots to tidy/polish here
* remove alternative/unused create account function
* set `Customer` role for signups during checkout
* eslint fix - switch case break
* remove comments that mirror code & might go stale
* tidy func comment
* remove unused function
* use store setting `allow signup` for default value of new block option
* refactor order signup logic to service class first cut:
- new CreateAccount service
- hook up via custom action (for now at least)
- paste over existing create account logic (temporary - will be replaced)
* adapt wc_create_new_customer logic in CreateAccount service (WIP)
* set default_password_nag on new account + throw instead of WP_Error
* rename `createAccount` => `shouldCreateAccount` to clarify meaning
* fix checkout block - renamed `shouldCreateAccount` (missed in prev commit)
* prototype sending alternative email template for checkout signup
* add magic link to set password to blocks new account html email
* tidy up new account email templates - set password link, subject/heading
* use same id so merchant setting tweaks apply to our new improved email
* remove logging
* code tidies in CreateAccount service:
- remove unnecessary constructor
- type-hint in should_create_customer_account
- streamline logic in should_create_customer_account - remove
unnecessary `empty` check
- add comments to illuminate different use-cases handled by should_create_customer_account
* don't provide password to new account email templates (no longer used)
* declare dependencies in root namespace
* code tidies on new account email class:
- correct namespace and camelcase name
- declare class in file, don't instantiate; instantiate in client code
(CreateAccount service) when used
- no require/file import, use `use`
* move CustomerNewEmail to folder matching namespace
* use Package->get_path for email template paths:
- CreateAccount service now depends on Package
- CreateAccount passes Package to email class so it can use `get_path`
- note: CustomerNewAccount is not registered with DI container as it
needs to be instantiated after Woo init (for `WC_Email`)
- shift email templates to {plugin}/templates, consistent with WP
convention
* call CreateAccount::from_order_request directly, no custom hook:
- custom hook is not appropriate as we may not want to allow
extensibility in this way - TBD
* add appropriate margin above create account checkbox
* remove unnecessary direct-access protection
* generalise name of error-handling method
* simplify CustomerNewAccount - instantiate directly, when needed
* remove unused new_account_email member - now instantiated on demand
* numerous fixes and updates due to rebase changes
* fix typo in name of CustomerNewAccount php file (missing `n`)
* experiment - link to lost-password form in my-account (prototype branded screen)
* Revert "experiment - link to lost-password form in my-account (prototype branded screen)"
This reverts commit e1dc6dd5e9f0218ede81da92188d813c2d0856d9.
* feature gate CreateAccount service init to dev build only +
+ remove stale comment
* feature gate front end "Create account" checkbox to feature plugin only
* feature gate editor "allow signup" option to dev build only
* feature gate checkout api create account - dev build only
* tweak feature gating PHP logic so it's robust:
- all PHP feature gating is in the service class
- all publicly-available methods return early if feature gate off
- Checkout rest API transparently calls service - no explicit feature
gate at API level
* ensure frontend/editor features are feature gated (isExperimentalBuild is a function)
* feature gate value of checkoutAllowsSignup - can only be true in feature plugin
* fix a / an typo in comment
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* remove commented code
* hello world unit test (doesn't test anything yet)
* add a command for running unit tests when container already up:
- this should probably move to another PR/branch
* basic tests of core logic in CreateAccount service
* import isExperimentalBuild direct:
- import from alias package was causing an issue, likely a dependency cycle
* refactor from_order_request to return new user ID so it's easier to test
* test creating a customer from an order + rest request:
- i.e. a full end-to-end integration test
* delete redundant test and tidy comments
* generalise test to provider format
* refactor create-dup-user err test to use same approach as success test
* add test for when user should not be created
* don't hard-code options in "create" test, remove redundant provider in no-account-requested test
* de-generalise "user already signed up" test
* add test for malformed email
* flesh out & comment successful signup tests
* flesh out "invalid email" tests
* clarify no account requested test comment
* remove phpunit:quick - I don't think it's needed
* add comment explaining this is an integration test
* experiment – disable feature flag, is this why the tests are failing?
* revert test commit - restore feature gate (experimental flag)
* skip all tests if CreateAccount is disabled due to feature flag
* d'oh - expose CreateAccount:is_feature_enabled so can be used in tests
* add jsdoc for checkout-state shouldCreateAccount field
* remove unnecessary comment + fix whitespace/indentation
* simulate logged-out user for createaccount signup tests
* use a single, compound if statement for early return (review nitpick)
* don't hide `checkoutAllowsSignup` store setting behind feature flag:
- the feature flag should be used to enable/disable behaviour
- it's dangerous to adjust store settings/options based on feature flag
* rejig tests so they require woocommerce_blocks_phase==3:
- make feature gate method private to avoid exposing
- remove feature flag check & test skip for other builds
- set blocks phase in travis config
* remove redundant user-logout in test setup - cleaner to just require this
* use WP function bracket style (same line)
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
2020-10-01 02:07:16 +00:00
|
|
|
case SET_SHOULD_CREATE_ACCOUNT:
|
|
|
|
if ( shouldCreateAccount !== state.shouldCreateAccount ) {
|
|
|
|
newState = {
|
|
|
|
...state,
|
|
|
|
shouldCreateAccount,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
break;
|
2020-07-31 15:17:01 +00:00
|
|
|
case SET_ORDER_NOTES:
|
|
|
|
if ( state.orderNotes !== orderNotes ) {
|
|
|
|
newState = {
|
|
|
|
...state,
|
|
|
|
orderNotes,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
break;
|
2020-03-10 13:39:21 +00:00
|
|
|
}
|
|
|
|
// automatically update state to idle from pristine as soon as it
|
|
|
|
// initially changes.
|
|
|
|
if (
|
|
|
|
newState !== state &&
|
|
|
|
type !== SET_PRISTINE &&
|
|
|
|
newState.status === PRISTINE
|
|
|
|
) {
|
|
|
|
newState.status = IDLE;
|
|
|
|
}
|
|
|
|
return newState;
|
|
|
|
};
|