import{r as e,h as t,H as a}from"./p-e97fde0a.js";import{s}from"./p-3aa9debd.js";import{a as i}from"./p-dd3464cd.js";import"./p-401e165e.js";import"./p-d3366af3.js";const n=":host{display:block}";const d=n;const r=class{constructor(t){e(this,t);this.liveMode=true;this.customerId=undefined;this.successUrl=undefined;this.currency=undefined;this.loading=undefined;this.loaded=undefined;this.error=undefined;this.paymentIntent=undefined}async handlePaymentIntentCreate(){var e,t;const{public_key:a,access_code:i}=((t=(e=this.paymentIntent)===null||e===void 0?void 0:e.processor_data)===null||t===void 0?void 0:t.paystack)||{};if(!a||!i)return;const n=new s;await n.newTransaction({key:a,accessCode:i,onSuccess:async e=>{if((e===null||e===void 0?void 0:e.status)!=="success"){throw{message:wp.i18n.sprintf(wp.i18n.__("Paystack transaction could not be finished. Status: %s","surecart"),e===null||e===void 0?void 0:e.status)}}window.location.assign(this.successUrl)},onClose:e=>{console.error(e);alert((e===null||e===void 0?void 0:e.message)||wp.i18n.__("The payment did not process. Please try again.","surecart"))}})}async createPaymentIntent(){var e,t;try{this.loading=true;this.error="";this.paymentIntent=await i({method:"POST",path:"surecart/v1/payment_intents",data:{processor_type:"paystack",reusable:true,live_mode:this.liveMode,customer_id:this.customerId,currency:this.currency,refresh_status:true}})}catch(a){this.error=((t=(e=a===null||a===void 0?void 0:a.additional_errors)===null||e===void 0?void 0:e[0])===null||t===void 0?void 0:t.message)||(a===null||a===void 0?void 0:a.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=false}}render(){return t(a,{key:"e4e7073e5a5277540a3b771fe7f3e4c602a5bd05"},this.error&&t("sc-alert",{key:"045b2d9f5ed9d62da99fa93f02c191d712c54f4a",open:!!this.error,type:"danger"},t("span",{key:"338d2180eacb05c3faec04c22b43863c25b3271b",slot:"title"},wp.i18n.__("Error","surecart")),this.error),t("div",{key:"4a49a8471f5b2ba17af999f48b0091d93b708d95",class:"sc-paystack-button-container"},t("sc-alert",{key:"8110b6ea618cb7fa89e4a00fe4cf34e6818adbae",open:true,type:"warning"},wp.i18n.__("In order to add a new card, we will need to make a small transaction to authenticate it. This is for authentication purposes and will be immediately refunded.","surecart"),t("div",{key:"b3b0cb4d9fb3a4578d44f9fb1f805492f935f7a3"},t("sc-button",{key:"f7d6e62241cccfef7859f61ab674e5d50f605d43",loading:this.loading,type:"primary",onClick:()=>this.createPaymentIntent(),style:{marginTop:"var(--sc-spacing-medium)"}},wp.i18n.__("Add New Card","surecart"))))))}static get watchers(){return{paymentIntent:["handlePaymentIntentCreate"]}}};r.style=d;export{r as sc_paystack_add_method};
//# sourceMappingURL=p-8ee4af08.entry.js.map