import{r as e,h as t,H as s}from"./p-e97fde0a.js";import{s as a}from"./p-3aa9debd.js";import{a as i}from"./p-d9fa04f9.js";import"./p-401e165e.js";import"./p-d3366af3.js";const n=":host{display:block}";const d=n;const c=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:s,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(!s||!i)return;const n=new a;await n.newTransaction({key:s,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(s){this.error=((t=(e=s===null||s===void 0?void 0:s.additional_errors)===null||e===void 0?void 0:e[0])===null||t===void 0?void 0:t.message)||(s===null||s===void 0?void 0:s.message)||wp.i18n.__("Something went wrong","surecart")}finally{this.loading=false}}render(){return t(s,{key:"c7834e27c130521d7944a6df4adc15bccdfdf67e"},this.error&&t("sc-alert",{key:"c0f0ff2bcf73e6e18b513275cecf6092d0b6d84d",open:!!this.error,type:"danger"},t("span",{key:"050c49e02d40ae4c6d62da7c4a67219723b6ac31",slot:"title"},wp.i18n.__("Error","surecart")),this.error),t("div",{key:"131c553e7867a53bbbf586609df2e97066f4c7a4",class:"sc-paystack-button-container"},t("sc-alert",{key:"95f980fbf168fdc9fd528846ed0ae983eeb6c161",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:"d8b8bdce1b6d20c48442fe755c92e07ded997893"},t("sc-button",{key:"e579bcf3a4d801c1981a8ee97450043c544b989f",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"]}}};c.style=d;export{c as sc_paystack_add_method};
//# sourceMappingURL=p-c0b80eac.entry.js.map