import PaystackPop from"@paystack/inline-js";import{__,sprintf}from"@wordpress/i18n";import{state as checkoutState}from"../../../../store/checkout/index";import{state as selectedProcessor}from"../../../../store/selected-processor/index";import{onChange as onChangeFormState}from"../../../../store/form/index";import{currentFormState}from"../../../../store/form/getters";import{updateFormState}from"../../../../store/form/mutations";import{createErrorNotice}from"../../../../store/notices/mutations";export class ScCheckoutPaystackPaymentProvider{componentWillLoad(){this.unlistenToFormState=onChangeFormState("formState",(()=>{"paying"===currentFormState()&&this.confirm()}))}disconnectedCallback(){this.unlistenToFormState()}async confirm(){var t,e,o,r;if("paystack"===(null==selectedProcessor?void 0:selectedProcessor.id)&&(null===(e=null===(t=null==checkoutState?void 0:checkoutState.checkout)||void 0===t?void 0:t.payment_intent)||void 0===e?void 0:e.processor_data.paystack)&&"paid"!==(null===(o=null==checkoutState?void 0:checkoutState.checkout)||void 0===o?void 0:o.status))try{const{public_key:t,access_code:e}=null===(r=null==checkoutState?void 0:checkoutState.checkout)||void 0===r?void 0:r.payment_intent.processor_data.paystack;if(!t||!e)return void createErrorNotice({message:sprintf(__("Payment gateway configuration incomplete. Please ensure Paystack is properly configured for transactions.","surecart"))});const o=new PaystackPop;await o.newTransaction({key:t,accessCode:e,onSuccess:async t=>{if("success"!==(null==t?void 0:t.status))throw{message:sprintf(__("Paystack transaction could not be finished. Status: %s","surecart"),null==t?void 0:t.status)};return updateFormState("PAID")},onClose:()=>updateFormState("REJECT")})}catch(t){createErrorNotice(t),console.error(t),updateFormState("REJECT")}}static get is(){return"sc-checkout-paystack-payment-provider"}static get encapsulation(){return"shadow"}}