@feexpay/react-sdk
Version:
SDK React officiel pour intégrer les paiements FeexPay dans vos applications React
2 lines (1 loc) • 40.3 kB
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("react"),je=({selectedCountry:r,onChange:i})=>e.jsxs("div",{className:"relative",children:[e.jsxs("select",{value:r,onChange:t=>i(t.target.value),className:"block w-full px-2 py-2 pr-8 border rounded-md appearance-none focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",children:[e.jsx("option",{value:"BENIN",children:"🇧🇯 Benin"}),e.jsx("option",{value:"BURKINA_FASO",children:"🇧🇫 Burkina Faso"}),e.jsx("option",{value:"CONGO_BRAZZAVILLE",children:"🇨🇬 Congo Brazzaville"}),e.jsx("option",{value:"COTE_D_IVOIRE",children:"🇨🇮 Côte d'Ivoire"}),e.jsx("option",{value:"SENEGAL",children:"🇸🇳 Sénégal"}),e.jsx("option",{value:"TOGO",children:"🇹🇬 Togo"})]}),e.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none",children:e.jsx("svg",{className:"w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})})]}),J={MTN:["0142","0146","0150","0151","0152","0153","0154","0156","0157","0159","0161","0162","0166","0167","0169","0190","0191","0192","0193","0196","0197"],MOOV:["0145","0155","0158","0160","0163","0164","0165","0168","0194","0195","0198","0199"],CELTIIS:["0140","0141","0143","0144","0147"]},le={MOOV:["01","02","03","40","41","42","43","50","51","52","53","70","71","72","73","80","81","82","83","90","91","92","93"],MTN:["04","05","06","44","45","46","54","55","56","64","65","66","74","75","76","84","85","86","94","95","96"]},X={BENIN:{MTN:.017,MOOV:.017,CELTIIS:.017,CORIS:.017},COTE_D_IVOIRE:{MTN:.029,MOOV:.029,ORANGE:.029,WAVE:.032},BURKINA_FASO:{MOOV:.032,ORANGE:.039},CONGO_BRAZZAVILLE:{MTN:.03},SENEGAL:{ORANGE:.019,FREE:.019},TOGO:{TOGOCOM:.03,MOOV:.03}},Ie={BENIN:{MTN:"MTN",MOOV:"MOOV",CELTIIS:"CELTIIS BJ",CORIS:"CORIS"},COTE_D_IVOIRE:{MTN:"MTN CI",MOOV:"MOOV CI",ORANGE:"ORANGE CI",WAVE:"WAVE CI"},BURKINA_FASO:{MOOV:"MOOV BF",ORANGE:"ORANGE BF"},CONGO_BRAZZAVILLE:{MTN:"MTN CG"},SENEGAL:{ORANGE:"ORANGE SN",FREE:"FREE SN"},TOGO:{TOGOCOM:"TOGOCOM TG",MOOV:"MOOV TG"}},ce=(r,i)=>le.MTN.includes(r)?"MTN":le.MOOV.includes(r)?"MOOV":J.MTN.includes(r)?"MTN":J.MOOV.includes(r)?"MOOV":J.CELTIIS.includes(r)?"CELTIIS":null,Y=r=>{switch(r){case"BENIN":return["MTN","MOOV","CELTIIS"];case"COTE_D_IVOIRE":return["MTN","MOOV","ORANGE","WAVE"];case"BURKINA_FASO":return["MOOV","ORANGE"];case"CONGO_BRAZZAVILLE":return["MTN"];case"SENEGAL":return["ORANGE","FREE"];case"TOGO":return["TOGOCOM","MOOV"];default:return["MTN","MOOV"]}},ke=(r,i,t,a,d)=>{if(a==="CARD"&&(d==="VISA"||d==="MASTERCARD"))return Math.ceil(r*.045);const o=X[i];let x=0;o&&o[t]&&(x=o[t]);const n=r*x;return Math.ceil(n)},Q=(r,i)=>{const t=Ie[r];return t&&t[i]?t[i]:i.toLowerCase()},Le=({selectedNetwork:r,onChange:i,country:t})=>{const a=Y(t);return u.useEffect(()=>{a.length>0&&!a.includes(r)&&i(a[0])},[t,r,a,i]),e.jsxs("div",{className:"relative",children:[e.jsx("select",{value:r,onChange:d=>i(d.target.value),className:"block w-full px-2 py-2 pr-8 border rounded-md appearance-none focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",children:a==null?void 0:a.map(d=>e.jsx("option",{value:d,children:d.replace("_"," ")},d))}),e.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center px-2 pointer-events-none",children:e.jsx("svg",{className:"w-4 h-4 text-gray-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 9l-7 7-7-7"})})})]})},_e=({isOpen:r,onClose:i,status:t,message:a})=>{if(u.useEffect(()=>{if(t==="SUCCESSFUL"||t==="SUCCESS"){const n=setTimeout(()=>{i()},5e3);return()=>clearTimeout(n)}},[t,i]),!r)return null;const d=()=>{switch(t){case"SUCCESSFUL":case"SUCCESS":return e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-green-100 rounded-full flex items-center justify-center",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-10 w-10 text-green-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})});case"FAILED":return e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-red-100 rounded-full flex items-center justify-center",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-10 w-10 text-red-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})});case"PENDING":return e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-yellow-100 rounded-full flex items-center justify-center",children:e.jsxs("svg",{className:"animate-spin h-10 w-10 text-yellow-500",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})});case"TIMEOUT":return e.jsx("div",{className:"w-16 h-16 mx-auto mb-4 bg-gray-100 rounded-full flex items-center justify-center",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-10 w-10 text-gray-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})})});default:return null}},o=()=>{switch(t){case"SUCCESSFUL":case"SUCCESS":return"Continuer";case"FAILED":case"TIMEOUT":return"Réessayer";default:return"Fermer"}},x=()=>{switch(t){case"SUCCESSFUL":case"SUCCESS":return"bg-green-500 hover:bg-green-600";case"FAILED":return"bg-red-500 hover:bg-red-600";case"TIMEOUT":return"bg-gray-500 hover:bg-gray-600";default:return"bg-gray-500 hover:bg-gray-600"}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-50",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-sm p-6 text-center",children:[d(),e.jsx("h3",{className:"text-xl font-bold mb-2",children:t==="SUCCESSFUL"?"Paiement Réussi":t==="FAILED"?"Paiement Échoué":t==="SUCCESS"?"Paiement Réussi":t==="PENDING"?"Traitement en cours":"Vérification expirée"}),e.jsx("p",{className:"text-gray-600 mb-6",children:a}),e.jsx("button",{onClick:i,className:`w-full ${x()} text-white font-bold py-3 px-4 rounded-md transition-colors duration-300`,children:o()})]})})},Ae=({isOpen:r,onClose:i,onSubmit:t})=>{const[a,d]=u.useState(""),[o,x]=u.useState(!1),n=f=>{f.preventDefault(),x(!0),t(a)};return r?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-50 overflow-hidden",children:e.jsxs("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md relative",children:[e.jsxs("div",{className:"flex justify-between items-center border-b p-4",children:[e.jsx("h3",{className:"text-lg font-medium",children:"Confirmation de paiement"}),e.jsx("button",{onClick:i,className:"text-gray-500 hover:text-gray-700",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),e.jsxs("div",{className:"p-6",children:[e.jsx("p",{className:"text-sm text-gray-600 mb-4",children:"Un code de confirmation a été envoyé à votre téléphone. Veuillez le saisir ci-dessous pour finaliser votre paiement."}),e.jsxs("form",{onSubmit:n,children:[e.jsxs("div",{className:"mb-4",children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Code OTP"}),e.jsx("input",{type:"text",value:a,onChange:f=>d(f.target.value),placeholder:"Entrez le code reçu par SMS",className:"w-full px-4 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange",required:!0})]}),e.jsx("button",{type:"submit",disabled:o,className:"w-full bg-primary-orange text-white py-2 px-4 rounded-md hover:bg-orange-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-orange disabled:opacity-50",children:o?"Traitement en cours...":"Confirmer le paiement"})]})]})]})}):null},fe=u.createContext(void 0),me=()=>{const r=u.useContext(fe);if(!r)throw new Error("useFeexPay must be used within a FeexPayProvider");return r},Fe={amount:0,description:"",id:"",token:"",mode:"SANDBOX"},Te=({children:r})=>{const[i,t]=u.useState(Fe);return e.jsx(fe.Provider,{value:{paymentConfig:i,setPaymentConfig:t},children:r})},Me=async()=>{try{return(await(await fetch("https://api.ipify.org?format=json")).json()).ip}catch{return"unknown"}},he=async r=>{if(r.mode==="SANDBOX")return{status:"SUCCESSFUL",message:"Payment successful (SANDBOX MODE)",transaction_id:"ref_c36484845FDVvgDFEGEGEGE_REACT",reference:"ref_c36484845FDVvgDFEGEGEGE_REACT"};const i=Q(r.country,r.network),t="https://api.feexpay.me/api/transactions/requesttopay/integration";let a=r.phoneNumber.replace(/\+/g,"");if(a.length>=8){const d=a.slice(0,3);a.startsWith(d+d)&&(a=a.slice(d.length))}try{const d=window.location.origin,o=await Me();let x=r.description;r.network==="MTN"&&(x=x.replace(/[^a-zA-Z0-9 ]/g,""));const n={phoneNumber:a,amount:r.amount,reseau:i,description:x,customId:r.customId,shop:r.id,token:r.token,merchant_domain:d,merchant_ip:o,payment_interface:"REACT",callback_info:r.callback_info||{},currency:r.currency||"XOF",first_name:r.first_name,email:r.email,otp:r.otp||""},f=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.token}`},body:JSON.stringify(n)});if(!f.ok)throw new Error("Payment request failed");return await f.json()}catch(d){throw console.error("Payment request error:",d),d}},Re=async r=>{const i=`https://api.feexpay.me/api/transactions/getrequesttopay/integration/${r}`;try{const t=await fetch(i);if(!t.ok)throw new Error("Status check failed");return await t.json()}catch(t){throw console.error("Status check error:",t),t}},Pe=async r=>{const i="https://api.feexpay.me/api/transactions/details";try{const a={network:Q(r.country,r.network),amount:r.amount,shop:r.id},d=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.token}`},body:JSON.stringify(a)});if(!d.ok)throw new Error("Failed to get transaction details");return await d.json()}catch(t){throw console.error("Transaction details error:",t),t}},De=async r=>{const i="https://api.feexpay.me/api/transactions/public/initcard";try{const t={phone:r.phone,amount:r.amount,shop:r.id,first_name:r.first_name,last_name:r.last_name,email:r.email,type_card:r.type_card,currency:"XOF"},a=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.token}`},body:JSON.stringify(t)});if(!a.ok)throw new Error("Card payment request failed");return await a.json()}catch(t){throw console.error("Card payment request error:",t),t}},ue=async r=>{if(r.mode==="SANDBOX")return{status:"SUCCESSFUL",message:"Payment successful (SANDBOX MODE)",transaction_id:"sandbox-tx-id-"+new Date().getTime(),reference:r.customId||"sandbox-ref-"+new Date().getTime()};const i="https://api.feexpay.me/api/transactions/requesttopay/integration";let t=r.description;r.network==="MTN"&&(t=t.replace(/[^a-zA-Z0-9 ]/g,""));try{const a="229",d=r.phoneNumber.startsWith("+229")?r.phoneNumber.substring(4):r.phoneNumber.startsWith("229")?r.phoneNumber.substring(3):r.phoneNumber,o={phoneNumber:`229${d}`,country:a,phoneNumberRight:d,amount:r.amount,currency:"XOF",description:t,email:r.email,first_name:r.first_name,otp:r.otp||"",reseau:"CORIS",shop:r.id,token:r.token,callback_info:r.callback_info||{}},x=await fetch(i,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(o)});return{...await x.json(),statusCode:x.status.toString()}}catch(a){throw console.error("Wallet Coris payment request error:",a),a}},pe=async r=>{const i=`https://api.feexpay.me/api/shop/${r}/get_shop`;try{const t=await fetch(i);if(!t.ok)throw new Error("Shop retrieval failed");return await t.json()}catch(t){throw console.error("Shop retrieval error:",t),t}},de=async(r,i,t,a)=>{if(r.preventDefault(),!t())return;const{baseAmount:d,network:o,country:x,paymentConfig:n,generateRandomId:f,fullName:h,email:k,setStateCallbacks:y}=i,{setTransactionReference:A,setPaymentStatus:g,setStatusMessage:_,setStatusModalOpen:I,setIsLoading:N}=y;N(!0);try{const b=a(),m=await he({mode:n.mode,phoneNumber:b,amount:d,network:o,country:x,description:n.description,customId:n.customId||f(),id:n.id,token:n.token,currency:n.currency||"XOF",callback_info:n.callback_info||{},first_name:h,email:k});if(m.status==="SUCCESSFUL"){g("SUCCESSFUL"),N(!1),n.callback&&n.callback({...m,status:"SUCCESSFUL",message:m.message??"Payment successful (SANDBOX)",transaction_id:m.transaction_id??`sandbox-tx-${Date.now()}`,reference:m.reference??"",reseau:o,phoneNumber:b,amount:d,currency:n.currency||"XOF",description:n.description||"",callback_info:n.callback_info||{},first_name:h||"",email:k||""});return}if(m.statusCode==="10"){g("INSUFFICIENT_FUNDS"),_("Fonds insuffisants. Veuillez vérifier votre solde et réessayer."),I(!0),N(!1),n.callback&&n.callback({reference:m.reference,status:"FAILED",phoneNumber:b,reseau:o,callback_info:n.callback_info||{},description:n.description,transaction_id:m.reference,message:"Le paiement a échoué. Veuillez vérifier votre solde et réessayer.",amount:n.amount,currency:n.currency||"XOF",first_name:h,email:k}),n.error_callback_url&&(window.location.href=`${n.error_callback_url}?ref=${m.reference}`);return}else if(m.statusCode==="37"){g("FAILED"),_("Le montant est inférieur au minimum autorisé par l'opérateur."),I(!0),N(!1),n.callback&&n.callback({reference:m.reference,status:"FAILED",phoneNumber:b,reseau:o,callback_info:n.callback_info||{},description:n.description,transaction_id:m.reference,message:"Le montant est inférieur au minimum autorisé par l'opérateur.",amount:n.amount,currency:n.currency||"XOF",first_name:h,email:k}),n.error_callback_url&&(window.location.href=`${n.error_callback_url}?ref=${m.reference}`);return}else if(m.statusCode==="92"){g("FAILED"),_("La transaction a été annulée. Veuillez réessayer."),I(!0),N(!1),n.callback&&n.callback({reference:m.reference,status:"FAILED",phoneNumber:b,reseau:o,callback_info:n.callback_info||{},description:n.description,transaction_id:m.reference,message:"La transaction a été annulée. Veuillez réessayer.",amount:n.amount,first_name:h,email:k,currency:n.currency||"XOF"}),n.error_callback_url&&(window.location.href=`${n.error_callback_url}?ref=${m.reference}`);return}return A(m.reference),xe(m.reference,i,o,a),{reference:m.reference}}catch(b){console.error("Payment error:",b),g("FAILED"),_("Le paiement a échoué. Veuillez réessayer."),I(!0),N(!1)}},xe=(r,i,t,a)=>{let d=0;const o=12;let x=!1,n=null;const{paymentConfig:f,setStateCallbacks:h,fullName:k,email:y}=i,{setPaymentStatus:A,setStatusMessage:g,setStatusModalOpen:_,setIsLoading:I}=h,N=(m,M,F)=>{if(i.isCallbackCalledRef.current)return;i.isCallbackCalledRef.current=!0,n&&clearTimeout(n),A(m),g(M),_(!0),I(!1);const D={reference:r,status:F,phoneNumber:a(),reseau:t,callback_info:f.callback_info||{},description:f.description,transaction_id:r,message:M,amount:f.amount,currency:f.currency||"XOF",first_name:k,email:y};f.callback&&f.callback(D);const R=F==="SUCCESSFUL"||F==="SUCCESS";R&&f.callback_url?window.location.href=`${f.callback_url}?ref=${r}`:!R&&f.error_callback_url&&(window.location.href=`${f.error_callback_url}?ref=${r}`)},b=async()=>{if(!x){d++;try{const m=await Re(r);if(m.reason==="LOW_BALANCE_OR_PAYEE_LIMIT_REACHED_OR_NOT_ALLOWED"){N("INSUFFICIENT_FUNDS","Fonds insuffisants. Veuillez vérifier votre solde et réessayer.","FAILED");return}else if(m.reason==="PAYER NOT FOUND"||m.reason==="PAYER_NOT_FOUND"){N("FAILED","Numéro de téléphone non trouvé. Veuillez vérifier le numéro et réessayer.","FAILED");return}const M=m.status.toUpperCase();switch(M){case"SUCCESSFUL":case"SUCCESS":N("SUCCESSFUL","Paiement réussi !",M);break;case"FAILED":N("FAILED","Le paiement a échoué. Veuillez réessayer.","FAILED");break;case"INSUFFICIENT_FUNDS":N("INSUFFICIENT_FUNDS","Fonds insuffisants. Veuillez vérifier votre solde et réessayer.","INSUFFICIENT_FUNDS");break;case"TIMEOUT":N("TIMEOUT","La vérification du paiement a expiré.","TIMEOUT");break;case"PENDING":d>=o?N("TIMEOUT","La vérification du paiement a expiré. Veuillez vérifier votre compte.","TIMEOUT"):n=setTimeout(b,1e4);break;default:d>=o&&N("TIMEOUT","Statut de transaction inconnu après plusieurs tentatives.","TIMEOUT");break}}catch(m){console.error(`Status check failed for ref ${r}:`,m),d>=o&&N("TIMEOUT","La vérification du paiement a échoué après plusieurs tentatives.","TIMEOUT")}}};return b(),()=>{n&&clearTimeout(n),x=!0}},Ve=({id:r,onClose:i})=>{const[t,a]=u.useState(null);return u.useEffect(()=>{(async()=>{try{const o=await pe(r);a(o)}catch(o){console.error("Erreur de récupération du id :",o)}})()},[r]),e.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-gray-200",children:[e.jsx("div",{children:e.jsx("img",{src:"https://api.feexpay.me/api/static/feexpay_logo-h.png",width:"100",alt:"Logo"})}),e.jsx("div",{className:"text-right text-xs text-gray-700 ",children:t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"font-semibold",children:["MARCHAND: ",t.name]}),e.jsxs("div",{className:"text-xs text-gray-500",children:["ID : ",t.reference]})]})}),e.jsx("button",{onClick:i,className:"text-gray-500 hover:text-gray-700",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]})},Ue=({isOpen:r,onClose:i})=>{var ie;const{paymentConfig:t}=me(),[a,d]=u.useState(()=>t.case&&["MOBILE","CARD","WALLET"].includes(t.case)?t.case:"MOBILE"),[o,x]=u.useState("BENIN"),[n,f]=u.useState("MTN"),[h,k]=u.useState(""),[y,A]=u.useState(""),[g,_]=u.useState(""),[I,N]=u.useState("VISA"),[b,m]=u.useState(0),[M,F]=u.useState(0),[D,R]=u.useState(0),[z,T]=u.useState(0),[U,V]=u.useState(""),[ge,E]=u.useState(!1),[q,j]=u.useState("PENDING"),[ye,C]=u.useState(""),[Z,O]=u.useState(!1),[Ne,W]=u.useState(!1),[be,Ee]=u.useState(""),[ee,te]=u.useState(null),B=u.useRef(!1),re=u.useRef(null),H=u.useCallback((s,c,p,S)=>{const v=ke(s,c,p,S||a,I);if(R(v),F(s+v),m(s),a==="CARD"&&(I==="VISA"||I==="MASTERCARD"))T(4.5);else{const P=X[c];P&&P[p]?T(P[p]*100):T(0)}},[a,I]),L=u.useCallback(async(s,c,p,S)=>{try{const l=S||a,v=await Pe({network:p,country:c,amount:s,id:t.id,token:t.token});if(v&&v.iffees){let P=!1;if(s<=30){const w=X[c];w&&w[p]&&w[p]>0&&(R(1),F(s+1),T(w[p]*100),P=!0)}if(!P){if(v.total!==void 0){const w=v.total-s;R(w),F(v.total)}else H(s,c,p,l);if(l==="CARD")T(4.5);else{const w=X[c];w&&w[p]?T(w[p]*100):T(0)}}}else R(0),F(s),T(0);m(s)}catch(l){console.error("Erreur lors de la récupération des détails de transaction:",l),H(s,c,p,S)}},[a,t.id,t.token,H]);u.useEffect(()=>{t.amount&&(m(t.amount),L(t.amount,o,n))},[t,o,n,L]),u.useEffect(()=>{a==="WALLET"&&(o==="BENIN"?(f("CORIS"),t.amount&&L(t.amount,o,"CORIS",a)):o==="COTE_D_IVOIRE"?(f("WAVE"),t.amount&&L(t.amount,o,"WAVE",a)):(x("BENIN"),f("CORIS"),t.amount&&L(t.amount,"BENIN","CORIS",a)))},[]),u.useEffect(()=>{if(q==="SUCCESSFUL"){const s=setTimeout(()=>{i()},1500);return()=>clearTimeout(s)}},[q,i]);const se=s=>{f(s),t.amount&&L(t.amount,o,s)},Ce=()=>{A(""),_(""),k(""),N("VISA")},Se=s=>{if(Ce(),R(0),F(t.amount||0),T(0),d(s),s==="WALLET")o==="BENIN"?(f("CORIS"),t.amount&&L(t.amount,o,"CORIS",s)):o==="COTE_D_IVOIRE"?(f("WAVE"),t.amount&&L(t.amount,o,"WAVE",s)):(x("BENIN"),f("CORIS"),t.amount&&L(t.amount,"BENIN","CORIS",s));else if(s==="MOBILE"){const c=Y(o);c.length>0&&(c.includes(n)||f(c[0]),t.amount&&L(t.amount,o,n,s))}else s==="CARD"&&t.amount&&L(t.amount,o,n,s)},ne=s=>{if(x(s),a==="WALLET")s==="BENIN"?(f("CORIS"),t.amount&&L(t.amount,s,"CORIS")):s==="COTE_D_IVOIRE"&&(f("WAVE"),t.amount&&L(t.amount,s,"WAVE"));else{const c=Y(s);f(c[0]),t.amount&&L(t.amount,s,c[0])}},ae=s=>{const c=s.target.value;if(a==="WALLET"){k(c);return}if(o==="COTE_D_IVOIRE"){if(c.length>=2){const p=c.substring(0,2),S=ce(p);console.log(`[DEBUG] CIV Prefix: ${p}, Detected Network: ${S}`),S&&f(S)}}else if(o==="BENIN"&&c.length>=4){const p=c.substring(0,4),S=ce(p);S&&f(S)}k(c)},G=()=>{if(!h)return h;let s=h.replace(/[^0-9]/g,""),c="";switch(o){case"BENIN":c="229";break;case"COTE_D_IVOIRE":c="225";break;case"BURKINA_FASO":c="226";break;case"CONGO_BRAZZAVILLE":c="242";break;case"SENEGAL":c="221";break;case"TOGO":c="228";break;default:return s}return s.startsWith(c+c)&&(s=s.slice(c.length)),s.startsWith(c)?s:c+s},ve=s=>{switch(s){case"BENIN":return"+229";case"COTE_D_IVOIRE":return"+225";case"BURKINA_FASO":return"+226";case"CONGO_BRAZZAVILLE":return"+242";case"SENEGAL":return"+221";case"TOGO":return"+228";default:return""}},Oe=async s=>{var S;if(s.preventDefault(),!K())return;B.current=!1,O(!0);const c=["MOOV CI","ORANGE CI","MOOV BF","ORANGE BF","FREE SN","WAVE CI","ORANGE SN"],p=Q(o,n);if(c.includes(p)){try{const l=await he({mode:t.mode,phoneNumber:G(),amount:b,network:n,country:o,description:t.description||"Payment",customId:t.customId||"",id:t.id,token:t.token,currency:t.currency||"XOF",callback_info:t.callback_info||{},first_name:y||"",email:g||"",otp:((S=re.current)==null?void 0:S.value)||""});if(l.status==="SUCCESSFUL"){t.callback&&!B.current&&(t.callback({...l,transaction_id:l.transaction_id??"sandbox-tx-id",message:l.message??"Payment successful",status:"SUCCESSFUL",reseau:n,phoneNumber:G(),amount:b,currency:t.currency||"XOF",description:t.description||"Payment",callback_info:t.callback_info||{},first_name:y||"",email:g||""}),B.current=!0),O(!1),j("SUCCESSFUL");return}if(l.payment_url&&te(l.payment_url),l.reference)V(l.reference),$(l.reference);else if(!l.payment_url)throw new Error("La réponse de paiement est invalide.")}catch(l){console.error("Payment error:",l),j("FAILED"),C("Le paiement a échoué. Veuillez réessayer."),E(!0)}finally{O(!1)}return}try{if(a==="CARD"){const l=y.split(" "),v=l[0]||"",P=l.slice(1).join(" ")||"",w=await De({phone:h,amount:b,id:t.id,first_name:v,last_name:P,email:g,type_card:I,token:t.token,currency:t.currency||"XOF"});w&&w.reference?(V(w.reference),$(w.reference)):(j("FAILED"),C("La demande de paiement par carte a échoué. Veuillez réessayer."),E(!0),O(!1))}else if(a==="MOBILE"){const l=await de(s,{phoneNumber:h,baseAmount:b,network:n,country:o,paymentConfig:t,transactionReference:U,fullName:y,email:g,generateRandomId:oe,isCallbackCalledRef:B,setStateCallbacks:{setTransactionReference:V,setPaymentStatus:j,setStatusMessage:C,setStatusModalOpen:E,setIsLoading:O}},K,G);l&&l.reference&&$(l.reference)}else if(a==="WALLET")if(o==="BENIN"&&n==="CORIS")try{const v=y.split(" ")[0]||"",P=h.startsWith("+229")?h:`+229${h}`,w=await ue({phoneNumber:P,amount:b,id:t.id,email:g,first_name:v,description:"Paiement via FeexPay",token:t.token,currency:t.currency||"XOF",callback_info:t.callback_info||{},network:n,country:o,customId:t.customId||""});w.statusCode==="201"?(Ee(w.reference),W(!0),O(!1)):(j("FAILED"),C("La demande de paiement a échoué. Veuillez réessayer."),E(!0),O(!1))}catch(l){console.error("Error in Coris Wallet payment:",l),j("FAILED"),C("Une erreur est survenue lors du traitement du paiement. Veuillez réessayer."),E(!0),O(!1)}else{const v=await de(s,{phoneNumber:h,baseAmount:b,network:n,country:o,paymentConfig:t,transactionReference:U,generateRandomId:oe,fullName:y,email:g,isCallbackCalledRef:B,setStateCallbacks:{setTransactionReference:V,setPaymentStatus:j,setStatusMessage:C,setStatusModalOpen:E,setIsLoading:O}},K,G);v&&v.reference&&$(v.reference)}}catch(l){console.error("Error in payment submission:",l),j("FAILED"),C("Une erreur est survenue lors du traitement du paiement. Veuillez réessayer."),E(!0),O(!1)}},K=()=>{const s=t.fields_to_hide||[];if(a==="MOBILE"||a==="WALLET"){if(!s.includes("name")&&!y.trim())return C("Veuillez entrer votre nom complet"),E(!0),!1;if(!s.includes("email")&&(!g.trim()||!g.includes("@")))return C("Veuillez entrer une adresse email valide"),E(!0),!1;if(!h.trim()||h.length<8)return C("Veuillez entrer un numéro de téléphone valide"),E(!0),!1;if(a==="WALLET"&&o!=="BENIN"&&o!=="COTE_D_IVOIRE")return C("Seuls le Bénin (Coris) et la Côte d'Ivoire (Wave) sont supportés pour les paiements Wallet"),E(!0),!1}else if(a==="CARD"){if(!y||y.trim().split(" ").length<2)return C("Veuillez entrer votre nom et prénom complets"),j("FAILED"),E(!0),!1;if(!g||!g.includes("@"))return C("Veuillez entrer une adresse email valide"),j("FAILED"),E(!0),!1;if(!h)return C("Veuillez entrer un numéro de téléphone valide"),j("FAILED"),E(!0),!1}return!0},oe=()=>`TRX-${Math.random().toString(36).substring(2,10).toUpperCase()}`,we=async s=>{O(!0);try{const p=y.split(" ")[0]||"",S=h.startsWith("+229")?h:`+229${h}`,l=await ue({phoneNumber:S,amount:b,id:t.id,email:g,first_name:p,description:"Paiement via FeexPay",otp:s,token:t.token,currency:t.currency||"XOF",callback_info:t.callback_info||{},network:n,country:o,customId:t.customId||""});if(W(!1),l.status==="FAILED"){j("FAILED"),C(l.message??"Le paiement a échoué."),E(!0),O(!1),t.callback&&t.callback({reference:l.reference??"",status:"FAILED",phoneNumber:S,reseau:n,callback_info:t.callback_info||{},description:t.description??"",transaction_id:l.reference??"",message:l.message??"Le paiement a échoué.",amount:t.amount,currency:t.currency||"XOF",first_name:y,email:g}),t.error_callback_url&&(window.location.href=`${t.error_callback_url}?ref=${l.reference}`);return}if(l.reference)l.status&&(l.status.toUpperCase()==="SUCCESSFUL"||l.status.toUpperCase()==="SUCCESS")?(j("SUCCESSFUL"),C("Paiement effectué avec succès!"),E(!0),O(!1),t.onPaymentSuccess&&t.onPaymentSuccess({status:"SUCCESSFUL",reference:l.reference,message:"Paiement effectué avec succès!"}),t.callback_url&&setTimeout(()=>{window.location.href=`${t.callback_url}?ref=${l.reference}`},2e3)):(j("FAILED"),C(l.message||"La transaction a échoué. Veuillez réessayer."),E(!0),O(!1),t.onPaymentFailure&&t.onPaymentFailure({status:"FAILED",reference:l.reference,message:l.message||"La transaction a échoué. Veuillez réessayer."}),t.error_callback_url&&setTimeout(()=>{window.location.href=`${t.error_callback_url}?ref=${l.reference}`},2e3));else{const v=l.message||"La confirmation du paiement a échoué. Veuillez réessayer.";j("FAILED"),C(v),E(!0),O(!1),t.onPaymentFailure&&t.onPaymentFailure({status:"FAILED",message:v})}}catch(c){console.error("Error in OTP submission:",c);const p="Une erreur est survenue lors de la confirmation du paiement. Veuillez réessayer.";j("FAILED"),C(p),E(!0),O(!1),W(!1),t.onPaymentFailure&&t.onPaymentFailure({status:"FAILED",message:p})}},$=s=>{xe(s,{paymentConfig:t,fullName:y,email:g,isCallbackCalledRef:B,setStateCallbacks:{setTransactionReference:V,setPaymentStatus:j,setStatusMessage:C,setStatusModalOpen:E,setIsLoading:O}},n,G)};return r?e.jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black bg-opacity-50 overflow-hidden",children:[e.jsxs("div",{className:"bg-white rounded-lg shadow-xl w-full max-w-md relative max-h-[90vh] flex flex-col",children:[ee&&e.jsxs("div",{className:"absolute inset-0 bg-white z-10 rounded-lg overflow-hidden",children:[e.jsx("button",{onClick:()=>te(null),className:"absolute top-2 right-2 z-20 bg-gray-200 text-gray-800 rounded-full p-1 hover:bg-gray-300 focus:outline-none","aria-label":"Fermer la passerelle de paiement",children:e.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("iframe",{src:ee,className:"w-full h-full border-0",title:"Payment Gateway",allow:"payment"})]}),e.jsx(Ve,{id:t.id,onClose:i}),e.jsxs("div",{className:"p-6 overflow-y-auto flex-grow",children:[e.jsx("p",{className:"text-sm text-gray-600 text-center mb-4",children:"Remplissez les champs suivants pour effectuer votre paiement"}),!t.case&&e.jsx("div",{className:"flex justify-center mb-6 border-b pb-4 w-fit gap-2",children:[{label:"Mobile Money",value:"MOBILE",icon:e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"#D45D00",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2",ry:"2"}),e.jsx("line",{x1:"12",y1:"18",x2:"12",y2:"18"})]})},{label:"Carte Bancaire",value:"CARD",icon:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:[e.jsx("path",{d:"M4 4a2 2 0 00-2 2v1h16V6a2 2 0 00-2-2H4z"}),e.jsx("path",{fillRule:"evenodd",d:"M18 9H2v5a2 2 0 002 2h12a2 2 0 002-2V9zM4 13a1 1 0 011-1h1a1 1 0 110 2H5a1 1 0 01-1-1zm5-1a1 1 0 100 2h1a1 1 0 100-2H9z",clipRule:"evenodd"})]})},{label:"Wallet",value:"WALLET",icon:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M10 2a1 1 0 00-1 1v1a1 1 0 002 0V3a1 1 0 00-1-1zM4 4h3a3 3 0 006 0h3a2 2 0 012 2v9a2 2 0 01-2 2H4a2 2 0 01-2-2V6a2 2 0 012-2zm2.5 7a1.5 1.5 0 100-3 1.5 1.5 0 000 3zm2.45 4a2.5 2.5 0 10-4.9 0h4.9zM12 9a1 1 0 100 2h3a1 1 0 100-2h-3zm-1 4a1 1 0 011-1h2a1 1 0 110 2h-2a1 1 0 01-1-1z",clipRule:"evenodd"})})}].map(({label:s,value:c,icon:p})=>{const S=a===c;return e.jsxs("div",{className:`flex flex-col items-center px-4 py-2 cursor-pointer rounded border ${S?"bg-[#fff7ed] border-[#D45D00]":"bg-white border-[#D45D00]"}`,onClick:()=>Se(c),children:[e.jsx("div",{className:"w-8 h-8 rounded-full flex items-center justify-center mb-1",children:p}),e.jsx("span",{className:"text-xs font-medium",children:s})]},c)})}),e.jsxs("div",{className:"space-y-6",children:[!((t.fields_to_hide||[]).includes("email")&&(t.fields_to_hide||[]).includes("name"))&&a!=="CARD"?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"font-bold text-gray-800 mb-2 flex items-center",children:[e.jsx("span",{className:"bg-gray-800 text-white rounded-full w-5 h-5 inline-flex items-center justify-center text-xs mr-2",children:"1"}),"Informations Personnelles"]}),!(t.fields_to_hide||[]).includes("name")&&e.jsx("div",{children:e.jsx("input",{type:"text",placeholder:"Nom et Prénoms",className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:y,onChange:s=>A(s.target.value)})}),!(t.fields_to_hide||[]).includes("email")&&e.jsx("div",{children:e.jsx("input",{type:"email",placeholder:"Email",className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:g,onChange:s=>_(s.target.value)})})]}):null,e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"font-bold text-gray-800 mb-2 flex items-center",children:[e.jsx("span",{className:"bg-gray-800 text-white rounded-full w-5 h-5 inline-flex items-center justify-center text-xs mr-2",children:a==="CARD"||(t.fields_to_hide||[]).includes("email")&&(t.fields_to_hide||[]).includes("name")?"1":"2"}),a==="CARD"?"Méthode de paiement":"Méthodes de paiement"]}),a==="MOBILE"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx("div",{children:e.jsx(je,{selectedCountry:o,onChange:ne})}),e.jsx("div",{children:e.jsx(Le,{selectedNetwork:n,onChange:se,country:o})})]}),e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"bg-gray-100 px-3 py-2 border border-r-0 rounded-l-md flex items-center justify-center",children:e.jsx("span",{className:"text-gray-600 text-xs",children:ve(o)})}),e.jsx("input",{type:"tel",placeholder:"Numéro de téléphone sans indicatif",className:"flex-1 px-2 py-2 border rounded-r-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:h,onChange:ae})]}),o==="SENEGAL"&&n==="ORANGE"&&e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"text",ref:re,id:"otp",placeholder:"L’otp de validation",className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs"}),e.jsx("span",{className:"text-xs text-gray-900",children:"L’otp de validation de la transaction obtenu en tapant #144#391# sur votre téléphone"})]})]}),a==="CARD"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Prénom"}),e.jsx("input",{type:"text",placeholder:"Prénom",className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:y.split(" ")[0]||"",onChange:s=>{const c=y.split(" ").slice(1).join(" ");A(`${s.target.value} ${c}`.trim())}})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Nom"}),e.jsx("input",{type:"text",placeholder:"Nom",className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:y.split(" ").slice(1).join(" ")||"",onChange:s=>{const c=y.split(" ")[0]||"";A(`${c} ${s.target.value}`.trim())}})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Email"}),e.jsx("input",{type:"email",placeholder:"exemple@email.com",className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:g,onChange:s=>_(s.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Téléphone"}),e.jsx("input",{type:"tel",placeholder:"Numéro de téléphone avec indicatif",className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:h,onChange:s=>k(s.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Type de carte"}),e.jsxs("select",{className:"w-full px-2 py-2 border rounded-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:I,onChange:s=>N(s.target.value),children:[e.jsx("option",{value:"VISA",children:"VISA"}),e.jsx("option",{value:"MASTERCARD",children:"MASTERCARD"})]})]})]}),a==="WALLET"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Pays"}),e.jsxs("select",{value:o,onChange:s=>ne(s.target.value),className:"block w-full px-2 py-2 pr-8 border rounded-md appearance-none focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",children:[e.jsx("option",{value:"BENIN",children:"🇧🇯 Bénin"}),e.jsx("option",{value:"COTE_D_IVOIRE",children:"🇨🇮 Côte d'Ivoire"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Réseau"}),e.jsxs("select",{value:n,onChange:s=>se(s.target.value),className:"block w-full px-2 py-2 pr-8 border rounded-md appearance-none focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",disabled:!0,children:[o==="BENIN"&&e.jsx("option",{value:"CORIS",children:"CORIS"}),o==="COTE_D_IVOIRE"&&e.jsx("option",{value:"WAVE",children:"WAVE"})]})]})]}),e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"bg-gray-100 px-3 py-2 border border-r-0 rounded-l-md flex items-center justify-center",children:e.jsx("span",{className:"text-gray-600 text-sm",children:o==="BENIN"?"+229":o==="COTE_D_IVOIRE"?"+225":""})}),e.jsx("input",{type:"tel",placeholder:"Numéro de téléphone sans indicatif",className:"flex-1 px-2 py-2 border rounded-r-md focus:outline-none focus:ring-2 focus:ring-primary-orange text-xs",value:h,onChange:ae})]})]}),e.jsxs("div",{className:"bg-gray-50 p-4 rounded-md",children:[e.jsxs("div",{className:"flex justify-between mb-1",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Montant :"}),e.jsxs("span",{className:"text-sm font-medium",children:[(ie=t.amount)==null?void 0:ie.toLocaleString("fr-FR")," ",t.currency]})]}),e.jsxs("div",{className:"flex justify-between mb-1",children:[e.jsx("span",{className:"text-sm text-gray-600",children:"Frais* :"}),e.jsx("span",{className:"text-sm font-medium",children:D>0?`${D.toLocaleString("fr-FR")} ${t.currency}`:`0 ${t.currency}`})]}),e.jsxs("div",{className:"flex justify-between font-bold",children:[e.jsx("span",{children:"Montant Total à payer :"}),e.jsxs("span",{children:[M.toLocaleString("fr-FR")," ",t.currency]})]}),e.jsx("p",{className:"text-xs text-gray-500 mt-2",children:D>0?`*Les frais de transaction sont de ${z.toFixed(1).replace(".",",")}% du montant.`:"*Aucun frais de transaction applicable pour cette transaction."})]}),e.jsx("div",{className:"pt-2",children:e.jsxs("div",{className:"flex space-x-2",children:[e.jsx("button",{onClick:()=>i(),className:"w-1/3 bg-gray-200 hover:bg-gray-300 text-primary-blue font-bold py-2 px-4 rounded-md transition-colors duration-300 flex items-center justify-center",children:"Retour"}),e.jsxs("button",{onClick:Oe,disabled:Z,className:`w-2/3 bg-primary-orange hover:bg-orange-700 text-white font-bold py-2 px-4 rounded-md transition-colors duration-300 flex items-center justify-center ${Z?"opacity-70 cursor-not-allowed":""}`,children:[Z?e.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-white",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}):null,"Payer ",M.toLocaleString("fr-FR")," ",t.currency]})]})})]})]}),e.jsxs("div",{className:"mt-6 text-center text-xs text-gray-500 flex-shrink-0 bg-gray-50 w-full p-2",children:[e.jsx("p",{className:"mt-2",children:"Paiements sécurisés par FeexPay"}),e.jsxs("p",{className:"mt-2",children:["En payant par ce plugin, vous acceptez les ",e.jsx("a",{className:"text-blue-900",style:{textDecoration:"underline"},target:"_blank",href:"https://feexpay.me/fr/terms-and-conditions",children:"conditions générales d'utilisation de FeexPay"})]})]})]})]}),e.jsx(_e,{isOpen:ge,onClose:()=>E(!1),status:q,message:ye}),e.jsx(Ae,{isOpen:Ne,onClose:()=>{W(!1),O(!1)},onSubmit:we,reference:be})]}):null},Be=({amount:r,description:i,id:t,token:a,callback_url:d,mode:o="LIVE",customId:x,fields_to_hide:n,callback:f,currency:h="XOF",case:k,callback_info:y,error_callback_url:A,buttonText:g=`Payer ${r} ${h}`,buttonClass:_})=>{const[I,N]=u.useState(!1),{setPaymentConfig:b}=me(),m=u.useRef(null),[M,F]=u.useState(!1),[D,R]=u.useState(null);u.useEffect(()=>{(async()=>{try{await pe(t),F(!0)}catch{R("Veuillez vérifier vos identifiants de boutique (ID et token) et rester en mode LIVE.")}})()},[t]);const z=u.useCallback(()=>{b({amount:r,description:i,id:t,token:a,callback_url:d,mode:o,customId:x,fields_to_hide:n,callback:f,currency:h,case:k,callback_info:y,error_callback_url:A}),N(!0)},[r,i,t,a,d,o,x,n,f,h,k,y,A,b]);u.useEffect(()=>{const U=m.current;if(!U)return;const V=()=>{z()};return U.addEventListener("feexpay:trigger",V),()=>{U.removeEventListener("feexpay:trigger",V)}},[z]);const T=()=>{N(!1)};return e.jsxs("div",{ref:m,children:[D?e.jsx("p",{className:"text-red-600 text-sm mb-2",children:D}):M&&e.jsx("button",{onClick:z,className:_||"bg-primary-orange hover:bg-orange-700 text-white font-bold py-3 px-4 rounded-md transition-colors duration-300 flex items-center justify-center",children:g}),I&&e.jsx(Ue,{isOpen:I,onClose:T})]})};exports.FeexPayButton=Be;exports.FeexPayProvider=Te;