@jsdev_ninja/core 0.8.36 → 0.8.38
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/lib/entities/Atoms.ts +7 -0
- package/lib/entities/Locale.ts +3 -1
- package/lib/entities/Order.ts +1 -1
- package/lib/entities/Payment.ts +80 -10
- package/lib/entities/Store.ts +6 -8
- package/lib/entities/index.ts +9 -3
- package/lib/hypPaymentService/hypPaymentService.ts +32 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
// 600 - Checking a card number700 - Approved without charge800 - Postpone transaction - success handle ass error
|
|
4
|
+
|
|
5
|
+
export const hypBooleanSchema = z.enum(["True", "False"]);
|
|
6
|
+
export const notEmptyTextSchema = z.string().min(1);
|
|
7
|
+
export const numericTextSchema = z.string().regex(/^\d+$/, "Must be a numeric string");
|
package/lib/entities/Locale.ts
CHANGED
package/lib/entities/Order.ts
CHANGED
|
@@ -25,7 +25,7 @@ export const OrderSchema = z.object({
|
|
|
25
25
|
"completed",
|
|
26
26
|
"refunded",
|
|
27
27
|
]),
|
|
28
|
-
paymentStatus: z.enum(["pending", "completed", "failed", "refunded"]),
|
|
28
|
+
paymentStatus: z.enum(["pending", "completed", "failed", "refunded"]), //todo check if hyp support partial refund
|
|
29
29
|
cart: z.object({
|
|
30
30
|
id: z.string(),
|
|
31
31
|
items: z.array(z.object({ product: ProductSchema, amount: z.number() })),
|
package/lib/entities/Payment.ts
CHANGED
|
@@ -1,13 +1,83 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { hypBooleanSchema } from "./Atoms";
|
|
2
3
|
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
// 600 - Checking a card number700 - Approved without charge800 - Postpone transaction - success handle ass error
|
|
5
|
+
|
|
6
|
+
const textSchema = z.string().min(1);
|
|
7
|
+
const numericTextSchema = z.string().regex(/^\d+$/, "Must be a numeric string");
|
|
8
|
+
|
|
9
|
+
export const PayProtocolGeneralSchema = z.object({
|
|
10
|
+
Amount: textSchema,
|
|
11
|
+
Order: textSchema.optional(), // order id generated by store
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const PayProtocolResponseSchema = PayProtocolGeneralSchema.extend({
|
|
15
|
+
Id: textSchema, // transaction Id in Hypay
|
|
16
|
+
ACode: numericTextSchema, // confirmation code from credit card company
|
|
17
|
+
CCode: z.string(), // todo,
|
|
18
|
+
Sign: z.string(), //
|
|
19
|
+
Fild1: z.string(), // client full name
|
|
20
|
+
Fild2: z.string(), // client email
|
|
21
|
+
Fild3: z.string(), // client phone number
|
|
22
|
+
|
|
23
|
+
// if more data equal to True
|
|
24
|
+
Bank: z.string().optional(),
|
|
25
|
+
TransType: z.string().optional(),
|
|
26
|
+
Payments: z.string().optional(), // Number of payments charged
|
|
27
|
+
UserId: z.string().optional(),
|
|
28
|
+
Brand: z.string().optional(),
|
|
29
|
+
Issuer: z.string().optional(),
|
|
30
|
+
L4digit: z.string().optional(),
|
|
31
|
+
street: z.string().optional(),
|
|
32
|
+
city: z.string().optional(),
|
|
33
|
+
zip: z.string().optional(),
|
|
34
|
+
cell: z.string().optional(),
|
|
35
|
+
Coin: z.string().optional(),
|
|
36
|
+
Tmonth: z.string().optional(), // MM format
|
|
37
|
+
Tyear: z.string().optional(), // YYYY format
|
|
38
|
+
Hesh: z.string().optional(), // invoice number (if invoice module is not active Hesh would get 0)
|
|
39
|
+
UID: z.string().optional(), // UID unique value receive from response after successful transaction from request with action pay/soft
|
|
40
|
+
spType: z.string().optional(),
|
|
41
|
+
bincard: z.string().optional(),
|
|
13
42
|
});
|
|
43
|
+
|
|
44
|
+
// generate payment link
|
|
45
|
+
export const HypPaymentLinkRequestSchema = PayProtocolGeneralSchema.extend({
|
|
46
|
+
Masof: textSchema, // store masof number
|
|
47
|
+
PassP: textSchema, // store masof password,
|
|
48
|
+
KEY: textSchema, // hyp api key
|
|
49
|
+
action: z.literal("APISign"),
|
|
50
|
+
What: z.literal("SIGN"),
|
|
51
|
+
Info: textSchema, // text that will be displayed in transaction, report and the management system.
|
|
52
|
+
Sign: hypBooleanSchema, // Sign on sent parameters in answer
|
|
53
|
+
UTF8: hypBooleanSchema, // request is utf8
|
|
54
|
+
UTF8out: hypBooleanSchema, // response is utf8
|
|
55
|
+
Tash: numericTextSchema, // Max number of payments that can be selected by the customer
|
|
56
|
+
FixTash: hypBooleanSchema.optional(),
|
|
57
|
+
sendemail: hypBooleanSchema.optional(),
|
|
58
|
+
MoreData: hypBooleanSchema.optional(), // extra data in response
|
|
59
|
+
J5: z.literal("True").optional(),
|
|
60
|
+
// tashType: - Payment type optional NOT_IN_USE
|
|
61
|
+
|
|
62
|
+
// EzCount Invoice parameters - Pay Protocol
|
|
63
|
+
SendHesh: hypBooleanSchema.optional(), // send invoice in email
|
|
64
|
+
heshDesc: hypBooleanSchema.optional(), // [0~Item 1~1~8][0~Item 2~2~1]
|
|
65
|
+
Pritim: hypBooleanSchema.optional(), // The invoice description contains items
|
|
66
|
+
|
|
67
|
+
// client data
|
|
68
|
+
UserId: numericTextSchema,
|
|
69
|
+
ClientName: textSchema, // first name
|
|
70
|
+
ClientLName: textSchema.optional(), // last name
|
|
71
|
+
street: textSchema.optional(),
|
|
72
|
+
city: textSchema.optional(),
|
|
73
|
+
zip: textSchema.optional(),
|
|
74
|
+
phone: textSchema.optional(),
|
|
75
|
+
cell: textSchema.optional(),
|
|
76
|
+
email: textSchema.optional(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// create payment link
|
|
80
|
+
export type TPaymentLinkRequest = z.infer<typeof HypPaymentLinkRequestSchema>;
|
|
81
|
+
|
|
82
|
+
// after payment success (in client)
|
|
83
|
+
export type TPayProtocolResponse = z.infer<typeof PayProtocolResponseSchema>;
|
package/lib/entities/Store.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { hypBooleanSchema } from "./Atoms";
|
|
2
3
|
|
|
3
4
|
const StoreSchema = z.object({
|
|
4
5
|
id: z.string(),
|
|
@@ -7,14 +8,11 @@ const StoreSchema = z.object({
|
|
|
7
8
|
urls: z.array(z.string()),
|
|
8
9
|
logoUrl: z.string(),
|
|
9
10
|
tenantId: z.string(), // firebase auth tenantId
|
|
10
|
-
|
|
11
|
-
.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
})
|
|
16
|
-
)
|
|
17
|
-
.optional(),
|
|
11
|
+
hypData: z.object({
|
|
12
|
+
masof: z.string().min(1),
|
|
13
|
+
password: z.string().min(1),
|
|
14
|
+
isJ5: hypBooleanSchema,
|
|
15
|
+
}),
|
|
18
16
|
});
|
|
19
17
|
|
|
20
18
|
// private sub collection
|
package/lib/entities/index.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./Address";
|
|
2
|
+
export * from "./Atoms";
|
|
3
|
+
export * from "./Cart";
|
|
2
4
|
export * from "./Category";
|
|
5
|
+
export * from "./Company";
|
|
6
|
+
export * from "./FavoriteProduct";
|
|
7
|
+
export * from "./Locale";
|
|
3
8
|
export * from "./Order";
|
|
9
|
+
export * from "./Payment";
|
|
4
10
|
export * from "./Product";
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
11
|
+
export * from "./Profile";
|
|
12
|
+
export * from "./Store";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TPaymentLinkRequest } from "../entities/Payment";
|
|
2
|
+
|
|
3
|
+
const baseUrl = "https://pay.hyp.co.il/p/";
|
|
4
|
+
|
|
5
|
+
function objectToQueryParams(obj: any) {
|
|
6
|
+
return Object.keys(obj)
|
|
7
|
+
.map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`)
|
|
8
|
+
.join("&");
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const hypPaymentService = {
|
|
12
|
+
async createPaymentLink(params: TPaymentLinkRequest) {
|
|
13
|
+
try {
|
|
14
|
+
const queryString = objectToQueryParams(params);
|
|
15
|
+
|
|
16
|
+
const url = `${baseUrl}?${queryString}`;
|
|
17
|
+
|
|
18
|
+
console.log("createPaymentLink url", url);
|
|
19
|
+
|
|
20
|
+
const signResponse = await fetch(url);
|
|
21
|
+
|
|
22
|
+
const linkData = await signResponse.text();
|
|
23
|
+
|
|
24
|
+
const paymentLink = `${baseUrl}?${linkData}`;
|
|
25
|
+
|
|
26
|
+
return { success: true, paymentLink };
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
console.log(error);
|
|
29
|
+
return { success: false, errMessage: error.message };
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
} as const;
|