washday-sdk 1.6.55 → 1.6.57
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.js +1 -0
- package/dist/interfaces/DomainUrls.js +1 -0
- package/package.json +1 -1
- package/src/api/integrations/post.ts +14 -4
- package/src/api/stripe/post.ts +31 -10
- package/src/index.ts +8 -0
- package/src/interfaces/DomainUrls.ts +11 -0
- package/src/interfaces/Store.ts +5 -0
- package/test/domainUrls.types.test.ts +52 -0
- package/test/integrations.domainReturnUrls.test.ts +25 -0
- package/test/store.publicReceiptConfig.test.ts +14 -0
- package/test/stripe.domainReturnUrls.test.ts +92 -0
package/dist/index.js
CHANGED
|
@@ -5,5 +5,6 @@ export * from './interfaces/Config';
|
|
|
5
5
|
export * from './interfaces/Cfdi';
|
|
6
6
|
export * from './interfaces/Auth';
|
|
7
7
|
export * from './interfaces/Customer';
|
|
8
|
+
export * from './interfaces/DomainUrls';
|
|
8
9
|
export * from './interfaces/GoogleMaps';
|
|
9
10
|
export { WashdayClient, utils };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
+
import { AppReturnUrlOptions } from "../../interfaces/DomainUrls";
|
|
2
3
|
|
|
3
4
|
const BASE_ROUTER = 'api/integrations';
|
|
4
5
|
const BASE_ROUTER_MP_ATTEMPTS = 'api/payments/mp/attempts';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export interface StartMPOAuthFlowRequest extends AppReturnUrlOptions {
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated The backend owns the Mercado Pago OAuth callback now.
|
|
10
|
+
* Use returnToUrl or returnToOrigin/returnPath for the final app redirect.
|
|
11
|
+
*/
|
|
12
|
+
redirectUri?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const startMPOAuthFlow = async function (
|
|
16
|
+
this: WashdayClientInstance,
|
|
17
|
+
data: StartMPOAuthFlowRequest
|
|
18
|
+
): Promise<any> {
|
|
9
19
|
try {
|
|
10
20
|
const config = {
|
|
11
21
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
@@ -119,4 +129,4 @@ export const cancelMPAttempt = async function (this: WashdayClientInstance, data
|
|
|
119
129
|
catch (error) {
|
|
120
130
|
throw error;
|
|
121
131
|
}
|
|
122
|
-
};
|
|
132
|
+
};
|
package/src/api/stripe/post.ts
CHANGED
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
import { WashdayClientInstance } from "../../interfaces/Api";
|
|
2
|
-
import
|
|
2
|
+
import { StripeReturnUrlOptions } from "../../interfaces/DomainUrls";
|
|
3
3
|
const GET_SET_STRIPE = 'api/stripe';
|
|
4
4
|
const GENERATE_CHECKOUT_SESSION = 'api/orders/create-checkout-session';
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
priceId: string
|
|
8
|
-
|
|
6
|
+
export interface CreateSubscriptionCheckoutSessionRequest extends StripeReturnUrlOptions {
|
|
7
|
+
priceId: string;
|
|
8
|
+
planKey?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface CreateGetMoreCheckoutSessionRequest extends StripeReturnUrlOptions {
|
|
12
|
+
priceId: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CreateCFDISubscriptionCheckoutSessionRequest extends StripeReturnUrlOptions {}
|
|
16
|
+
|
|
17
|
+
export interface CreateCustomerPortalSessionRequest extends StripeReturnUrlOptions {}
|
|
18
|
+
|
|
19
|
+
export const createCreateSuscriptionCheckoutSession = async function (
|
|
20
|
+
this: WashdayClientInstance,
|
|
21
|
+
data: CreateSubscriptionCheckoutSessionRequest
|
|
22
|
+
): Promise<any> {
|
|
9
23
|
try {
|
|
10
24
|
const config = {
|
|
11
25
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
@@ -18,7 +32,10 @@ export const createCreateSuscriptionCheckoutSession = async function (this: Wash
|
|
|
18
32
|
}
|
|
19
33
|
};
|
|
20
34
|
|
|
21
|
-
export const createCustomerPortalSession = async function (
|
|
35
|
+
export const createCustomerPortalSession = async function (
|
|
36
|
+
this: WashdayClientInstance,
|
|
37
|
+
data?: CreateCustomerPortalSessionRequest
|
|
38
|
+
): Promise<any> {
|
|
22
39
|
try {
|
|
23
40
|
const config = {
|
|
24
41
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
@@ -31,7 +48,10 @@ export const createCustomerPortalSession = async function (this: WashdayClientIn
|
|
|
31
48
|
}
|
|
32
49
|
};
|
|
33
50
|
|
|
34
|
-
export const createCFDISuscrptionCheckoutSession = async function (
|
|
51
|
+
export const createCFDISuscrptionCheckoutSession = async function (
|
|
52
|
+
this: WashdayClientInstance,
|
|
53
|
+
data?: CreateCFDISubscriptionCheckoutSessionRequest
|
|
54
|
+
): Promise<any> {
|
|
35
55
|
try {
|
|
36
56
|
const config = {
|
|
37
57
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
@@ -44,9 +64,10 @@ export const createCFDISuscrptionCheckoutSession = async function (this: Washday
|
|
|
44
64
|
}
|
|
45
65
|
};
|
|
46
66
|
|
|
47
|
-
export const createGetMoreCheckoutSession = async function (
|
|
48
|
-
|
|
49
|
-
|
|
67
|
+
export const createGetMoreCheckoutSession = async function (
|
|
68
|
+
this: WashdayClientInstance,
|
|
69
|
+
data: CreateGetMoreCheckoutSessionRequest
|
|
70
|
+
): Promise<any> {
|
|
50
71
|
try {
|
|
51
72
|
const config = {
|
|
52
73
|
headers: { Authorization: `Bearer ${this.apiToken}` }
|
|
@@ -56,4 +77,4 @@ export const createGetMoreCheckoutSession = async function (this: WashdayClientI
|
|
|
56
77
|
console.error('Error fetching createGetMoreCheckoutSession:', error);
|
|
57
78
|
throw error;
|
|
58
79
|
}
|
|
59
|
-
};
|
|
80
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,14 @@ export * from './interfaces/Config';
|
|
|
5
5
|
export * from './interfaces/Cfdi';
|
|
6
6
|
export * from './interfaces/Auth';
|
|
7
7
|
export * from './interfaces/Customer';
|
|
8
|
+
export * from './interfaces/DomainUrls';
|
|
8
9
|
export * from './interfaces/GoogleMaps';
|
|
10
|
+
export type { StartMPOAuthFlowRequest } from './api/integrations/post';
|
|
11
|
+
export type {
|
|
12
|
+
CreateCFDISubscriptionCheckoutSessionRequest,
|
|
13
|
+
CreateCustomerPortalSessionRequest,
|
|
14
|
+
CreateGetMoreCheckoutSessionRequest,
|
|
15
|
+
CreateSubscriptionCheckoutSessionRequest,
|
|
16
|
+
} from './api/stripe/post';
|
|
9
17
|
|
|
10
18
|
export { WashdayClient, utils };
|
package/src/interfaces/Store.ts
CHANGED
|
@@ -48,6 +48,10 @@ export interface ICustomersAppConfig {
|
|
|
48
48
|
}[]
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
export interface IPublicReceiptConfig {
|
|
52
|
+
showEvidence?: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
51
55
|
export interface IStore {
|
|
52
56
|
name: string,
|
|
53
57
|
streetAddress?: string,
|
|
@@ -85,6 +89,7 @@ export interface IStore {
|
|
|
85
89
|
ticketStructure?: ITicketStructure | null,
|
|
86
90
|
ticketForLaundryStructure?: ITicketForLaundryStructure | null,
|
|
87
91
|
labelTicketStructure?: ILabelTicketStructure | null,
|
|
92
|
+
publicReceiptConfig?: IPublicReceiptConfig,
|
|
88
93
|
ticketScanMode?: 'order' | 'customer',
|
|
89
94
|
storeDiscounts: IStoreDiscount | null,
|
|
90
95
|
discountCodes: IDiscountCode | null,
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { StartMPOAuthFlowRequest } from "../src/api/integrations/post";
|
|
2
|
+
import {
|
|
3
|
+
CreateCFDISubscriptionCheckoutSessionRequest,
|
|
4
|
+
CreateCustomerPortalSessionRequest,
|
|
5
|
+
CreateGetMoreCheckoutSessionRequest,
|
|
6
|
+
CreateSubscriptionCheckoutSessionRequest,
|
|
7
|
+
} from "../src/api/stripe/post";
|
|
8
|
+
import { AppReturnUrlOptions } from "../src/interfaces/DomainUrls";
|
|
9
|
+
|
|
10
|
+
describe("domain return URL request types", () => {
|
|
11
|
+
it("supports app and provider return URL options", () => {
|
|
12
|
+
const appReturnUrlOptions: AppReturnUrlOptions = {
|
|
13
|
+
returnToUrl: "https://app.washdaypos.com/settings/mercado-pago?storeId=store-1",
|
|
14
|
+
returnToOrigin: "https://app.washdaypos.com",
|
|
15
|
+
returnPath: "/settings/mercado-pago?storeId=store-1",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const mpRequest: StartMPOAuthFlowRequest = {
|
|
19
|
+
returnToUrl: "https://app.washdaypos.com/settings/mercado-pago?storeId=store-1",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const legacyMpRequest: StartMPOAuthFlowRequest = {
|
|
23
|
+
redirectUri: "https://app.washday.mx/integrations/mercadopago/callback",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const subscriptionRequest: CreateSubscriptionCheckoutSessionRequest = {
|
|
27
|
+
priceId: "price_1",
|
|
28
|
+
returnToOrigin: "https://app.washdaypos.com",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const extraOrdersRequest: CreateGetMoreCheckoutSessionRequest = {
|
|
32
|
+
priceId: "price_extra",
|
|
33
|
+
returnToOrigin: "https://app.washday.mx",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const cfdiRequest: CreateCFDISubscriptionCheckoutSessionRequest = {
|
|
37
|
+
returnToUrl: "https://app.washdaypos.com/settings/company-info",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const portalRequest: CreateCustomerPortalSessionRequest = {
|
|
41
|
+
returnToUrl: "https://app.washdaypos.com/settings",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
expect(appReturnUrlOptions.returnToOrigin).toBe("https://app.washdaypos.com");
|
|
45
|
+
expect(mpRequest.returnToUrl).toBe("https://app.washdaypos.com/settings/mercado-pago?storeId=store-1");
|
|
46
|
+
expect(legacyMpRequest.redirectUri).toBe("https://app.washday.mx/integrations/mercadopago/callback");
|
|
47
|
+
expect(subscriptionRequest.returnToOrigin).toBe("https://app.washdaypos.com");
|
|
48
|
+
expect(extraOrdersRequest.returnToOrigin).toBe("https://app.washday.mx");
|
|
49
|
+
expect(cfdiRequest.returnToUrl).toBe("https://app.washdaypos.com/settings/company-info");
|
|
50
|
+
expect(portalRequest.returnToUrl).toBe("https://app.washdaypos.com/settings");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { startMPOAuthFlow } from "../src/api/integrations/post";
|
|
2
|
+
|
|
3
|
+
describe("startMPOAuthFlow return URL options", () => {
|
|
4
|
+
it("posts returnToUrl without requiring callers to provide the OAuth callback redirectUri", async () => {
|
|
5
|
+
const post = jest.fn().mockResolvedValue({ data: { data: { authUrl: "https://mp.example/auth" } } });
|
|
6
|
+
const client = {
|
|
7
|
+
apiToken: "token-1",
|
|
8
|
+
axiosInstance: { post },
|
|
9
|
+
} as any;
|
|
10
|
+
|
|
11
|
+
await startMPOAuthFlow.call(client, {
|
|
12
|
+
returnToUrl: "https://app.washdaypos.com/settings/mercado-pago?storeId=store-1",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(post).toHaveBeenCalledWith(
|
|
16
|
+
"api/integrations/mp/oauth/start",
|
|
17
|
+
{
|
|
18
|
+
returnToUrl: "https://app.washdaypos.com/settings/mercado-pago?storeId=store-1",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
headers: { Authorization: "Bearer token-1" },
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IPublicReceiptConfig, IStore } from "../src/interfaces/Store";
|
|
2
|
+
|
|
3
|
+
describe("store public receipt config types", () => {
|
|
4
|
+
it("accepts publicReceiptConfig.showEvidence", () => {
|
|
5
|
+
const publicReceiptConfig: IPublicReceiptConfig = {
|
|
6
|
+
showEvidence: false,
|
|
7
|
+
};
|
|
8
|
+
const store: Partial<IStore> = {
|
|
9
|
+
publicReceiptConfig,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
expect(store.publicReceiptConfig?.showEvidence).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCFDISuscrptionCheckoutSession,
|
|
3
|
+
createCreateSuscriptionCheckoutSession,
|
|
4
|
+
createCustomerPortalSession,
|
|
5
|
+
createGetMoreCheckoutSession,
|
|
6
|
+
} from "../src/api/stripe/post";
|
|
7
|
+
|
|
8
|
+
describe("stripe checkout return URL options", () => {
|
|
9
|
+
it("passes returnToOrigin for subscription checkout", async () => {
|
|
10
|
+
const post = jest.fn().mockResolvedValue({ data: { data: { url: "https://stripe.example" } } });
|
|
11
|
+
const client = {
|
|
12
|
+
apiToken: "token-1",
|
|
13
|
+
axiosInstance: { post },
|
|
14
|
+
} as any;
|
|
15
|
+
|
|
16
|
+
await createCreateSuscriptionCheckoutSession.call(client, {
|
|
17
|
+
priceId: "price_1",
|
|
18
|
+
returnToOrigin: "https://app.washdaypos.com",
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(post).toHaveBeenCalledWith(
|
|
22
|
+
"api/stripe/create-subscription-checkout-session",
|
|
23
|
+
{
|
|
24
|
+
priceId: "price_1",
|
|
25
|
+
returnToOrigin: "https://app.washdaypos.com",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
headers: { Authorization: "Bearer token-1" },
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("passes returnToOrigin for extra orders checkout", async () => {
|
|
34
|
+
const post = jest.fn().mockResolvedValue({ data: { data: { url: "https://stripe.example" } } });
|
|
35
|
+
const client = {
|
|
36
|
+
apiToken: "token-1",
|
|
37
|
+
axiosInstance: { post },
|
|
38
|
+
} as any;
|
|
39
|
+
|
|
40
|
+
await createGetMoreCheckoutSession.call(client, {
|
|
41
|
+
priceId: "price_extra",
|
|
42
|
+
returnToOrigin: "https://app.washday.mx",
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(post).toHaveBeenCalledWith(
|
|
46
|
+
"api/orders/create-checkout-session",
|
|
47
|
+
{
|
|
48
|
+
priceId: "price_extra",
|
|
49
|
+
returnToOrigin: "https://app.washday.mx",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
headers: { Authorization: "Bearer token-1" },
|
|
53
|
+
},
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("passes returnToUrl for CFDI checkout and customer portal", async () => {
|
|
58
|
+
const post = jest.fn().mockResolvedValue({ data: { data: { url: "https://stripe.example" } } });
|
|
59
|
+
const client = {
|
|
60
|
+
apiToken: "token-1",
|
|
61
|
+
axiosInstance: { post },
|
|
62
|
+
} as any;
|
|
63
|
+
|
|
64
|
+
await createCFDISuscrptionCheckoutSession.call(client, {
|
|
65
|
+
returnToUrl: "https://app.washdaypos.com/settings/company-info",
|
|
66
|
+
});
|
|
67
|
+
await createCustomerPortalSession.call(client, {
|
|
68
|
+
returnToUrl: "https://app.washdaypos.com/settings",
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(post).toHaveBeenNthCalledWith(
|
|
72
|
+
1,
|
|
73
|
+
"api/stripe/create-cfdi-subscription-checkout-session",
|
|
74
|
+
{
|
|
75
|
+
returnToUrl: "https://app.washdaypos.com/settings/company-info",
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
headers: { Authorization: "Bearer token-1" },
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
expect(post).toHaveBeenNthCalledWith(
|
|
82
|
+
2,
|
|
83
|
+
"api/stripe/create-customer-portal-session",
|
|
84
|
+
{
|
|
85
|
+
returnToUrl: "https://app.washdaypos.com/settings",
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
headers: { Authorization: "Bearer token-1" },
|
|
89
|
+
},
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
});
|