{"version":3,"file":"stripe-google-pay-adapter-B346KXt4.mjs","names":[],"sources":["../src/payment-methods/stripe-google-pay-adapter.ts"],"sourcesContent":["import type { PaymentRequest, PaymentRequestPaymentMethodEvent, Stripe, StripeConstructor } from \"@stripe/stripe-js\";\n\n// Stripe.js must be loaded via script tag for PCI compliance\ndeclare global {\n  interface Window {\n    Stripe?: StripeConstructor;\n  }\n}\n\nexport interface PaymentRequestConfig {\n  country: string;\n  currency: string;\n  total: { label: string; amount: number };\n  requestPayerName: boolean;\n  requestPayerEmail: boolean;\n}\n\nexport type ShowPaymentSheetResult =\n  | {\n      success: true;\n      paymentMethodId: string;\n      payerEmail?: string;\n      complete: (status: \"success\" | \"fail\") => void;\n    }\n  | { success: false; cancelled: true }\n  | { success: false; error: string };\n\nexport type ConfirmResult = { success: true } | { success: false; error: string };\n\nexport enum GooglePayMockScenario {\n  None = \"none\",\n  Success = \"success\",\n  Cancelled = \"cancelled\",\n}\n\nexport class StripeGooglePayAdapter {\n  private stripe: Stripe | null = null;\n  private paymentRequest: PaymentRequest | null = null;\n  private mockScenario: GooglePayMockScenario;\n\n  constructor(mockScenario?: GooglePayMockScenario) {\n    this.mockScenario = mockScenario ?? GooglePayMockScenario.None;\n  }\n\n  initialize(publishableKey: string): boolean {\n    switch (this.mockScenario) {\n      case GooglePayMockScenario.None: {\n        console.log(\"[GooglePay] initialize called\");\n        if (!window.Stripe) {\n          console.log(\"[GooglePay] Stripe.js not loaded\");\n          return false;\n        }\n        this.stripe = window.Stripe(publishableKey);\n        const success = this.stripe !== null;\n        console.log(\"[GooglePay] initialize result:\", success);\n        return success;\n      }\n      case GooglePayMockScenario.Success:\n      case GooglePayMockScenario.Cancelled: {\n        console.log(\"[MockGooglePay] initialize called\");\n        console.log(\"[MockGooglePay] initialize result:\", true);\n        return true;\n      }\n    }\n  }\n\n  createPaymentRequest(config: PaymentRequestConfig): void {\n    switch (this.mockScenario) {\n      case GooglePayMockScenario.None: {\n        console.log(\"[GooglePay] createPaymentRequest called\", config);\n        if (!this.stripe) {\n          throw new Error(\"Stripe not initialized\");\n        }\n        this.paymentRequest = this.stripe.paymentRequest(config);\n        console.log(\"[GooglePay] paymentRequest created\");\n        return;\n      }\n      case GooglePayMockScenario.Success:\n      case GooglePayMockScenario.Cancelled: {\n        console.log(\"[MockGooglePay] createPaymentRequest called\", config);\n        return;\n      }\n    }\n  }\n\n  async canMakePayment(): Promise<boolean> {\n    switch (this.mockScenario) {\n      case GooglePayMockScenario.None: {\n        console.log(\"[GooglePay] canMakePayment called\");\n        if (!this.paymentRequest) {\n          console.log(\"[GooglePay] canMakePayment: no paymentRequest\");\n          return false;\n        }\n        const result = await this.paymentRequest.canMakePayment();\n        const isAvailable = result?.googlePay ?? false;\n        console.log(\"[GooglePay] canMakePayment result:\", { result, isAvailable });\n        return isAvailable;\n      }\n      case GooglePayMockScenario.Success:\n      case GooglePayMockScenario.Cancelled: {\n        console.log(\"[MockGooglePay] canMakePayment called\");\n        console.log(\"[MockGooglePay] canMakePayment result:\", { result: { googlePay: true }, isAvailable: true });\n        return true;\n      }\n    }\n  }\n\n  async showPaymentSheet(): Promise<ShowPaymentSheetResult> {\n    switch (this.mockScenario) {\n      case GooglePayMockScenario.None: {\n        console.log(\"[GooglePay] showPaymentSheet called\");\n        if (!this.paymentRequest) {\n          console.log(\"[GooglePay] showPaymentSheet: no paymentRequest\");\n          return { success: false, error: \"Payment request not created\" };\n        }\n\n        return new Promise((resolve) => {\n          // biome-ignore lint/style/noNonNullAssertion: checked above\n          this.paymentRequest!.on(\"paymentmethod\", (event: PaymentRequestPaymentMethodEvent) => {\n            console.log(\"[GooglePay] showPaymentSheet: paymentmethod event\", {\n              paymentMethodId: event.paymentMethod.id,\n              payerEmail: event.payerEmail,\n            });\n            resolve({\n              success: true,\n              paymentMethodId: event.paymentMethod.id,\n              payerEmail: event.payerEmail ?? undefined,\n              complete: (status) => {\n                console.log(\"[GooglePay] complete called:\", status);\n                event.complete(status);\n              },\n            });\n          });\n\n          // biome-ignore lint/style/noNonNullAssertion: checked above\n          this.paymentRequest!.on(\"cancel\", () => {\n            console.log(\"[GooglePay] showPaymentSheet: cancelled by user\");\n            resolve({ success: false, cancelled: true });\n          });\n\n          console.log(\"[GooglePay] showing payment sheet...\");\n          // biome-ignore lint/style/noNonNullAssertion: checked above\n          this.paymentRequest!.show();\n        });\n      }\n      case GooglePayMockScenario.Success: {\n        console.log(\"[MockGooglePay] showPaymentSheet: success\");\n        await new Promise((resolve) => setTimeout(resolve, 500));\n        return {\n          success: true,\n          paymentMethodId: \"pm_mock_123456789\",\n          payerEmail: \"mock@example.com\",\n          complete: (status) => console.log(`[MockGooglePay] complete: ${status}`),\n        };\n      }\n      case GooglePayMockScenario.Cancelled: {\n        console.log(\"[MockGooglePay] showPaymentSheet: cancelled\");\n        await new Promise((resolve) => setTimeout(resolve, 500));\n        return { success: false, cancelled: true };\n      }\n    }\n  }\n\n  async confirmCardSetup(clientSecret: string, paymentMethodId: string): Promise<ConfirmResult> {\n    switch (this.mockScenario) {\n      case GooglePayMockScenario.None: {\n        console.log(\"[GooglePay] confirmCardSetup called\", {\n          clientSecret: `${clientSecret.slice(0, 20)}...`,\n          paymentMethodId,\n        });\n        if (!this.stripe) {\n          console.log(\"[GooglePay] confirmCardSetup: Stripe not initialized\");\n          return { success: false, error: \"Stripe not initialized\" };\n        }\n\n        const { error } = await this.stripe.confirmCardSetup(clientSecret, {\n          payment_method: paymentMethodId,\n        });\n\n        if (error) {\n          console.log(\"[GooglePay] confirmCardSetup error:\", error);\n          return { success: false, error: error.message ?? \"Card setup failed\" };\n        }\n\n        console.log(\"[GooglePay] confirmCardSetup success\");\n        return { success: true };\n      }\n      case GooglePayMockScenario.Success: {\n        console.log(\"[MockGooglePay] confirmCardSetup called\", { clientSecret, paymentMethodId });\n        return { success: true };\n      }\n      case GooglePayMockScenario.Cancelled: {\n        throw new Error(\"confirmCardSetup should not be called when scenario is Cancelled\");\n      }\n    }\n  }\n}\n"],"mappings":";AA6BA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