@bcc-code/payment-client 1.1.3 → 1.1.5
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 +39 -32
- package/dist/components/index.js +1 -1
- package/dist/components/index.mjs +155 -134
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/styles/adyen.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -196,19 +196,26 @@ For manual payment processing via invoice or bank transfer:
|
|
|
196
196
|
|
|
197
197
|
```vue
|
|
198
198
|
<template>
|
|
199
|
-
<
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
199
|
+
<div v-if="!paymentSuccess">
|
|
200
|
+
<DelayedPayment
|
|
201
|
+
:payment-id="payment.paymentId"
|
|
202
|
+
:client-data="payment.clientData"
|
|
203
|
+
:amount="99.99"
|
|
204
|
+
currency="EUR"
|
|
205
|
+
:tenant-id="tenantId"
|
|
206
|
+
@success="handleSuccess"
|
|
207
|
+
@error="handleError"
|
|
208
|
+
@ready="handleReady"
|
|
209
|
+
/>
|
|
210
|
+
</div>
|
|
211
|
+
<div v-else>
|
|
212
|
+
<h2>✅ Payment Confirmed!</h2>
|
|
213
|
+
<p>{{ successMessage }}</p>
|
|
214
|
+
</div>
|
|
209
215
|
</template>
|
|
210
216
|
|
|
211
217
|
<script setup lang="ts">
|
|
218
|
+
import { ref } from 'vue'
|
|
212
219
|
import { PaymentClient } from '@bcc-code/payment-client'
|
|
213
220
|
import { DelayedPayment } from '@bcc-code/payment-client/components'
|
|
214
221
|
|
|
@@ -221,15 +228,20 @@ const paymentClient = new PaymentClient({
|
|
|
221
228
|
const payment = await paymentClient.createPayment({
|
|
222
229
|
amount: 99.99,
|
|
223
230
|
currency: 'EUR',
|
|
224
|
-
paymentMethodType: 'delayed-payment'
|
|
225
|
-
returnUrl: 'https://clientapp.pl/success' // IMPORTANT: User returns here after confirmation
|
|
231
|
+
paymentMethodType: 'delayed-payment'
|
|
226
232
|
})
|
|
227
233
|
|
|
228
234
|
const tenantId = 'your-tenant-uuid'
|
|
235
|
+
const paymentSuccess = ref(false)
|
|
236
|
+
const successMessage = ref('')
|
|
229
237
|
|
|
230
238
|
const handleSuccess = (result: any) => {
|
|
231
239
|
console.log('Payment confirmed:', result)
|
|
240
|
+
paymentSuccess.value = true
|
|
241
|
+
successMessage.value = result.message
|
|
242
|
+
|
|
232
243
|
// Payment will be processed manually
|
|
244
|
+
// result contains: { status, message, paymentId, transactionNumber }
|
|
233
245
|
}
|
|
234
246
|
|
|
235
247
|
const handleError = (error: any) => {
|
|
@@ -242,22 +254,14 @@ const handleReady = () => {
|
|
|
242
254
|
</script>
|
|
243
255
|
```
|
|
244
256
|
|
|
245
|
-
**
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const message = urlParams.get('message') // User-friendly message
|
|
257
|
+
**How it works:**
|
|
258
|
+
1. User reviews invoice details
|
|
259
|
+
2. User clicks "Confirm Payment"
|
|
260
|
+
3. Component makes API call in-place (no redirect!)
|
|
261
|
+
4. Success event emitted with payment details
|
|
262
|
+
5. Your app shows success message
|
|
252
263
|
|
|
253
|
-
|
|
254
|
-
// Payment confirmed successfully
|
|
255
|
-
showSuccessMessage(message)
|
|
256
|
-
} else if (status === 'error') {
|
|
257
|
-
// Payment confirmation failed
|
|
258
|
-
showErrorMessage(message)
|
|
259
|
-
}
|
|
260
|
-
```
|
|
264
|
+
**No redirect, no return URL handling needed!** The delayed payment component now works exactly like Stripe and Adyen components - simple event-driven API.
|
|
261
265
|
|
|
262
266
|
### Component Props
|
|
263
267
|
|
|
@@ -296,13 +300,15 @@ if (status === 'success') {
|
|
|
296
300
|
|
|
297
301
|
### Component Events
|
|
298
302
|
|
|
299
|
-
|
|
303
|
+
All components emit the same events for consistency:
|
|
300
304
|
|
|
301
305
|
- `@success` - Payment completed successfully
|
|
306
|
+
- **Stripe/Adyen:** Payment authorized/captured
|
|
307
|
+
- **Delayed Payment:** Invoice confirmation completed
|
|
302
308
|
- `@error` - Payment error occurred
|
|
303
309
|
- `@ready` - Payment form is ready
|
|
304
|
-
- `@submit` - Payment
|
|
305
|
-
- `@additionalDetails` - Additional details required (Adyen only)
|
|
310
|
+
- `@submit` - Payment submission started (fired before processing)
|
|
311
|
+
- `@additionalDetails` - Additional details required (Adyen only, for 3D Secure)
|
|
306
312
|
|
|
307
313
|
### Tree-shaking
|
|
308
314
|
|
|
@@ -413,8 +419,9 @@ const createPayment = async () => {
|
|
|
413
419
|
payment.value = await paymentClient.createPayment({
|
|
414
420
|
amount,
|
|
415
421
|
currency,
|
|
416
|
-
paymentMethodType: provider
|
|
417
|
-
returnUrl
|
|
422
|
+
paymentMethodType: provider
|
|
423
|
+
// No returnUrl needed for delayed-payment in v2.0+
|
|
424
|
+
// Stripe/Adyen may still use returnUrl for 3D Secure redirects
|
|
418
425
|
})
|
|
419
426
|
} catch (err) {
|
|
420
427
|
error.value = err instanceof Error ? err.message : 'Failed to create payment'
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var S=Object.create;var P=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var w=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var R=(s,m,l,t)=>{if(m&&typeof m=="object"||typeof m=="function")for(let a of B(m))!K.call(s,a)&&a!==l&&P(s,a,{get:()=>m[a],enumerable:!(t=V(m,a))||t.enumerable});return s};var C=(s,m,l)=>(l=s!=null?S(w(s)):{},R(m||!s||!s.__esModule?P(l,"default",{value:s,enumerable:!0}):l,s));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),U={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(s,{expose:m,emit:l}){const t=s,a=l,v=e.ref(),p=e.ref(!0),o=e.ref(!1),d=e.ref("");let y=null,b=null,f=null;const D=e.computed(()=>({EUR:"€",USD:"$",GBP:"£",CHF:"CHF",NOK:"kr",SEK:"kr",DKK:"kr",PLN:"zł",CZK:"Kč",HUF:"Ft"})[t.currency]||t.currency),k=e.computed(()=>t.amount.toFixed(2)),r=e.computed(()=>{if(t.clientData)try{const i=JSON.parse(t.clientData);return i.clientSecret||i.client_secret}catch{return}}),u=async()=>{if(!v.value)return;let i=t.publishableKey;if(!i&&t.clientData)try{const c=JSON.parse(t.clientData);i=c.publishableKey||c.publishable_key}catch{}if(!i){d.value="Publishable key is required",p.value=!1;return}try{p.value=!0,d.value="";const{loadStripe:c}=await import("@stripe/stripe-js");if(y=await c(i),!y)throw new Error("Failed to load Stripe");const n=r.value,h={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&&(h.clientSecret=n),b=y.elements(h),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",_=>{_.error?(d.value=_.error.message,a("error",_.error)):d.value=""})}catch(c){d.value=c instanceof Error?c.message:"Failed to initialize payment form",p.value=!1,a("error",c)}},E=async()=>{if(!(!y||!f)){o.value=!0,d.value="";try{const i=t.returnUrl||`${window.location.origin}/payment/return`,{error:c,paymentIntent:n}=await y.confirmPayment({elements:b,confirmParams:{return_url:i},redirect:"if_required"});c?(d.value=c.message||"Payment failed",a("error",c)):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(i){d.value=i instanceof Error?i.message:"Payment failed",a("error",i)}finally{o.value=!1}}},g=()=>{f&&(f.destroy(),f=null),b&&(b=null),y&&(y=null)};return e.onMounted(()=>{u()}),e.onUnmounted(()=>{g()}),e.watch(()=>t.currency,()=>{g(),u()}),e.watch([()=>t.publishableKey,()=>t.clientData],()=>{(t.publishableKey||t.clientData)&&(g(),u())}),m({destroyElements:g}),(i,c)=>(e.openBlock(),e.createElementBlock("div",U,[e.createElementVNode("div",{ref_key:"elementsContainer",ref:v,class:"elements-container"},null,512),p.value?(e.openBlock(),e.createElementBlock("div",A,[...c[0]||(c[0]=[e.createElementVNode("div",{class:"loading-spinner"},null,-1),e.createElementVNode("p",null,"Loading payment form...",-1)])])):e.createCommentVNode("",!0),d.value?(e.openBlock(),e.createElementBlock("div",F,[c[1]||(c[1]=e.createElementVNode("div",{class:"error-icon"}," ⚠️ ",-1)),e.createElementVNode("p",null,e.toDisplayString(d.value),1),e.createElementVNode("button",{class:"retry-btn",onClick:u}," Retry ")])):e.createCommentVNode("",!0),s.showPayButton&&!p.value&&!d.value?(e.openBlock(),e.createElementBlock("div",I,[e.createElementVNode("button",{disabled:o.value,class:"payment-button",onClick:E},e.toDisplayString(o.value?"Processing...":`Pay ${D.value}${k.value}`),9,$)])):e.createCommentVNode("",!0)]))}}),N=(s,m)=>{const l=s.__vccOpts||s;for(const[t,a]of m)l[t]=a;return l},M=N(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(s,{emit:m}){const l=s,t=m,a=e.ref(null),v=()=>{if(!l.clientData)return console.error("No clientData provided"),null;try{const o=JSON.parse(l.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 d;if(!l.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:D,Klarna:k,Blik:r,Dropin:u}=await import("@adyen/adyen-web"),E={environment:l.environment||"test",clientKey:l.clientKey,session:o,onPaymentCompleted:(n,h)=>{console.info("Payment Completed:",n,h),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,h)=>{console.error("Adyen Error:",n.name,n.message,n.stack,h),t("error",n)}},g={showPayButton:!0,paymentMethodComponents:[b,f,D,k,r],paymentMethodsConfiguration:{card:{hasHolderName:!0,holderNameRequired:!0,billingAddressRequired:!1,enableStoreDetails:!1},applePay:{showPayButton:!0},googlePay:{showPayButton:!0},klarna:{useKlarnaWidget:!0},blik:{}}},i=await y(E);console.log("Adyen Checkout created:",i),console.log("Available payment methods from session:",(d=i.paymentMethodsResponse)==null?void 0:d.paymentMethods);const c=new u(i,g);console.log("Adyen Drop-in created with session payment methods"),a.value&&(c.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(()=>l.clientData,()=>{a.value&&(a.value.innerHTML="",p())}),(o,d)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"dropinContainer",ref:a,class:"payment-dropin"},null,512))}}),H=N(O,[["__scopeId","data-v-ef2ec054"]]),z={class:"delayed-payment"},L={class:"payment-form"},q={class:"amount-display"},J={class:"amount-value"},G={key:0,class:"session-info"},T={key:0,class:"info-row"},j={class:"value"},W={key:1,class:"info-row"},Z={class:"value"},Q={key:1,class:"error-message"},X={class:"button-container"},Y=["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(s,{expose:m,emit:l}){const t=s,a=l,v=e.ref(!1),p=e.ref(""),o=e.ref({}),d=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.confirmationUrl),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,paymentId:r.paymentId,confirmationUrl:r.confirmationUrl,returnUrl:r.returnUrl},a("ready")}catch(r){console.error("Failed to parse clientData:",r),p.value="Invalid session data",a("error",r)}},D=()=>{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,timestamp:new Date().toISOString()};if(a("submit",r),!o.value.confirmationUrl)throw new Error("Confirmation URL not provided");window.location.href=o.value.confirmationUrl}catch(r){p.value=r instanceof Error?r.message:"Failed to confirm payment",a("error",r),v.value=!1}}},k=()=>{p.value=""};return e.onMounted(()=>{f()}),m({clearError:k}),(r,u)=>(e.openBlock(),e.createElementBlock("div",z,[e.createElementVNode("div",L,[u[4]||(u[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,[u[0]||(u[0]=e.createElementVNode("span",{class:"amount-label"},"Amount to pay:",-1)),e.createElementVNode("span",J,e.toDisplayString(d.value)+e.toDisplayString(y.value),1)]),b.value?(e.openBlock(),e.createElementBlock("div",G,[o.value.invoiceNumber?(e.openBlock(),e.createElementBlock("div",T,[u[1]||(u[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,[u[2]||(u[2]=e.createElementVNode("span",{class:"label"},"Reference:",-1)),e.createElementVNode("span",Z,e.toDisplayString(o.value.merchantReference),1)])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),p.value?(e.openBlock(),e.createElementBlock("div",Q,[u[3]||(u[3]=e.createElementVNode("div",{class:"error-icon"}," ⚠️ ",-1)),e.createElementVNode("p",null,e.toDisplayString(p.value),1)])):e.createCommentVNode("",!0),e.createElementVNode("div",X,[e.createElementVNode("button",{disabled:v.value||!b.value,class:"submit-button",onClick:D},e.toDisplayString(v.value?"Processing...":`Confirm Payment ${d.value}${y.value}`),9,Y)])])]))}}),te=N(ee,[["__scopeId","data-v-d0f79a32"]]);exports.AdyenPayment=H;exports.DelayedPayment=te;exports.StripePayment=M;
|
|
1
|
+
"use strict";var S=Object.create;var P=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var B=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var R=(l,m,i,t)=>{if(m&&typeof m=="object"||typeof m=="function")for(let o of V(m))!K.call(l,o)&&o!==i&&P(l,o,{get:()=>m[o],enumerable:!(t=w(m,o))||t.enumerable});return l};var C=(l,m,i)=>(i=l!=null?S(B(l)):{},R(m||!l||!l.__esModule?P(i,"default",{value:l,enumerable:!0}):i,l));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),A={class:"stripe-elements"},U={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,o=i,v=e.ref(),p=e.ref(!0),a=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,o("ready")}),f.on("change",N=>{N.error?(u.value=N.error.message,o("error",N.error)):u.value=""})}catch(d){u.value=d instanceof Error?d.message:"Failed to initialize payment form",p.value=!1,o("error",d)}},h=async()=>{if(!(!y||!f)){a.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",o("error",d)):n?n.status==="succeeded"?o("success",{paymentIntent:n,status:"succeeded",message:"Payment completed successfully!"}):n.status==="processing"?o("success",{paymentIntent:n,status:"processing",message:"Payment is being processed..."}):o("submit",{paymentIntent:n,status:n.status}):o("submit",f)}catch(s){u.value=s instanceof Error?s.message:"Payment failed",o("error",s)}finally{a.value=!1}}},g=()=>{f&&(f.destroy(),f=null),b&&(b=null),y&&(y=null)};return e.onMounted(()=>{c()}),e.onUnmounted(()=>{g()}),e.watch(()=>t.currency,()=>{g(),c()}),e.watch([()=>t.publishableKey,()=>t.clientData],()=>{(t.publishableKey||t.clientData)&&(g(),c())}),m({destroyElements:g}),(s,d)=>(e.openBlock(),e.createElementBlock("div",A,[e.createElementVNode("div",{ref_key:"elementsContainer",ref:v,class:"elements-container"},null,512),p.value?(e.openBlock(),e.createElementBlock("div",U,[...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:a.value,class:"payment-button",onClick:h},e.toDisplayString(a.value?"Processing...":`Pay ${k.value}${E.value}`),9,$)])):e.createCommentVNode("",!0)]))}}),_=(l,m)=>{const i=l.__vccOpts||l;for(const[t,o]of m)i[t]=o;return i},M=_(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,o=e.ref(null),v=()=>{if(!i.clientData)return console.error("No clientData provided"),null;try{const a=JSON.parse(i.clientData);return console.log("Parsed Adyen session data:",a),{id:a.id,sessionData:a.sessionData,amount:a.amount,reference:a.reference,returnUrl:a.returnUrl,merchantAccount:a.merchantAccount}}catch(a){return console.error("Failed to parse clientData:",a),null}},p=async()=>{var u;if(!i.clientKey||!o.value){console.error("Initialization failed: Missing clientKey or container.");return}const a=v();if(!a){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"),h={environment:i.environment||"test",clientKey:i.clientKey,session:a,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)}},g={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(h);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,g);console.log("Adyen Drop-in created with session payment methods"),o.value&&(d.mount(o.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,()=>{o.value&&(o.value.innerHTML="",p())}),(a,u)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"dropinContainer",ref:o,class:"payment-dropin"},null,512))}}),H=_(O,[["__scopeId","data-v-ef2ec054"]]),T={class:"delayed-payment"},z={class:"payment-form"},L={class:"amount-display"},j={class:"amount-value"},q={key:0,class:"session-info"},J={key:0,class:"info-row"},G={class:"value"},W={key:1,class:"info-row"},X={class:"value"},Z={key:1,class:"error-message"},Q={class:"button-container"},Y=["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,o=i,v=e.ref(!1),p=e.ref(""),a=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(()=>a.value.transactionNumber&&a.value.confirmationUrl),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),a.value={transactionNumber:r.transactionNumber,merchantReference:r.merchantReference,providerUid:r.providerUid,paymentId:r.paymentId,confirmationUrl:r.confirmationUrl},o("ready")}catch(r){console.error("Failed to parse clientData:",r),p.value="Invalid session data",o("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,transactionNumber:a.value.transactionNumber,merchantReference:a.value.merchantReference,timestamp:new Date().toISOString()};if(o("submit",r),!a.value.confirmationUrl)throw new Error("Confirmation URL not provided");const c={"Content-Type":"application/json",Accept:"application/json"};t.tenantId&&(c["X-Tenant-ID"]=t.tenantId);const h=await fetch(a.value.confirmationUrl,{method:"POST",headers:c,credentials:"include"});if(!h.ok){const s=await h.json();throw new Error(s.message||"Failed to confirm payment")}const g=await h.json();o("success",{status:"succeeded",message:g.message,paymentId:g.paymentId,transactionNumber:a.value.transactionNumber})}catch(r){p.value=r instanceof Error?r.message:"Failed to confirm payment",o("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",L,[c[0]||(c[0]=e.createElementVNode("span",{class:"amount-label"},"Amount to pay:",-1)),e.createElementVNode("span",j,e.toDisplayString(u.value)+e.toDisplayString(y.value),1)]),b.value?(e.openBlock(),e.createElementBlock("div",q,[a.value.transactionNumber?(e.openBlock(),e.createElementBlock("div",J,[c[1]||(c[1]=e.createElementVNode("span",{class:"label"},"Transaction Number:",-1)),e.createElementVNode("span",G,e.toDisplayString(a.value.transactionNumber),1)])):e.createCommentVNode("",!0),a.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(a.value.merchantReference),1)])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),p.value?(e.openBlock(),e.createElementBlock("div",Z,[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",Q,[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,Y)])])]))}}),te=_(ee,[["__scopeId","data-v-ebc5d9c9"]]);exports.AdyenPayment=H;exports.DelayedPayment=te;exports.StripePayment=M;
|