UNPKG

@shopgate/engage

Version:
5 lines 2.4 kB
import _regeneratorRuntime from"@babel/runtime/regenerator";function asyncGeneratorStep(gen,resolve,reject,_next,_throw,key,arg){try{var info=gen[key](arg);var value=info.value;}catch(error){reject(error);return;}if(info.done){resolve(value);}else{Promise.resolve(value).then(_next,_throw);}}function _asyncToGenerator(fn){return function(){var self=this,args=arguments;return new Promise(function(resolve,reject){var gen=fn.apply(self,args);function _next(value){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"next",value);}function _throw(err){asyncGeneratorStep(gen,resolve,reject,_next,_throw,"throw",err);}_next(undefined);});};}import{PipelineRequest,LoadingProvider}from'@shopgate/engage/core';import{CHECKOUT_PATTERN}from"../constants/routes";import{SUBMIT_CHECKOUT_ORDER,SUBMIT_CHECKOUT_ORDER_SUCCESS,SUBMIT_CHECKOUT_ORDER_ERROR}from"../constants/actionTypes";import{ERROR_CODE_CHECKOUT_GENERIC}from"../constants/errorCodes";import{errorCheckout}from"./errorCheckout";/** * Completes the checkout order by fulfilling with checkout params for each transaction. * @param {Object} payload The action input. * @returns {Function} */export var submitCheckoutOrder=function submitCheckoutOrder(payload){return(/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(dispatch){var pipelineError,pipelineOutput;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:LoadingProvider.setLoading(CHECKOUT_PATTERN);dispatch({type:SUBMIT_CHECKOUT_ORDER,payload:payload});_context.prev=2;_context.next=5;return new PipelineRequest('shopgate.checkout.submit').setInput(payload).setErrorBlacklist([ERROR_CODE_CHECKOUT_GENERIC]).dispatch();case 5:pipelineOutput=_context.sent;dispatch({type:SUBMIT_CHECKOUT_ORDER_SUCCESS});_context.next=14;break;case 9:_context.prev=9;_context.t0=_context["catch"](2);pipelineError=_context.t0;dispatch(errorCheckout('checkout.errors.genericSubmit','shopgate.checkout.submit',_context.t0,false,[1001,1003]));dispatch({type:SUBMIT_CHECKOUT_ORDER_ERROR});case 14:LoadingProvider.unsetLoading(CHECKOUT_PATTERN);if(!pipelineError){_context.next=17;break;}throw pipelineError;case 17:return _context.abrupt("return",pipelineOutput);case 18:case"end":return _context.stop();}},_callee,null,[[2,9]]);}));return function(_x){return _ref.apply(this,arguments);};}());};