UNPKG

@100pay-hq/checkout

Version:

accept crypto payments on your website and apps in 3 mins

86 lines (84 loc) 5.38 kB
var A=a=>typeof a==='string';let b;var c=_=>` #show100Pay { top: 0; left: 0; position: fixed; background-color: #000000c2; width: 100%; height: 100%; z-index: 1050; display: none; } .show100Pay { transition: 0.3s; height: 100%; width: 100%; max-width: ${_?.maxWidth||400}; max-height: ${_?.maxHeight||'unset'}; left: 50%; transform: translateX(-50%); position: fixed; z-index: 1050; top: 100%; padding-top: 0; border-radius: 16px 16px 0 0; overflow: hidden; } .show100Pay .show100Pay_modal { height: calc(100% - 66px); width: 100%; border: none; border-radius: 16px 16px 0 0; padding-bottom: 0; } .show100Pay.show { top: 66px; } #close_100pay_btn { padding: 15px 0; display: flex; color: white; max-width: ${_?.maxWidth||400}; text-align: right; margin: auto; text-transform: uppercase; justify-content: end; align-items: center; } .img_wrapper { display: flex; gap: 8px; } .connected_img, .vic_hand_img { height: 20px; } .vic_hand_img { animation: shake 0.2s ease-in-out infinite alternate-reverse; } .close_100pay_btn { color: #fff; text-align: right; outline: none; border: none; padding: 6px 12px; border-radius: 8px; font-weight: 700; cursor: pointer; } .body-overflow-hidden { overflow: hidden; } @keyframes shake { 0% { transform: rotate(15deg); } 100% { transform: rotate(-15deg); } } `;class PayWith100Pay{constructor(B){}appendStyle(C){let _b=document.createElement('STYLE');_b.id='100pay_style';_b.type='text/css';_b.appendChild(document.createTextNode(C));document.head.appendChild(_b)}setup(_a,d){b=_a;let _c=b.api_key;delete b.callback;delete b.api_key;fetch('https://api.100pay.co/api/v1/pay/charge',{method:'POST',headers:{'Content-Type':'application/json','api-key':_c},body:JSON.stringify(b)}).then(D=>D.json()).then(_A=>this.createElements(_A,d)).catch(E=>b.onError(E))}createElements(aA,_B){this.appendStyle(c(_B));let _C=document.createElement('div');let _d=document.createElement('div');let _e=document.createElement('iframe');let f=document.createElement('p');let g=document.createElement('div');let h=document.createElement('img');let i=document.createElement('img');let j=document.createElement('button');_C.insertAdjacentHTML('afterbegin',`<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; background: none; display: block; shape-rendering: auto;" width="271px" height="271px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"> <path fill="none" stroke="#ffffff" stroke-width="4" stroke-dasharray="220.66647827148438 35.92244995117187" d="M24.3 30C11.4 30 5 43.3 5 50s6.4 20 19.3 20c19.3 0 32.1-40 51.4-40 C88.6 30 95 43.3 95 50s-6.4 20-19.3 20C56.4 70 43.6 30 24.3 30z" stroke-linecap="round" style="transform:scale(0.4);transform-origin:50px 50px"> <animate attributeName="stroke-dashoffset" repeatCount="indefinite" dur="1.4492753623188404s" keyTimes="0;1" values="0;256.58892822265625"></animate> </path> <text x="50%" y="50%" fill="#ffffff" dy=".3em" style="font-size:24px;/* font-weight:bold; */text-anchor:middle;transform: scale(0.2);transform-origin: 50px 75px;"> Connecting you to the Blockchain </text> </svg>`);j.appendChild(document.createTextNode('Close'));_C.id='100pay_loader';f.id='close_100pay_btn';g.className='img_wrapper';h.className='connected_img';i.className='vic_hand_img';i.src='https://res.cloudinary.com/estaterally/image/upload/v1647615169/100Pay/victory-hand_zaueti.svg';h.src='https://res.cloudinary.com/estaterally/image/upload/v1647617288/100Pay/100pay-connected_dov5km.svg';j.className='btn text-white close_100pay_btn';j.id='close_100pay_modal';f.appendChild(j);_e.className='show100Pay_modal';_e.id='show100PayModal';_d.className='show100Pay';_d.id='show100PayWrapper';_d.appendChild(_e);document.body.classList.add('body-overflow-hidden');var k=document.getElementById('show100Pay');let l=k;console.log({shop100TargetEl:l,targetEl:k});if(!k){var o=document.createElement('div');o.id='show100Pay';document.body.appendChild(o);l=o}window.shop100TargetEl=l;l.style='display: block;';l.appendChild(f);l.appendChild(_C);l.appendChild(_d);let m=document.getElementById('close_100pay_modal');m.addEventListener('click',()=>confirm('Are you sure you want to close this payment?')&&this.closeModal(b));let n=document.getElementById('show100PayModal');n.addEventListener('load',()=>{document.getElementById('show100PayWrapper').classList.add('show');window.addEventListener('message',aB=>{var aC=aB.data;console.log({type:typeof aC,data:aC});if(!A(aC))return;let aD=aC.split('_');(aD.length===2&&aD[0]==='100PAY-PAYMENT-REF')&&b.onPayment(aD[1])})});n.src=aA.hosted_url}newPayment(aE,aF){aE.onPayment(aF)}closeModal(aG){document.getElementById('show100PayWrapper').classList.remove('show');let aH=document.getElementById('show100PayWrapper');let aI=document.getElementById('close_100pay_btn');let _D=document.getElementById('100pay_loader');_D.remove();aH.remove();aI.remove();shop100TargetEl.style='display: none;';document.body.classList.remove('body-overflow-hidden');let _E=document.getElementById('100pay_style');_E.remove();aG.onClose()}}var e=new PayWith100Pay();typeof window!=='undefined'&&(window.shop100Pay=e);export{e as shop100Pay};