@funnelsgrove/payments 0.1.25 → 0.1.27

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.
@@ -30,7 +30,6 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
30
30
  normalizeRuntimeConfigValue(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelVersionId),
31
31
  normalizeRuntimeConfigValue(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelSdkPublishableKey),
32
32
  ].join('|');
33
- const analyticsMetadataSignature = JSON.stringify(analyticsMetadata !== null && analyticsMetadata !== void 0 ? analyticsMetadata : {});
34
33
  const configured = enabled &&
35
34
  (isStripeConfigured(checkoutMode) ||
36
35
  Boolean(normalizeRuntimeConfigValue(runtimeConfig === null || runtimeConfig === void 0 ? void 0 : runtimeConfig.funnelSdkPublishableKey)));
@@ -38,7 +37,6 @@ export function useStripeSubscriptionCheckoutSession({ checkoutMode, analyticsMe
38
37
  'stripe',
39
38
  checkoutMode,
40
39
  runtimeConfigSignature,
41
- analyticsMetadataSignature,
42
40
  (couponId === null || couponId === void 0 ? void 0 : couponId.trim()) || '',
43
41
  returnUrl.trim(),
44
42
  ].join('|');
@@ -65,6 +65,28 @@ type CreatePaymentIntentResponse = {
65
65
  environment?: 'test' | 'live';
66
66
  };
67
67
  export declare function createStripePaymentIntent(input: CreatePaymentIntentInput): Promise<CreatePaymentIntentResponse>;
68
+ type ChargeOneClickPaymentInput = {
69
+ planId: string;
70
+ amountCents: number;
71
+ analyticsMetadata?: Record<string, unknown> | null;
72
+ checkoutSessionId?: string | null;
73
+ currency?: string | null;
74
+ idempotencyKey?: string | null;
75
+ stripe_customer_id?: string | null;
76
+ user_id?: string | null;
77
+ environment?: RuntimeMode;
78
+ runtimeConfig?: StripeRuntimeConfigOverrides;
79
+ };
80
+ type ChargeOneClickPaymentResponse = {
81
+ paymentIntentId: string;
82
+ status: string;
83
+ amountCents?: number;
84
+ clientSecret?: string;
85
+ currency?: string;
86
+ environment?: 'test' | 'live';
87
+ stripePublishableKey?: string;
88
+ };
89
+ export declare function chargeStripeOneClickPayment(input: ChargeOneClickPaymentInput): Promise<ChargeOneClickPaymentResponse>;
68
90
  type CreateSubscriptionCheckoutInput = {
69
91
  plan: CheckoutSessionPlanInput;
70
92
  couponId?: string | null;
@@ -527,12 +527,50 @@ export const resolveCheckoutPlanRecurringConfig = (plan) => {
527
527
  inferCheckoutPlanRecurringFromText(plan.id) ||
528
528
  inferCheckoutPlanRecurringFromText(plan.description));
529
529
  };
530
- const normalizeAnalyticsMetadata = (metadata) => {
531
- if (!metadata || !isRecord(metadata)) {
530
+ const SENSITIVE_CHECKOUT_URL_QUERY_KEYS = new Set([
531
+ 'customeremail',
532
+ 'customer_email',
533
+ 'email',
534
+ 'fullname',
535
+ 'full_name',
536
+ 'name',
537
+ 'phone',
538
+ 'phonenumber',
539
+ 'phone_number',
540
+ ]);
541
+ const sanitizeCheckoutUrl = (value) => {
542
+ if (typeof value !== 'string') {
543
+ return undefined;
544
+ }
545
+ const trimmed = value.trim();
546
+ if (!trimmed) {
547
+ return undefined;
548
+ }
549
+ try {
550
+ const parsed = new URL(trimmed, typeof window !== 'undefined' ? window.location.origin : 'https://example.invalid');
551
+ for (const key of Array.from(parsed.searchParams.keys())) {
552
+ if (SENSITIVE_CHECKOUT_URL_QUERY_KEYS.has(key.trim().toLowerCase())) {
553
+ parsed.searchParams.delete(key);
554
+ }
555
+ }
556
+ return parsed.toString();
557
+ }
558
+ catch (_a) {
559
+ return trimmed;
560
+ }
561
+ };
562
+ const currentCheckoutUrl = () => {
563
+ var _a;
564
+ if (typeof window === 'undefined') {
532
565
  return undefined;
533
566
  }
534
- const normalized = Object.fromEntries(Object.entries(metadata).filter(([, value]) => value !== undefined && value !== null && value !== ''));
535
- return Object.keys(normalized).length > 0 ? normalized : undefined;
567
+ return sanitizeCheckoutUrl((_a = window.location) === null || _a === void 0 ? void 0 : _a.href);
568
+ };
569
+ const normalizeAnalyticsMetadata = (metadata) => {
570
+ const normalized = Object.fromEntries(Object.entries(isRecord(metadata) ? metadata : {}).filter(([, value]) => value !== undefined && value !== null && value !== ''));
571
+ const checkoutUrl = sanitizeCheckoutUrl(normalized.url) || currentCheckoutUrl();
572
+ const withCheckoutUrl = checkoutUrl ? Object.assign(Object.assign({}, normalized), { url: checkoutUrl }) : normalized;
573
+ return Object.keys(withCheckoutUrl).length > 0 ? withCheckoutUrl : undefined;
536
574
  };
537
575
  export async function createStripePaymentIntent(input) {
538
576
  var _a, _b;
@@ -560,6 +598,35 @@ export async function createStripePaymentIntent(input) {
560
598
  }
561
599
  return (await response.json());
562
600
  }
601
+ export async function chargeStripeOneClickPayment(input) {
602
+ var _a, _b, _c, _d, _e;
603
+ const runtimeConfig = resolveStripeRuntimeConfig(input.runtimeConfig);
604
+ const response = await fetch(buildStripeRuntimeApiUrl('/sdk/public/payments/one-click', runtimeConfig), {
605
+ method: 'POST',
606
+ headers: buildStripeRuntimeHeaders(runtimeConfig, {
607
+ 'Content-Type': 'application/json',
608
+ }),
609
+ body: JSON.stringify({
610
+ publishableKey: runtimeConfig.funnelSdkPublishableKey || undefined,
611
+ funnelId: runtimeConfig.funnelId || undefined,
612
+ funnelVersionId: runtimeConfig.funnelVersionId || undefined,
613
+ planId: input.planId,
614
+ amountCents: input.amountCents,
615
+ currency: ((_a = input.currency) === null || _a === void 0 ? void 0 : _a.trim()) || undefined,
616
+ analyticsMetadata: normalizeAnalyticsMetadata(input.analyticsMetadata),
617
+ user_id: ((_b = input.user_id) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
618
+ stripe_customer_id: ((_c = input.stripe_customer_id) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
619
+ checkoutSessionId: ((_d = input.checkoutSessionId) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
620
+ idempotencyKey: ((_e = input.idempotencyKey) === null || _e === void 0 ? void 0 : _e.trim()) || undefined,
621
+ environment: input.environment || undefined,
622
+ }),
623
+ });
624
+ if (!response.ok) {
625
+ const errorMessage = await parseErrorMessage(response, 'Unable to charge one-click payment');
626
+ throw new Error(errorMessage);
627
+ }
628
+ return (await response.json());
629
+ }
563
630
  export async function createStripeSubscriptionCheckout(input) {
564
631
  var _a, _b, _c, _d, _e;
565
632
  const recurring = resolveCheckoutPlanRecurringConfig(input.plan);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnelsgrove/payments",
3
- "version": "0.1.25",
3
+ "version": "0.1.27",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",