· 6 months ago · Apr 06, 2025, 05:05 AM
1import { Container } from 'inversify';
2import 'reflect-metadata';
3import { PayTechService, PaytechRegisterRequest } from './paytech-service';
4
5// Set up dependency injection container
6const container = new Container();
7container.bind(PayTechService).toSelf();
8
9// Get an instance of the service
10const paytechService = container.get(PayTechService);
11
12/**
13 * Example 1: Register a new customer
14 */
15async function registerExample() {
16 const registerRequest: PaytechRegisterRequest = {
17 fname: "Moussa",
18 lname: "Ndour",
19 phone: "+221777679700",
20 countryCode: "sn",
21 email: "moussa_ndour@hotmail.fr",
22 adress: "Almadies",
23 pass: "azerty",
24 confPass: "azerty",
25 business_name: "Mon Business",
26 website: "https://github.com/touskar", //optionnel can send ""
27 type_acount: "simple", // simple => Business(Pas de site web), pro => Site E-Commerce (Pour les sites web)
28 promo_code: "",
29 day_get_funds: "Mardi"
30 };
31
32 try {
33 const response = await paytechService.register(registerRequest);
34
35 if (response.isSuccess) {
36 console.log("Registration successful!");
37 console.log("Message:", response.message);
38 } else {
39 console.error("Registration failed!");
40 console.error("Error message:", response.message);
41 }
42 } catch (error) {
43 console.error("Exception occurred during registration:", error);
44 }
45}
46
47/**
48 * Example 2: Login to get customer information
49 */
50async function loginExample() {
51 const email = "moussa_ndour@hotmail.fr";
52 const password = "azerty";
53
54 try {
55 const response = await paytechService.getCustomerInfo(email, password);
56
57 if (response.isSuccess && response.customerInfo) {
58 console.log("Login successful!");
59 console.log("Customer name:", `${response.customerInfo.customer.firstName} ${response.customerInfo.customer.lastName}`);
60 console.log("Business name:", response.customerInfo.customer.businessName);
61 console.log("Account balance:", response.customerInfo.customer.balance.amount);
62 console.log("Account type:", response.customerInfo.customer.accountType);
63 } else {
64 console.error("Login failed!");
65 console.error("Error message:", response.message);
66 }
67 } catch (error) {
68 console.error("Exception occurred during login:", error);
69 }
70}
71
72// Run the examples
73(async () => {
74 console.log("===== Register Example =====");
75 await registerExample();
76
77 console.log("\n===== Login Example =====");
78 await loginExample();
79})();