cppay-sdk 0.0.2-beta.32 → 0.0.2-beta.34
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.
- package/dist/{inject-style-Cd5D3aj8.cjs → locales-DAKREZkH.cjs} +1 -1
- package/dist/{inject-style-DtFJ9cds.js → locales-DGvDecya.js} +108 -3
- package/dist/react.cjs +1 -1
- package/dist/react.d.ts +6 -0
- package/dist/react.js +245 -223
- package/dist/vue.cjs +1 -1
- package/dist/vue.d.ts +6 -0
- package/dist/vue.js +230 -215
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),c=`:root{--cppay-bg:#fff;--cppay-bg-secondary:#fafafa;--cppay-surface:#f7f7f8;--cppay-surface-hover:#efeff0;--cppay-text-main:#18181b;--cppay-text-sub:#71717a;--cppay-text-muted:#a1a1aa;--cppay-accent:#18181b;--cppay-accent-primary:#6366f1;--cppay-accent-primary-light:#eef2ff;--cppay-accent-primary-border:#c7d2fe;--cppay-border:#e4e4e7;--cppay-border-dark:#d4d4d8;--cppay-danger:#ef4444;--cppay-danger-light:#fee2e2;--cppay-danger-border:#fecaca;--cppay-warning:#f97316;--cppay-warning-light:#fef3c7;--cppay-warning-border:#fcd34d;--cppay-success:#16a34a;--cppay-radius-lg:24px;--cppay-radius-md:16px;--cppay-radius-sm:12px;--cppay-radius-xs:8px;--cppay-space-xs:4px;--cppay-space-sm:8px;--cppay-space-md:12px;--cppay-space-lg:16px;--cppay-space-xl:24px;--cppay-space-2xl:32px;--cppay-shadow-sm:0 1px 2px 0 #0000000d;--cppay-shadow-md:0 4px 6px -1px #0000001a;--cppay-shadow-lg:0 10px 15px -3px #0000001a;--cppay-shadow-xl:0 20px 25px -5px #0000001a;--cppay-transition:all .2s cubic-bezier(.4, 0, .2, 1)}._cppay-overlay{-webkit-backdrop-filter:blur(4px);z-index:999;padding:var(--cppay-space-lg);background-color:#00000080;justify-content:center;align-items:center;animation:.3s ease-out _cppay-fadeIn;display:flex;position:fixed;inset:0}._cppay-dialog{background-color:var(--cppay-bg);border-radius:var(--cppay-radius-md);box-shadow:var(--cppay-shadow-xl);flex-direction:column;width:100%;max-width:500px;max-height:90vh;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,sans-serif;animation:.3s cubic-bezier(.4,0,.2,1) _cppay-slideUp;display:flex;overflow:hidden}._cppay-header{padding:var(--cppay-space-xl);border-bottom:1px solid var(--cppay-border);background:var(--cppay-bg);flex-shrink:0;justify-content:space-between;align-items:center;display:flex}._cppay-title{color:var(--cppay-text-main);letter-spacing:-.01em;margin:0;font-size:20px;font-weight:600}._cppay-close-btn{color:var(--cppay-text-muted);cursor:pointer;background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;padding:.5rem;transition:all .2s;display:flex}._cppay-close-btn:hover{background-color:var(--cppay-surface);color:var(--cppay-text-main)}._cppay-close-btn svg{width:1.5rem;height:1.5rem}._cppay-content{flex:1;padding:1rem 2rem 2rem;overflow-y:auto}._cppay-content::-webkit-scrollbar{width:0;height:0}._cppay-section{margin-bottom:1.5rem}._cppay-section:last-child{margin-bottom:0}._cppay-label{color:var(--cppay-text-sub);margin-bottom:.75rem;font-size:.875rem;font-weight:600;display:block}._cppay-grid{grid-template-columns:repeat(2,1fr);gap:.75rem;display:grid}._cppay-select-btn{border-radius:var(--cppay-radius-sm);background:var(--cppay-surface);cursor:pointer;color:var(--cppay-text-main);border:2px solid #0000;justify-content:flex-start;align-items:center;gap:.75rem;padding:.875rem 1rem;font-family:inherit;font-size:.95rem;font-weight:500;transition:all .2s cubic-bezier(.4,0,.2,1);display:flex;position:relative}._cppay-select-btn:hover{background-color:var(--cppay-surface-hover)}._cppay-select-btn._cppay-selected{background-color:var(--cppay-bg);border-color:var(--cppay-accent);box-shadow:0 4px 12px #0000000d}._cppay-select-btn img{object-fit:cover;border-radius:50%;width:1.5rem;height:1.5rem}._cppay-price-box{text-align:center;padding:1.5rem 0;position:relative}._cppay-price-label{color:var(--cppay-text-sub);margin-bottom:.5rem;font-size:.875rem;font-weight:500;display:block}._cppay-price-main{color:var(--cppay-text-main);letter-spacing:-.03em;justify-content:center;align-items:baseline;gap:.5rem;font-size:2.5rem;font-weight:800;line-height:1.1;display:flex}._cppay-price-symbol{color:var(--cppay-text-sub);font-size:1rem;font-weight:600;transform:translateY(-4px)}._cppay-price-sub{color:var(--cppay-text-muted);margin-top:.75rem;font-size:.95rem;font-weight:500}._cppay-btn{border-radius:var(--cppay-radius-md);cursor:pointer;letter-spacing:-.01em;border:none;justify-content:center;align-items:center;gap:.5rem;width:100%;padding:1rem;font-size:1rem;font-weight:600;transition:all .2s;display:flex}._cppay-btn-primary{background:var(--cppay-accent);color:#fff;box-shadow:0 4px 6px -1px #0000001a}._cppay-btn-primary:hover:not(:disabled){background:#222;transform:translateY(-1px);box-shadow:0 10px 15px -3px #0000001a}._cppay-btn-primary:active:not(:disabled){transform:scale(.98)}._cppay-btn-primary:disabled{color:#a3a3a3;cursor:not-allowed;box-shadow:none;background:#e5e5e5}._cppay-btn-text{color:var(--cppay-text-sub);background:0 0;margin-top:.5rem;font-size:.875rem}._cppay-btn-text:hover:not(:disabled){color:var(--cppay-text-main)}._cppay-btn-text:disabled{opacity:.5;cursor:not-allowed}._cppay-qr-container{justify-content:center;margin:1.5rem 0 2rem;display:flex}._cppay-qr-code{border-radius:var(--cppay-radius-md);border:1px solid var(--cppay-border);background:#fff;padding:.75rem;box-shadow:0 10px 20px #00000008}._cppay-qr-image{border-radius:8px;width:190px;height:190px;display:block}._cppay-info-box{background-color:var(--cppay-surface);border-radius:var(--cppay-radius-sm);border:1px solid #0000;margin-bottom:.75rem;padding:1rem;transition:all .2s}._cppay-info-box:hover{background-color:var(--cppay-surface-hover);border-color:var(--cppay-border)}._cppay-info-header{justify-content:space-between;align-items:center;margin-bottom:.5rem;display:flex}._cppay-info-label{text-transform:uppercase;color:var(--cppay-text-sub);letter-spacing:.05em;font-size:.75rem;font-weight:700}._cppay-info-label-flex{justify-content:space-between;align-items:center;gap:.5rem;display:flex}._cppay-info-value{color:var(--cppay-text-main);word-break:break-all;font-size:.95rem}._cppay-info-value-flex{flex-direction:column;gap:.5rem;margin-top:.5rem;display:flex}._cppay-info-value-flex span:first-child{font-size:1rem;font-weight:600}._cppay-info-value-flex span:last-child{color:var(--cppay-text-muted);font-size:.85rem}._cppay-info-flex-container{flex-direction:column;gap:.75rem;display:flex}._cppay-info-flex-child{flex-direction:column;gap:.5rem;display:flex}._cppay-address-row{justify-content:space-between;align-items:center;gap:.75rem;margin-top:.5rem;display:flex}._cppay-address-row code{border:1px solid var(--cppay-border);color:var(--cppay-text-main);word-break:break-all;overflow-wrap:break-word;background:#fff;border-radius:4px;flex:1;padding:.5rem .75rem;font-family:SF Mono,Monaco,Inconsolata,monospace;font-size:.85rem}._cppay-countdown{color:#d97706;background:#fffbeb;border-radius:4px;padding:2px 6px;font-size:.75rem;font-weight:600}._cppay-address-wrapper{justify-content:space-between;align-items:center;gap:.5rem;display:flex}._cppay-address-text{color:var(--cppay-text-main);text-overflow:ellipsis;white-space:nowrap;font-family:SF Mono,Monaco,monospace;font-size:.9rem;overflow:hidden}._cppay-copy-btn{border:1px solid var(--cppay-border);cursor:pointer;width:32px;height:32px;color:var(--cppay-text-main);background:#fff;border-radius:6px;flex-shrink:0;justify-content:center;align-items:center;padding:0;transition:all .2s;display:flex}._cppay-copy-btn:hover:not(._cppay-copy-success){background:var(--cppay-text-main);border-color:var(--cppay-text-main);color:#fff}._cppay-copy-btn._cppay-copy-success{color:#fff;background:#22c55e;border-color:#22c55e;animation:.3s ease-out _cppay-copyPulse}._cppay-copy-icon{justify-content:center;align-items:center;width:1rem;height:1rem;display:flex}._cppay-subscription-box{background-color:#fef3c7;border-color:#fcd34d}._cppay-subscription-label{color:#92400e;font-size:.85rem;font-weight:600}._cppay-subscription-message{color:#b45309;font-size:.85rem;line-height:1.5}._cppay-state-container{text-align:center;padding:3rem 1rem}._cppay-state-icon{background:var(--cppay-surface);border-radius:50%;justify-content:center;align-items:center;width:80px;height:80px;margin:0 auto 1.5rem;font-size:2.5rem;display:flex}._cppay-wallet-address-btn{color:var(--cppay-text-muted);margin-top:.5rem;cursor:pointer;background:0 0;border-radius:0;justify-content:center;align-items:center;gap:.5rem;margin-inline:auto;padding:.5rem 0;font-size:.85rem;font-weight:400;transition:all .2s;display:inline-flex}._cppay-wallet-address-btn:hover:not(:disabled){border-bottom-color:var(--cppay-text-main);color:var(--cppay-text-main);background:0 0}._cppay-wallet-address-btn:active:not(:disabled){transform:scale(.98)}._cppay-wallet-address-btn:disabled{opacity:.5;cursor:not-allowed}._cppay-wallet-icon{width:1rem;height:1rem;color:inherit;flex-shrink:0}._cppay-wallet-address-text{text-align:center;color:inherit;flex-shrink:0;font-family:SF Mono,Monaco,Inconsolata,monospace;font-size:.8rem}._cppay-wallet-arrow{width:.85rem;height:.85rem;color:inherit;opacity:.7;flex-shrink:0;transition:transform .2s}._cppay-wallet-address-btn:hover:not(:disabled) ._cppay-wallet-arrow{opacity:1;transform:translateY(1px)}._cppay-wallet-status{background:var(--cppay-surface);border-radius:var(--cppay-radius-sm);justify-content:space-between;align-items:center;margin-top:1rem;padding:.75rem 1rem;display:flex}._cppay-wallet-addr{color:var(--cppay-text-sub);font-family:monospace;font-size:.875rem}._cppay-divider{border-color:var(--cppay-border);border-top:0}._cppay-wallet-disconnect{color:var(--cppay-text-muted);cursor:pointer;background:0 0;border:none;font-size:.75rem}._cppay-wallet-disconnect:hover{color:var(--cppay-danger)}._cppay-error-tooltip-wrapper{position:relative}._cppay-error-tooltip{color:#991b1b;cursor:help;background-color:#fef2f2;border:1px solid #fecaca;border-radius:.375rem;align-items:center;gap:.5rem;margin-bottom:.5rem;padding:.5rem .75rem;font-size:.8125rem;line-height:1.25;transition:all .2s;display:flex}._cppay-error-tooltip:hover{background-color:#fee2e2;border-color:#fca5a5}._cppay-error-tooltip svg{flex-shrink:0;width:1rem;height:1rem}._cppay-error-tooltip span{text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;overflow:hidden}._cppay-error-tooltip-full{color:#fff;z-index:10;word-wrap:break-word;white-space:normal;background-color:#7f1d1d;border-radius:.5rem;margin-bottom:.25rem;padding:.625rem .875rem;font-size:.8125rem;line-height:1.4;animation:.2s ease-out _cppay-tooltipFadeIn;position:absolute;bottom:100%;left:0;right:0;box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}._cppay-error-tooltip-full:after{content:"";border:.375rem solid #0000;border-top-color:#7f1d1d;position:absolute;top:100%;left:1rem}@keyframes _cppay-fadeIn{0%{opacity:0}to{opacity:1}}@keyframes _cppay-slideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@keyframes _cppay-scaleIn{0%{opacity:0;transform:scale(.95)translateY(10px)}to{opacity:1;transform:scale(1)translateY(0)}}@keyframes _cppay-copyPulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@keyframes _cppay-pulse{0%,to{opacity:1}50%{opacity:.7}}@keyframes _cppay-tooltipFadeIn{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}@media (max-width:640px){._cppay-dialog{max-width:100%;margin:var(--cppay-space-lg);border-radius:var(--cppay-radius-md)}._cppay-header{padding:var(--cppay-space-lg)}._cppay-title{font-size:18px}._cppay-content{padding:var(--cppay-space-lg)}._cppay-grid{gap:var(--cppay-space-sm);grid-template-columns:repeat(auto-fit,minmax(80px,1fr))}._cppay-select-btn{padding:var(--cppay-space-md) var(--cppay-space-sm);font-size:12px}._cppay-select-btn img{width:28px;height:28px}._cppay-price-main{font-size:18px}._cppay-qr-image{width:160px;height:160px}}`;function l(e){if(typeof document>`u`||document.getElementById(`_cppay-payment-dialog-style`))return;let t=document.createElement(`style`);t.id=`_cppay-payment-dialog-style`,t.textContent=e,document.head.appendChild(t)}Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return l}});
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),c=`:root{--cppay-bg:#fff;--cppay-bg-secondary:#fafafa;--cppay-surface:#f7f7f8;--cppay-surface-hover:#efeff0;--cppay-text-main:#18181b;--cppay-text-sub:#71717a;--cppay-text-muted:#a1a1aa;--cppay-accent:#18181b;--cppay-accent-primary:#6366f1;--cppay-accent-primary-light:#eef2ff;--cppay-accent-primary-border:#c7d2fe;--cppay-border:#e4e4e7;--cppay-border-dark:#d4d4d8;--cppay-danger:#ef4444;--cppay-danger-light:#fee2e2;--cppay-danger-border:#fecaca;--cppay-warning:#f97316;--cppay-warning-light:#fef3c7;--cppay-warning-border:#fcd34d;--cppay-success:#16a34a;--cppay-radius-lg:24px;--cppay-radius-md:16px;--cppay-radius-sm:12px;--cppay-radius-xs:8px;--cppay-space-xs:4px;--cppay-space-sm:8px;--cppay-space-md:12px;--cppay-space-lg:16px;--cppay-space-xl:24px;--cppay-space-2xl:32px;--cppay-shadow-sm:0 1px 2px 0 #0000000d;--cppay-shadow-md:0 4px 6px -1px #0000001a;--cppay-shadow-lg:0 10px 15px -3px #0000001a;--cppay-shadow-xl:0 20px 25px -5px #0000001a;--cppay-transition:all .2s cubic-bezier(.4, 0, .2, 1)}._cppay-overlay{-webkit-backdrop-filter:blur(4px);z-index:999;padding:var(--cppay-space-lg);background-color:#00000080;justify-content:center;align-items:center;animation:.3s ease-out _cppay-fadeIn;display:flex;position:fixed;inset:0}._cppay-dialog{background-color:var(--cppay-bg);border-radius:var(--cppay-radius-md);box-shadow:var(--cppay-shadow-xl);flex-direction:column;width:100%;max-width:500px;max-height:90vh;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,sans-serif;animation:.3s cubic-bezier(.4,0,.2,1) _cppay-slideUp;display:flex;overflow:hidden}._cppay-header{padding:var(--cppay-space-xl);border-bottom:1px solid var(--cppay-border);background:var(--cppay-bg);flex-shrink:0;justify-content:space-between;align-items:center;display:flex}._cppay-title{color:var(--cppay-text-main);letter-spacing:-.01em;margin:0;font-size:20px;font-weight:600}._cppay-close-btn{color:var(--cppay-text-muted);cursor:pointer;background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;padding:.5rem;transition:all .2s;display:flex}._cppay-close-btn:hover{background-color:var(--cppay-surface);color:var(--cppay-text-main)}._cppay-close-btn svg{width:1.5rem;height:1.5rem}._cppay-content{flex:1;padding:1rem 2rem 2rem;overflow-y:auto}._cppay-content::-webkit-scrollbar{width:0;height:0}._cppay-section{margin-bottom:1.5rem}._cppay-section:last-child{margin-bottom:0}._cppay-label{color:var(--cppay-text-sub);margin-bottom:.75rem;font-size:.875rem;font-weight:600;display:block}._cppay-grid{grid-template-columns:repeat(2,1fr);gap:.75rem;display:grid}._cppay-select-btn{border-radius:var(--cppay-radius-sm);background:var(--cppay-surface);cursor:pointer;color:var(--cppay-text-main);border:2px solid #0000;justify-content:flex-start;align-items:center;gap:.75rem;padding:.875rem 1rem;font-family:inherit;font-size:.95rem;font-weight:500;transition:all .2s cubic-bezier(.4,0,.2,1);display:flex;position:relative}._cppay-select-btn:hover{background-color:var(--cppay-surface-hover)}._cppay-select-btn._cppay-selected{background-color:var(--cppay-bg);border-color:var(--cppay-accent);box-shadow:0 4px 12px #0000000d}._cppay-select-btn img{object-fit:cover;border-radius:50%;width:1.5rem;height:1.5rem}._cppay-price-box{text-align:center;padding:1.5rem 0;position:relative}._cppay-price-label{color:var(--cppay-text-sub);margin-bottom:.5rem;font-size:.875rem;font-weight:500;display:block}._cppay-price-main{color:var(--cppay-text-main);letter-spacing:-.03em;justify-content:center;align-items:baseline;gap:.5rem;font-size:2.5rem;font-weight:800;line-height:1.1;display:flex}._cppay-price-symbol{color:var(--cppay-text-sub);font-size:1rem;font-weight:600;transform:translateY(-4px)}._cppay-price-sub{color:var(--cppay-text-muted);margin-top:.75rem;font-size:.95rem;font-weight:500}._cppay-btn{border-radius:var(--cppay-radius-md);cursor:pointer;letter-spacing:-.01em;border:none;justify-content:center;align-items:center;gap:.5rem;width:100%;padding:1rem;font-size:1rem;font-weight:600;transition:all .2s;display:flex}._cppay-btn-primary{background:var(--cppay-accent);color:#fff;box-shadow:0 4px 6px -1px #0000001a}._cppay-btn-primary:hover:not(:disabled){background:#222;transform:translateY(-1px);box-shadow:0 10px 15px -3px #0000001a}._cppay-btn-primary:active:not(:disabled){transform:scale(.98)}._cppay-btn-primary:disabled{color:#a3a3a3;cursor:not-allowed;box-shadow:none;background:#e5e5e5}._cppay-btn-text{color:var(--cppay-text-sub);background:0 0;margin-top:.5rem;font-size:.875rem}._cppay-btn-text:hover:not(:disabled){color:var(--cppay-text-main)}._cppay-btn-text:disabled{opacity:.5;cursor:not-allowed}._cppay-qr-container{justify-content:center;margin:1.5rem 0 2rem;display:flex}._cppay-qr-code{border-radius:var(--cppay-radius-md);border:1px solid var(--cppay-border);background:#fff;padding:.75rem;box-shadow:0 10px 20px #00000008}._cppay-qr-image{border-radius:8px;width:190px;height:190px;display:block}._cppay-info-box{background-color:var(--cppay-surface);border-radius:var(--cppay-radius-sm);border:1px solid #0000;margin-bottom:.75rem;padding:1rem;transition:all .2s}._cppay-info-box:hover{background-color:var(--cppay-surface-hover);border-color:var(--cppay-border)}._cppay-info-header{justify-content:space-between;align-items:center;margin-bottom:.5rem;display:flex}._cppay-info-label{text-transform:uppercase;color:var(--cppay-text-sub);letter-spacing:.05em;font-size:.75rem;font-weight:700}._cppay-info-label-flex{justify-content:space-between;align-items:center;gap:.5rem;display:flex}._cppay-info-value{color:var(--cppay-text-main);word-break:break-all;font-size:.95rem}._cppay-info-value-flex{flex-direction:column;gap:.5rem;margin-top:.5rem;display:flex}._cppay-info-value-flex span:first-child{font-size:1rem;font-weight:600}._cppay-info-value-flex span:last-child{color:var(--cppay-text-muted);font-size:.85rem}._cppay-info-flex-container{flex-direction:column;gap:.75rem;display:flex}._cppay-info-flex-child{flex-direction:column;gap:.5rem;display:flex}._cppay-address-row{justify-content:space-between;align-items:center;gap:.75rem;margin-top:.5rem;display:flex}._cppay-address-row code{border:1px solid var(--cppay-border);color:var(--cppay-text-main);word-break:break-all;overflow-wrap:break-word;background:#fff;border-radius:4px;flex:1;padding:.5rem .75rem;font-family:SF Mono,Monaco,Inconsolata,monospace;font-size:.85rem}._cppay-countdown{color:#d97706;background:#fffbeb;border-radius:4px;padding:2px 6px;font-size:.75rem;font-weight:600}._cppay-address-wrapper{justify-content:space-between;align-items:center;gap:.5rem;display:flex}._cppay-address-text{color:var(--cppay-text-main);text-overflow:ellipsis;white-space:nowrap;font-family:SF Mono,Monaco,monospace;font-size:.9rem;overflow:hidden}._cppay-copy-btn{border:1px solid var(--cppay-border);cursor:pointer;width:32px;height:32px;color:var(--cppay-text-main);background:#fff;border-radius:6px;flex-shrink:0;justify-content:center;align-items:center;padding:0;transition:all .2s;display:flex}._cppay-copy-btn:hover:not(._cppay-copy-success){background:var(--cppay-text-main);border-color:var(--cppay-text-main);color:#fff}._cppay-copy-btn._cppay-copy-success{color:#fff;background:#22c55e;border-color:#22c55e;animation:.3s ease-out _cppay-copyPulse}._cppay-copy-icon{justify-content:center;align-items:center;width:1rem;height:1rem;display:flex}._cppay-subscription-box{background-color:#fef3c7;border-color:#fcd34d}._cppay-subscription-label{color:#92400e;font-size:.85rem;font-weight:600}._cppay-subscription-message{color:#b45309;font-size:.85rem;line-height:1.5}._cppay-state-container{text-align:center;padding:3rem 1rem}._cppay-state-icon{background:var(--cppay-surface);border-radius:50%;justify-content:center;align-items:center;width:80px;height:80px;margin:0 auto 1.5rem;font-size:2.5rem;display:flex}._cppay-wallet-address-btn{color:var(--cppay-text-muted);margin-top:.5rem;cursor:pointer;background:0 0;border-radius:0;justify-content:center;align-items:center;gap:.5rem;margin-inline:auto;padding:.5rem 0;font-size:.85rem;font-weight:400;transition:all .2s;display:inline-flex}._cppay-wallet-address-btn:hover:not(:disabled){border-bottom-color:var(--cppay-text-main);color:var(--cppay-text-main);background:0 0}._cppay-wallet-address-btn:active:not(:disabled){transform:scale(.98)}._cppay-wallet-address-btn:disabled{opacity:.5;cursor:not-allowed}._cppay-wallet-icon{width:1rem;height:1rem;color:inherit;flex-shrink:0}._cppay-wallet-address-text{text-align:center;color:inherit;flex-shrink:0;font-family:SF Mono,Monaco,Inconsolata,monospace;font-size:.8rem}._cppay-wallet-arrow{width:.85rem;height:.85rem;color:inherit;opacity:.7;flex-shrink:0;transition:transform .2s}._cppay-wallet-address-btn:hover:not(:disabled) ._cppay-wallet-arrow{opacity:1;transform:translateY(1px)}._cppay-wallet-status{background:var(--cppay-surface);border-radius:var(--cppay-radius-sm);justify-content:space-between;align-items:center;margin-top:1rem;padding:.75rem 1rem;display:flex}._cppay-wallet-addr{color:var(--cppay-text-sub);font-family:monospace;font-size:.875rem}._cppay-divider{border-color:var(--cppay-border);border-top:0}._cppay-wallet-disconnect{color:var(--cppay-text-muted);cursor:pointer;background:0 0;border:none;font-size:.75rem}._cppay-wallet-disconnect:hover{color:var(--cppay-danger)}._cppay-error-tooltip-wrapper{position:relative}._cppay-error-tooltip{color:#991b1b;cursor:help;background-color:#fef2f2;border:1px solid #fecaca;border-radius:.375rem;align-items:center;gap:.5rem;margin-bottom:.5rem;padding:.5rem .75rem;font-size:.8125rem;line-height:1.25;transition:all .2s;display:flex}._cppay-error-tooltip:hover{background-color:#fee2e2;border-color:#fca5a5}._cppay-error-tooltip svg{flex-shrink:0;width:1rem;height:1rem}._cppay-error-tooltip span{text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;overflow:hidden}._cppay-error-tooltip-full{color:#fff;z-index:10;word-wrap:break-word;white-space:normal;background-color:#7f1d1d;border-radius:.5rem;margin-bottom:.25rem;padding:.625rem .875rem;font-size:.8125rem;line-height:1.4;animation:.2s ease-out _cppay-tooltipFadeIn;position:absolute;bottom:100%;left:0;right:0;box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}._cppay-error-tooltip-full:after{content:"";border:.375rem solid #0000;border-top-color:#7f1d1d;position:absolute;top:100%;left:1rem}@keyframes _cppay-fadeIn{0%{opacity:0}to{opacity:1}}@keyframes _cppay-slideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@keyframes _cppay-scaleIn{0%{opacity:0;transform:scale(.95)translateY(10px)}to{opacity:1;transform:scale(1)translateY(0)}}@keyframes _cppay-copyPulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@keyframes _cppay-pulse{0%,to{opacity:1}50%{opacity:.7}}@keyframes _cppay-tooltipFadeIn{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}@media (max-width:640px){._cppay-dialog{max-width:100%;margin:var(--cppay-space-lg);border-radius:var(--cppay-radius-md)}._cppay-header{padding:var(--cppay-space-lg)}._cppay-title{font-size:18px}._cppay-content{padding:var(--cppay-space-lg)}._cppay-grid{gap:var(--cppay-space-sm);grid-template-columns:repeat(auto-fit,minmax(80px,1fr))}._cppay-select-btn{padding:var(--cppay-space-md) var(--cppay-space-sm);font-size:12px}._cppay-select-btn img{width:28px;height:28px}._cppay-price-main{font-size:18px}._cppay-qr-image{width:160px;height:160px}}`;function l(e){if(typeof document>`u`||document.getElementById(`_cppay-payment-dialog-style`))return;let t=document.createElement(`style`);t.id=`_cppay-payment-dialog-style`,t.textContent=e,document.head.appendChild(t)}const u={"zh-CN":{selectPaymentMethod:`选择支付方式`,completePayment:`完成支付`,paymentResult:`支付结果`,paymentExpired:`支付已过期`,paymentFailed:`支付失败`,error:`出错`,authorizationSuccess:`授权成功!`,paymentSuccess:`支付成功!`,subscriptionActivated:`订阅已激活`,transactionCompleted:`交易已完成`,paymentExpiredMessage:`支付已过期,请重选创建支付订单`,orderPaymentFailed:`订单支付失败!`,returnButton:`返回`,continuePayment:`继续支付`,processing:`处理中...`,connectWallet:`💳 连接钱包`,connecting:`连接中...`,walletAuthorize:`💳 钱包授权`,walletPay:`💳 钱包支付`,authorizing:`授权中...`,paying:`支付中...`,completedPayment:`我已完成支付`,checking:`检查中...`,changePaymentMethod:`更改支付方式`,paymentNetwork:`支付网络`,paymentToken:`支付代币`,paymentAmount:`支付金额`,authorizationAmount:`授权金额`,paymentAddress:`支付地址`,authorizationContractAddress:`授权合约地址`,copyAddress:`复制地址`,copied:`已复制!`,subscriptionNotice:`📌 订阅说明`,subscriptionNoticeMessage:`订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。`,clickToModifyWallet:`点击修改或查看钱包状态`,expired:`已过期`,hours:`时`,minutes:`分`,seconds:`秒`,loadPaymentNetworkFailed:`加载支付网络失败`,createPaymentFailed:`创建支付失败`,walletConnectionFailed:`钱包连接失败`,walletPaymentFailed:`钱包支付失败`,walletAuthorizationFailed:`钱包授权失败`,pleaseConnectWallet:`请先连接钱包`,pleaseAddNetwork:`请在钱包中添加该网络`,subscriptionDoesNotSupportNative:`订阅支付不支持原生代币`,checkPaymentStatusFailed:`检查支付状态失败`},"en-US":{selectPaymentMethod:`Select Payment Method`,completePayment:`Complete Payment`,paymentResult:`Payment Result`,paymentExpired:`Payment Expired`,paymentFailed:`Payment Failed`,error:`Error`,authorizationSuccess:`Authorization Successful!`,paymentSuccess:`Payment Successful!`,subscriptionActivated:`Subscription Activated`,transactionCompleted:`Transaction Completed`,paymentExpiredMessage:`Payment has expired, please create a new payment order`,orderPaymentFailed:`Order payment failed!`,returnButton:`Return`,continuePayment:`Continue Payment`,processing:`Processing...`,connectWallet:`💳 Connect Wallet`,connecting:`Connecting...`,walletAuthorize:`💳 Wallet Authorize`,walletPay:`💳 Wallet Pay`,authorizing:`Authorizing...`,paying:`Paying...`,completedPayment:`I have completed payment`,checking:`Checking...`,changePaymentMethod:`Change Payment Method`,paymentNetwork:`Payment Network`,paymentToken:`Payment Token`,paymentAmount:`Payment Amount`,authorizationAmount:`Authorization Amount`,paymentAddress:`Payment Address`,authorizationContractAddress:`Authorization Contract Address`,copyAddress:`Copy Address`,copied:`Copied!`,subscriptionNotice:`📌 Subscription Notice`,subscriptionNoticeMessage:`Subscription payment requires token authorization to the contract address. The system will automatically deduct payment periodically. No manual payment is needed after authorization.`,clickToModifyWallet:`Click to modify or view wallet status`,expired:`Expired`,hours:`h`,minutes:`m`,seconds:`s`,loadPaymentNetworkFailed:`Failed to load payment network`,createPaymentFailed:`Failed to create payment`,walletConnectionFailed:`Wallet connection failed`,walletPaymentFailed:`Wallet payment failed`,walletAuthorizationFailed:`Wallet authorization failed`,pleaseConnectWallet:`Please connect wallet first`,pleaseAddNetwork:`Please add this network in your wallet`,subscriptionDoesNotSupportNative:`Subscription payment does not support native tokens`,checkPaymentStatusFailed:`Failed to check payment status`}};function d(e=`zh-CN`){return u[e]||u[`zh-CN`]}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return d}});
|
|
@@ -1,7 +1,112 @@
|
|
|
1
1
|
var payment_dialog_default = ":root{--cppay-bg:#fff;--cppay-bg-secondary:#fafafa;--cppay-surface:#f7f7f8;--cppay-surface-hover:#efeff0;--cppay-text-main:#18181b;--cppay-text-sub:#71717a;--cppay-text-muted:#a1a1aa;--cppay-accent:#18181b;--cppay-accent-primary:#6366f1;--cppay-accent-primary-light:#eef2ff;--cppay-accent-primary-border:#c7d2fe;--cppay-border:#e4e4e7;--cppay-border-dark:#d4d4d8;--cppay-danger:#ef4444;--cppay-danger-light:#fee2e2;--cppay-danger-border:#fecaca;--cppay-warning:#f97316;--cppay-warning-light:#fef3c7;--cppay-warning-border:#fcd34d;--cppay-success:#16a34a;--cppay-radius-lg:24px;--cppay-radius-md:16px;--cppay-radius-sm:12px;--cppay-radius-xs:8px;--cppay-space-xs:4px;--cppay-space-sm:8px;--cppay-space-md:12px;--cppay-space-lg:16px;--cppay-space-xl:24px;--cppay-space-2xl:32px;--cppay-shadow-sm:0 1px 2px 0 #0000000d;--cppay-shadow-md:0 4px 6px -1px #0000001a;--cppay-shadow-lg:0 10px 15px -3px #0000001a;--cppay-shadow-xl:0 20px 25px -5px #0000001a;--cppay-transition:all .2s cubic-bezier(.4, 0, .2, 1)}._cppay-overlay{-webkit-backdrop-filter:blur(4px);z-index:999;padding:var(--cppay-space-lg);background-color:#00000080;justify-content:center;align-items:center;animation:.3s ease-out _cppay-fadeIn;display:flex;position:fixed;inset:0}._cppay-dialog{background-color:var(--cppay-bg);border-radius:var(--cppay-radius-md);box-shadow:var(--cppay-shadow-xl);flex-direction:column;width:100%;max-width:500px;max-height:90vh;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,sans-serif;animation:.3s cubic-bezier(.4,0,.2,1) _cppay-slideUp;display:flex;overflow:hidden}._cppay-header{padding:var(--cppay-space-xl);border-bottom:1px solid var(--cppay-border);background:var(--cppay-bg);flex-shrink:0;justify-content:space-between;align-items:center;display:flex}._cppay-title{color:var(--cppay-text-main);letter-spacing:-.01em;margin:0;font-size:20px;font-weight:600}._cppay-close-btn{color:var(--cppay-text-muted);cursor:pointer;background:0 0;border:none;border-radius:50%;justify-content:center;align-items:center;padding:.5rem;transition:all .2s;display:flex}._cppay-close-btn:hover{background-color:var(--cppay-surface);color:var(--cppay-text-main)}._cppay-close-btn svg{width:1.5rem;height:1.5rem}._cppay-content{flex:1;padding:1rem 2rem 2rem;overflow-y:auto}._cppay-content::-webkit-scrollbar{width:0;height:0}._cppay-section{margin-bottom:1.5rem}._cppay-section:last-child{margin-bottom:0}._cppay-label{color:var(--cppay-text-sub);margin-bottom:.75rem;font-size:.875rem;font-weight:600;display:block}._cppay-grid{grid-template-columns:repeat(2,1fr);gap:.75rem;display:grid}._cppay-select-btn{border-radius:var(--cppay-radius-sm);background:var(--cppay-surface);cursor:pointer;color:var(--cppay-text-main);border:2px solid #0000;justify-content:flex-start;align-items:center;gap:.75rem;padding:.875rem 1rem;font-family:inherit;font-size:.95rem;font-weight:500;transition:all .2s cubic-bezier(.4,0,.2,1);display:flex;position:relative}._cppay-select-btn:hover{background-color:var(--cppay-surface-hover)}._cppay-select-btn._cppay-selected{background-color:var(--cppay-bg);border-color:var(--cppay-accent);box-shadow:0 4px 12px #0000000d}._cppay-select-btn img{object-fit:cover;border-radius:50%;width:1.5rem;height:1.5rem}._cppay-price-box{text-align:center;padding:1.5rem 0;position:relative}._cppay-price-label{color:var(--cppay-text-sub);margin-bottom:.5rem;font-size:.875rem;font-weight:500;display:block}._cppay-price-main{color:var(--cppay-text-main);letter-spacing:-.03em;justify-content:center;align-items:baseline;gap:.5rem;font-size:2.5rem;font-weight:800;line-height:1.1;display:flex}._cppay-price-symbol{color:var(--cppay-text-sub);font-size:1rem;font-weight:600;transform:translateY(-4px)}._cppay-price-sub{color:var(--cppay-text-muted);margin-top:.75rem;font-size:.95rem;font-weight:500}._cppay-btn{border-radius:var(--cppay-radius-md);cursor:pointer;letter-spacing:-.01em;border:none;justify-content:center;align-items:center;gap:.5rem;width:100%;padding:1rem;font-size:1rem;font-weight:600;transition:all .2s;display:flex}._cppay-btn-primary{background:var(--cppay-accent);color:#fff;box-shadow:0 4px 6px -1px #0000001a}._cppay-btn-primary:hover:not(:disabled){background:#222;transform:translateY(-1px);box-shadow:0 10px 15px -3px #0000001a}._cppay-btn-primary:active:not(:disabled){transform:scale(.98)}._cppay-btn-primary:disabled{color:#a3a3a3;cursor:not-allowed;box-shadow:none;background:#e5e5e5}._cppay-btn-text{color:var(--cppay-text-sub);background:0 0;margin-top:.5rem;font-size:.875rem}._cppay-btn-text:hover:not(:disabled){color:var(--cppay-text-main)}._cppay-btn-text:disabled{opacity:.5;cursor:not-allowed}._cppay-qr-container{justify-content:center;margin:1.5rem 0 2rem;display:flex}._cppay-qr-code{border-radius:var(--cppay-radius-md);border:1px solid var(--cppay-border);background:#fff;padding:.75rem;box-shadow:0 10px 20px #00000008}._cppay-qr-image{border-radius:8px;width:190px;height:190px;display:block}._cppay-info-box{background-color:var(--cppay-surface);border-radius:var(--cppay-radius-sm);border:1px solid #0000;margin-bottom:.75rem;padding:1rem;transition:all .2s}._cppay-info-box:hover{background-color:var(--cppay-surface-hover);border-color:var(--cppay-border)}._cppay-info-header{justify-content:space-between;align-items:center;margin-bottom:.5rem;display:flex}._cppay-info-label{text-transform:uppercase;color:var(--cppay-text-sub);letter-spacing:.05em;font-size:.75rem;font-weight:700}._cppay-info-label-flex{justify-content:space-between;align-items:center;gap:.5rem;display:flex}._cppay-info-value{color:var(--cppay-text-main);word-break:break-all;font-size:.95rem}._cppay-info-value-flex{flex-direction:column;gap:.5rem;margin-top:.5rem;display:flex}._cppay-info-value-flex span:first-child{font-size:1rem;font-weight:600}._cppay-info-value-flex span:last-child{color:var(--cppay-text-muted);font-size:.85rem}._cppay-info-flex-container{flex-direction:column;gap:.75rem;display:flex}._cppay-info-flex-child{flex-direction:column;gap:.5rem;display:flex}._cppay-address-row{justify-content:space-between;align-items:center;gap:.75rem;margin-top:.5rem;display:flex}._cppay-address-row code{border:1px solid var(--cppay-border);color:var(--cppay-text-main);word-break:break-all;overflow-wrap:break-word;background:#fff;border-radius:4px;flex:1;padding:.5rem .75rem;font-family:SF Mono,Monaco,Inconsolata,monospace;font-size:.85rem}._cppay-countdown{color:#d97706;background:#fffbeb;border-radius:4px;padding:2px 6px;font-size:.75rem;font-weight:600}._cppay-address-wrapper{justify-content:space-between;align-items:center;gap:.5rem;display:flex}._cppay-address-text{color:var(--cppay-text-main);text-overflow:ellipsis;white-space:nowrap;font-family:SF Mono,Monaco,monospace;font-size:.9rem;overflow:hidden}._cppay-copy-btn{border:1px solid var(--cppay-border);cursor:pointer;width:32px;height:32px;color:var(--cppay-text-main);background:#fff;border-radius:6px;flex-shrink:0;justify-content:center;align-items:center;padding:0;transition:all .2s;display:flex}._cppay-copy-btn:hover:not(._cppay-copy-success){background:var(--cppay-text-main);border-color:var(--cppay-text-main);color:#fff}._cppay-copy-btn._cppay-copy-success{color:#fff;background:#22c55e;border-color:#22c55e;animation:.3s ease-out _cppay-copyPulse}._cppay-copy-icon{justify-content:center;align-items:center;width:1rem;height:1rem;display:flex}._cppay-subscription-box{background-color:#fef3c7;border-color:#fcd34d}._cppay-subscription-label{color:#92400e;font-size:.85rem;font-weight:600}._cppay-subscription-message{color:#b45309;font-size:.85rem;line-height:1.5}._cppay-state-container{text-align:center;padding:3rem 1rem}._cppay-state-icon{background:var(--cppay-surface);border-radius:50%;justify-content:center;align-items:center;width:80px;height:80px;margin:0 auto 1.5rem;font-size:2.5rem;display:flex}._cppay-wallet-address-btn{color:var(--cppay-text-muted);margin-top:.5rem;cursor:pointer;background:0 0;border-radius:0;justify-content:center;align-items:center;gap:.5rem;margin-inline:auto;padding:.5rem 0;font-size:.85rem;font-weight:400;transition:all .2s;display:inline-flex}._cppay-wallet-address-btn:hover:not(:disabled){border-bottom-color:var(--cppay-text-main);color:var(--cppay-text-main);background:0 0}._cppay-wallet-address-btn:active:not(:disabled){transform:scale(.98)}._cppay-wallet-address-btn:disabled{opacity:.5;cursor:not-allowed}._cppay-wallet-icon{width:1rem;height:1rem;color:inherit;flex-shrink:0}._cppay-wallet-address-text{text-align:center;color:inherit;flex-shrink:0;font-family:SF Mono,Monaco,Inconsolata,monospace;font-size:.8rem}._cppay-wallet-arrow{width:.85rem;height:.85rem;color:inherit;opacity:.7;flex-shrink:0;transition:transform .2s}._cppay-wallet-address-btn:hover:not(:disabled) ._cppay-wallet-arrow{opacity:1;transform:translateY(1px)}._cppay-wallet-status{background:var(--cppay-surface);border-radius:var(--cppay-radius-sm);justify-content:space-between;align-items:center;margin-top:1rem;padding:.75rem 1rem;display:flex}._cppay-wallet-addr{color:var(--cppay-text-sub);font-family:monospace;font-size:.875rem}._cppay-divider{border-color:var(--cppay-border);border-top:0}._cppay-wallet-disconnect{color:var(--cppay-text-muted);cursor:pointer;background:0 0;border:none;font-size:.75rem}._cppay-wallet-disconnect:hover{color:var(--cppay-danger)}._cppay-error-tooltip-wrapper{position:relative}._cppay-error-tooltip{color:#991b1b;cursor:help;background-color:#fef2f2;border:1px solid #fecaca;border-radius:.375rem;align-items:center;gap:.5rem;margin-bottom:.5rem;padding:.5rem .75rem;font-size:.8125rem;line-height:1.25;transition:all .2s;display:flex}._cppay-error-tooltip:hover{background-color:#fee2e2;border-color:#fca5a5}._cppay-error-tooltip svg{flex-shrink:0;width:1rem;height:1rem}._cppay-error-tooltip span{text-overflow:ellipsis;white-space:nowrap;flex:1;min-width:0;overflow:hidden}._cppay-error-tooltip-full{color:#fff;z-index:10;word-wrap:break-word;white-space:normal;background-color:#7f1d1d;border-radius:.5rem;margin-bottom:.25rem;padding:.625rem .875rem;font-size:.8125rem;line-height:1.4;animation:.2s ease-out _cppay-tooltipFadeIn;position:absolute;bottom:100%;left:0;right:0;box-shadow:0 4px 6px -1px #0000001a,0 2px 4px -1px #0000000f}._cppay-error-tooltip-full:after{content:\"\";border:.375rem solid #0000;border-top-color:#7f1d1d;position:absolute;top:100%;left:1rem}@keyframes _cppay-fadeIn{0%{opacity:0}to{opacity:1}}@keyframes _cppay-slideUp{0%{opacity:0;transform:translateY(20px)}to{opacity:1;transform:translateY(0)}}@keyframes _cppay-scaleIn{0%{opacity:0;transform:scale(.95)translateY(10px)}to{opacity:1;transform:scale(1)translateY(0)}}@keyframes _cppay-copyPulse{0%{transform:scale(1)}50%{transform:scale(1.1)}to{transform:scale(1)}}@keyframes _cppay-pulse{0%,to{opacity:1}50%{opacity:.7}}@keyframes _cppay-tooltipFadeIn{0%{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:translateY(0)}}@media (max-width:640px){._cppay-dialog{max-width:100%;margin:var(--cppay-space-lg);border-radius:var(--cppay-radius-md)}._cppay-header{padding:var(--cppay-space-lg)}._cppay-title{font-size:18px}._cppay-content{padding:var(--cppay-space-lg)}._cppay-grid{gap:var(--cppay-space-sm);grid-template-columns:repeat(auto-fit,minmax(80px,1fr))}._cppay-select-btn{padding:var(--cppay-space-md) var(--cppay-space-sm);font-size:12px}._cppay-select-btn img{width:28px;height:28px}._cppay-price-main{font-size:18px}._cppay-qr-image{width:160px;height:160px}}";
|
|
2
2
|
function injectStyle(e) {
|
|
3
3
|
if (typeof document > "u" || document.getElementById("_cppay-payment-dialog-style")) return;
|
|
4
|
-
let
|
|
5
|
-
|
|
4
|
+
let r = document.createElement("style");
|
|
5
|
+
r.id = "_cppay-payment-dialog-style", r.textContent = e, document.head.appendChild(r);
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
const locales = {
|
|
8
|
+
"zh-CN": {
|
|
9
|
+
selectPaymentMethod: "选择支付方式",
|
|
10
|
+
completePayment: "完成支付",
|
|
11
|
+
paymentResult: "支付结果",
|
|
12
|
+
paymentExpired: "支付已过期",
|
|
13
|
+
paymentFailed: "支付失败",
|
|
14
|
+
error: "出错",
|
|
15
|
+
authorizationSuccess: "授权成功!",
|
|
16
|
+
paymentSuccess: "支付成功!",
|
|
17
|
+
subscriptionActivated: "订阅已激活",
|
|
18
|
+
transactionCompleted: "交易已完成",
|
|
19
|
+
paymentExpiredMessage: "支付已过期,请重选创建支付订单",
|
|
20
|
+
orderPaymentFailed: "订单支付失败!",
|
|
21
|
+
returnButton: "返回",
|
|
22
|
+
continuePayment: "继续支付",
|
|
23
|
+
processing: "处理中...",
|
|
24
|
+
connectWallet: "💳 连接钱包",
|
|
25
|
+
connecting: "连接中...",
|
|
26
|
+
walletAuthorize: "💳 钱包授权",
|
|
27
|
+
walletPay: "💳 钱包支付",
|
|
28
|
+
authorizing: "授权中...",
|
|
29
|
+
paying: "支付中...",
|
|
30
|
+
completedPayment: "我已完成支付",
|
|
31
|
+
checking: "检查中...",
|
|
32
|
+
changePaymentMethod: "更改支付方式",
|
|
33
|
+
paymentNetwork: "支付网络",
|
|
34
|
+
paymentToken: "支付代币",
|
|
35
|
+
paymentAmount: "支付金额",
|
|
36
|
+
authorizationAmount: "授权金额",
|
|
37
|
+
paymentAddress: "支付地址",
|
|
38
|
+
authorizationContractAddress: "授权合约地址",
|
|
39
|
+
copyAddress: "复制地址",
|
|
40
|
+
copied: "已复制!",
|
|
41
|
+
subscriptionNotice: "📌 订阅说明",
|
|
42
|
+
subscriptionNoticeMessage: "订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。",
|
|
43
|
+
clickToModifyWallet: "点击修改或查看钱包状态",
|
|
44
|
+
expired: "已过期",
|
|
45
|
+
hours: "时",
|
|
46
|
+
minutes: "分",
|
|
47
|
+
seconds: "秒",
|
|
48
|
+
loadPaymentNetworkFailed: "加载支付网络失败",
|
|
49
|
+
createPaymentFailed: "创建支付失败",
|
|
50
|
+
walletConnectionFailed: "钱包连接失败",
|
|
51
|
+
walletPaymentFailed: "钱包支付失败",
|
|
52
|
+
walletAuthorizationFailed: "钱包授权失败",
|
|
53
|
+
pleaseConnectWallet: "请先连接钱包",
|
|
54
|
+
pleaseAddNetwork: "请在钱包中添加该网络",
|
|
55
|
+
subscriptionDoesNotSupportNative: "订阅支付不支持原生代币",
|
|
56
|
+
checkPaymentStatusFailed: "检查支付状态失败"
|
|
57
|
+
},
|
|
58
|
+
"en-US": {
|
|
59
|
+
selectPaymentMethod: "Select Payment Method",
|
|
60
|
+
completePayment: "Complete Payment",
|
|
61
|
+
paymentResult: "Payment Result",
|
|
62
|
+
paymentExpired: "Payment Expired",
|
|
63
|
+
paymentFailed: "Payment Failed",
|
|
64
|
+
error: "Error",
|
|
65
|
+
authorizationSuccess: "Authorization Successful!",
|
|
66
|
+
paymentSuccess: "Payment Successful!",
|
|
67
|
+
subscriptionActivated: "Subscription Activated",
|
|
68
|
+
transactionCompleted: "Transaction Completed",
|
|
69
|
+
paymentExpiredMessage: "Payment has expired, please create a new payment order",
|
|
70
|
+
orderPaymentFailed: "Order payment failed!",
|
|
71
|
+
returnButton: "Return",
|
|
72
|
+
continuePayment: "Continue Payment",
|
|
73
|
+
processing: "Processing...",
|
|
74
|
+
connectWallet: "💳 Connect Wallet",
|
|
75
|
+
connecting: "Connecting...",
|
|
76
|
+
walletAuthorize: "💳 Wallet Authorize",
|
|
77
|
+
walletPay: "💳 Wallet Pay",
|
|
78
|
+
authorizing: "Authorizing...",
|
|
79
|
+
paying: "Paying...",
|
|
80
|
+
completedPayment: "I have completed payment",
|
|
81
|
+
checking: "Checking...",
|
|
82
|
+
changePaymentMethod: "Change Payment Method",
|
|
83
|
+
paymentNetwork: "Payment Network",
|
|
84
|
+
paymentToken: "Payment Token",
|
|
85
|
+
paymentAmount: "Payment Amount",
|
|
86
|
+
authorizationAmount: "Authorization Amount",
|
|
87
|
+
paymentAddress: "Payment Address",
|
|
88
|
+
authorizationContractAddress: "Authorization Contract Address",
|
|
89
|
+
copyAddress: "Copy Address",
|
|
90
|
+
copied: "Copied!",
|
|
91
|
+
subscriptionNotice: "📌 Subscription Notice",
|
|
92
|
+
subscriptionNoticeMessage: "Subscription payment requires token authorization to the contract address. The system will automatically deduct payment periodically. No manual payment is needed after authorization.",
|
|
93
|
+
clickToModifyWallet: "Click to modify or view wallet status",
|
|
94
|
+
expired: "Expired",
|
|
95
|
+
hours: "h",
|
|
96
|
+
minutes: "m",
|
|
97
|
+
seconds: "s",
|
|
98
|
+
loadPaymentNetworkFailed: "Failed to load payment network",
|
|
99
|
+
createPaymentFailed: "Failed to create payment",
|
|
100
|
+
walletConnectionFailed: "Wallet connection failed",
|
|
101
|
+
walletPaymentFailed: "Wallet payment failed",
|
|
102
|
+
walletAuthorizationFailed: "Wallet authorization failed",
|
|
103
|
+
pleaseConnectWallet: "Please connect wallet first",
|
|
104
|
+
pleaseAddNetwork: "Please add this network in your wallet",
|
|
105
|
+
subscriptionDoesNotSupportNative: "Subscription payment does not support native tokens",
|
|
106
|
+
checkPaymentStatusFailed: "Failed to check payment status"
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
function getLocaleMessages(e = "zh-CN") {
|
|
110
|
+
return locales[e] || locales["zh-CN"];
|
|
111
|
+
}
|
|
112
|
+
export { injectStyle as n, payment_dialog_default as r, getLocaleMessages as t };
|
package/dist/react.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`./inject-style-Cd5D3aj8.cjs`),t=require(`./cppay-BYRjTzRF.cjs`);let n=require(`qrcode`);n=e.r(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`viem`),o=require(`viem/chains`),s=require(`@reown/appkit`),c=require(`@reown/appkit-adapter-ethers`),l=require(`react`);l=e.r(l);let u=require(`react/jsx-runtime`);var d=({apikey:e,ott:d,plain:f,orderId:p,amount:m,intervalDays:h,onSuccess:g,onExpired:_,onFailed:v,onError:y,Slots:b,paymentStep:x,onPaymentStepChange:S,loading:C=!1,isCheckingPayment:w=!1,error:T,onErrorChange:E})=>{let D=(0,l.useMemo)(()=>new t.t(e,d),[e,d]),[O,ee]=(0,l.useState)([]),[k,te]=(0,l.useState)(),[A,j]=(0,l.useState)(),[ne,M]=(0,l.useState)(),[N,P]=(0,l.useState)(),[re,F]=(0,l.useState)(!1),[I,L]=(0,l.useState)(),[R,ie]=(0,l.useState)(``),[z,B]=(0,l.useState)(!1),[ae,V]=(0,l.useState)(!1),H=(0,l.useRef)(null),U=(0,l.useRef)(null),W=(0,l.useRef)(null);(0,l.useEffect)(()=>{typeof window<`u`&&!H.current&&(H.current=(0,s.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new c.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[o.mainnet,o.bsc,o.polygon,o.arbitrum,o.optimism,o.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),P(H.current.getAddress()),L(H.current.getProvider(`eip155`)),H.current.subscribeAccount(e=>{e.isConnected?P(e.address):(P(void 0),L(void 0))}),H.current.subscribeProviders(e=>{let t=e?.eip155;L(t)}))},[]);let G=async()=>{try{F(!0),E?.(void 0),H.current&&await H.current.open()}catch(e){console.error(`钱包连接失败:`,e);let t=e instanceof Error?e.message:`钱包连接失败`;E?.(t),y?.(e)}finally{F(!1)}},K=(0,l.useMemo)(()=>O.find(e=>e.chain===k),[O,k]),q=(0,l.useMemo)(()=>K?.tokens||[],[K]),J=(0,l.useMemo)(()=>q.find(e=>e.symbol===A),[q,A]),Y=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,X=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},oe=e=>{if(e<=0)return`已过期`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60;return t>0?`${t}时${n}分${r}秒`:`${n}分${r}秒`},se=e=>{W.current&&clearInterval(W.current);let t=()=>{let t=e-Math.floor(Date.now()/1e3);ie(oe(t)),t<=0&&(S(`expired`),ce())};t(),W.current=setInterval(t,1e3)},ce=()=>{W.current&&=(clearInterval(W.current),null)},Z=(0,l.useMemo)(()=>{if(!A||!J)return`0`;let e=parseFloat(J.price);if(isNaN(e)||e===0)return`0`;let t=Y(A);return X((parseFloat(m)/e).toFixed(t),t)},[m,A,J]),le=async()=>{try{E?.(void 0);let e=await D.getSupportedChains();ee(e),e.length>0&&te(e[0].chain)}catch(e){let t=e instanceof Error?e.message:`加载支付网络失败`;E?.(t),y?.(e)}},ue=async e=>{if(I)try{await I.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(`请在钱包中添加该网络`):e}},de=async()=>{if(!(!N||!I||!Q.current||!J||!K))try{let e=Q.current;await ue(K.chainId);let t=(0,a.createWalletClient)({account:N,transport:(0,a.custom)(I)});J.address?await t.writeContract({address:J.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,a.parseUnits)(e.paymentAmount,J.decimals)],chain:null}):await t.sendTransaction({to:e.receiveAddress,value:(0,a.parseUnits)(e.paymentAmount,J.decimals),chain:null}),M(void 0)}catch(e){console.error(`钱包支付失败:`,e);let t=e instanceof Error?e.message:`钱包支付失败`;E?.(t),y?.(e)}},fe=async()=>{if(!(!N||!I||!Q.current||!J||!K))try{let e=Q.current;await ue(K.chainId);let t=(0,a.createWalletClient)({account:N,transport:(0,a.custom)(I)});if(!J.address)throw Error(`订阅支付不支持原生代币`);await t.writeContract({address:J.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,a.parseUnits)(e.approveAmount,J.decimals)],chain:null}),M(void 0)}catch(e){console.error(`钱包授权失败:`,e);let t=e instanceof Error?e.message:`钱包授权失败`;E?.(t),y?.(e)}},pe=async()=>{if(!N){let e=`请先连接钱包`;E?.(e),y?.(Error(e));return}f===`one-time`?await de():f===`subscription`&&await fe()},Q=(0,l.useRef)(null),me=async()=>{if(!(!k||!A))try{E?.(void 0);let e=``;f===`one-time`?(Q.current=await D.createOnetimePayment({paymentChain:k,paymentToken:A,orderId:p,amount:Z}),e=`${k.toLowerCase()}:${Q.current.receiveAddress}?amount=${Q.current.paymentAmount}`,se(Q.current.expireAt),$({paymentId:Q.current.paymentId})):f===`subscription`&&(Q.current=await D.createSubscriptionPayment({paymentChain:k,paymentToken:A,orderId:p,amountOfUsd:Z,intervalDays:h||30}),e=`${k.toLowerCase()}:${Q.current.spenderAddress}?amount=${Q.current.approveAmount}`,se(Q.current.expireAt),$({subscriptionId:Q.current.subscriptionId})),S(`payment`),M(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){let t=e instanceof Error?e.message:`创建支付失败`;E?.(t),y?.(e)}},$=e=>{U.current?.unsubscribe();let t=()=>(0,r.defer)(()=>f===`subscription`?D.checkSubscriptionPaymentStatus(e):D.checkOnetimePaymentStatus(e)).pipe((0,i.timeout)(15e3),(0,i.retry)({delay:2e3}));U.current=t().pipe((0,i.expand)(e=>e.status===`pending`?(0,r.timer)(2e3).pipe((0,i.switchMap)(()=>t())):r.EMPTY),(0,i.tap)(e=>{(e.status===`paid`||e.status===`approved`)&&(S(`success`),g?.(e)),e.status===`expired`&&(S(`expired`),_?.(e)),e.status===`failed`&&(S(`failed`),v?.(e))})).subscribe({error:e=>{if(Q.current){let t=e instanceof Error?e.message:`检查支付状态失败`;S(`error`),E?.(t),y?.(e)}},complete:()=>{U.current?.unsubscribe()}})};return(0,l.useEffect)(()=>{O.length===0&&le()},[]),(0,l.useEffect)(()=>{q.length>0&&j(q[0].symbol)},[q]),(0,l.useEffect)(()=>(p&&$({orderId:p}),()=>{U.current?.unsubscribe(),ce()}),[p]),(0,u.jsx)(`div`,{className:`_cppay-content`,children:x===`success`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`✅`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:f===`subscription`?`授权成功!`:`支付成功!`}),(0,u.jsx)(`p`,{className:`_cppay-state-message`,children:f===`subscription`?`订阅已激活`:`交易已完成`})]}):x===`expired`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`⏰`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:`支付已过期,请重选创建支付订单`}),(0,u.jsx)(`button`,{onClick:()=>S(`select`),disabled:C||w,className:`_cppay-btn _cppay-btn-text`,children:`返回`})]}):x===`error`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:`检查订单支付状态失败!`})]}):x===`failed`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:`订单支付失败!`})]}):x===`select`?(0,u.jsxs)(`div`,{children:[b?.ChooseTop,(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:`支付网络`}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:O.map(e=>(0,u.jsxs)(`button`,{onClick:()=>te(e.chain),className:`_cppay-select-btn ${k===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,u.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:`支付代币`}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:q.map(e=>(0,u.jsxs)(`button`,{onClick:()=>j(e.symbol),className:`_cppay-select-btn ${A===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,u.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),b?.ChooseBottom,(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`div`,{className:`_cppay-price-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,u.jsx)(`span`,{className:`_cppay-price-label`,children:`支付金额`}),(0,u.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,u.jsxs)(`div`,{className:`_cppay-price-main`,children:[Z??`-`,` `,A??``]}),(0,u.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,m]})]})]})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[T&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>V(!0),onMouseLeave:()=>V(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:T})]}),ae&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:T})]}),(0,u.jsx)(`button`,{onClick:me,disabled:!k||!A||C,className:`_cppay-btn _cppay-btn-primary`,children:C?`处理中...`:`继续支付`})]})]}):(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,u.jsx)(`div`,{className:`_cppay-qr-code`,children:ne&&(0,u.jsx)(`img`,{src:ne,alt:`Payment QR Code`,className:`_cppay-qr-image`})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[J&&(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsx)(`div`,{className:`_cppay-info-flex-container`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:f===`subscription`?`授权金额`:`支付金额`}),(0,u.jsxs)(`div`,{className:`_cppay-info-value _cppay-info-value-flex`,children:[(0,u.jsx)(`span`,{children:f===`subscription`?`${X(Q.current.approveAmount,Y(J.symbol))} ${J.symbol}`:`${X(Q.current.paymentAmount,Y(J.symbol))} ${J.symbol}`}),(0,u.jsxs)(`span`,{children:[`≈ $`,m]})]})]})})}),(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsxs)(`div`,{className:`_cppay-info-label _cppay-info-label-flex`,children:[(0,u.jsx)(`span`,{children:f===`subscription`?`授权合约地址`:`支付地址`}),R&&(0,u.jsxs)(`span`,{className:`_cppay-countdown`,children:[`⏰ `,R]})]}),(0,u.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,u.jsx)(`code`,{children:f===`subscription`?Q.current.spenderAddress:Q.current.receiveAddress}),(0,u.jsx)(`button`,{onClick:async()=>{if(!Q.current)return;let e=f===`subscription`?Q.current.spenderAddress:Q.current.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),B(!0),setTimeout(()=>{B(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},className:`_cppay-copy-btn ${z?`_cppay-copy-success`:``}`,title:z?`已复制!`:`复制地址`,children:z?(0,u.jsx)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,u.jsx)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})}):(0,u.jsxs)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,u.jsx)(`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`}),(0,u.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]})}),f===`subscription`&&(0,u.jsxs)(`div`,{className:`_cppay-info-box _cppay-subscription-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label _cppay-subscription-label`,children:`📌 订阅说明`}),(0,u.jsx)(`div`,{className:`_cppay-info-value _cppay-subscription-message`,children:`订阅支付需要授权代币给合约地址,系统将按周期自动扣款。授权后无需每次手动支付。`})]})]}),T&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>V(!0),onMouseLeave:()=>V(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:T})]}),ae&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:T})]}),!w&&(0,u.jsx)(`div`,{className:`_cppay-section`,children:N?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`button`,{onClick:pe,disabled:C,className:`_cppay-btn _cppay-btn-primary`,children:C?f===`subscription`?`授权中...`:`支付中...`:f===`subscription`?`💳 钱包授权`:`💳 钱包支付`}),(0,u.jsxs)(`button`,{onClick:G,disabled:C,className:`_cppay-btn _cppay-wallet-address-btn`,title:`点击修改或查看钱包状态`,children:[(0,u.jsxs)(`span`,{className:`_cppay-wallet-address-text`,children:[N.slice(0,10),`...`,N.slice(-4)]}),(0,u.jsx)(`svg`,{className:`_cppay-wallet-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,u.jsx)(`path`,{d:`M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z`})})]})]}):(0,u.jsx)(`button`,{onClick:G,disabled:re,className:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`,children:(0,u.jsx)(`span`,{children:re?`连接中...`:`💳 连接钱包`})})})]})})},f=d,p=({open:e,onClose:t,ott:n,apikey:r,plain:i,orderId:a,amount:o,intervalDays:s,onExpired:c,onSuccess:d,onFailed:p,onError:m,Slots:h})=>{let[g,_]=(0,l.useState)(`select`),[v,y]=(0,l.useState)(!1),[b,x]=(0,l.useState)(!1),[S,C]=(0,l.useState)();(0,l.useEffect)(()=>{if(g===`success`){let e=setTimeout(()=>{w()},1e3);return()=>clearTimeout(e)}},[g]),(0,l.useEffect)(()=>{e||(_(`select`),C(void 0),y(!1),x(!1))},[e]),(0,l.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&!v&&!b&&w()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,v,b]);let w=()=>{v||b||t()};return e?(0,u.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&!v&&!b&&w(),children:(0,u.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,u.jsxs)(`div`,{className:`_cppay-header`,children:[(0,u.jsx)(`h2`,{className:`_cppay-title`,children:(()=>{switch(g){case`success`:return`支付结果`;case`expired`:return`支付已过期`;case`failed`:return`支付失败`;case`error`:return`出错`;case`payment`:return`完成支付`;default:return`选择支付方式`}})()}),(0,u.jsx)(`button`,{onClick:w,disabled:v||b,className:`_cppay-close-btn`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,u.jsx)(f,{apikey:r,ott:n,plain:i,orderId:a,amount:o,intervalDays:s,onSuccess:d,onExpired:c,onFailed:p,onError:m,Slots:h,paymentStep:g,onPaymentStepChange:_,loading:v,isCheckingPayment:b,error:S,onErrorChange:C})]})}):null},m=p,h=(0,l.createContext)(null);const g=({apikey:e,children:t})=>{let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(null),o=(0,l.useCallback)(e=>{a(e),r(!0)},[]),s=(0,l.useCallback)(()=>{r(!1)},[]),c=(0,l.useCallback)(()=>{r(!1)},[]),d=(0,l.useCallback)(e=>{i?.onSuccess?.(e),setTimeout(()=>r(!1),1e3)},[i]),f=(0,l.useCallback)(e=>{i?.onExpired?.(e)},[i]),p=(0,l.useCallback)(e=>{i?.onFailed?.(e)},[i]),g=(0,l.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,l.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&c()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[n,c]),(0,u.jsxs)(h.Provider,{value:{showPayment:o,closePayment:s},children:[t,i&&(0,u.jsx)(m,{open:n,onClose:c,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:d,onExpired:f,onFailed:p,onError:g})]})},_=()=>{let e=(0,l.useContext)(h);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.t(e.n),exports.CppayProvider=g,exports.PaymentContent=f,exports.PaymentDialog=m,exports.useCppayPayment=_;
|
|
1
|
+
const e=require(`./locales-DAKREZkH.cjs`),t=require(`./cppay-BYRjTzRF.cjs`);let n=require(`qrcode`);n=e.i(n);let r=require(`rxjs`),i=require(`rxjs/operators`),a=require(`viem`),o=require(`viem/chains`),s=require(`@reown/appkit`),c=require(`@reown/appkit-adapter-ethers`),l=require(`react`);l=e.i(l);let u=require(`react/jsx-runtime`);var d=({apikey:d,ott:f,plain:p,orderId:m,amount:h,intervalDays:g,locale:_=`zh-CN`,onSuccess:v,onExpired:y,onFailed:b,onError:x,Slots:S,paymentStep:C,onPaymentStepChange:w,loading:T=!1,isCheckingPayment:E=!1,error:D,onErrorChange:O})=>{let k=(0,l.useMemo)(()=>new t.t(d,f),[d,f]),A=(0,l.useMemo)(()=>e.t(_),[_]),[j,ee]=(0,l.useState)([]),[M,N]=(0,l.useState)(),[P,te]=(0,l.useState)(),[ne,F]=(0,l.useState)(),[I,L]=(0,l.useState)(),[re,ie]=(0,l.useState)(!1),[R,z]=(0,l.useState)(),[B,ae]=(0,l.useState)(``),[V,oe]=(0,l.useState)(!1),[se,H]=(0,l.useState)(!1),U=(0,l.useRef)(null),W=(0,l.useRef)(null),G=(0,l.useRef)(null);(0,l.useEffect)(()=>{typeof window<`u`&&!U.current&&(U.current=(0,s.createAppKit)({debug:!1,enableNetworkSwitch:!1,adapters:[new c.EthersAdapter],projectId:`8d2e1854d3f1782e45aa15fbd8938894`,allowUnsupportedChain:!0,networks:[o.mainnet,o.bsc,o.polygon,o.arbitrum,o.optimism,o.base],metadata:{name:`Cppay`,description:`Cppay Payment Gateway`,url:window.location.origin,icons:[`https://cppay.com/icon.png`]},features:{analytics:!1}}),L(U.current.getAddress()),z(U.current.getProvider(`eip155`)),U.current.subscribeAccount(e=>{e.isConnected?L(e.address):(L(void 0),z(void 0))}),U.current.subscribeProviders(e=>{let t=e?.eip155;z(t)}))},[]);let ce=async()=>{try{ie(!0),O?.(void 0),U.current&&await U.current.open()}catch(e){console.error(`钱包连接失败:`,e);let t=e instanceof Error?e.message:A.walletConnectionFailed;O?.(t),x?.(e)}finally{ie(!1)}},K=(0,l.useMemo)(()=>j.find(e=>e.chain===M),[j,M]),q=(0,l.useMemo)(()=>K?.tokens||[],[K]),J=(0,l.useMemo)(()=>q.find(e=>e.symbol===P),[q,P]),Y=e=>[`USDT`,`USDC`,`BUSD`,`DAI`,`TUSD`,`USDD`,`FDUSD`].includes(e.toUpperCase())?2:6,X=(e,t)=>{let n=parseFloat(e);return isNaN(n)?`0`:n.toFixed(t).replace(/\.?0+$/,``)},le=e=>{if(e<=0)return A.expired;let t=Math.floor(e/3600),n=Math.floor(e%3600/60),r=e%60;return t>0?`${t}${A.hours}${n}${A.minutes}${r}${A.seconds}`:`${n}${A.minutes}${r}${A.seconds}`},ue=e=>{G.current&&clearInterval(G.current);let t=()=>{let t=e-Math.floor(Date.now()/1e3);ae(le(t)),t<=0&&(w(`expired`),de())};t(),G.current=setInterval(t,1e3)},de=()=>{G.current&&=(clearInterval(G.current),null)},Z=(0,l.useMemo)(()=>{if(!P||!J)return`0`;let e=parseFloat(J.price);if(isNaN(e)||e===0)return`0`;let t=Y(P);return X((parseFloat(h)/e).toFixed(t),t)},[h,P,J]),fe=async()=>{try{O?.(void 0);let e=await k.getSupportedChains();ee(e),e.length>0&&N(e[0].chain)}catch(e){let t=e instanceof Error?e.message:A.loadPaymentNetworkFailed;O?.(t),x?.(e)}},pe=async e=>{if(R)try{await R.request({method:`wallet_switchEthereumChain`,params:[{chainId:`0x${e.toString(16)}`}]})}catch(e){throw e.code===4902?Error(A.pleaseAddNetwork):e}},me=async()=>{if(!(!I||!R||!Q.current||!J||!K))try{let e=Q.current;await pe(K.chainId);let t=(0,a.createWalletClient)({account:I,transport:(0,a.custom)(R)});J.address?await t.writeContract({address:J.address,abi:[{name:`transfer`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`to`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`transfer`,args:[e.receiveAddress,(0,a.parseUnits)(e.paymentAmount,J.decimals)],chain:null}):await t.sendTransaction({to:e.receiveAddress,value:(0,a.parseUnits)(e.paymentAmount,J.decimals),chain:null}),F(void 0)}catch(e){console.error(`钱包支付失败:`,e);let t=e instanceof Error?e.message:A.walletPaymentFailed;O?.(t),x?.(e)}},he=async()=>{if(!(!I||!R||!Q.current||!J||!K))try{let e=Q.current;await pe(K.chainId);let t=(0,a.createWalletClient)({account:I,transport:(0,a.custom)(R)});if(!J.address)throw Error(A.subscriptionDoesNotSupportNative);await t.writeContract({address:J.address,abi:[{name:`approve`,type:`function`,stateMutability:`nonpayable`,inputs:[{name:`spender`,type:`address`},{name:`amount`,type:`uint256`}],outputs:[{type:`bool`}]}],functionName:`approve`,args:[e.spenderAddress,(0,a.parseUnits)(e.approveAmount,J.decimals)],chain:null}),F(void 0)}catch(e){console.error(`钱包授权失败:`,e);let t=e instanceof Error?e.message:A.walletPaymentFailed;O?.(t),x?.(e)}},ge=async()=>{if(!I){let e=A.pleaseConnectWallet;O?.(e),x?.(Error(e));return}p===`one-time`?await me():p===`subscription`&&await he()},Q=(0,l.useRef)(null),_e=async()=>{if(!(!M||!P))try{O?.(void 0);let e=``;p===`one-time`?(Q.current=await k.createOnetimePayment({paymentChain:M,paymentToken:P,orderId:m,amount:Z}),e=`${M.toLowerCase()}:${Q.current.receiveAddress}?amount=${Q.current.paymentAmount}`,ue(Q.current.expireAt),$({paymentId:Q.current.paymentId})):p===`subscription`&&(Q.current=await k.createSubscriptionPayment({paymentChain:M,paymentToken:P,orderId:m,amountOfUsd:Z,intervalDays:g||30}),e=`${M.toLowerCase()}:${Q.current.spenderAddress}?amount=${Q.current.approveAmount}`,ue(Q.current.expireAt),$({subscriptionId:Q.current.subscriptionId})),w(`payment`),F(await n.toDataURL(e,{width:200,margin:2,errorCorrectionLevel:`H`}))}catch(e){let t=e instanceof Error?e.message:A.createPaymentFailed;O?.(t),x?.(e)}},$=e=>{W.current?.unsubscribe();let t=()=>(0,r.defer)(()=>p===`subscription`?k.checkSubscriptionPaymentStatus(e):k.checkOnetimePaymentStatus(e)).pipe((0,i.timeout)(15e3),(0,i.retry)({delay:2e3}));W.current=t().pipe((0,i.expand)(e=>e.status===`pending`?(0,r.timer)(2e3).pipe((0,i.switchMap)(()=>t())):r.EMPTY),(0,i.tap)(e=>{(e.status===`paid`||e.status===`approved`)&&(w(`success`),v?.(e)),e.status===`expired`&&(w(`expired`),y?.(e)),e.status===`failed`&&(w(`failed`),b?.(e))})).subscribe({error:e=>{if(Q.current){let t=e instanceof Error?e.message:A.checkPaymentStatusFailed;w(`error`),O?.(t),x?.(e)}},complete:()=>{W.current?.unsubscribe()}})};return(0,l.useEffect)(()=>{j.length===0&&fe()},[]),(0,l.useEffect)(()=>{q.length>0&&te(q[0].symbol)},[q]),(0,l.useEffect)(()=>(m&&$({orderId:m}),()=>{W.current?.unsubscribe(),de()}),[m]),(0,u.jsx)(`div`,{className:`_cppay-content`,children:C===`success`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`✅`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:p===`subscription`?A.authorizationSuccess:A.paymentSuccess}),(0,u.jsx)(`p`,{className:`_cppay-state-message`,children:p===`subscription`?A.subscriptionActivated:A.transactionCompleted})]}):C===`expired`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`⏰`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:A.paymentExpired}),(0,u.jsx)(`button`,{onClick:()=>w(`select`),disabled:T||E,className:`_cppay-btn _cppay-btn-text`,children:A.returnButton})]}):C===`error`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:D||A.error})]}):C===`failed`?(0,u.jsxs)(`div`,{className:`_cppay-state-container`,children:[(0,u.jsx)(`div`,{className:`_cppay-state-icon`,children:`❌`}),(0,u.jsx)(`h3`,{className:`_cppay-state-title`,children:A.paymentFailed})]}):C===`select`?(0,u.jsxs)(`div`,{children:[S?.ChooseTop,(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:A.paymentNetwork}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:j.map(e=>(0,u.jsxs)(`button`,{onClick:()=>N(e.chain),className:`_cppay-select-btn ${M===e.chain?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.chain}),(0,u.jsx)(`span`,{children:e.chain})]},e.chain))})]}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[(0,u.jsx)(`label`,{className:`_cppay-label`,children:A.paymentToken}),(0,u.jsx)(`div`,{className:`_cppay-grid`,children:q.map(e=>(0,u.jsxs)(`button`,{onClick:()=>te(e.symbol),className:`_cppay-select-btn ${P===e.symbol?`_cppay-selected`:``}`,children:[e.icon&&(0,u.jsx)(`img`,{src:e.icon,alt:e.symbol}),(0,u.jsx)(`span`,{children:e.symbol})]},e.symbol))})]}),S?.ChooseBottom,(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`div`,{className:`_cppay-price-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-price-row`,children:[(0,u.jsx)(`span`,{className:`_cppay-price-label`,children:A.paymentAmount}),(0,u.jsxs)(`div`,{className:`_cppay-price-amount`,children:[(0,u.jsxs)(`div`,{className:`_cppay-price-main`,children:[Z??`-`,` `,P??``]}),(0,u.jsxs)(`div`,{className:`_cppay-price-sub`,children:[`≈ $`,h]})]})]})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[D&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>H(!0),onMouseLeave:()=>H(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:D})]}),se&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:D})]}),(0,u.jsx)(`button`,{onClick:_e,disabled:!M||!P||T,className:`_cppay-btn _cppay-btn-primary`,children:T?A.processing:A.continuePayment})]})]}):(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`_cppay-qr-container`,children:(0,u.jsx)(`div`,{className:`_cppay-qr-code`,children:ne&&(0,u.jsx)(`img`,{src:ne,alt:`Payment QR Code`,className:`_cppay-qr-image`})})}),(0,u.jsxs)(`div`,{className:`_cppay-section`,children:[J&&(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsx)(`div`,{className:`_cppay-info-flex-container`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label`,children:p===`subscription`?A.authorizationAmount:A.paymentAmount}),(0,u.jsxs)(`div`,{className:`_cppay-info-value _cppay-info-value-flex`,children:[(0,u.jsx)(`span`,{children:p===`subscription`?`${X(Q.current.approveAmount,Y(J.symbol))} ${J.symbol}`:`${X(Q.current.paymentAmount,Y(J.symbol))} ${J.symbol}`}),(0,u.jsxs)(`span`,{children:[`≈ $`,h]})]})]})})}),(0,u.jsx)(`div`,{className:`_cppay-info-box`,children:(0,u.jsxs)(`div`,{className:`_cppay-info-flex-child`,children:[(0,u.jsxs)(`div`,{className:`_cppay-info-label _cppay-info-label-flex`,children:[(0,u.jsx)(`span`,{children:p===`subscription`?A.authorizationContractAddress:A.paymentAddress}),B&&(0,u.jsxs)(`span`,{className:`_cppay-countdown`,children:[`⏰ `,B]})]}),(0,u.jsxs)(`div`,{className:`_cppay-address-row`,children:[(0,u.jsx)(`code`,{children:p===`subscription`?Q.current.spenderAddress:Q.current.receiveAddress}),(0,u.jsx)(`button`,{onClick:async()=>{if(!Q.current)return;let e=p===`subscription`?Q.current.spenderAddress:Q.current.receiveAddress;if(e)try{await navigator.clipboard.writeText(e),oe(!0),setTimeout(()=>{oe(!1)},2e3)}catch(e){console.error(`复制失败:`,e)}},className:`_cppay-copy-btn ${V?`_cppay-copy-success`:``}`,title:V?A.copied:A.copyAddress,children:V?(0,u.jsx)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`currentColor`,children:(0,u.jsx)(`path`,{d:`M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z`})}):(0,u.jsxs)(`svg`,{className:`_cppay-copy-icon`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,u.jsx)(`path`,{d:`M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2`}),(0,u.jsx)(`rect`,{x:`8`,y:`2`,width:`8`,height:`4`,rx:`1`,ry:`1`})]})})]})]})}),p===`subscription`&&(0,u.jsxs)(`div`,{className:`_cppay-info-box _cppay-subscription-box`,children:[(0,u.jsx)(`div`,{className:`_cppay-info-label _cppay-subscription-label`,children:A.subscriptionNotice}),(0,u.jsx)(`div`,{className:`_cppay-info-value _cppay-subscription-message`,children:A.subscriptionNoticeMessage})]})]}),D&&(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip-wrapper`,onMouseEnter:()=>H(!0),onMouseLeave:()=>H(!1),children:[(0,u.jsxs)(`div`,{className:`_cppay-error-tooltip`,children:[(0,u.jsx)(`svg`,{viewBox:`0 0 20 20`,fill:`currentColor`,children:(0,u.jsx)(`path`,{fillRule:`evenodd`,d:`M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z`,clipRule:`evenodd`})}),(0,u.jsx)(`span`,{children:D})]}),se&&(0,u.jsx)(`div`,{className:`_cppay-error-tooltip-full`,children:D})]}),!E&&(0,u.jsx)(`div`,{className:`_cppay-section`,children:I?(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`button`,{onClick:ge,disabled:T,className:`_cppay-btn _cppay-btn-primary`,children:T?p===`subscription`?A.authorizing:A.processing:p===`subscription`?`💳 ${A.connectWallet}`:`💳 ${A.walletPay}`}),(0,u.jsxs)(`button`,{onClick:ce,disabled:T,className:`_cppay-btn _cppay-wallet-address-btn`,title:A.clickToModifyWallet,children:[(0,u.jsxs)(`span`,{className:`_cppay-wallet-address-text`,children:[I.slice(0,10),`...`,I.slice(-4)]}),(0,u.jsx)(`svg`,{className:`_cppay-wallet-arrow`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,u.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})]})]}):(0,u.jsx)(`button`,{onClick:ce,disabled:re,className:`_cppay-btn _cppay-btn-secondary _cppay-connect-wallet-btn`,children:(0,u.jsx)(`span`,{children:re?A.processing:`💳 ${A.connectWallet}`})})}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:()=>{w(`payment`)},disabled:E,className:`_cppay-btn _cppay-btn-primary`,children:E?A.checking:A.completedPayment})}),(0,u.jsx)(`hr`,{className:`_cppay-divider`}),(0,u.jsx)(`div`,{className:`_cppay-section`,children:(0,u.jsx)(`button`,{onClick:()=>w(`select`),disabled:T||E,className:`_cppay-btn _cppay-btn-text`,children:A.changePaymentMethod})})]})})},f=d,p=({open:t,onClose:n,ott:r,apikey:i,plain:a,orderId:o,amount:s,intervalDays:c,locale:d,onExpired:p,onSuccess:m,onFailed:h,onError:g,Slots:_})=>{let[v,y]=(0,l.useState)(`select`),[b,x]=(0,l.useState)(!1),[S,C]=(0,l.useState)(!1),[w,T]=(0,l.useState)();(0,l.useEffect)(()=>{if(v===`success`){let e=setTimeout(()=>{E()},1e3);return()=>clearTimeout(e)}},[v]),(0,l.useEffect)(()=>{t||(y(`select`),T(void 0),x(!1),C(!1))},[t]),(0,l.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&!b&&!S&&E()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,b,S]);let E=()=>{b||S||n()},D=(0,l.useMemo)(()=>e.t(d),[d]);return t?(0,u.jsx)(`div`,{className:`_cppay-overlay`,onClick:e=>e.target===e.currentTarget&&!b&&!S&&E(),children:(0,u.jsxs)(`div`,{className:`_cppay-dialog`,children:[(0,u.jsxs)(`div`,{className:`_cppay-header`,children:[(0,u.jsx)(`h2`,{className:`_cppay-title`,children:(()=>{switch(v){case`success`:return D.paymentResult;case`expired`:return D.paymentExpired;case`failed`:return D.paymentFailed;case`error`:return D.error;case`payment`:return D.completePayment;default:return D.selectPaymentMethod}})()}),(0,u.jsx)(`button`,{onClick:E,disabled:b||S,className:`_cppay-close-btn`,children:(0,u.jsx)(`svg`,{fill:`none`,stroke:`currentColor`,viewBox:`0 0 24 24`,children:(0,u.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M6 18L18 6M6 6l12 12`})})})]}),(0,u.jsx)(f,{apikey:i,ott:r,plain:a,orderId:o,amount:s,intervalDays:c,locale:d,onSuccess:m,onExpired:p,onFailed:h,onError:g,Slots:_,paymentStep:v,onPaymentStepChange:y,loading:b,isCheckingPayment:S,error:w,onErrorChange:T})]})}):null},m=p,h=(0,l.createContext)(null);const g=({apikey:e,children:t})=>{let[n,r]=(0,l.useState)(!1),[i,a]=(0,l.useState)(null),o=(0,l.useCallback)(e=>{a(e),r(!0)},[]),s=(0,l.useCallback)(()=>{r(!1)},[]),c=(0,l.useCallback)(()=>{r(!1)},[]),d=(0,l.useCallback)(e=>{i?.onSuccess?.(e),setTimeout(()=>r(!1),1e3)},[i]),f=(0,l.useCallback)(e=>{i?.onExpired?.(e)},[i]),p=(0,l.useCallback)(e=>{i?.onFailed?.(e)},[i]),g=(0,l.useCallback)(e=>{i?.onError?.(e)},[i]);return(0,l.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&c()};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[n,c]),(0,u.jsxs)(h.Provider,{value:{showPayment:o,closePayment:s},children:[t,i&&(0,u.jsx)(m,{open:n,onClose:c,apikey:e,plain:i.plain,orderId:i.orderId,amount:i.amount,intervalDays:i.intervalDays,onSuccess:d,onExpired:f,onFailed:p,onError:g})]})},_=()=>{let e=(0,l.useContext)(h);if(!e)throw Error(`useCppayPayment must be used within CppayProvider`);return e};e.n(e.r),exports.CppayProvider=g,exports.PaymentContent=f,exports.PaymentDialog=m,exports.useCppayPayment=_;
|
package/dist/react.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ declare interface CppayProviderProps {
|
|
|
25
25
|
children: ReactNode;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
export declare type Locale = "zh-CN" | "en-US";
|
|
29
|
+
|
|
28
30
|
declare type Numberic = `${number}.${number}` | `${number}`;
|
|
29
31
|
|
|
30
32
|
declare interface OnetimePaymentOrderStatus {
|
|
@@ -71,6 +73,8 @@ declare interface PaymentContentProps {
|
|
|
71
73
|
amount: string;
|
|
72
74
|
/** 订阅间隔天数 */
|
|
73
75
|
intervalDays?: number;
|
|
76
|
+
/** 语言设置 */
|
|
77
|
+
locale?: Locale;
|
|
74
78
|
/** 支付成功回调 */
|
|
75
79
|
onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
|
|
76
80
|
/** 支付过期回调 */
|
|
@@ -142,6 +146,8 @@ declare interface PaymentDialogProps {
|
|
|
142
146
|
amount: string;
|
|
143
147
|
/** 订阅间隔天数 */
|
|
144
148
|
intervalDays?: number;
|
|
149
|
+
/** 语言设置 */
|
|
150
|
+
locale?: Locale;
|
|
145
151
|
/** 支付成功回调 */
|
|
146
152
|
onSuccess?: (order: SubscriptionPaymentOrderStatus | OnetimePaymentOrderStatus) => void;
|
|
147
153
|
/** 支付过期回调 */
|