Esempio n. 1
0
		/**
		 * Issues a PUT request to payment_gateways/${ method.id }
		 * @param {Object} store - Redux store
		 * @param {Object} action - and action with the following fields: siteId, method, successAction, failureAction
		 */
		( store, action ) => {
			const { siteId, method, successAction, failureAction } = action;

			const settings = {
				enabled: method.enabled ? 'yes' : 'no',
			};

			Object.keys( method.settings ).map( ( settingKey ) => {
				settings[ settingKey ] = method.settings[ settingKey ].value;
			} );

			const payload = {
				settings,
				description: method.description,
			};

			/**
			 * A callback issued after a successful request
			 * @param {Function} dispatch - dispatch function
			 * @param {Function} getState - getState function
			 * @param {Object} data - data returned by the server
			 */
			const updatedAction = ( dispatch, getState, { data } ) => {
				dispatch( savePaymentMethodSuccess( siteId, data, action ) );
				dispatch( successAction );
			};

			store.dispatch( put( siteId, `payment_gateways/${ method.id }`, payload, updatedAction, failureAction ) );
		},
Esempio n. 2
0
export function handleProductUpdate( { dispatch }, action ) {
	const { siteId, product, successAction, failureAction } = action;

	// Verify the id
	if ( typeof product.id !== 'number' ) {
		dispatch( setError( siteId, action, {
			message: 'Attempting to update a product without a valid id.',
			product,
		} ) );
		return;
	}

	const updatedSuccessAction = updatedAction( siteId, action, successAction, product );
	dispatch( put( siteId, 'products/' + product.id, product, updatedSuccessAction, failureAction ) );
}
Esempio n. 3
0
		( store, action ) => {
			const { siteId, zoneId, methodId, method, successAction, failureAction } = action;
			const payload = {
				enabled: method.enabled,
				settings: omit( method, 'enabled' ),
			};

			const updatedAction = ( dispatch, getState, { data } ) => {
				dispatch( shippingZoneMethodUpdated( siteId, data, action ) );

				const props = { sentData: method, receivedData: data };
				dispatchWithProps( dispatch, getState, successAction, props );
			};

			store.dispatch(
				put(
					siteId,
					'shipping/zones/' + zoneId + '/methods/' + methodId,
					payload,
					updatedAction,
					failureAction
				)
			);
		},