UNPKG

@2c2p/pgw-sdk-react-native

Version:

2C2P PGW SDK for react native and allows merchants to build an excellent payment experience within their mobile apps by integrating easily with 2C2P's payment gateway.

53 lines (37 loc) 1.53 kB
/* * Created by DavidBilly PK on 15/10/24. */ export class PGWWebViewNavigation { /** * @param {string} url web url. * @param {Function} callback callback for payment token. */ static inquiry(url, callback) { if(url && callback) { const doWebUrlCapture = new RegExp('^https:\/\/([a-zA-Z0-9\\-]+).2c2p.com\/payment\/(.*)\/#\/info\/([^?]*)').exec(url); const doAppSchemeCapture = new RegExp('^pgw(.*):\/\/2c2p').exec(url); if(doWebUrlCapture || doAppSchemeCapture) { var paymentToken = ''; if(doWebUrlCapture) { try { const matched = doWebUrlCapture[3]; paymentToken = (matched) ? matched : ''; } catch(e) { paymentToken = ''; } } else if(doAppSchemeCapture) { try { const doPaymentTokenCapture = new RegExp(/paymentToken=([^?]*)/).exec(url); if(doPaymentTokenCapture) { const matched = doPaymentTokenCapture[0]; paymentToken = (matched) ? matched.replace('paymentToken=', '') : ''; } } catch(e) { paymentToken = ''; } } callback(paymentToken); } } } }