Advertisement
sidson

Paytech Service Use

Apr 6th, 2025 (edited)
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { PayTechService, PaytechRegisterRequest } from './paytech-service';
  2.  
  3.  
  4. // Get an instance of the service
  5. const paytechService = PayTechService();
  6.  
  7. /**
  8.  * Example 1: Register a new customer
  9.  */
  10. async function registerExample() {
  11.   const registerRequest: PaytechRegisterRequest = {
  12.     fname: "Moussa",
  13.     lname: "Ndour",
  14.     phone: "+221777679700",
  15.     countryCode: "sn",
  16.     email: "[email protected]",
  17.     adress: "Almadies",
  18.     pass: "azerty",
  19.     confPass: "azerty",
  20.     business_name: "Mon Business",
  21.     website: "https://github.com/touskar", //optionnel can send ""
  22.     type_acount: "simple", // simple => Business(Pas de site web), pro => Site E-Commerce (Pour les sites web)
  23.     promo_code: "",
  24.     day_get_funds: "Mardi"//Mardi, Vendredi
  25.   };
  26.  
  27.   try {
  28.     const response = await paytechService.register(registerRequest);
  29.    
  30.     if (response.isSuccess) {
  31.       console.log("Registration successful!");
  32.       console.log("Message:", response.message);
  33.     } else {
  34.       console.error("Registration failed!");
  35.       console.error("Error message:", response.message);
  36.     }
  37.   } catch (error) {
  38.     console.error("Exception occurred during registration:", error);
  39.   }
  40. }
  41.  
  42. /**
  43.  * Example 2: Login to get customer information
  44.  */
  45. async function loginExample() {
  46.   const email = "[email protected]";
  47.   const password = "azerty";
  48.  
  49.   try {
  50.     const response = await paytechService.getCustomerInfo(email, password);
  51.    
  52.     if (response.isSuccess && response.customerInfo) {
  53.       console.log("Login successful!");
  54.       console.log("Customer name:", `${response.customerInfo.customer.firstName} ${response.customerInfo.customer.lastName}`);
  55.       console.log("Business name:", response.customerInfo.customer.businessName);
  56.       console.log("Account balance:", response.customerInfo.customer.balance.amount);
  57.       console.log("Account type:", response.customerInfo.customer.accountType);
  58.     } else {
  59.       console.error("Login failed!");
  60.       console.error("Error message:", response.message);
  61.     }
  62.   } catch (error) {
  63.     console.error("Exception occurred during login:", error);
  64.   }
  65. }
  66.  
  67. // Run the examples
  68. (async () => {
  69.   console.log("===== Register Example =====");
  70.   await registerExample();
  71.  
  72.   console.log("\n===== Login Example =====");
  73.   await loginExample();
  74. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement