@shopgate/engage 7.5.1-beta.1 → 7.5.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
- 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);});};}function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import React,{useLayoutEffect,useEffect,useRef,useState,Fragment}from'react';import PropTypes from'prop-types';import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';import{isIOSTheme,getThemeSettings}from'@shopgate/engage/core';import{i18n}from"../../../core/helpers/i18n";import{useCheckoutContext}from"../../hooks/common";import{usePaypal}from"./sdk";var colors=themeConfig.colors;var styles={headline:css(_extends({color:colors.shade3,fontSize:'1.25rem',fontWeight:'normal',textTransform:'uppercase',margin:'12px 0 12px 0'},!isIOSTheme()?{color:'var(--color-text-high-emphasis)',textTransform:'none'}:{})).toString()};/**
1
+ 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);});};}function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj;};}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj;};}return _typeof(obj);}function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}import React,{useLayoutEffect,useEffect,useRef,useState,Fragment}from'react';import PropTypes from'prop-types';import{css}from'glamor';import{themeConfig}from'@shopgate/pwa-common/helpers/config';import{isIOSTheme,getThemeSettings,showModal,MODAL_PIPELINE_ERROR}from'@shopgate/engage/core';import{connect}from'react-redux';import{i18n}from"../../../core/helpers/i18n";import{useCheckoutContext}from"../../hooks/common";import{usePaypal}from"./sdk";var colors=themeConfig.colors;var styles={headline:css(_extends({color:colors.shade3,fontSize:'1.25rem',fontWeight:'normal',textTransform:'uppercase',margin:'12px 0 12px 0'},!isIOSTheme()?{color:'var(--color-text-high-emphasis)',textTransform:'none'}:{})).toString()};/**
2
2
  * Paypal Pay button
3
3
  * @returns {JSX}
4
- */var PaypalPayButton=function PaypalPayButton(_ref){var disabled=_ref.disabled,onSubmit=_ref.onSubmit,onValidate=_ref.onValidate;var _useCheckoutContext=useCheckoutContext(),paymentData=_useCheckoutContext.paymentData,paymentTransactions=_useCheckoutContext.paymentTransactions;var _useState=useState(null),_useState2=_slicedToArray(_useState,2),paypalActions=_useState2[0],setPaypalActions=_useState2[1];var paypal=usePaypal();var paypalButton=useRef(null);var button=useRef(null);var fundingSource=paymentData===null||paymentData===void 0?void 0:paymentData.meta;// Store form actions inside ref as they would trigger
4
+ */var PaypalPayButton=function PaypalPayButton(_ref){var disabled=_ref.disabled,onSubmit=_ref.onSubmit,onValidate=_ref.onValidate,showModal=_ref.showModal;var _useCheckoutContext=useCheckoutContext(),paymentData=_useCheckoutContext.paymentData,paymentTransactions=_useCheckoutContext.paymentTransactions;var _useState=useState(null),_useState2=_slicedToArray(_useState,2),paypalActions=_useState2[0],setPaypalActions=_useState2[1];var paypal=usePaypal();var paypalButton=useRef(null);var button=useRef(null);var fundingSource=paymentData===null||paymentData===void 0?void 0:paymentData.meta;// Store form actions inside ref as they would trigger
5
5
  // rerenders everytime the form changes, but here we
6
6
  // only need them once validating.
7
7
  // paypal unfortunately doesn't allow updating button props.
8
8
  var formActions=useRef({});useEffect(function(){formActions.current={onSubmit:onSubmit,onValidate:onValidate};},[onSubmit,onValidate]);// Trigger rendering the paypal button whenever a property changes.
9
9
  useLayoutEffect(function(){if(!paypal)return;if(_typeof(fundingSource)==='object')return;if(paypalButton.current){paypalButton.current.close();}var customSettings=getThemeSettings('PayPal')||{};paypalButton.current=paypal.Buttons({fundingSource:fundingSource||paypal.FUNDING.PAYPAL,createOrder:function createOrder(){var _paymentTransactions$;var externalCode=(_paymentTransactions$=paymentTransactions[0])===null||_paymentTransactions$===void 0?void 0:_paymentTransactions$.externalCode;return externalCode;},onInit:function onInit(_,actions){// Here again thanks paypal, there is no way access the actions outside these handlers.
10
10
  setPaypalActions(actions);},onClick:function onClick(_,actions){// Trigger manual form validation to comply to paypal standards.
11
- var isValid=formActions.current.onValidate();if(isValid&&!disabled){return actions.resolve();}return actions.reject();},onApprove:function(){var _onApprove=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_,actions){var redirect;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return formActions.current.onSubmit();case 2:redirect=_context.sent;console.warn('xx',redirect);if(redirect){actions.restart();}case 5:case"end":return _context.stop();}}},_callee);}));function onApprove(_x,_x2){return _onApprove.apply(this,arguments);}return onApprove;}(),style:_extends({label:'pay',color:'white'},customSettings)});paypalButton.current.render(button.current);},[disabled,fundingSource,paymentTransactions,paypal]);// Sync our internal disabled state with paypals disabled state.
12
- useEffect(function(){if(!paypalActions)return;if(disabled){paypalActions.disable();return;}paypalActions.enable();},[disabled,paypalActions]);if(_typeof(fundingSource)==='object')return null;if(!paypal){return null;}return React.createElement(Fragment,null,React.createElement("h3",{className:styles.headline},i18n.text('checkout.finalizePayment')),React.createElement("div",{ref:button}));};export default PaypalPayButton;
11
+ var isValid=formActions.current.onValidate();if(isValid&&!disabled){return actions.resolve();}return actions.reject();},onApprove:function(){var _onApprove=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_,actions){var redirect;return _regeneratorRuntime.wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.next=2;return formActions.current.onSubmit();case 2:redirect=_context.sent;if(redirect){showModal({type:MODAL_PIPELINE_ERROR,title:null,confirm:null,dismiss:'modal.ok',message:'checkout.errors.paypalFunding'});actions.restart();}case 4:case"end":return _context.stop();}}},_callee);}));function onApprove(_x,_x2){return _onApprove.apply(this,arguments);}return onApprove;}(),style:_extends({label:'pay',color:'white'},customSettings)});paypalButton.current.render(button.current);},[disabled,fundingSource,paymentTransactions,paypal,showModal]);// Sync our internal disabled state with paypals disabled state.
12
+ useEffect(function(){if(!paypalActions)return;if(disabled){paypalActions.disable();return;}paypalActions.enable();},[disabled,paypalActions]);if(_typeof(fundingSource)==='object')return null;if(!paypal){return null;}return React.createElement(Fragment,null,React.createElement("h3",{className:styles.headline},i18n.text('checkout.finalizePayment')),React.createElement("div",{ref:button}));};var mapDispatchToProps={showModal:showModal};export default connect(null,mapDispatchToProps)(PaypalPayButton);
@@ -3,7 +3,7 @@ function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimi
3
3
  * @param {Object} settings Payment method settings
4
4
  * @param {Object} order The active order
5
5
  * @returns {Promise}
6
- * */export var loadWebSdk=function loadWebSdk(settings,order){return new Promise(function(resolve,reject){if(document.querySelector("#".concat(SDK_ID))){resolve();return;}var script=document.createElement('script');script.id=SDK_ID;script.setAttribute('data-partner-attribution-id','ShopgateGmbH_Cart_PPCP');script.onload=function(){resolve();renderQueue.forEach(function(cb){return cb();});renderQueue=[];};script.onerror=reject;var parameters=_extends({'client-id':settings.clientId,'merchant-id':settings.merchantIdInPayPal,'disable-funding':'credit,card','integration-date':'2020-12-07',currency:order.currencyCode,intent:'authorize',components:'buttons,funding-eligibility,marks'},settings.env==='sandbox'?{debug:'true'}:{});var parametersString=Object.entries(parameters).map(function(_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],value=_ref2[1];return"".concat(key,"=").concat(value);}).join('&');script.src="https://www.paypal.com/sdk/js?".concat(parametersString);document.head.appendChild(script);});};/**
6
+ * */export var loadWebSdk=function loadWebSdk(settings,order){return new Promise(function(resolve,reject){if(document.querySelector("#".concat(SDK_ID))){resolve();return;}var script=document.createElement('script');script.id=SDK_ID;script.setAttribute('data-partner-attribution-id','ShopgateGmbH_Cart_PPCP');script.onload=function(){resolve();renderQueue.forEach(function(cb){return cb();});renderQueue=[];};script.onerror=reject;var parameters=_extends({'client-id':settings.clientId,'merchant-id':settings.merchantIdInPayPal,'disable-funding':'credit,card','integration-date':'2020-12-07',commit:'true',currency:order.currencyCode,intent:'authorize',components:'buttons,funding-eligibility,marks'},settings.env==='sandbox'?{debug:'true'}:{});var parametersString=Object.entries(parameters).map(function(_ref){var _ref2=_slicedToArray(_ref,2),key=_ref2[0],value=_ref2[1];return"".concat(key,"=").concat(value);}).join('&');script.src="https://www.paypal.com/sdk/js?".concat(parametersString);document.head.appendChild(script);});};/**
7
7
  * Hook that ensures that component will be supplied with the sdk once loaded.
8
8
  * @returns {Object}
9
9
  */export var usePaypal=function usePaypal(){var _useState=useState(window.paypal||null),_useState2=_slicedToArray(_useState,2),paypal=_useState2[0],setPaypal=_useState2[1];useEffect(function(){if(paypal){return;}renderQueue.push(function(){return setPaypal(window.paypal);});},[paypal]);return paypal;};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopgate/engage",
3
- "version": "7.5.1-beta.1",
3
+ "version": "7.5.1-beta.2",
4
4
  "description": "Shopgate's ENGAGE library.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Shopgate <support@shopgate.com>",
@@ -16,12 +16,12 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@shopgate/native-modules": "1.0.0-beta.18",
19
- "@shopgate/pwa-common": "7.5.1-beta.1",
20
- "@shopgate/pwa-common-commerce": "7.5.1-beta.1",
21
- "@shopgate/pwa-core": "7.5.1-beta.1",
22
- "@shopgate/pwa-ui-ios": "7.5.1-beta.1",
23
- "@shopgate/pwa-ui-material": "7.5.1-beta.1",
24
- "@shopgate/pwa-ui-shared": "7.5.1-beta.1",
19
+ "@shopgate/pwa-common": "7.5.1-beta.2",
20
+ "@shopgate/pwa-common-commerce": "7.5.1-beta.2",
21
+ "@shopgate/pwa-core": "7.5.1-beta.2",
22
+ "@shopgate/pwa-ui-ios": "7.5.1-beta.2",
23
+ "@shopgate/pwa-ui-material": "7.5.1-beta.2",
24
+ "@shopgate/pwa-ui-shared": "7.5.1-beta.2",
25
25
  "@stripe/react-stripe-js": "^1.1.2",
26
26
  "@stripe/stripe-js": "^1.3.1",
27
27
  "@virtuous/conductor": "~2.5.0",