@shopgate/engage
Version:
Shopgate's ENGAGE library.
6 lines • 2.33 kB
JavaScript
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{useEffect,useContext}from'react';import PropTypes from'prop-types';import{isAvailable,PayPalRiskCheck}from'@shopgate/native-modules';import PaymentContext from"../context";/**
* Paypal provider
* @return {JSX}
*/var PaypalProvider=function PaypalProvider(_ref){var activeFundingSource=_ref.activePaymentMeta;var _useContext=useContext(PaymentContext),registerPaymentMethod=_useContext.registerPaymentMethod;useEffect(function(){// Register payment method.
registerPaymentMethod({// Paypal doesn't need to fulfill any transactions.
fulfillTransaction:function(){var _fulfillTransaction=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2){var paymentTransactions,_paymentTransactions$,id;return _regeneratorRuntime.wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:paymentTransactions=_ref2.paymentTransactions;if(!isAvailable()){_context.next=10;break;}id=paymentTransactions===null||paymentTransactions===void 0?void 0:(_paymentTransactions$=paymentTransactions[0])===null||_paymentTransactions$===void 0?void 0:_paymentTransactions$.id;_context.prev=3;_context.next=6;return PayPalRiskCheck.submit(id);case 6:_context.next=10;break;case 8:_context.prev=8;_context.t0=_context["catch"](3);case 10:return _context.abrupt("return",[]);case 11:case"end":return _context.stop();}},_callee,null,[[3,8]]);}));function fulfillTransaction(_x){return _fulfillTransaction.apply(this,arguments);}return fulfillTransaction;}()});},[activeFundingSource,registerPaymentMethod]);return null;};PaypalProvider.propTypes={activePaymentMeta:PropTypes.string};PaypalProvider.defaultProps={activePaymentMeta:null};export default PaypalProvider;