@flopay/js 1.0.3 → 1.1.0
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/dist/index.cjs +36 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -14
- package/dist/index.d.ts +13 -14
- package/dist/index.mjs +36 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _flopay_shared from '@flopay/shared';
|
|
2
|
-
import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails,
|
|
2
|
+
import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails, CheckoutGateways, ProcessPaymentParams, InlineSessionDraft, CreateSessionParams, CheckoutSessionResult } from '@flopay/shared';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Manages the creation and lifecycle of payment elements.
|
|
@@ -106,8 +106,7 @@ declare class FloPay {
|
|
|
106
106
|
*
|
|
107
107
|
* Instances are cached per `publishableKey`, so calling `loadFloPay` twice
|
|
108
108
|
* with the same key returns the same instance. Different keys produce
|
|
109
|
-
* independent instances that can run side-by-side
|
|
110
|
-
* PayPal Stripe account).
|
|
109
|
+
* independent instances that can run side-by-side.
|
|
111
110
|
*
|
|
112
111
|
* @example
|
|
113
112
|
* ```ts
|
|
@@ -226,11 +225,10 @@ declare function clearSessionDisplayData(sessionId: string): void;
|
|
|
226
225
|
interface BillingResponse<T> {
|
|
227
226
|
data: T;
|
|
228
227
|
}
|
|
229
|
-
/** Raw checkout session from the billing API
|
|
228
|
+
/** Raw checkout session from the billing API. */
|
|
230
229
|
interface RawCheckoutSession {
|
|
231
230
|
uuid: string;
|
|
232
231
|
nonce: string;
|
|
233
|
-
gateway?: BillingProvider;
|
|
234
232
|
status: 'pending' | 'completed' | 'expired';
|
|
235
233
|
successUrl: string;
|
|
236
234
|
cancelUrl: string;
|
|
@@ -286,11 +284,7 @@ interface RawCheckoutSession {
|
|
|
286
284
|
}>;
|
|
287
285
|
coupons?: string[];
|
|
288
286
|
checkoutMode?: 'full' | 'auto' | 'confirm';
|
|
289
|
-
|
|
290
|
-
publishableKey?: string | null;
|
|
291
|
-
stripeClientSecret?: string | null;
|
|
292
|
-
paypalPublishableKey?: string | null;
|
|
293
|
-
};
|
|
287
|
+
gateways?: CheckoutGateways;
|
|
294
288
|
accountData: {
|
|
295
289
|
userId: string;
|
|
296
290
|
firstName: string;
|
|
@@ -352,9 +346,9 @@ declare class PaymentAPI {
|
|
|
352
346
|
/**
|
|
353
347
|
* Fetch and normalize a checkout session.
|
|
354
348
|
*
|
|
355
|
-
* Reads the backend's `
|
|
356
|
-
* then wraps the session in a `NormalizedCheckoutSession` for
|
|
357
|
-
*
|
|
349
|
+
* Reads the backend's `gateways` map to enumerate provider-specific data,
|
|
350
|
+
* then wraps the session in a `NormalizedCheckoutSession` for provider-
|
|
351
|
+
* agnostic consumption.
|
|
358
352
|
*/
|
|
359
353
|
getUnifiedCheckoutSession(checkoutSessionId: string): Promise<NormalizedCheckoutSession>;
|
|
360
354
|
/**
|
|
@@ -362,8 +356,13 @@ declare class PaymentAPI {
|
|
|
362
356
|
*
|
|
363
357
|
* The backend will either succeed, return `type: '3ds_required'`
|
|
364
358
|
* (with a `threeDSecureToken`), or return `type: 'paypal_redirect_required'`.
|
|
359
|
+
*
|
|
360
|
+
* @param userId Vestigial — backend's GatewayInterceptor routes via session,
|
|
361
|
+
* not headers, so this value is no longer sent on the wire. Kept in the
|
|
362
|
+
* signature for back-compat with existing callers; will be removed in a
|
|
363
|
+
* future major version.
|
|
365
364
|
*/
|
|
366
|
-
processPayment(
|
|
365
|
+
processPayment(_userId: string, data: ProcessPaymentParams, options?: {
|
|
367
366
|
pollTimeoutMs?: number;
|
|
368
367
|
}): Promise<Response>;
|
|
369
368
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _flopay_shared from '@flopay/shared';
|
|
2
|
-
import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails,
|
|
2
|
+
import { PaymentProviderAdapter, ElementOptions, ElementType, MountedElement, FloPayError, FloPayConfig, CreatePaymentMethodResult, ConfirmCardPaymentParams, ConfirmCardPaymentResult, ConfirmPaymentParams, PaymentResult, CheckoutSession, NormalizedCheckoutSession, BillingDetails, CheckoutGateways, ProcessPaymentParams, InlineSessionDraft, CreateSessionParams, CheckoutSessionResult } from '@flopay/shared';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Manages the creation and lifecycle of payment elements.
|
|
@@ -106,8 +106,7 @@ declare class FloPay {
|
|
|
106
106
|
*
|
|
107
107
|
* Instances are cached per `publishableKey`, so calling `loadFloPay` twice
|
|
108
108
|
* with the same key returns the same instance. Different keys produce
|
|
109
|
-
* independent instances that can run side-by-side
|
|
110
|
-
* PayPal Stripe account).
|
|
109
|
+
* independent instances that can run side-by-side.
|
|
111
110
|
*
|
|
112
111
|
* @example
|
|
113
112
|
* ```ts
|
|
@@ -226,11 +225,10 @@ declare function clearSessionDisplayData(sessionId: string): void;
|
|
|
226
225
|
interface BillingResponse<T> {
|
|
227
226
|
data: T;
|
|
228
227
|
}
|
|
229
|
-
/** Raw checkout session from the billing API
|
|
228
|
+
/** Raw checkout session from the billing API. */
|
|
230
229
|
interface RawCheckoutSession {
|
|
231
230
|
uuid: string;
|
|
232
231
|
nonce: string;
|
|
233
|
-
gateway?: BillingProvider;
|
|
234
232
|
status: 'pending' | 'completed' | 'expired';
|
|
235
233
|
successUrl: string;
|
|
236
234
|
cancelUrl: string;
|
|
@@ -286,11 +284,7 @@ interface RawCheckoutSession {
|
|
|
286
284
|
}>;
|
|
287
285
|
coupons?: string[];
|
|
288
286
|
checkoutMode?: 'full' | 'auto' | 'confirm';
|
|
289
|
-
|
|
290
|
-
publishableKey?: string | null;
|
|
291
|
-
stripeClientSecret?: string | null;
|
|
292
|
-
paypalPublishableKey?: string | null;
|
|
293
|
-
};
|
|
287
|
+
gateways?: CheckoutGateways;
|
|
294
288
|
accountData: {
|
|
295
289
|
userId: string;
|
|
296
290
|
firstName: string;
|
|
@@ -352,9 +346,9 @@ declare class PaymentAPI {
|
|
|
352
346
|
/**
|
|
353
347
|
* Fetch and normalize a checkout session.
|
|
354
348
|
*
|
|
355
|
-
* Reads the backend's `
|
|
356
|
-
* then wraps the session in a `NormalizedCheckoutSession` for
|
|
357
|
-
*
|
|
349
|
+
* Reads the backend's `gateways` map to enumerate provider-specific data,
|
|
350
|
+
* then wraps the session in a `NormalizedCheckoutSession` for provider-
|
|
351
|
+
* agnostic consumption.
|
|
358
352
|
*/
|
|
359
353
|
getUnifiedCheckoutSession(checkoutSessionId: string): Promise<NormalizedCheckoutSession>;
|
|
360
354
|
/**
|
|
@@ -362,8 +356,13 @@ declare class PaymentAPI {
|
|
|
362
356
|
*
|
|
363
357
|
* The backend will either succeed, return `type: '3ds_required'`
|
|
364
358
|
* (with a `threeDSecureToken`), or return `type: 'paypal_redirect_required'`.
|
|
359
|
+
*
|
|
360
|
+
* @param userId Vestigial — backend's GatewayInterceptor routes via session,
|
|
361
|
+
* not headers, so this value is no longer sent on the wire. Kept in the
|
|
362
|
+
* signature for back-compat with existing callers; will be removed in a
|
|
363
|
+
* future major version.
|
|
365
364
|
*/
|
|
366
|
-
processPayment(
|
|
365
|
+
processPayment(_userId: string, data: ProcessPaymentParams, options?: {
|
|
367
366
|
pollTimeoutMs?: number;
|
|
368
367
|
}): Promise<Response>;
|
|
369
368
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -603,9 +603,9 @@ var PaymentAPI = class {
|
|
|
603
603
|
/**
|
|
604
604
|
* Fetch and normalize a checkout session.
|
|
605
605
|
*
|
|
606
|
-
* Reads the backend's `
|
|
607
|
-
* then wraps the session in a `NormalizedCheckoutSession` for
|
|
608
|
-
*
|
|
606
|
+
* Reads the backend's `gateways` map to enumerate provider-specific data,
|
|
607
|
+
* then wraps the session in a `NormalizedCheckoutSession` for provider-
|
|
608
|
+
* agnostic consumption.
|
|
609
609
|
*/
|
|
610
610
|
async getUnifiedCheckoutSession(checkoutSessionId) {
|
|
611
611
|
const res = await this.getCheckoutSession(checkoutSessionId);
|
|
@@ -616,16 +616,18 @@ var PaymentAPI = class {
|
|
|
616
616
|
*
|
|
617
617
|
* The backend will either succeed, return `type: '3ds_required'`
|
|
618
618
|
* (with a `threeDSecureToken`), or return `type: 'paypal_redirect_required'`.
|
|
619
|
+
*
|
|
620
|
+
* @param userId Vestigial — backend's GatewayInterceptor routes via session,
|
|
621
|
+
* not headers, so this value is no longer sent on the wire. Kept in the
|
|
622
|
+
* signature for back-compat with existing callers; will be removed in a
|
|
623
|
+
* future major version.
|
|
619
624
|
*/
|
|
620
|
-
async processPayment(
|
|
625
|
+
async processPayment(_userId, data, options) {
|
|
621
626
|
const response = await fetch(
|
|
622
627
|
`${this.baseUrl}/v1/checkouts/sessions/process`,
|
|
623
628
|
{
|
|
624
629
|
method: "POST",
|
|
625
|
-
headers: {
|
|
626
|
-
"Content-Type": "application/json",
|
|
627
|
-
"x-user-id": userId
|
|
628
|
-
},
|
|
630
|
+
headers: { "Content-Type": "application/json" },
|
|
629
631
|
body: JSON.stringify(data)
|
|
630
632
|
}
|
|
631
633
|
);
|
|
@@ -756,7 +758,7 @@ var PaymentAPI = class {
|
|
|
756
758
|
throw await buildApiErrorFromResponse(response, "Failed to create checkout session");
|
|
757
759
|
}
|
|
758
760
|
const body = await response.json();
|
|
759
|
-
if (body.data && "
|
|
761
|
+
if (body.data && "gateways" in body.data) {
|
|
760
762
|
this.autoCacheDisplayData(body.data.uuid, params);
|
|
761
763
|
const merged = this.mergeCachedDisplayData(body.data);
|
|
762
764
|
return {
|
|
@@ -809,41 +811,38 @@ var PaymentAPI = class {
|
|
|
809
811
|
}
|
|
810
812
|
/** Normalize a raw session into a provider-agnostic shape. */
|
|
811
813
|
normalizeRawSession(session) {
|
|
812
|
-
const
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
}
|
|
821
|
-
if (gateway === "stripe") {
|
|
814
|
+
const gateways = session.gateways ?? {};
|
|
815
|
+
const providers = [];
|
|
816
|
+
const data = {
|
|
817
|
+
session: this.toCheckoutSession(session)
|
|
818
|
+
};
|
|
819
|
+
const stripeGateway = gateways.stripe;
|
|
820
|
+
if (stripeGateway?.publishableKey) {
|
|
821
|
+
providers.push("stripe");
|
|
822
822
|
const rawSession = session;
|
|
823
|
-
const gatewayDataRecord = session.gatewayData ?? {};
|
|
824
823
|
const stripeClientSecret = [
|
|
825
824
|
rawSession["stripeClientSecret"],
|
|
826
|
-
|
|
827
|
-
gatewayDataRecord["clientSecret"]
|
|
825
|
+
stripeGateway.stripeClientSecret
|
|
828
826
|
].find((value) => typeof value === "string" && value.length > 0);
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
827
|
+
data.stripe = {
|
|
828
|
+
clientSecret: stripeClientSecret ?? "",
|
|
829
|
+
publishableKey: stripeGateway.publishableKey ?? void 0,
|
|
830
|
+
paypalPublishableKey: stripeGateway.paypalPublishableKey ?? void 0,
|
|
831
|
+
environment: stripeGateway.environment
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
const paypalGateway = gateways.paypal;
|
|
835
|
+
if (paypalGateway?.publishableKey) {
|
|
836
|
+
providers.push("paypal");
|
|
837
|
+
data.paypal = {
|
|
838
|
+
publishableKey: paypalGateway.publishableKey,
|
|
839
|
+
environment: paypalGateway.environment
|
|
841
840
|
};
|
|
842
841
|
}
|
|
843
842
|
return {
|
|
844
|
-
|
|
843
|
+
providers,
|
|
845
844
|
mode: "tokenize",
|
|
846
|
-
data
|
|
845
|
+
data,
|
|
847
846
|
raw: { data: session }
|
|
848
847
|
};
|
|
849
848
|
}
|
|
@@ -885,8 +884,7 @@ var PaymentAPI = class {
|
|
|
885
884
|
cancelUrl: raw.cancelUrl,
|
|
886
885
|
coupons: raw.coupons,
|
|
887
886
|
createdAt: raw.createdAt,
|
|
888
|
-
|
|
889
|
-
gatewayData: raw.gatewayData,
|
|
887
|
+
gateways: raw.gateways,
|
|
890
888
|
accountData: raw.accountData,
|
|
891
889
|
tagsData: raw.tagsData
|
|
892
890
|
};
|