@payment-kit-js/vanilla 0.1.0-alpha.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/README.md +755 -0
- package/dist/cardsetupintent-D2gBMj3e.d.mts +35 -0
- package/dist/cardsetupintent-D2gBMj3e.d.mts.map +1 -0
- package/dist/connect-card-DO2EJxu6.mjs +19 -0
- package/dist/connect-card-DO2EJxu6.mjs.map +1 -0
- package/dist/connect-card-EaOlRbPS.d.mts +25 -0
- package/dist/connect-card-EaOlRbPS.d.mts.map +1 -0
- package/dist/connect-tunnel-x-BhVAej5Q.mjs +44 -0
- package/dist/connect-tunnel-x-BhVAej5Q.mjs.map +1 -0
- package/dist/connect-tunnel-x-Ce423Pa2.d.mts +92 -0
- package/dist/connect-tunnel-x-Ce423Pa2.d.mts.map +1 -0
- package/dist/index.d.mts +11 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +69 -0
- package/dist/index.mjs.map +1 -0
- package/dist/next-action-handlers-DTsWjUIA.mjs +53 -0
- package/dist/next-action-handlers-DTsWjUIA.mjs.map +1 -0
- package/dist/payment-methods/card.d.mts +22 -0
- package/dist/payment-methods/card.d.mts.map +1 -0
- package/dist/payment-methods/card.mjs +183 -0
- package/dist/payment-methods/card.mjs.map +1 -0
- package/dist/payment-methods/google-pay.d.mts +49 -0
- package/dist/payment-methods/google-pay.d.mts.map +1 -0
- package/dist/payment-methods/google-pay.mjs +135 -0
- package/dist/payment-methods/google-pay.mjs.map +1 -0
- package/dist/payment-methods/next-action-handlers.d.mts +24 -0
- package/dist/payment-methods/next-action-handlers.d.mts.map +1 -0
- package/dist/payment-methods/next-action-handlers.mjs +3 -0
- package/dist/payment-methods/paypal.d.mts +49 -0
- package/dist/payment-methods/paypal.d.mts.map +1 -0
- package/dist/payment-methods/paypal.mjs +93 -0
- package/dist/payment-methods/paypal.mjs.map +1 -0
- package/dist/payment-methods/stripe-google-pay-adapter.d.mts +2 -0
- package/dist/payment-methods/stripe-google-pay-adapter.mjs +3 -0
- package/dist/penpal/connect-card.d.mts +4 -0
- package/dist/penpal/connect-card.mjs +4 -0
- package/dist/penpal/connect-tunnel-x.d.mts +3 -0
- package/dist/penpal/connect-tunnel-x.mjs +4 -0
- package/dist/penpal-BFKeZTVz.mjs +16 -0
- package/dist/penpal-BFKeZTVz.mjs.map +1 -0
- package/dist/publiccardcheckoutresponse-wxFCeVdO.d.mts +40 -0
- package/dist/publiccardcheckoutresponse-wxFCeVdO.d.mts.map +1 -0
- package/dist/stripe-google-pay-adapter-CkV5HWI-.d.mts +54 -0
- package/dist/stripe-google-pay-adapter-CkV5HWI-.d.mts.map +1 -0
- package/dist/stripe-google-pay-adapter-DMDArVp2.mjs +163 -0
- package/dist/stripe-google-pay-adapter-DMDArVp2.mjs.map +1 -0
- package/dist/types-6mOKdjCh.d.mts +64 -0
- package/dist/types-6mOKdjCh.d.mts.map +1 -0
- package/dist/utils-h0dxplHy.mjs +62 -0
- package/dist/utils-h0dxplHy.mjs.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region ../../packages/sdk/esm/models/cardsetupintent.d.ts
|
|
2
|
+
|
|
3
|
+
type CardSetupIntent = {
|
|
4
|
+
/**
|
|
5
|
+
* Card setup intent identifier
|
|
6
|
+
*/
|
|
7
|
+
id: string;
|
|
8
|
+
/**
|
|
9
|
+
* Whether all card details have been collected
|
|
10
|
+
*/
|
|
11
|
+
isCardAllSet: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether card PAN is set
|
|
14
|
+
*/
|
|
15
|
+
isCardPanSet: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether card expiry is set
|
|
18
|
+
*/
|
|
19
|
+
isCardExpSet: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether card CVC is set
|
|
22
|
+
*/
|
|
23
|
+
isCardCvcSet: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* When the card setup intent was created
|
|
26
|
+
*/
|
|
27
|
+
createdAt: Date;
|
|
28
|
+
/**
|
|
29
|
+
* When the card setup intent was last updated
|
|
30
|
+
*/
|
|
31
|
+
updatedAt: Date;
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { CardSetupIntent as t };
|
|
35
|
+
//# sourceMappingURL=cardsetupintent-D2gBMj3e.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cardsetupintent-D2gBMj3e.d.mts","names":["z","Result","SafeParseResult","SDKValidationError","CardSetupIntent","Date","CardSetupIntent$inboundSchema","ZodTypeDef","ZodType","cardSetupIntentFromJSON"],"sources":["../../../packages/sdk/esm/models/cardsetupintent.d.ts"],"sourcesContent":["import * as z from \"zod/v3\";\nimport { Result as SafeParseResult } from \"../types/fp.js\";\nimport { SDKValidationError } from \"./errors/sdkvalidationerror.js\";\nexport type CardSetupIntent = {\n /**\n * Card setup intent identifier\n */\n id: string;\n /**\n * Whether all card details have been collected\n */\n isCardAllSet: boolean;\n /**\n * Whether card PAN is set\n */\n isCardPanSet: boolean;\n /**\n * Whether card expiry is set\n */\n isCardExpSet: boolean;\n /**\n * Whether card CVC is set\n */\n isCardCvcSet: boolean;\n /**\n * When the card setup intent was created\n */\n createdAt: Date;\n /**\n * When the card setup intent was last updated\n */\n updatedAt: Date;\n};\n/** @internal */\nexport declare const CardSetupIntent$inboundSchema: z.ZodType<CardSetupIntent, z.ZodTypeDef, unknown>;\nexport declare function cardSetupIntentFromJSON(jsonString: string): SafeParseResult<CardSetupIntent, SDKValidationError>;\n//# sourceMappingURL=cardsetupintent.d.ts.map"],"mappings":";;KAGYI,eAAAA;;;;;;;;;;;;;;;;;;;;;;;;aAwBGC;;;;aAIAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { t as connectToWindow } from "./penpal-BFKeZTVz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/penpal/connect-card.ts
|
|
4
|
+
const connectToCardIframe = (iframe, methods) => {
|
|
5
|
+
return connectToWindow({
|
|
6
|
+
window: iframe.contentWindow,
|
|
7
|
+
methods
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const connectToCardParent = (methods) => {
|
|
11
|
+
return connectToWindow({
|
|
12
|
+
window: window.parent,
|
|
13
|
+
methods
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { connectToCardParent as n, connectToCardIframe as t };
|
|
19
|
+
//# sourceMappingURL=connect-card-DO2EJxu6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-card-DO2EJxu6.mjs","names":[],"sources":["../src/penpal/connect-card.ts"],"sourcesContent":["import type { CardSetupIntent, PublicCardCheckoutResponse } from \"@pkg/sdk/models\";\nimport type { Connection } from \"penpal\";\nimport { connectToWindow } from \".\";\n\ntype CardIFrameMethods = {\n onSubmit: (cardSetupIntentId: string) => Promise<CardSetupIntent | { error: CardErrorCode }>;\n onValidate: () => Promise<CardErrorCode | undefined>;\n};\n\ntype CardParentMethods = {\n onLoaded: () => void;\n onFocusChange: (isFocused: boolean) => void;\n};\n\nexport type CardInputType = \"card_pan\" | \"card_exp\" | \"card_cvc\";\n\nexport type CardErrorCode =\n | \"invalid\"\n | \"required\"\n | \"unknown_error\"\n | \"penpal_not_connected\"\n | \"missing_checkout_token\";\n\nexport type IFrameConnection = Connection<CardIFrameMethods>;\n\nexport type ParentConnection = Connection<CardParentMethods>;\n\nexport type CheckoutResponse = PublicCardCheckoutResponse;\n\nexport const connectToCardIframe = (iframe: HTMLIFrameElement, methods: CardParentMethods) => {\n return connectToWindow<CardIFrameMethods>({ window: iframe.contentWindow as Window, methods });\n};\n\nexport const connectToCardParent = (methods: CardIFrameMethods) => {\n return connectToWindow<CardParentMethods>({ window: window.parent, methods });\n};\n"],"mappings":";;;AA6BA,MAAa,uBAAuB,QAA2B,YAA+B;AAC5F,QAAO,gBAAmC;EAAE,QAAQ,OAAO;EAAyB;EAAS,CAAC;;AAGhG,MAAa,uBAAuB,YAA+B;AACjE,QAAO,gBAAmC;EAAE,QAAQ,OAAO;EAAQ;EAAS,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { t as CardSetupIntent } from "./cardsetupintent-D2gBMj3e.mjs";
|
|
2
|
+
import { t as PublicCardCheckoutResponse } from "./publiccardcheckoutresponse-wxFCeVdO.mjs";
|
|
3
|
+
import { Connection } from "penpal";
|
|
4
|
+
|
|
5
|
+
//#region src/penpal/connect-card.d.ts
|
|
6
|
+
type CardIFrameMethods = {
|
|
7
|
+
onSubmit: (cardSetupIntentId: string) => Promise<CardSetupIntent | {
|
|
8
|
+
error: CardErrorCode;
|
|
9
|
+
}>;
|
|
10
|
+
onValidate: () => Promise<CardErrorCode | undefined>;
|
|
11
|
+
};
|
|
12
|
+
type CardParentMethods = {
|
|
13
|
+
onLoaded: () => void;
|
|
14
|
+
onFocusChange: (isFocused: boolean) => void;
|
|
15
|
+
};
|
|
16
|
+
type CardInputType = "card_pan" | "card_exp" | "card_cvc";
|
|
17
|
+
type CardErrorCode = "invalid" | "required" | "unknown_error" | "penpal_not_connected" | "missing_checkout_token";
|
|
18
|
+
type IFrameConnection = Connection<CardIFrameMethods>;
|
|
19
|
+
type ParentConnection = Connection<CardParentMethods>;
|
|
20
|
+
type CheckoutResponse = PublicCardCheckoutResponse;
|
|
21
|
+
declare const connectToCardIframe: (iframe: HTMLIFrameElement, methods: CardParentMethods) => Connection<CardIFrameMethods>;
|
|
22
|
+
declare const connectToCardParent: (methods: CardIFrameMethods) => Connection<CardParentMethods>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { ParentConnection as a, IFrameConnection as i, CardInputType as n, connectToCardIframe as o, CheckoutResponse as r, connectToCardParent as s, CardErrorCode as t };
|
|
25
|
+
//# sourceMappingURL=connect-card-EaOlRbPS.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-card-EaOlRbPS.d.mts","names":[],"sources":["../src/penpal/connect-card.ts"],"sourcesContent":[],"mappings":";;;;;KAIK,iBAAA;2CACsC,QAAQ;WAA2B;EADzE,CAAA,CAAA;EAC8C,UAAA,EAAA,GAAA,GAC/B,OAD+B,CACvB,aADuB,GAAA,SAAA,CAAA;CAA2B;KAIzE,iBAAA,GAJsC;EACf,QAAA,EAAA,GAAA,GAAA,IAAA;EAAR,aAAA,EAAA,CAAA,SAAA,EAAA,OAAA,EAAA,GAAA,IAAA;CAAO;AAGtB,KAKO,aAAA,GALU,UAAA,GAAA,UAAA,GAAA,UAAA;AAKV,KAEA,aAAA,GAFa,SAAA,GAAA,UAAA,GAAA,eAAA,GAAA,sBAAA,GAAA,wBAAA;AAEb,KAOA,gBAAA,GAAmB,UAPN,CAOiB,iBAPjB,CAAA;AAOb,KAEA,gBAAA,GAAmB,UAFW,CAEA,iBAFX,CAAA;AAEnB,KAEA,gBAAA,GAAmB,0BAFA;AAEnB,cAEC,mBAFkB,EAAA,CAAA,MAAA,EAEa,iBAFa,EAAA,OAAA,EAEe,iBAFf,EAAA,GAEgC,UAFhC,CAEgC,iBAFhC,CAAA;AAE5C,cAIA,mBAFZ,EAAA,CAAA,OAAA,EAE4C,iBAF5C,EAAA,GAE6D,UAF7D,CAE6D,iBAF7D,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { t as connectToWindow } from "./penpal-BFKeZTVz.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/penpal/connect-tunnel-x.ts
|
|
4
|
+
const connectToTunnelXIframe = (iframe, methods) => {
|
|
5
|
+
return connectToWindow({
|
|
6
|
+
window: iframe.contentWindow,
|
|
7
|
+
methods
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
const connectToTunnelXParent = (methods) => {
|
|
11
|
+
return connectToWindow({
|
|
12
|
+
window: window.parent,
|
|
13
|
+
methods
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var TunnelXManager = class TunnelXManager {
|
|
17
|
+
penpalConn;
|
|
18
|
+
_methods;
|
|
19
|
+
static createFromPenpalConnection = async (penpalConn) => {
|
|
20
|
+
return new TunnelXManager(penpalConn, await penpalConn.promise);
|
|
21
|
+
};
|
|
22
|
+
constructor(penpalConn, penpalMethods) {
|
|
23
|
+
this.penpalConn = penpalConn;
|
|
24
|
+
this._methods = penpalMethods;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Makes publicEndpoints act like a real PK client, but actually forwards all calls
|
|
28
|
+
* through queryPublicEndpoint and sends it through penpal.
|
|
29
|
+
*/
|
|
30
|
+
get publicEndpoints() {
|
|
31
|
+
return new Proxy({}, { get: (_target, prop) => {
|
|
32
|
+
return async (...args) => {
|
|
33
|
+
return await this._methods.queryPublicEndpoint(prop, args[0], args[1]);
|
|
34
|
+
};
|
|
35
|
+
} });
|
|
36
|
+
}
|
|
37
|
+
destroy() {
|
|
38
|
+
this.penpalConn.destroy();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
//#endregion
|
|
43
|
+
export { connectToTunnelXIframe as n, connectToTunnelXParent as r, TunnelXManager as t };
|
|
44
|
+
//# sourceMappingURL=connect-tunnel-x-BhVAej5Q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-tunnel-x-BhVAej5Q.mjs","names":[],"sources":["../src/penpal/connect-tunnel-x.ts"],"sourcesContent":["import type { RequestOptions } from \"@pkg/sdk/lib/sdks\";\nimport type { CardSetupIntent, CreateCardSetupIntentRes } from \"@pkg/sdk/models\";\nimport type { Connection } from \"penpal\";\nimport { connectToWindow } from \".\";\n\n// Note: this file is paired with customer-portal/src/routes/embeds/v1/tunnel-x\n// The methods below should also be present in CheckoutTunnelX\n\ntype TunnelXIFrameMethods = {\n startPayment: () => void;\n confirmPayment: () => void;\n submitCheckout: (values: Record<string, string>) => Promise<unknown>;\n getCheckoutPreview: () => void;\n getCardSetupIntent: (cardSetupIntentId: string) => Promise<CardSetupIntent>;\n createCardSetupIntent: (secureToken: string) => Promise<CreateCardSetupIntentRes>;\n queryPublicEndpoint: (methodName: string, params: unknown, options?: RequestOptions) => Promise<unknown>;\n};\n\ntype TunnelXParentMethods = Record<string, never>;\n\nexport type TunnelXIFrameConnection = Connection<TunnelXIFrameMethods>;\n\nexport type TunnelXParentConnection = Connection<TunnelXParentMethods>;\n\nexport const connectToTunnelXIframe = (iframe: HTMLIFrameElement, methods: TunnelXParentMethods) => {\n return connectToWindow<TunnelXIFrameMethods>({ window: iframe.contentWindow as Window, methods });\n};\n\nexport const connectToTunnelXParent = (methods: TunnelXIFrameMethods) => {\n return connectToWindow<TunnelXParentMethods>({ window: window.parent, methods });\n};\n\n/**\n * SDK type for publicEndpoints proxy.\n * This is a simplified version that matches the TunnelX iframe methods.\n */\ntype PublicEndpointsProxy = {\n [methodName: string]: (params: unknown, options?: RequestOptions) => Promise<unknown>;\n};\n\nexport class TunnelXManager {\n private penpalConn: TunnelXIFrameConnection;\n public _methods: TunnelXIFrameMethods;\n\n static createFromPenpalConnection = async (penpalConn: TunnelXIFrameConnection) => {\n const methods = await penpalConn.promise;\n const manager = new TunnelXManager(penpalConn, methods);\n return manager;\n };\n\n private constructor(penpalConn: TunnelXIFrameConnection, penpalMethods: TunnelXIFrameMethods) {\n this.penpalConn = penpalConn;\n this._methods = penpalMethods;\n }\n\n /**\n * Makes publicEndpoints act like a real PK client, but actually forwards all calls\n * through queryPublicEndpoint and sends it through penpal.\n */\n get publicEndpoints(): PublicEndpointsProxy {\n const handler = {\n get: (_target: Record<string, never>, prop: string) => {\n return async (...args: unknown[]) => {\n return await this._methods.queryPublicEndpoint(prop, args[0], args[1] as RequestOptions | undefined);\n };\n },\n };\n return new Proxy({}, handler) as unknown as PublicEndpointsProxy;\n }\n\n destroy() {\n this.penpalConn.destroy();\n }\n}\n"],"mappings":";;;AAwBA,MAAa,0BAA0B,QAA2B,YAAkC;AAClG,QAAO,gBAAsC;EAAE,QAAQ,OAAO;EAAyB;EAAS,CAAC;;AAGnG,MAAa,0BAA0B,YAAkC;AACvE,QAAO,gBAAsC;EAAE,QAAQ,OAAO;EAAQ;EAAS,CAAC;;AAWlF,IAAa,iBAAb,MAAa,eAAe;CAC1B,AAAQ;CACR,AAAO;CAEP,OAAO,6BAA6B,OAAO,eAAwC;AAGjF,SADgB,IAAI,eAAe,YADnB,MAAM,WAAW,QACsB;;CAIzD,AAAQ,YAAY,YAAqC,eAAqC;AAC5F,OAAK,aAAa;AAClB,OAAK,WAAW;;;;;;CAOlB,IAAI,kBAAwC;AAQ1C,SAAO,IAAI,MAAM,EAAE,EAPH,EACd,MAAM,SAAgC,SAAiB;AACrD,UAAO,OAAO,GAAG,SAAoB;AACnC,WAAO,MAAM,KAAK,SAAS,oBAAoB,MAAM,KAAK,IAAI,KAAK,GAAiC;;KAGzG,CAC4B;;CAG/B,UAAU;AACR,OAAK,WAAW,SAAS"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { t as CardSetupIntent } from "./cardsetupintent-D2gBMj3e.mjs";
|
|
2
|
+
import { Connection } from "penpal";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/sdk/esm/models/createcardsetupintentres.d.ts
|
|
5
|
+
type CreateCardSetupIntentRes = {
|
|
6
|
+
/**
|
|
7
|
+
* The ID of the card setup intent
|
|
8
|
+
*/
|
|
9
|
+
cardSetupIntentId: string;
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region ../../packages/sdk/esm/lib/retries.d.ts
|
|
13
|
+
type BackoffStrategy = {
|
|
14
|
+
initialInterval: number;
|
|
15
|
+
maxInterval: number;
|
|
16
|
+
exponent: number;
|
|
17
|
+
maxElapsedTime: number;
|
|
18
|
+
};
|
|
19
|
+
type RetryConfig = {
|
|
20
|
+
strategy: "none";
|
|
21
|
+
} | {
|
|
22
|
+
strategy: "backoff";
|
|
23
|
+
backoff?: BackoffStrategy;
|
|
24
|
+
retryConnectionErrors?: boolean;
|
|
25
|
+
};
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region ../../packages/sdk/esm/lib/sdks.d.ts
|
|
28
|
+
type RequestOptions = {
|
|
29
|
+
/**
|
|
30
|
+
* Sets a timeout, in milliseconds, on HTTP requests made by an SDK method. If
|
|
31
|
+
* `fetchOptions.signal` is set then it will take precedence over this option.
|
|
32
|
+
*/
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Set or override a retry policy on HTTP calls.
|
|
36
|
+
*/
|
|
37
|
+
retries?: RetryConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Specifies the status codes which should be retried using the given retry policy.
|
|
40
|
+
*/
|
|
41
|
+
retryCodes?: string[];
|
|
42
|
+
/**
|
|
43
|
+
* Overrides the base server URL that will be used by an operation.
|
|
44
|
+
*/
|
|
45
|
+
serverURL?: string | URL;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated `fetchOptions` has been flattened into `RequestOptions`.
|
|
48
|
+
*
|
|
49
|
+
* Sets various request options on the `fetch` call made by an SDK method.
|
|
50
|
+
*
|
|
51
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options|Request}
|
|
52
|
+
*/
|
|
53
|
+
fetchOptions?: Omit<RequestInit, "method" | "body">;
|
|
54
|
+
} & Omit<RequestInit, "method" | "body">;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/penpal/connect-tunnel-x.d.ts
|
|
57
|
+
type TunnelXIFrameMethods = {
|
|
58
|
+
startPayment: () => void;
|
|
59
|
+
confirmPayment: () => void;
|
|
60
|
+
submitCheckout: (values: Record<string, string>) => Promise<unknown>;
|
|
61
|
+
getCheckoutPreview: () => void;
|
|
62
|
+
getCardSetupIntent: (cardSetupIntentId: string) => Promise<CardSetupIntent>;
|
|
63
|
+
createCardSetupIntent: (secureToken: string) => Promise<CreateCardSetupIntentRes>;
|
|
64
|
+
queryPublicEndpoint: (methodName: string, params: unknown, options?: RequestOptions) => Promise<unknown>;
|
|
65
|
+
};
|
|
66
|
+
type TunnelXParentMethods = Record<string, never>;
|
|
67
|
+
type TunnelXIFrameConnection = Connection<TunnelXIFrameMethods>;
|
|
68
|
+
type TunnelXParentConnection = Connection<TunnelXParentMethods>;
|
|
69
|
+
declare const connectToTunnelXIframe: (iframe: HTMLIFrameElement, methods: TunnelXParentMethods) => Connection<TunnelXIFrameMethods>;
|
|
70
|
+
declare const connectToTunnelXParent: (methods: TunnelXIFrameMethods) => Connection<TunnelXParentMethods>;
|
|
71
|
+
/**
|
|
72
|
+
* SDK type for publicEndpoints proxy.
|
|
73
|
+
* This is a simplified version that matches the TunnelX iframe methods.
|
|
74
|
+
*/
|
|
75
|
+
type PublicEndpointsProxy = {
|
|
76
|
+
[methodName: string]: (params: unknown, options?: RequestOptions) => Promise<unknown>;
|
|
77
|
+
};
|
|
78
|
+
declare class TunnelXManager {
|
|
79
|
+
private penpalConn;
|
|
80
|
+
_methods: TunnelXIFrameMethods;
|
|
81
|
+
static createFromPenpalConnection: (penpalConn: TunnelXIFrameConnection) => Promise<TunnelXManager>;
|
|
82
|
+
private constructor();
|
|
83
|
+
/**
|
|
84
|
+
* Makes publicEndpoints act like a real PK client, but actually forwards all calls
|
|
85
|
+
* through queryPublicEndpoint and sends it through penpal.
|
|
86
|
+
*/
|
|
87
|
+
get publicEndpoints(): PublicEndpointsProxy;
|
|
88
|
+
destroy(): void;
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { connectToTunnelXParent as a, connectToTunnelXIframe as i, TunnelXManager as n, TunnelXParentConnection as r, TunnelXIFrameConnection as t };
|
|
92
|
+
//# sourceMappingURL=connect-tunnel-x-Ce423Pa2.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect-tunnel-x-Ce423Pa2.d.mts","names":["z","Result","SafeParseResult","SDKValidationError","CreateCardSetupIntentRes","CreateCardSetupIntentRes$inboundSchema","ZodTypeDef","ZodType","createCardSetupIntentResFromJSON","BackoffStrategy","RetryConfig","PermanentError","Error","TemporaryError","Response","retry","Promise","SDKHooks","HookContext","ConnectionError","InvalidRequestError","RequestAbortedError","RequestTimeoutError","UnexpectedClientError","Result","SDKOptions","RetryConfig","SecurityState","RequestOptions","URL","RequestInit","Omit","RequestConfig","HeadersInit","ClientSDK","Request","Response","Promise"],"sources":["../../../packages/sdk/esm/models/createcardsetupintentres.d.ts","../../../packages/sdk/esm/lib/retries.d.ts","../../../packages/sdk/esm/lib/sdks.d.ts","../src/penpal/connect-tunnel-x.ts"],"sourcesContent":["import * as z from \"zod/v3\";\nimport { Result as SafeParseResult } from \"../types/fp.js\";\nimport { SDKValidationError } from \"./errors/sdkvalidationerror.js\";\nexport type CreateCardSetupIntentRes = {\n /**\n * The ID of the card setup intent\n */\n cardSetupIntentId: string;\n};\n/** @internal */\nexport declare const CreateCardSetupIntentRes$inboundSchema: z.ZodType<CreateCardSetupIntentRes, z.ZodTypeDef, unknown>;\nexport declare function createCardSetupIntentResFromJSON(jsonString: string): SafeParseResult<CreateCardSetupIntentRes, SDKValidationError>;\n//# sourceMappingURL=createcardsetupintentres.d.ts.map","export type BackoffStrategy = {\n initialInterval: number;\n maxInterval: number;\n exponent: number;\n maxElapsedTime: number;\n};\nexport type RetryConfig = {\n strategy: \"none\";\n} | {\n strategy: \"backoff\";\n backoff?: BackoffStrategy;\n retryConnectionErrors?: boolean;\n};\n/**\n * PermanentError is an error that is not recoverable. Throwing this error will\n * cause a retry loop to terminate.\n */\nexport declare class PermanentError extends Error {\n /** The underlying cause of the error. */\n readonly cause: unknown;\n constructor(message: string, options?: {\n cause?: unknown;\n });\n}\n/**\n * TemporaryError is an error is used to signal that an HTTP request can be\n * retried as part of a retry loop. If retry attempts are exhausted and this\n * error is thrown, the response will be returned to the caller.\n */\nexport declare class TemporaryError extends Error {\n response: Response;\n constructor(message: string, response: Response);\n}\nexport declare function retry(fetchFn: () => Promise<Response>, options: {\n config: RetryConfig;\n statusCodes: string[];\n}): Promise<Response>;\n//# sourceMappingURL=retries.d.ts.map","import { SDKHooks } from \"../hooks/hooks.js\";\nimport { HookContext } from \"../hooks/types.js\";\nimport { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from \"../models/errors/httpclienterrors.js\";\nimport { Result } from \"../types/fp.js\";\nimport { SDKOptions } from \"./config.js\";\nimport { RetryConfig } from \"./retries.js\";\nimport { SecurityState } from \"./security.js\";\nexport type RequestOptions = {\n /**\n * Sets a timeout, in milliseconds, on HTTP requests made by an SDK method. If\n * `fetchOptions.signal` is set then it will take precedence over this option.\n */\n timeoutMs?: number;\n /**\n * Set or override a retry policy on HTTP calls.\n */\n retries?: RetryConfig;\n /**\n * Specifies the status codes which should be retried using the given retry policy.\n */\n retryCodes?: string[];\n /**\n * Overrides the base server URL that will be used by an operation.\n */\n serverURL?: string | URL;\n /**\n * @deprecated `fetchOptions` has been flattened into `RequestOptions`.\n *\n * Sets various request options on the `fetch` call made by an SDK method.\n *\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#options|Request}\n */\n fetchOptions?: Omit<RequestInit, \"method\" | \"body\">;\n} & Omit<RequestInit, \"method\" | \"body\">;\ntype RequestConfig = {\n method: string;\n path: string;\n baseURL?: string | URL | undefined;\n query?: string;\n body?: RequestInit[\"body\"];\n headers?: HeadersInit;\n security?: SecurityState | null;\n uaHeader?: string;\n userAgent?: string | undefined;\n timeoutMs?: number;\n};\nexport declare class ClientSDK {\n #private;\n readonly _baseURL: URL | null;\n readonly _options: SDKOptions & {\n hooks?: SDKHooks;\n };\n constructor(options: SDKOptions);\n _createRequest(context: HookContext, conf: RequestConfig, options?: RequestOptions): Result<Request, InvalidRequestError | UnexpectedClientError>;\n _do(request: Request, options: {\n context: HookContext;\n errorCodes: number | string | (number | string)[];\n retryConfig: RetryConfig;\n retryCodes: string[];\n }): Promise<Result<Response, RequestAbortedError | RequestTimeoutError | ConnectionError | UnexpectedClientError>>;\n}\nexport {};\n//# sourceMappingURL=sdks.d.ts.map"],"mappings":";;;;KAGYI,wBAAAA;EAAAA;;;;ACHZ,CAAA;;;KAAYK,eAAAA;;;;EDGAL,cAAAA,EAAAA,MAAAA;;KCGAM,WAAAA;;AANZ,CAAA,GAAYD;EAMAC,QAAAA,EAAAA,SAAW;YAITD;;;;;KCHFmB,cAAAA;EDPAnB;AAMZ;;;;ECCYmB;;;EAyBYE,OAAAA,CAAAA,EAhBVJ,WAgBUI;EAALC;;;EACX,UAAA,CAAA,EAAA,MAAA,EAAA;;;;ECzBH,SAAA,CAAA,EAAA,MAAA,GDgBoBF,GChBA;EAGE;;;;;;;EAI+D,YAAA,CAAA,EDiBvEE,ICjBuE,CDiBlED,WCjBkE,EAAA,QAAA,GAAA,MAAA,CAAA;CAAO,GDkB7FC,IClB6F,CDkBxFD,WClBwF,EAAA,QAAA,GAAA,MAAA,CAAA;;;KAP5F,oBAAA;EHLO1B,YAAAA,EAAAA,GAAAA,GAAAA,IAAAA;;2BGQe,2BAA2B;;EFX1CK,kBAAe,EAAA,CAAA,iBAAA,EAAA,MAAA,EAAA,GEa0B,OFb1B,CEakC,eFblC,CAAA;EAMfC,qBAAW,EAAA,CAAA,WAITD,EAAAA,MAAe,EAAA,GEIqB,OFJrB,CEI6B,wBFJ7B,CAAA;uEEK0C,mBAAmB;;KAGrF,oBAAA,GAAuB;ADXhBmB,KCaA,uBAAA,GAA0B,UDbZ,CCauB,oBDbvB,CAAA;AASZF,KCMF,uBAAA,GAA0B,UDNxBA,CCMmC,oBDNnCA,CAAAA;AAQWG,cCAZ,sBDAYA,EAAAA,CAAAA,MAAAA,ECAsB,iBDAtBA,EAAAA,OAAAA,ECAkD,oBDAlDA,EAAAA,GCAsE,UDAtEA,CCAsE,oBDAtEA,CAAAA;AAQDC,cCJX,sBDIWA,EAAAA,CAAAA,OAAAA,ECJwB,oBDIxBA,EAAAA,GCJ4C,UDI5CA,CCJ4C,oBDI5CA,CAAAA;;;;;KCInB,oBAAA;oDAC+C,mBAAmB;;AA7BlE,cAgCQ,cAAA,CAhCY;EAGE,QAAA,UAAA;EAA2B,QAAA,EA+BnC,oBA/BmC;EAEO,OAAA,0BAAA,EAAA,CAAA,UAAA,EA+BJ,uBA/BI,EAAA,GA+BmB,OA/BnB,CA+BmB,cA/BnB,CAAA;EAAR,QAAA,WAAA,CAAA;EACK;;;;EACuC,IAAA,eAAA,CAAA,CAAA,EA4CxE,oBA5CwE;EAG5F,OAAA,CAAA,CAAA,EAAA,IAAA;AAEL"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import "./cardsetupintent-D2gBMj3e.mjs";
|
|
2
|
+
import "./connect-tunnel-x-Ce423Pa2.mjs";
|
|
3
|
+
import "./publiccardcheckoutresponse-wxFCeVdO.mjs";
|
|
4
|
+
import "./connect-card-EaOlRbPS.mjs";
|
|
5
|
+
import { n as PaymentKitFields, t as PaymentKit$1 } from "./types-6mOKdjCh.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/index.d.ts
|
|
8
|
+
declare const PaymentKit: PaymentKit$1;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { type PaymentKitFields, PaymentKit as default };
|
|
11
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;cAwBM,YAAY"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import "./penpal-BFKeZTVz.mjs";
|
|
2
|
+
import { n as connectToTunnelXIframe } from "./connect-tunnel-x-BhVAej5Q.mjs";
|
|
3
|
+
import { r as createCheckoutIFrame } from "./utils-h0dxplHy.mjs";
|
|
4
|
+
|
|
5
|
+
//#region package.json
|
|
6
|
+
var version = "0.1.0-alpha.0";
|
|
7
|
+
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/index.ts
|
|
10
|
+
const createTunnelXConnection = (baseUrl, apiBaseUrl, token) => {
|
|
11
|
+
const iframe = createCheckoutIFrame("tunnel-x", baseUrl, {
|
|
12
|
+
checkout_token: token,
|
|
13
|
+
api_base_url: apiBaseUrl
|
|
14
|
+
});
|
|
15
|
+
document.body.appendChild(iframe);
|
|
16
|
+
const connection = connectToTunnelXIframe(iframe, {});
|
|
17
|
+
const unmount = () => {
|
|
18
|
+
connection.destroy();
|
|
19
|
+
document.body.removeChild(iframe);
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
unmount,
|
|
23
|
+
connection
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const PaymentKit = ({ baseUrl, apiBaseUrl, secureToken, paymentMethods }) => {
|
|
27
|
+
console.log(`[PaymentKit] v${version} initialized`);
|
|
28
|
+
const { connection: tunnelXConnection, unmount: unmountTunnelX } = createTunnelXConnection(baseUrl, apiBaseUrl, secureToken);
|
|
29
|
+
const paymentKitStates = {
|
|
30
|
+
baseUrl,
|
|
31
|
+
apiBaseUrl,
|
|
32
|
+
secureToken,
|
|
33
|
+
tunnelXConnection
|
|
34
|
+
};
|
|
35
|
+
const pmInstances = paymentMethods.map((paymentMethod) => paymentMethod(paymentKitStates));
|
|
36
|
+
const externalFuncsMapByPm = pmInstances.reduce((acc, { name, externalFuncs }) => {
|
|
37
|
+
acc[name] = externalFuncs;
|
|
38
|
+
return acc;
|
|
39
|
+
}, {});
|
|
40
|
+
const submit = ({ paymentMethod: paymentMethodName, fields, options, onSuccess, onError }) => {
|
|
41
|
+
const paymentMethod = pmInstances.find(({ name }) => name === paymentMethodName);
|
|
42
|
+
if (!paymentMethod) {
|
|
43
|
+
onError({ root: "payment_method_not_found" });
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
paymentMethod.internalFuncs.submitPayment(fields, options).then(({ data, errors }) => {
|
|
47
|
+
errors ? onError(errors) : onSuccess(data);
|
|
48
|
+
}).catch((e) => {
|
|
49
|
+
console.error("PaymentKit:submit:catch", e);
|
|
50
|
+
if (e?.response?.data) onError(e.response.data);
|
|
51
|
+
else if (e?.message) onError({ root: e.message });
|
|
52
|
+
else onError({ root: "unknown_error" });
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const cleanup = () => {
|
|
56
|
+
for (const pm of pmInstances) if (pm.internalFuncs.cleanup) pm.internalFuncs.cleanup();
|
|
57
|
+
unmountTunnelX();
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
submit,
|
|
61
|
+
cleanup,
|
|
62
|
+
...externalFuncsMapByPm
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
var src_default = PaymentKit;
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
export { src_default as default };
|
|
69
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["PaymentKit: PaymentKitType","PACKAGE_VERSION","externalFuncsMapByPm: ExternalFuncsMapByPm<PaymentMethods>","submit: PaymentKitReturnType[\"submit\"]"],"sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@payment-kit-js/vanilla\",\n \"version\": \"0.1.0-alpha.0\",\n \"main\": \"./dist/index.mjs\",\n \"types\": \"./dist/index.d.mts\",\n \"module\": \"./dist/index.mjs\",\n \"exports\": {\n \".\": \"./dist/index.mjs\",\n \"./payment-methods/card\": \"./dist/payment-methods/card.mjs\",\n \"./payment-methods/google-pay\": \"./dist/payment-methods/google-pay.mjs\",\n \"./payment-methods/next-action-handlers\": \"./dist/payment-methods/next-action-handlers.mjs\",\n \"./payment-methods/paypal\": \"./dist/payment-methods/paypal.mjs\",\n \"./payment-methods/stripe-google-pay-adapter\": \"./dist/payment-methods/stripe-google-pay-adapter.mjs\",\n \"./penpal/connect-card\": \"./dist/penpal/connect-card.mjs\",\n \"./penpal/connect-tunnel-x\": \"./dist/penpal/connect-tunnel-x.mjs\",\n \"./package.json\": \"./package.json\"\n },\n \"license\": \"MIT\",\n \"description\": \"Vanilla JavaScript SDK for PaymentKit\",\n \"keywords\": [\n \"payment\",\n \"payments\",\n \"paymentkit\",\n \"checkout\",\n \"stripe\",\n \"paypal\",\n \"googlepay\",\n \"card\",\n \"sdk\"\n ],\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/ProjectPayAdly/core.git\",\n \"directory\": \"frontend/payment-kit-js/vanilla\"\n },\n \"bugs\": {\n \"url\": \"https://github.com/ProjectPayAdly/core/issues\"\n },\n \"homepage\": \"https://github.com/ProjectPayAdly/core#readme\",\n \"files\": [\n \"dist\",\n \"README.md\"\n ],\n \"scripts\": {\n \"dev\": \"yarn tsdown --watch ./src\",\n \"build\": \"yarn tsdown\"\n },\n \"packageManager\": \"yarn@4.10.3\",\n \"dependencies\": {\n \"penpal\": \"^7.0.4\",\n \"valibot\": \"^1.1.0\"\n },\n \"devDependencies\": {\n \"@pkg/sdk\": \"workspace:*\",\n \"@pkg/tsconfig\": \"workspace:*\",\n \"tsdown\": \"^0.15.10\",\n \"typescript\": \"^5.9.3\"\n },\n \"stableVersion\": \"0.1.0\"\n}\n","import { version as PACKAGE_VERSION } from \"../package.json\";\nimport { connectToTunnelXIframe } from \"./penpal/connect-tunnel-x\";\nimport type { ExternalFuncsMapByPm, PaymentKitFields, PaymentKit as PaymentKitType } from \"./types\";\nimport { createCheckoutIFrame } from \"./utils\";\n\ntype PaymentKitReturnType = ReturnType<PaymentKitType>;\n\nconst createTunnelXConnection = (baseUrl: string, apiBaseUrl: string, token: string) => {\n const iframe = createCheckoutIFrame(\"tunnel-x\", baseUrl, {\n checkout_token: token,\n api_base_url: apiBaseUrl,\n });\n document.body.appendChild(iframe);\n\n const connection = connectToTunnelXIframe(iframe, {});\n\n const unmount = () => {\n connection.destroy();\n document.body.removeChild(iframe);\n };\n\n return { unmount, connection };\n};\n\nconst PaymentKit: PaymentKitType = ({ baseUrl, apiBaseUrl, secureToken, paymentMethods }) => {\n type PaymentMethods = typeof paymentMethods;\n\n // Log version for debugging\n console.log(`[PaymentKit] v${PACKAGE_VERSION} initialized`);\n\n const { connection: tunnelXConnection, unmount: unmountTunnelX } = createTunnelXConnection(\n baseUrl,\n apiBaseUrl,\n secureToken,\n );\n\n const paymentKitStates = {\n baseUrl,\n apiBaseUrl,\n secureToken,\n tunnelXConnection,\n };\n\n const pmInstances = paymentMethods.map((paymentMethod) => paymentMethod(paymentKitStates));\n\n const externalFuncsMapByPm: ExternalFuncsMapByPm<PaymentMethods> = pmInstances.reduce(\n (acc, { name, externalFuncs }) => {\n // @ts-expect-error - typecase this better in future\n acc[name] = externalFuncs;\n return acc;\n },\n {} as ExternalFuncsMapByPm<PaymentMethods>,\n );\n\n const submit: PaymentKitReturnType[\"submit\"] = ({\n paymentMethod: paymentMethodName,\n fields,\n options,\n onSuccess,\n onError,\n }) => {\n const paymentMethod = pmInstances.find(({ name }) => name === paymentMethodName);\n if (!paymentMethod) {\n onError({ root: \"payment_method_not_found\" });\n return;\n }\n paymentMethod.internalFuncs\n .submitPayment(fields, options)\n .then(({ data, errors }) => {\n errors ? onError(errors) : onSuccess(data);\n })\n .catch((e) => {\n console.error(\"PaymentKit:submit:catch\", e);\n\n // Try to extract error message from response\n if (e?.response?.data) {\n onError(e.response.data);\n } else if (e?.message) {\n onError({ root: e.message });\n } else {\n onError({ root: \"unknown_error\" });\n }\n });\n };\n\n const cleanup = () => {\n // Clean up all payment method instances\n for (const pm of pmInstances) {\n if (pm.internalFuncs.cleanup) {\n pm.internalFuncs.cleanup();\n }\n }\n unmountTunnelX();\n };\n\n return {\n submit,\n cleanup,\n ...externalFuncsMapByPm,\n };\n};\n\nexport type { PaymentKitFields };\n\nexport default PaymentKit;\n"],"mappings":";;;;;cAEa;;;;ACKb,MAAM,2BAA2B,SAAiB,YAAoB,UAAkB;CACtF,MAAM,SAAS,qBAAqB,YAAY,SAAS;EACvD,gBAAgB;EAChB,cAAc;EACf,CAAC;AACF,UAAS,KAAK,YAAY,OAAO;CAEjC,MAAM,aAAa,uBAAuB,QAAQ,EAAE,CAAC;CAErD,MAAM,gBAAgB;AACpB,aAAW,SAAS;AACpB,WAAS,KAAK,YAAY,OAAO;;AAGnC,QAAO;EAAE;EAAS;EAAY;;AAGhC,MAAMA,cAA8B,EAAE,SAAS,YAAY,aAAa,qBAAqB;AAI3F,SAAQ,IAAI,iBAAiBC,QAAgB,cAAc;CAE3D,MAAM,EAAE,YAAY,mBAAmB,SAAS,mBAAmB,wBACjE,SACA,YACA,YACD;CAED,MAAM,mBAAmB;EACvB;EACA;EACA;EACA;EACD;CAED,MAAM,cAAc,eAAe,KAAK,kBAAkB,cAAc,iBAAiB,CAAC;CAE1F,MAAMC,uBAA6D,YAAY,QAC5E,KAAK,EAAE,MAAM,oBAAoB;AAEhC,MAAI,QAAQ;AACZ,SAAO;IAET,EAAE,CACH;CAED,MAAMC,UAA0C,EAC9C,eAAe,mBACf,QACA,SACA,WACA,cACI;EACJ,MAAM,gBAAgB,YAAY,MAAM,EAAE,WAAW,SAAS,kBAAkB;AAChF,MAAI,CAAC,eAAe;AAClB,WAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC7C;;AAEF,gBAAc,cACX,cAAc,QAAQ,QAAQ,CAC9B,MAAM,EAAE,MAAM,aAAa;AAC1B,YAAS,QAAQ,OAAO,GAAG,UAAU,KAAK;IAC1C,CACD,OAAO,MAAM;AACZ,WAAQ,MAAM,2BAA2B,EAAE;AAG3C,OAAI,GAAG,UAAU,KACf,SAAQ,EAAE,SAAS,KAAK;YACf,GAAG,QACZ,SAAQ,EAAE,MAAM,EAAE,SAAS,CAAC;OAE5B,SAAQ,EAAE,MAAM,iBAAiB,CAAC;IAEpC;;CAGN,MAAM,gBAAgB;AAEpB,OAAK,MAAM,MAAM,YACf,KAAI,GAAG,cAAc,QACnB,IAAG,cAAc,SAAS;AAG9B,kBAAgB;;AAGlB,QAAO;EACL;EACA;EACA,GAAG;EACJ;;AAKH,kBAAe"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#region src/payment-methods/next-action-handlers.ts
|
|
2
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
|
+
const isStripeJsPresent = () => "Stripe" in window;
|
|
4
|
+
/**
|
|
5
|
+
* Get the Stripe instance from the global window object.
|
|
6
|
+
* Expects Stripe.js to be loaded via HTML script tag.
|
|
7
|
+
* Polls for up to 5 seconds waiting for Stripe to be available.
|
|
8
|
+
*/
|
|
9
|
+
const getLoadedStripe = async (publishableKey) => {
|
|
10
|
+
for (let i = 0; i < 10; i++) {
|
|
11
|
+
if (isStripeJsPresent()) break;
|
|
12
|
+
await sleep(500);
|
|
13
|
+
}
|
|
14
|
+
if (!isStripeJsPresent()) throw new Error("Stripe.js not loaded. Add this script tag to your HTML <head>:\n<script src=\"https://js.stripe.com/v3/\"><\/script>");
|
|
15
|
+
return new window.Stripe(publishableKey);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Handle Stripe 3DS authentication.
|
|
19
|
+
*/
|
|
20
|
+
const handleStripe3ds = async (nextAction) => {
|
|
21
|
+
console.log("3DS authentication required, loading Stripe...");
|
|
22
|
+
const { clientSecret, stripePk } = nextAction;
|
|
23
|
+
const { error: stripeError } = await (await getLoadedStripe(stripePk)).confirmCardPayment(clientSecret);
|
|
24
|
+
if (stripeError) {
|
|
25
|
+
console.error("3DS authentication failed:", stripeError);
|
|
26
|
+
return {
|
|
27
|
+
success: false,
|
|
28
|
+
error: stripeError.message || "3DS authentication failed"
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
console.log("3DS authentication completed");
|
|
32
|
+
return { success: true };
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Handle a next action based on its type.
|
|
36
|
+
* Routes to the appropriate processor-specific handler.
|
|
37
|
+
*
|
|
38
|
+
* @param nextAction - The next action from the checkout response
|
|
39
|
+
* @returns Result indicating success or failure with error message
|
|
40
|
+
*/
|
|
41
|
+
const handleNextAction = async (nextAction) => {
|
|
42
|
+
switch (nextAction.type) {
|
|
43
|
+
case "stripe_3ds": return handleStripe3ds(nextAction);
|
|
44
|
+
default: return {
|
|
45
|
+
success: false,
|
|
46
|
+
error: `Unknown next action type: ${nextAction.type}`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
export { handleNextAction as t };
|
|
53
|
+
//# sourceMappingURL=next-action-handlers-DTsWjUIA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"next-action-handlers-DTsWjUIA.mjs","names":[],"sources":["../src/payment-methods/next-action-handlers.ts"],"sourcesContent":["/**\n * Next action handlers for processor-specific user actions (e.g., 3DS authentication).\n *\n * This module abstracts processor-specific logic away from the generic card payment flow.\n * Each handler implements the logic needed for a specific next action type.\n */\n\nimport type { PublicCardCheckoutResponse } from \"@pkg/sdk/models\";\nimport type { Stripe } from \"@stripe/stripe-js\";\n\n// Helper to wait for a condition\nconst sleep = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));\n\n// Check if Stripe.js is loaded via script tag\nconst isStripeJsPresent = (): boolean => \"Stripe\" in window;\n\n/**\n * Get the Stripe instance from the global window object.\n * Expects Stripe.js to be loaded via HTML script tag.\n * Polls for up to 5 seconds waiting for Stripe to be available.\n */\nconst getLoadedStripe = async (publishableKey: string): Promise<Stripe> => {\n // Poll for Stripe.js to be loaded (up to 5 seconds)\n for (let i = 0; i < 10; i++) {\n if (isStripeJsPresent()) {\n break;\n }\n await sleep(500);\n }\n\n if (!isStripeJsPresent()) {\n throw new Error(\n \"Stripe.js not loaded. Add this script tag to your HTML <head>:\\n\" +\n '<script src=\"https://js.stripe.com/v3/\"></script>',\n );\n }\n\n // @ts-expect-error Stripe is loaded globally via script tag\n const stripe: Stripe = new window.Stripe(publishableKey);\n return stripe;\n};\n\n/**\n * Result of handling a next action.\n */\nexport type NextActionResult = { success: true } | { success: false; error: string };\n\n/**\n * Handle Stripe 3DS authentication.\n */\nconst handleStripe3ds = async (\n nextAction: Extract<PublicCardCheckoutResponse[\"nextAction\"], { type: \"stripe_3ds\" }>,\n): Promise<NextActionResult> => {\n console.log(\"3DS authentication required, loading Stripe...\");\n const { clientSecret, stripePk } = nextAction;\n\n const stripe = await getLoadedStripe(stripePk);\n\n // Show 3DS modal\n const { error: stripeError } = await stripe.confirmCardPayment(clientSecret);\n\n if (stripeError) {\n console.error(\"3DS authentication failed:\", stripeError);\n return { success: false, error: stripeError.message || \"3DS authentication failed\" };\n }\n\n console.log(\"3DS authentication completed\");\n return { success: true };\n};\n\n/**\n * Handle a next action based on its type.\n * Routes to the appropriate processor-specific handler.\n *\n * @param nextAction - The next action from the checkout response\n * @returns Result indicating success or failure with error message\n */\nexport const handleNextAction = async (\n nextAction: NonNullable<PublicCardCheckoutResponse[\"nextAction\"]>,\n): Promise<NextActionResult> => {\n switch (nextAction.type) {\n case \"stripe_3ds\":\n return handleStripe3ds(nextAction);\n default:\n // TypeScript will catch if we miss a case when new action types are added\n return { success: false, error: `Unknown next action type: ${(nextAction as { type: string }).type}` };\n }\n};\n"],"mappings":";AAWA,MAAM,SAAS,OAA8B,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC;AAG9F,MAAM,0BAAmC,YAAY;;;;;;AAOrD,MAAM,kBAAkB,OAAO,mBAA4C;AAEzE,MAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;AAC3B,MAAI,mBAAmB,CACrB;AAEF,QAAM,MAAM,IAAI;;AAGlB,KAAI,CAAC,mBAAmB,CACtB,OAAM,IAAI,MACR,uHAED;AAKH,QADuB,IAAI,OAAO,OAAO,eAAe;;;;;AAY1D,MAAM,kBAAkB,OACtB,eAC8B;AAC9B,SAAQ,IAAI,iDAAiD;CAC7D,MAAM,EAAE,cAAc,aAAa;CAKnC,MAAM,EAAE,OAAO,gBAAgB,OAHhB,MAAM,gBAAgB,SAAS,EAGF,mBAAmB,aAAa;AAE5E,KAAI,aAAa;AACf,UAAQ,MAAM,8BAA8B,YAAY;AACxD,SAAO;GAAE,SAAS;GAAO,OAAO,YAAY,WAAW;GAA6B;;AAGtF,SAAQ,IAAI,+BAA+B;AAC3C,QAAO,EAAE,SAAS,MAAM;;;;;;;;;AAU1B,MAAa,mBAAmB,OAC9B,eAC8B;AAC9B,SAAQ,WAAW,MAAnB;EACE,KAAK,aACH,QAAO,gBAAgB,WAAW;EACpC,QAEE,QAAO;GAAE,SAAS;GAAO,OAAO,6BAA8B,WAAgC;GAAQ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "../cardsetupintent-D2gBMj3e.mjs";
|
|
2
|
+
import "../connect-tunnel-x-Ce423Pa2.mjs";
|
|
3
|
+
import "../publiccardcheckoutresponse-wxFCeVdO.mjs";
|
|
4
|
+
import { n as CardInputType$1, o as connectToCardIframe, r as CheckoutResponse$1 } from "../connect-card-EaOlRbPS.mjs";
|
|
5
|
+
import { r as PaymentMethod } from "../types-6mOKdjCh.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/payment-methods/card.d.ts
|
|
8
|
+
type CardInputType = CardInputType$1;
|
|
9
|
+
type CheckoutResponse = CheckoutResponse$1;
|
|
10
|
+
type CreateElementOptions = Partial<Parameters<typeof connectToCardIframe>[1]> & {
|
|
11
|
+
style?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
declare const CardPaymentMethod: PaymentMethod<{
|
|
14
|
+
createElement: (type: CardInputType$1, options: CreateElementOptions) => {
|
|
15
|
+
mount: (parentSelector: string) => {
|
|
16
|
+
unmount: () => void;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}, "card">;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { CardInputType, CheckoutResponse, CardPaymentMethod as default };
|
|
22
|
+
//# sourceMappingURL=card.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"card.d.mts","names":[],"sources":["../../src/payment-methods/card.ts"],"sourcesContent":[],"mappings":";;;;;;;KAQY,aAAA,GAAgB;KAChB,gBAAA,GAAmB;KAgD1B,oBAAA,GAAuB,QAAQ,kBAAkB;UAC5C;;cA+MJ,mBAzM4D;EAxDtD,aAAA,EAAA,CAAa,IAAA,EAwDT,eAxDY,EAAmB,OAAA,EAwDD,oBAxDC,EAAA,GAAA;IACnC,KAAA,EAAA,CAAA,cAAgB,EAAA,MAAG,EAAA,GAAA;MAgD1B,OAAA,EAAA,GAAA,GAAoB,IAAA;IAA6B,CAAA;EAAlB,CAAA;CAAR,EAAA,MAAA,CAAA"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import "../penpal-BFKeZTVz.mjs";
|
|
2
|
+
import { t as TunnelXManager } from "../connect-tunnel-x-BhVAej5Q.mjs";
|
|
3
|
+
import { a as validateFormFields, i as definePaymentMethod, n as collectFraudMetadata, r as createCheckoutIFrame, t as $ } from "../utils-h0dxplHy.mjs";
|
|
4
|
+
import { t as connectToCardIframe } from "../connect-card-DO2EJxu6.mjs";
|
|
5
|
+
import { t as handleNextAction } from "../next-action-handlers-DTsWjUIA.mjs";
|
|
6
|
+
|
|
7
|
+
//#region src/payment-methods/card.ts
|
|
8
|
+
/**
|
|
9
|
+
* Splits a full name into first name and last name.
|
|
10
|
+
* First word becomes firstName, rest becomes lastName.
|
|
11
|
+
*/
|
|
12
|
+
const splitName = (fullName) => {
|
|
13
|
+
const trimmed = fullName.trim();
|
|
14
|
+
const spaceIndex = trimmed.indexOf(" ");
|
|
15
|
+
if (spaceIndex === -1) return { firstName: trimmed };
|
|
16
|
+
return {
|
|
17
|
+
firstName: trimmed.substring(0, spaceIndex),
|
|
18
|
+
lastName: trimmed.substring(spaceIndex + 1).trim() || void 0
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Maps PaymentKitFields to the customerInfo structure expected by the API.
|
|
23
|
+
*/
|
|
24
|
+
const mapFieldsToCustomerInfo = (fields) => {
|
|
25
|
+
const { firstName, lastName } = splitName(fields.customer_name);
|
|
26
|
+
return {
|
|
27
|
+
email: fields.customer_email || void 0,
|
|
28
|
+
firstName,
|
|
29
|
+
lastName,
|
|
30
|
+
billingAddress: fields.customer_country || fields.customer_zip_code ? {
|
|
31
|
+
country: fields.customer_country || void 0,
|
|
32
|
+
zipCode: fields.customer_zip_code || void 0
|
|
33
|
+
} : void 0
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const defCreateElement = (states) => {
|
|
37
|
+
const { baseUrl, apiBaseUrl, cardInputConnections, secureToken } = states;
|
|
38
|
+
return (type, options) => {
|
|
39
|
+
const { style, onLoaded, onFocusChange } = options;
|
|
40
|
+
const mountIFrame = (parentSelector) => {
|
|
41
|
+
const parent = $(parentSelector);
|
|
42
|
+
const params = {
|
|
43
|
+
checkout_token: secureToken,
|
|
44
|
+
api_base_url: apiBaseUrl
|
|
45
|
+
};
|
|
46
|
+
if (style) params.style = JSON.stringify(style);
|
|
47
|
+
const iframe = createCheckoutIFrame(type.replace("_", "-"), baseUrl, params);
|
|
48
|
+
parent.appendChild(iframe);
|
|
49
|
+
iframe.onload = () => {
|
|
50
|
+
const connection = connectToCardIframe(iframe, {
|
|
51
|
+
onLoaded: onLoaded || (() => {}),
|
|
52
|
+
onFocusChange: onFocusChange || (() => {})
|
|
53
|
+
});
|
|
54
|
+
states.cardInputConnections[type] = connection;
|
|
55
|
+
};
|
|
56
|
+
const unmount = () => {
|
|
57
|
+
cardInputConnections[type]?.destroy();
|
|
58
|
+
parent.removeChild(iframe);
|
|
59
|
+
states.cardInputConnections[type] = void 0;
|
|
60
|
+
};
|
|
61
|
+
return { unmount };
|
|
62
|
+
};
|
|
63
|
+
return { mount: mountIFrame };
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
const defSubmitPayment = (states) => {
|
|
67
|
+
const submitPayment = async (fields) => {
|
|
68
|
+
const tunnelX = await TunnelXManager.createFromPenpalConnection(states.tunnelXConnection);
|
|
69
|
+
const validateCardResult = await validateCardFields(states);
|
|
70
|
+
const validateFormResult = await validateFormFields(fields);
|
|
71
|
+
if (!(validateCardResult.isSuccess && validateFormResult.isSuccess)) return { errors: {
|
|
72
|
+
...validateCardResult.errors,
|
|
73
|
+
...validateFormResult.errors
|
|
74
|
+
} };
|
|
75
|
+
if (!states.cardSetupIntentId) states.cardSetupIntentId = (await tunnelX.publicEndpoints.createCardSetupIntent({ checkoutToken: states.secureToken })).cardSetupIntentId;
|
|
76
|
+
const submitCardResult = await submitCardFields(states);
|
|
77
|
+
if (!submitCardResult.isSuccess) return { errors: submitCardResult.errors };
|
|
78
|
+
const cardSetupIntent = await tunnelX.publicEndpoints.getCardSetupIntent({
|
|
79
|
+
cardSetupIntentId: states.cardSetupIntentId,
|
|
80
|
+
checkoutToken: states.secureToken
|
|
81
|
+
});
|
|
82
|
+
if (!cardSetupIntent.isCardAllSet) {
|
|
83
|
+
const errors = {};
|
|
84
|
+
if (!cardSetupIntent.isCardPanSet) errors.card_pan = "required";
|
|
85
|
+
if (!cardSetupIntent.isCardExpSet) errors.card_exp = "required";
|
|
86
|
+
if (!cardSetupIntent.isCardCvcSet) errors.card_cvc = "required";
|
|
87
|
+
return { errors };
|
|
88
|
+
}
|
|
89
|
+
console.log("Card setup intent is set ✅", cardSetupIntent);
|
|
90
|
+
console.log("Fields", fields);
|
|
91
|
+
let currentResult = await tunnelX.publicEndpoints.cardCheckout({
|
|
92
|
+
checkoutToken: states.secureToken,
|
|
93
|
+
publicCardCheckoutRequest: {
|
|
94
|
+
cardSetupIntentId: states.cardSetupIntentId,
|
|
95
|
+
customerInfo: mapFieldsToCustomerInfo(fields),
|
|
96
|
+
fraudMetadata: collectFraudMetadata()
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
console.log("Card checkout result:", currentResult);
|
|
100
|
+
const MAX_USER_ACTIONS = 5;
|
|
101
|
+
let userActionCount = 0;
|
|
102
|
+
while (currentResult.nextAction && userActionCount < MAX_USER_ACTIONS) {
|
|
103
|
+
userActionCount++;
|
|
104
|
+
console.log(`Handling user action ${userActionCount}/${MAX_USER_ACTIONS}...`);
|
|
105
|
+
const actionResult = await handleNextAction(currentResult.nextAction);
|
|
106
|
+
console.log("User action completed, verifying checkout...");
|
|
107
|
+
const verifyResult = await tunnelX.publicEndpoints.cardCheckoutVerify({ checkoutToken: states.secureToken });
|
|
108
|
+
if (verifyResult.nextAction) {
|
|
109
|
+
if (!actionResult.success) console.log("3DS failed but cascade triggered new action, continuing loop...");
|
|
110
|
+
else console.log("Another user action required, continuing loop...");
|
|
111
|
+
currentResult = verifyResult;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!actionResult.success) {
|
|
115
|
+
console.log("3DS authentication failed, checkout concluded:", verifyResult);
|
|
116
|
+
return { errors: { root: actionResult.error } };
|
|
117
|
+
}
|
|
118
|
+
console.log("Card checkout verified ✅", verifyResult);
|
|
119
|
+
return { data: verifyResult };
|
|
120
|
+
}
|
|
121
|
+
if (userActionCount >= MAX_USER_ACTIONS) {
|
|
122
|
+
console.error("Max user actions exceeded");
|
|
123
|
+
return { errors: { root: "Too many authentication attempts. Please try again." } };
|
|
124
|
+
}
|
|
125
|
+
console.log("Card checkout completed ✅", currentResult);
|
|
126
|
+
return { data: currentResult };
|
|
127
|
+
};
|
|
128
|
+
return submitPayment;
|
|
129
|
+
};
|
|
130
|
+
const submitCardFields = async (states) => {
|
|
131
|
+
const errors = {};
|
|
132
|
+
const { cardSetupIntentId, cardInputConnections } = states;
|
|
133
|
+
const submitPromises = Object.entries(cardInputConnections).map(async ([_type, connection]) => {
|
|
134
|
+
const type = _type;
|
|
135
|
+
const result = await (await connection.promise).onSubmit(cardSetupIntentId || "");
|
|
136
|
+
if ("error" in result) errors[type] = result.error;
|
|
137
|
+
});
|
|
138
|
+
await Promise.allSettled(submitPromises);
|
|
139
|
+
return {
|
|
140
|
+
errors,
|
|
141
|
+
isSuccess: Object.keys(errors).length === 0
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const validateCardFields = async (states) => {
|
|
145
|
+
const errors = {};
|
|
146
|
+
const { cardInputConnections } = states;
|
|
147
|
+
const validatePromises = Object.entries(cardInputConnections).map(async ([_type, connection]) => {
|
|
148
|
+
const type = _type;
|
|
149
|
+
if (!connection) {
|
|
150
|
+
errors[type] = "penpal_not_connected";
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const errorMsg = await (await connection.promise).onValidate();
|
|
154
|
+
if (errorMsg) errors[type] = errorMsg;
|
|
155
|
+
});
|
|
156
|
+
await Promise.allSettled(validatePromises);
|
|
157
|
+
return {
|
|
158
|
+
errors,
|
|
159
|
+
isSuccess: Object.keys(errors).length === 0
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const CardPaymentMethod = definePaymentMethod((paymentKitStates) => {
|
|
163
|
+
const localStates = {
|
|
164
|
+
...paymentKitStates,
|
|
165
|
+
cardInputConnections: {}
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
name: "card",
|
|
169
|
+
externalFuncs: { createElement: defCreateElement(localStates) },
|
|
170
|
+
internalFuncs: {
|
|
171
|
+
submitPayment: defSubmitPayment(localStates),
|
|
172
|
+
cleanup: () => {
|
|
173
|
+
for (const connection of Object.values(localStates.cardInputConnections)) connection?.destroy();
|
|
174
|
+
localStates.cardInputConnections = {};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
var card_default = CardPaymentMethod;
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
export { card_default as default };
|
|
183
|
+
//# sourceMappingURL=card.mjs.map
|