@bcc-code/payment-client 1.0.8 → 1.1.1

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/README.md CHANGED
@@ -50,7 +50,7 @@ const client = new PaymentClient({
50
50
  const payment = await client.createPayment({
51
51
  amount: 99.99,
52
52
  currency: 'EUR',
53
- paymentMethodType: 'stripe',
53
+ paymentMethodType: 'stripe', // or 'adyen', 'delayed-payment'
54
54
  returnUrl: 'https://yourapp.com/success',
55
55
  lineItems: [
56
56
  {
@@ -66,6 +66,14 @@ const status = await client.getPayment(payment.paymentId)
66
66
 
67
67
  // Get receipt
68
68
  const receipt = await client.getReceipt(payment.paymentId)
69
+
70
+ // Discover available payment methods for a specific context
71
+ const paymentMethods = await client.getPaymentMethods({
72
+ currency: 'EUR',
73
+ amount: 100,
74
+ churchId: 'your-church-uuid',
75
+ isCompany: false
76
+ })
69
77
  ```
70
78
 
71
79
  ## Vue Components Usage
@@ -182,6 +190,58 @@ const handleReady = () => {
182
190
  </script>
183
191
  ```
184
192
 
193
+ ### Delayed Payment Component
194
+
195
+ For manual payment processing via invoice or bank transfer:
196
+
197
+ ```vue
198
+ <template>
199
+ <DelayedPayment
200
+ :payment-id="payment.paymentId"
201
+ :client-data="payment.clientData"
202
+ :amount="99.99"
203
+ currency="EUR"
204
+ :tenant-id="tenantId"
205
+ @success="handleSuccess"
206
+ @error="handleError"
207
+ @ready="handleReady"
208
+ />
209
+ </template>
210
+
211
+ <script setup lang="ts">
212
+ import { PaymentClient } from '@bcc-code/payment-client'
213
+ import { DelayedPayment } from '@bcc-code/payment-client/components'
214
+
215
+ const paymentClient = new PaymentClient({
216
+ baseUrl: 'http://localhost:3200',
217
+ tenantId: 'your-tenant-uuid',
218
+ getAuthToken: async () => getBccAuthToken()
219
+ })
220
+
221
+ const payment = await paymentClient.createPayment({
222
+ amount: 99.99,
223
+ currency: 'EUR',
224
+ paymentMethodType: 'delayed-payment',
225
+ returnUrl: 'https://yourapp.com/success'
226
+ })
227
+
228
+ const tenantId = 'your-tenant-uuid'
229
+
230
+ const handleSuccess = (result: any) => {
231
+ console.log('Payment confirmed:', result)
232
+ // Payment will be processed manually
233
+ }
234
+
235
+ const handleError = (error: any) => {
236
+ console.error('Payment error:', error)
237
+ }
238
+
239
+ const handleReady = () => {
240
+ console.log('Delayed payment form ready')
241
+ }
242
+ </script>
243
+ ```
244
+
185
245
  ### Component Props
186
246
 
187
247
  #### StripePayment Props
@@ -209,6 +269,14 @@ const handleReady = () => {
209
269
  - `paymentData` (any, optional) - Additional payment data
210
270
  - `onCancel` (function, optional) - Cancel callback
211
271
 
272
+ #### DelayedPayment Props
273
+
274
+ - `paymentId` (string, required) - Payment ID from CreatePaymentResponse
275
+ - `clientData` (string, required) - Client data from CreatePaymentResponse
276
+ - `amount` (number, required) - Payment amount
277
+ - `currency` (string, required) - Currency code (EUR, USD, etc.)
278
+ - `tenantId` (string, optional) - Tenant ID for API calls
279
+
212
280
  ### Component Events
213
281
 
214
282
  Both components emit the following events:
@@ -230,8 +298,11 @@ import { StripePayment } from '@bcc-code/payment-client/components'
230
298
  // Import only Adyen component
231
299
  import { AdyenPayment } from '@bcc-code/payment-client/components'
232
300
 
233
- // Import both
234
- import { StripePayment, AdyenPayment } from '@bcc-code/payment-client/components'
301
+ // Import only Delayed Payment component
302
+ import { DelayedPayment } from '@bcc-code/payment-client/components'
303
+
304
+ // Import all
305
+ import { StripePayment, AdyenPayment, DelayedPayment } from '@bcc-code/payment-client/components'
235
306
 
236
307
  // Note: Components must be imported from the '/components' entry point
237
308
  // The main entry point only exports the API client and types
@@ -247,7 +318,8 @@ import type {
247
318
  CreatePaymentResponse,
248
319
  PaymentResponse,
249
320
  StripePaymentProps,
250
- AdyenPaymentProps
321
+ AdyenPaymentProps,
322
+ DelayedPaymentProps
251
323
  } from '@bcc-code/payment-client'
252
324
  ```
253
325
 
@@ -281,6 +353,16 @@ import type {
281
353
  @success="handlePaymentSuccess"
282
354
  @error="handlePaymentError"
283
355
  />
356
+ <DelayedPayment
357
+ v-else-if="payment && provider === 'delayed-payment'"
358
+ :payment-id="payment.paymentId"
359
+ :client-data="payment.clientData"
360
+ :amount="amount"
361
+ :currency="currency"
362
+ :tenant-id="tenantId"
363
+ @success="handlePaymentSuccess"
364
+ @error="handlePaymentError"
365
+ />
284
366
  </div>
285
367
  </template>
286
368
 
@@ -288,7 +370,7 @@ import type {
288
370
  import { ref } from 'vue'
289
371
  import '@bcc-code/payment-client/styles/adyen.css'
290
372
  import { PaymentClient } from '@bcc-code/payment-client'
291
- import { StripePayment, AdyenPayment } from '@bcc-code/payment-client/components'
373
+ import { StripePayment, AdyenPayment, DelayedPayment } from '@bcc-code/payment-client/components'
292
374
  import type { CreatePaymentResponse } from '@bcc-code/payment-client'
293
375
 
294
376
  const paymentClient = new PaymentClient({
@@ -299,7 +381,8 @@ const paymentClient = new PaymentClient({
299
381
 
300
382
  const amount = 99.99
301
383
  const currency = 'EUR'
302
- const provider = 'stripe' // or 'adyen'
384
+ const provider = 'stripe' // or 'adyen', 'delayed-payment'
385
+ const tenantId = 'your-tenant-uuid'
303
386
  const loading = ref(false)
304
387
  const error = ref<string | null>(null)
305
388
  const payment = ref<CreatePaymentResponse | null>(null)
@@ -1 +1 @@
1
- "use strict";var w=Object.create;var _=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var F=(s,u,i,n)=>{if(u&&typeof u=="object"||typeof u=="function")for(let o of K(u))!N.call(s,o)&&o!==i&&_(s,o,{get:()=>u[o],enumerable:!(n=B(u,o))||n.enumerable});return s};var E=(s,u,i)=>(i=s!=null?w(A(s)):{},F(u||!s||!s.__esModule?_(i,"default",{value:s,enumerable:!0}):i,s));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),R={class:"stripe-elements"},U={key:0,class:"elements-loading"},V={key:1,class:"elements-error"},M={key:2,class:"payment-button-container"},x=["disabled"],I=e.defineComponent({__name:"StripePayment",props:{paymentId:{},clientData:{default:void 0},clientKey:{default:void 0},amount:{},currency:{},publishableKey:{default:void 0},appearance:{default:void 0},showPayButton:{type:Boolean,default:!0},locale:{default:"en"},loader:{default:"auto"},returnUrl:{default:void 0}},emits:["submit","success","error","ready"],setup(s,{expose:u,emit:i}){const n=s,o=i,b=e.ref(),p=e.ref(!0),l=e.ref(!1),c=e.ref("");let d=null,y=null,m=null;const h=e.computed(()=>({EUR:"€",USD:"$",GBP:"£",CHF:"CHF",NOK:"kr",SEK:"kr",DKK:"kr",PLN:"zł",CZK:"Kč",HUF:"Ft"})[n.currency]||n.currency),P=e.computed(()=>n.amount.toFixed(2)),C=e.computed(()=>{if(n.clientData)try{const a=JSON.parse(n.clientData);return a.clientSecret||a.client_secret}catch{return}}),f=async()=>{if(!b.value)return;let a=n.publishableKey;if(!a&&n.clientData)try{const r=JSON.parse(n.clientData);a=r.publishableKey||r.publishable_key}catch{}if(!a){c.value="Publishable key is required",p.value=!1;return}try{p.value=!0,c.value="";const{loadStripe:r}=await import("@stripe/stripe-js");if(d=await r(a),!d)throw new Error("Failed to load Stripe");const t=C.value,g={appearance:n.appearance||{theme:"stripe",variables:{colorPrimary:"#0570de",colorBackground:"#ffffff",colorText:"#30313d",colorDanger:"#df1b41",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',spacingUnit:"4px",borderRadius:"4px"}},loader:n.loader,locale:n.locale};t&&(g.clientSecret=t),y=d.elements(g),m=y.create("payment",{layout:"tabs",defaultValues:{billingDetails:{name:"",email:"",phone:""}}}),m.mount(b.value),m.on("ready",()=>{p.value=!1,o("ready")}),m.on("change",D=>{D.error?(c.value=D.error.message,o("error",D.error)):c.value=""})}catch(r){c.value=r instanceof Error?r.message:"Failed to initialize payment form",p.value=!1,o("error",r)}},k=async()=>{if(!(!d||!m)){l.value=!0,c.value="";try{const a=n.returnUrl||`${window.location.origin}/payment/return`,{error:r,paymentIntent:t}=await d.confirmPayment({elements:y,confirmParams:{return_url:a},redirect:"if_required"});r?(c.value=r.message||"Payment failed",o("error",r)):t?t.status==="succeeded"?o("success",{paymentIntent:t,status:"succeeded",message:"Payment completed successfully!"}):t.status==="processing"?o("success",{paymentIntent:t,status:"processing",message:"Payment is being processed..."}):o("submit",{paymentIntent:t,status:t.status}):o("submit",m)}catch(a){c.value=a instanceof Error?a.message:"Payment failed",o("error",a)}finally{l.value=!1}}},v=()=>{m&&(m.destroy(),m=null),y&&(y=null),d&&(d=null)};return e.onMounted(()=>{f()}),e.onUnmounted(()=>{v()}),e.watch(()=>n.currency,()=>{v(),f()}),e.watch([()=>n.publishableKey,()=>n.clientData],()=>{(n.publishableKey||n.clientData)&&(v(),f())}),u({destroyElements:v}),(a,r)=>(e.openBlock(),e.createElementBlock("div",R,[e.createElementVNode("div",{ref_key:"elementsContainer",ref:b,class:"elements-container"},null,512),p.value?(e.openBlock(),e.createElementBlock("div",U,[...r[0]||(r[0]=[e.createElementVNode("div",{class:"loading-spinner"},null,-1),e.createElementVNode("p",null,"Loading payment form...",-1)])])):e.createCommentVNode("",!0),c.value?(e.openBlock(),e.createElementBlock("div",V,[r[1]||(r[1]=e.createElementVNode("div",{class:"error-icon"}," ⚠️ ",-1)),e.createElementVNode("p",null,e.toDisplayString(c.value),1),e.createElementVNode("button",{class:"retry-btn",onClick:f}," Retry ")])):e.createCommentVNode("",!0),s.showPayButton&&!p.value&&!c.value?(e.openBlock(),e.createElementBlock("div",M,[e.createElementVNode("button",{disabled:l.value,class:"payment-button",onClick:k},e.toDisplayString(l.value?"Processing...":`Pay ${h.value}${P.value}`),9,x)])):e.createCommentVNode("",!0)]))}}),S=(s,u)=>{const i=s.__vccOpts||s;for(const[n,o]of u)i[n]=o;return i},O=S(I,[["__scopeId","data-v-adbdf3c5"]]),q=e.defineComponent({__name:"AdyenPayment",props:{paymentId:{},clientData:{},clientKey:{},environment:{},amount:{},currency:{},paymentData:{},onCancel:{type:Function}},emits:["submit","additionalDetails","error","ready","success"],setup(s,{emit:u}){const i=s,n=u,o=e.ref(null),b=()=>{if(!i.clientData)return console.error("No clientData provided"),null;try{const l=JSON.parse(i.clientData);return console.log("Parsed Adyen session data:",l),{id:l.id,sessionData:l.sessionData,amount:l.amount,reference:l.reference,returnUrl:l.returnUrl,merchantAccount:l.merchantAccount}}catch(l){return console.error("Failed to parse clientData:",l),null}},p=async()=>{var c;if(!i.clientKey||!o.value){console.error("Initialization failed: Missing clientKey or container.");return}const l=b();if(!l){console.error("Failed to parse session data"),n("error",new Error("Failed to parse session data"));return}try{const{AdyenCheckout:d,Card:y,ApplePay:m,GooglePay:h,Klarna:P,Blik:C,Dropin:f}=await import("@adyen/adyen-web"),k={environment:i.environment||"test",clientKey:i.clientKey,session:l,onPaymentCompleted:(t,g)=>{console.info("Payment Completed:",t,g),n("submit",t),t.resultCode==="Authorised"||t.resultCode==="Received"?(console.info("Payment Successful:",t),n("success",{status:"succeeded",message:"Payment completed successfully",resultCode:t.resultCode,pspReference:t.pspReference,paymentData:t})):t.resultCode==="Pending"?(console.info("Payment Pending:",t),n("success",{status:"processing",message:"Payment is being processed",resultCode:t.resultCode,pspReference:t.pspReference,paymentData:t})):(t.resultCode==="Refused"||t.resultCode==="Error")&&(console.error("Payment Failed:",t),n("error",{message:t.refusalReason||"Payment was declined",resultCode:t.resultCode,paymentData:t}))},onError:(t,g)=>{console.error("Adyen Error:",t.name,t.message,t.stack,g),n("error",t)}},v={showPayButton:!0,paymentMethodComponents:[y,m,h,P,C],paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0,billingAddressRequired:!1,enableStoreDetails:!1},applePay:{showPayButton:!0},googlePay:{showPayButton:!0},klarna:{useKlarnaWidget:!0},blik:{}}},a=await d(k);console.log("Adyen Checkout created:",a),console.log("Available payment methods from session:",(c=a.paymentMethodsResponse)==null?void 0:c.paymentMethods);const r=new f(a,v);console.log("Adyen Drop-in created with session payment methods"),o.value&&(r.mount(o.value),console.log("Adyen Drop-in mounted successfully"),n("ready"))}catch(d){console.error("Error creating Adyen Drop-in:",d),n("error",d)}};return e.onMounted(()=>{p()}),e.watch(()=>i.clientData,()=>{o.value&&(o.value.innerHTML="",p())}),(l,c)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"dropinContainer",ref:o,class:"payment-dropin"},null,512))}}),z=S(q,[["__scopeId","data-v-ef2ec054"]]);exports.AdyenPayment=z;exports.StripePayment=O;
1
+ "use strict";var S=Object.create;var _=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var U=(l,m,i,t)=>{if(m&&typeof m=="object"||typeof m=="function")for(let a of V(m))!K.call(l,a)&&a!==i&&_(l,a,{get:()=>m[a],enumerable:!(t=w(m,a))||t.enumerable});return l};var C=(l,m,i)=>(i=l!=null?S(B(l)):{},U(m||!l||!l.__esModule?_(i,"default",{value:l,enumerable:!0}):i,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),R={class:"stripe-elements"},A={key:0,class:"elements-loading"},F={key:1,class:"elements-error"},I={key:2,class:"payment-button-container"},$=["disabled"],x=e.defineComponent({__name:"StripePayment",props:{paymentId:{},clientData:{default:void 0},clientKey:{default:void 0},amount:{},currency:{},publishableKey:{default:void 0},appearance:{default:void 0},showPayButton:{type:Boolean,default:!0},locale:{default:"en"},loader:{default:"auto"},returnUrl:{default:void 0}},emits:["submit","success","error","ready"],setup(l,{expose:m,emit:i}){const t=l,a=i,v=e.ref(),p=e.ref(!0),o=e.ref(!1),u=e.ref("");let y=null,b=null,f=null;const k=e.computed(()=>({EUR:"€",USD:"$",GBP:"£",CHF:"CHF",NOK:"kr",SEK:"kr",DKK:"kr",PLN:"zł",CZK:"Kč",HUF:"Ft"})[t.currency]||t.currency),E=e.computed(()=>t.amount.toFixed(2)),r=e.computed(()=>{if(t.clientData)try{const s=JSON.parse(t.clientData);return s.clientSecret||s.client_secret}catch{return}}),c=async()=>{if(!v.value)return;let s=t.publishableKey;if(!s&&t.clientData)try{const d=JSON.parse(t.clientData);s=d.publishableKey||d.publishable_key}catch{}if(!s){u.value="Publishable key is required",p.value=!1;return}try{p.value=!0,u.value="";const{loadStripe:d}=await import("@stripe/stripe-js");if(y=await d(s),!y)throw new Error("Failed to load Stripe");const n=r.value,D={appearance:t.appearance||{theme:"stripe",variables:{colorPrimary:"#0570de",colorBackground:"#ffffff",colorText:"#30313d",colorDanger:"#df1b41",fontFamily:'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',spacingUnit:"4px",borderRadius:"4px"}},loader:t.loader,locale:t.locale};n&&(D.clientSecret=n),b=y.elements(D),f=b.create("payment",{layout:"tabs",defaultValues:{billingDetails:{name:"",email:"",phone:""}}}),f.mount(v.value),f.on("ready",()=>{p.value=!1,a("ready")}),f.on("change",N=>{N.error?(u.value=N.error.message,a("error",N.error)):u.value=""})}catch(d){u.value=d instanceof Error?d.message:"Failed to initialize payment form",p.value=!1,a("error",d)}},g=async()=>{if(!(!y||!f)){o.value=!0,u.value="";try{const s=t.returnUrl||`${window.location.origin}/payment/return`,{error:d,paymentIntent:n}=await y.confirmPayment({elements:b,confirmParams:{return_url:s},redirect:"if_required"});d?(u.value=d.message||"Payment failed",a("error",d)):n?n.status==="succeeded"?a("success",{paymentIntent:n,status:"succeeded",message:"Payment completed successfully!"}):n.status==="processing"?a("success",{paymentIntent:n,status:"processing",message:"Payment is being processed..."}):a("submit",{paymentIntent:n,status:n.status}):a("submit",f)}catch(s){u.value=s instanceof Error?s.message:"Payment failed",a("error",s)}finally{o.value=!1}}},h=()=>{f&&(f.destroy(),f=null),b&&(b=null),y&&(y=null)};return e.onMounted(()=>{c()}),e.onUnmounted(()=>{h()}),e.watch(()=>t.currency,()=>{h(),c()}),e.watch([()=>t.publishableKey,()=>t.clientData],()=>{(t.publishableKey||t.clientData)&&(h(),c())}),m({destroyElements:h}),(s,d)=>(e.openBlock(),e.createElementBlock("div",R,[e.createElementVNode("div",{ref_key:"elementsContainer",ref:v,class:"elements-container"},null,512),p.value?(e.openBlock(),e.createElementBlock("div",A,[...d[0]||(d[0]=[e.createElementVNode("div",{class:"loading-spinner"},null,-1),e.createElementVNode("p",null,"Loading payment form...",-1)])])):e.createCommentVNode("",!0),u.value?(e.openBlock(),e.createElementBlock("div",F,[d[1]||(d[1]=e.createElementVNode("div",{class:"error-icon"}," ⚠️ ",-1)),e.createElementVNode("p",null,e.toDisplayString(u.value),1),e.createElementVNode("button",{class:"retry-btn",onClick:c}," Retry ")])):e.createCommentVNode("",!0),l.showPayButton&&!p.value&&!u.value?(e.openBlock(),e.createElementBlock("div",I,[e.createElementVNode("button",{disabled:o.value,class:"payment-button",onClick:g},e.toDisplayString(o.value?"Processing...":`Pay ${k.value}${E.value}`),9,$)])):e.createCommentVNode("",!0)]))}}),P=(l,m)=>{const i=l.__vccOpts||l;for(const[t,a]of m)i[t]=a;return i},M=P(x,[["__scopeId","data-v-adbdf3c5"]]),O=e.defineComponent({__name:"AdyenPayment",props:{paymentId:{},clientData:{},clientKey:{},environment:{},amount:{},currency:{},paymentData:{},onCancel:{type:Function}},emits:["submit","additionalDetails","error","ready","success"],setup(l,{emit:m}){const i=l,t=m,a=e.ref(null),v=()=>{if(!i.clientData)return console.error("No clientData provided"),null;try{const o=JSON.parse(i.clientData);return console.log("Parsed Adyen session data:",o),{id:o.id,sessionData:o.sessionData,amount:o.amount,reference:o.reference,returnUrl:o.returnUrl,merchantAccount:o.merchantAccount}}catch(o){return console.error("Failed to parse clientData:",o),null}},p=async()=>{var u;if(!i.clientKey||!a.value){console.error("Initialization failed: Missing clientKey or container.");return}const o=v();if(!o){console.error("Failed to parse session data"),t("error",new Error("Failed to parse session data"));return}try{const{AdyenCheckout:y,Card:b,ApplePay:f,GooglePay:k,Klarna:E,Blik:r,Dropin:c}=await import("@adyen/adyen-web"),g={environment:i.environment||"test",clientKey:i.clientKey,session:o,onPaymentCompleted:(n,D)=>{console.info("Payment Completed:",n,D),t("submit",n),n.resultCode==="Authorised"||n.resultCode==="Received"?(console.info("Payment Successful:",n),t("success",{status:"succeeded",message:"Payment completed successfully",resultCode:n.resultCode,pspReference:n.pspReference,paymentData:n})):n.resultCode==="Pending"?(console.info("Payment Pending:",n),t("success",{status:"processing",message:"Payment is being processed",resultCode:n.resultCode,pspReference:n.pspReference,paymentData:n})):(n.resultCode==="Refused"||n.resultCode==="Error")&&(console.error("Payment Failed:",n),t("error",{message:n.refusalReason||"Payment was declined",resultCode:n.resultCode,paymentData:n}))},onError:(n,D)=>{console.error("Adyen Error:",n.name,n.message,n.stack,D),t("error",n)}},h={showPayButton:!0,paymentMethodComponents:[b,f,k,E,r],paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0,billingAddressRequired:!1,enableStoreDetails:!1},applePay:{showPayButton:!0},googlePay:{showPayButton:!0},klarna:{useKlarnaWidget:!0},blik:{}}},s=await y(g);console.log("Adyen Checkout created:",s),console.log("Available payment methods from session:",(u=s.paymentMethodsResponse)==null?void 0:u.paymentMethods);const d=new c(s,h);console.log("Adyen Drop-in created with session payment methods"),a.value&&(d.mount(a.value),console.log("Adyen Drop-in mounted successfully"),t("ready"))}catch(y){console.error("Error creating Adyen Drop-in:",y),t("error",y)}};return e.onMounted(()=>{p()}),e.watch(()=>i.clientData,()=>{a.value&&(a.value.innerHTML="",p())}),(o,u)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"dropinContainer",ref:a,class:"payment-dropin"},null,512))}}),H=P(O,[["__scopeId","data-v-ef2ec054"]]),T={class:"delayed-payment"},z={class:"payment-form"},q={class:"amount-display"},L={class:"amount-value"},J={key:0,class:"session-info"},G={key:0,class:"info-row"},j={class:"value"},W={key:1,class:"info-row"},X={class:"value"},Y={key:1,class:"error-message"},Z={class:"button-container"},Q=["disabled"],ee=e.defineComponent({__name:"DelayedPayment",props:{paymentId:{default:void 0},clientData:{default:void 0},amount:{},currency:{},tenantId:{default:void 0}},emits:["submit","success","error","ready"],setup(l,{expose:m,emit:i}){const t=l,a=i,v=e.ref(!1),p=e.ref(""),o=e.ref({}),u=e.computed(()=>({EUR:"€",USD:"$",GBP:"£",CHF:"CHF",NOK:"kr",SEK:"kr",DKK:"kr",PLN:"zł"})[t.currency]||t.currency),y=e.computed(()=>t.amount.toFixed(2)),b=e.computed(()=>o.value.invoiceNumber&&o.value.providerUid),f=()=>{if(!t.clientData){console.error("No clientData provided for delayed payment");return}try{const r=JSON.parse(t.clientData);console.log("Parsed delayed payment session data:",r),o.value={invoiceNumber:r.invoiceNumber,merchantReference:r.merchantReference,providerUid:r.providerUid,paymentUid:r.paymentUid},a("ready")}catch(r){console.error("Failed to parse clientData:",r),p.value="Invalid session data",a("error",r)}},k=async()=>{if(!(!b.value||v.value)){v.value=!0,p.value="";try{const r={provider:"delayed-payment",amount:t.amount,currency:t.currency,invoiceNumber:o.value.invoiceNumber,merchantReference:o.value.merchantReference,providerUid:o.value.providerUid,timestamp:new Date().toISOString()};if(a("submit",r),!t.paymentId)throw new Error("Payment ID not provided");const c=window.location.origin,g={"Content-Type":"application/json"};t.tenantId&&(g["X-Tenant-ID"]=t.tenantId);const h=await fetch(`${c}/api/v1/webhooks/delayed-payments/confirm/${t.paymentId}`,{method:"POST",headers:g});if(!h.ok){const s=await h.text();throw new Error(`Failed to confirm payment: ${s}`)}a("success",{status:"succeeded",message:"Payment confirmed successfully. You will receive a receipt shortly.",resultCode:"Authorised",invoiceNumber:o.value.invoiceNumber,providerUid:o.value.providerUid,paymentData:r})}catch(r){p.value=r instanceof Error?r.message:"Failed to confirm payment",a("error",r)}finally{v.value=!1}}},E=()=>{p.value=""};return e.onMounted(()=>{f()}),m({clearError:E}),(r,c)=>(e.openBlock(),e.createElementBlock("div",T,[e.createElementVNode("div",z,[c[4]||(c[4]=e.createElementVNode("div",{class:"info-section"},[e.createElementVNode("div",{class:"info-icon"}," 📄 "),e.createElementVNode("h3",{class:"info-title"}," Delayed Payment "),e.createElementVNode("p",{class:"info-description"}," Payment will be processed manually via invoice or bank transfer ")],-1)),e.createElementVNode("div",q,[c[0]||(c[0]=e.createElementVNode("span",{class:"amount-label"},"Amount to pay:",-1)),e.createElementVNode("span",L,e.toDisplayString(u.value)+e.toDisplayString(y.value),1)]),b.value?(e.openBlock(),e.createElementBlock("div",J,[o.value.invoiceNumber?(e.openBlock(),e.createElementBlock("div",G,[c[1]||(c[1]=e.createElementVNode("span",{class:"label"},"Invoice Number:",-1)),e.createElementVNode("span",j,e.toDisplayString(o.value.invoiceNumber),1)])):e.createCommentVNode("",!0),o.value.merchantReference?(e.openBlock(),e.createElementBlock("div",W,[c[2]||(c[2]=e.createElementVNode("span",{class:"label"},"Reference:",-1)),e.createElementVNode("span",X,e.toDisplayString(o.value.merchantReference),1)])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),p.value?(e.openBlock(),e.createElementBlock("div",Y,[c[3]||(c[3]=e.createElementVNode("div",{class:"error-icon"}," ⚠️ ",-1)),e.createElementVNode("p",null,e.toDisplayString(p.value),1)])):e.createCommentVNode("",!0),e.createElementVNode("div",Z,[e.createElementVNode("button",{disabled:v.value||!b.value,class:"submit-button",onClick:k},e.toDisplayString(v.value?"Processing...":`Confirm Payment ${u.value}${y.value}`),9,Q)])])]))}}),te=P(ee,[["__scopeId","data-v-4d12cc1a"]]);exports.AdyenPayment=H;exports.DelayedPayment=te;exports.StripePayment=M;