react-squadpay
Version:
React GTCO Squad payment gateway
28 lines (24 loc) • 16 kB
JavaScript
(function(O,W){typeof exports=="object"&&typeof module<"u"?module.exports=W(require("react")):typeof define=="function"&&define.amd?define(["react"],W):(O=typeof globalThis<"u"?globalThis:O||self,O["react-squadpay"]=W(O.React))})(this,function(O){"use strict";const Z=(i=>i&&typeof i=="object"&&"default"in i?i:{default:i})(O),Oe=i=>{function h(){i=document.createElement("div"),i.style.padding="0.6rem 0.6rem",i.style.backgroundColor="#fff3cd",i.style.color="#664d03",i.style.borderColor="#ffecb5",i.style.borderRadius="0.25rem",i.style.position="fixed",i.style.width="100%",i.style.top="0px",i.style.textAlign="center";let g=document.createElement("p");g.innerText="Ooop! There seems to be an issue. please reload and try again!",g.style.fontWeight="700";const u=document.createElement("button");u.innerText="close",u.style.color="#000",u.style.backgroundColor="#f8f9fa",u.style.borderColor="#f8f9fa",u.style.backgroundColor="transparent",u.style.border="1px solid transparent",u.style.padding="0.375rem 0.75rem",u.style.fontSize="1rem",u.style.borderRadius="0.25rem",u.style.transition="color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out",u.onclick=function(){i=null,document.body.removeChild(i)},i.appendChild(g),i.appendChild(u),document.body.prepend(i)}return h},Pe=()=>{const[i,h]=O.useState(!1);let g=!0;return O.useEffect(()=>{function u(){const C="https://checkout.squadco.com/widget/squad.min.js",d=document.createElement("script"),_=()=>{h(!0),d.removeEventListener("error",b),d.removeEventListener("load",_)},b=()=>{h(!1),d.removeEventListener("error",b),d.removeEventListener("load",_)};d.src=C,console.log(C),d.async=!0,d.setAttribute("data-testid","squad-script"),document.body.appendChild(d),d.addEventListener("load",_),d.addEventListener("error",b)}return g&&u(),()=>{g=!1}},[]),i};var Q={exports:{}},F={};/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var ee;function xe(){if(ee)return F;ee=1;var i=Z.default,h=Symbol.for("react.element"),g=Symbol.for("react.fragment"),u=Object.prototype.hasOwnProperty,C=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,d={key:!0,ref:!0,__self:!0,__source:!0};function _(b,v,P){var p,R={},T=null,Y=null;P!==void 0&&(T=""+P),v.key!==void 0&&(T=""+v.key),v.ref!==void 0&&(Y=v.ref);for(p in v)u.call(v,p)&&!d.hasOwnProperty(p)&&(R[p]=v[p]);if(b&&b.defaultProps)for(p in v=b.defaultProps,v)R[p]===void 0&&(R[p]=v[p]);return{$$typeof:h,type:b,key:T,ref:Y,props:R,_owner:C.current}}return F.Fragment=g,F.jsx=_,F.jsxs=_,F}var A={};/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/var re;function je(){return re||(re=1,process.env.NODE_ENV!=="production"&&function(){var i=Z.default,h=Symbol.for("react.element"),g=Symbol.for("react.portal"),u=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),d=Symbol.for("react.profiler"),_=Symbol.for("react.provider"),b=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),P=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),T=Symbol.for("react.lazy"),Y=Symbol.for("react.offscreen"),te=Symbol.iterator,De="@@iterator";function Fe(e){if(e===null||typeof e!="object")return null;var r=te&&e[te]||e[De];return typeof r=="function"?r:null}var j=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function y(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),n=1;n<r;n++)t[n-1]=arguments[n];Ae("error",e,t)}}function Ae(e,r,t){{var n=j.ReactDebugCurrentFrame,s=n.getStackAddendum();s!==""&&(r+="%s",t=t.concat([s]));var l=t.map(function(o){return String(o)});l.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,l)}}var Le=!1,Ie=!1,We=!1,Ye=!1,Ne=!1,ne;ne=Symbol.for("react.module.reference");function $e(e){return!!(typeof e=="string"||typeof e=="function"||e===u||e===d||Ne||e===C||e===P||e===p||Ye||e===Y||Le||Ie||We||typeof e=="object"&&e!==null&&(e.$$typeof===T||e.$$typeof===R||e.$$typeof===_||e.$$typeof===b||e.$$typeof===v||e.$$typeof===ne||e.getModuleId!==void 0))}function Me(e,r,t){var n=e.displayName;if(n)return n;var s=r.displayName||r.name||"";return s!==""?t+"("+s+")":t}function ae(e){return e.displayName||"Context"}function S(e){if(e==null)return null;if(typeof e.tag=="number"&&y("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case u:return"Fragment";case g:return"Portal";case d:return"Profiler";case C:return"StrictMode";case P:return"Suspense";case p:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case b:var r=e;return ae(r)+".Consumer";case _:var t=e;return ae(t._context)+".Provider";case v:return Me(e,e.render,"ForwardRef");case R:var n=e.displayName||null;return n!==null?n:S(e.type)||"Memo";case T:{var s=e,l=s._payload,o=s._init;try{return S(o(l))}catch{return null}}}return null}var x=Object.assign,L=0,oe,ie,ue,se,le,ce,fe;function de(){}de.__reactDisabledLog=!0;function Ue(){{if(L===0){oe=console.log,ie=console.info,ue=console.warn,se=console.error,le=console.group,ce=console.groupCollapsed,fe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:de,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}L++}}function Ve(){{if(L--,L===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:x({},e,{value:oe}),info:x({},e,{value:ie}),warn:x({},e,{value:ue}),error:x({},e,{value:se}),group:x({},e,{value:le}),groupCollapsed:x({},e,{value:ce}),groupEnd:x({},e,{value:fe})})}L<0&&y("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var q=j.ReactCurrentDispatcher,B;function N(e,r,t){{if(B===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);B=n&&n[1]||""}return`
`+B+e}}var G=!1,$;{var qe=typeof WeakMap=="function"?WeakMap:Map;$=new qe}function ve(e,r){if(!e||G)return"";{var t=$.get(e);if(t!==void 0)return t}var n;G=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var l;l=q.current,q.current=null,Ue();try{if(r){var o=function(){throw Error()};if(Object.defineProperty(o.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(o,[])}catch(w){n=w}Reflect.construct(e,[],o)}else{try{o.call()}catch(w){n=w}e.call(o.prototype)}}else{try{throw Error()}catch(w){n=w}e()}}catch(w){if(w&&n&&typeof w.stack=="string"){for(var a=w.stack.split(`
`),m=n.stack.split(`
`),c=a.length-1,f=m.length-1;c>=1&&f>=0&&a[c]!==m[f];)f--;for(;c>=1&&f>=0;c--,f--)if(a[c]!==m[f]){if(c!==1||f!==1)do if(c--,f--,f<0||a[c]!==m[f]){var E=`
`+a[c].replace(" at new "," at ");return e.displayName&&E.includes("<anonymous>")&&(E=E.replace("<anonymous>",e.displayName)),typeof e=="function"&&$.set(e,E),E}while(c>=1&&f>=0);break}}}finally{G=!1,q.current=l,Ve(),Error.prepareStackTrace=s}var D=e?e.displayName||e.name:"",we=D?N(D):"";return typeof e=="function"&&$.set(e,we),we}function Be(e,r,t){return ve(e,!1)}function Ge(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function M(e,r,t){if(e==null)return"";if(typeof e=="function")return ve(e,Ge(e));if(typeof e=="string")return N(e);switch(e){case P:return N("Suspense");case p:return N("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case v:return Be(e.render);case R:return M(e.type,r,t);case T:{var n=e,s=n._payload,l=n._init;try{return M(l(s),r,t)}catch{}}}return""}var U=Object.prototype.hasOwnProperty,pe={},ye=j.ReactDebugCurrentFrame;function V(e){if(e){var r=e._owner,t=M(e.type,e._source,r?r.type:null);ye.setExtraStackFrame(t)}else ye.setExtraStackFrame(null)}function Je(e,r,t,n,s){{var l=Function.call.bind(U);for(var o in e)if(l(e,o)){var a=void 0;try{if(typeof e[o]!="function"){var m=Error((n||"React class")+": "+t+" type `"+o+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[o]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw m.name="Invariant Violation",m}a=e[o](r,o,n,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(c){a=c}a&&!(a instanceof Error)&&(V(s),y("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",t,o,typeof a),V(null)),a instanceof Error&&!(a.message in pe)&&(pe[a.message]=!0,V(s),y("Failed %s type: %s",t,a.message),V(null))}}}var ze=Array.isArray;function J(e){return ze(e)}function Ke(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function He(e){try{return me(e),!1}catch{return!0}}function me(e){return""+e}function be(e){if(He(e))return y("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ke(e)),me(e)}var I=j.ReactCurrentOwner,Xe={key:!0,ref:!0,__self:!0,__source:!0},he,ge,z;z={};function Ze(e){if(U.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function Qe(e){if(U.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function er(e,r){if(typeof e.ref=="string"&&I.current&&r&&I.current.stateNode!==r){var t=S(I.current.type);z[t]||(y('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',S(I.current.type),e.ref),z[t]=!0)}}function rr(e,r){{var t=function(){he||(he=!0,y("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function tr(e,r){{var t=function(){ge||(ge=!0,y("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var nr=function(e,r,t,n,s,l,o){var a={$$typeof:h,type:e,key:r,ref:t,props:o,_owner:l};return a._store={},Object.defineProperty(a._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(a,"_self",{configurable:!1,enumerable:!1,writable:!1,value:n}),Object.defineProperty(a,"_source",{configurable:!1,enumerable:!1,writable:!1,value:s}),Object.freeze&&(Object.freeze(a.props),Object.freeze(a)),a};function ar(e,r,t,n,s){{var l,o={},a=null,m=null;t!==void 0&&(be(t),a=""+t),Qe(r)&&(be(r.key),a=""+r.key),Ze(r)&&(m=r.ref,er(r,s));for(l in r)U.call(r,l)&&!Xe.hasOwnProperty(l)&&(o[l]=r[l]);if(e&&e.defaultProps){var c=e.defaultProps;for(l in c)o[l]===void 0&&(o[l]=c[l])}if(a||m){var f=typeof e=="function"?e.displayName||e.name||"Unknown":e;a&&rr(o,f),m&&tr(o,f)}return nr(e,a,m,s,n,I.current,o)}}var K=j.ReactCurrentOwner,Ee=j.ReactDebugCurrentFrame;function k(e){if(e){var r=e._owner,t=M(e.type,e._source,r?r.type:null);Ee.setExtraStackFrame(t)}else Ee.setExtraStackFrame(null)}var H;H=!1;function X(e){return typeof e=="object"&&e!==null&&e.$$typeof===h}function _e(){{if(K.current){var e=S(K.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function or(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return`
Check your code at `+r+":"+t+"."}return""}}var Re={};function ir(e){{var r=_e();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function Te(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=ir(r);if(Re[t])return;Re[t]=!0;var n="";e&&e._owner&&e._owner!==K.current&&(n=" It was passed a child from "+S(e._owner.type)+"."),k(e),y('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,n),k(null)}}function Ce(e,r){{if(typeof e!="object")return;if(J(e))for(var t=0;t<e.length;t++){var n=e[t];X(n)&&Te(n,r)}else if(X(e))e._store&&(e._store.validated=!0);else if(e){var s=Fe(e);if(typeof s=="function"&&s!==e.entries)for(var l=s.call(e),o;!(o=l.next()).done;)X(o.value)&&Te(o.value,r)}}}function ur(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===v||r.$$typeof===R))t=r.propTypes;else return;if(t){var n=S(r);Je(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!H){H=!0;var s=S(r);y("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",s||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&y("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function sr(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){k(e),y("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),k(null);break}}e.ref!==null&&(k(e),y("Invalid attribute `ref` supplied to `React.Fragment`."),k(null))}}function Se(e,r,t,n,s,l){{var o=$e(e);if(!o){var a="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(a+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var m=or(s);m?a+=m:a+=_e();var c;e===null?c="null":J(e)?c="array":e!==void 0&&e.$$typeof===h?(c="<"+(S(e.type)||"Unknown")+" />",a=" Did you accidentally export a JSX literal instead of a component?"):c=typeof e,y("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",c,a)}var f=ar(e,r,t,s,l);if(f==null)return f;if(o){var E=r.children;if(E!==void 0)if(n)if(J(E)){for(var D=0;D<E.length;D++)Ce(E[D],e);Object.freeze&&Object.freeze(E)}else y("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Ce(E,e)}return e===u?sr(f):ur(f),f}}function lr(e,r,t){return Se(e,r,t,!0)}function cr(e,r,t){return Se(e,r,t,!1)}var fr=cr,dr=lr;A.Fragment=u,A.jsx=fr,A.jsxs=dr}()),A}(function(i){process.env.NODE_ENV==="production"?i.exports=xe():i.exports=je()})(Q);const ke=Q.exports.jsx;return({children:i,className:h,text:g,params:u,onClose:C,onLoad:d,onSuccess:_})=>{const b=Pe(),P=Oe(null);function p(){if(!b){P();return}const R={onClose:C,onLoad:d,onSuccess:_,key:u.key,email:u.email,amount:u.amount*100,currency_code:u.currencyCode||"NGN",transaction_ref:u.reference||null,payment_channels:u.paymentChannels||null,Customer_name:u.customerName||null,callback_url:u.callbackUrl||null,metadata:u.metaData||null,pass_charge:u.passCharge||!1},T=new squad(R);T.setup(),T.open()}return ke("button",{className:h,onClick:p,children:g||i})}});