Advertisement
nodejsdeveloperskh

interface implementation faults

Dec 11th, 2021
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export enum PaymentDevice {
  2.     'mobile' = 'mobile',
  3.     'desktop' = 'desktop',
  4. }
  5.  
  6. export interface PaymentError {
  7.     redirectTo: string;
  8.     message: string;
  9.     paymentGatewayResponse: any;
  10. }
  11.  
  12. export interface IPaymentService {
  13.     device: PaymentDevice;
  14.     redirectUrl: string;
  15.     errorResponse?: PaymentError;
  16.     createPaymentGateway(
  17.         payment: CreatePaymentGatewayInput,
  18.     ): string;
  19.     verifyPayment(): boolean;
  20. }
  21.  
  22. interface CreatePaymentGatewayInput {
  23.     amount: number;
  24.     description: string;
  25.     phoneNumber: string;
  26.     email: string;
  27. }
  28.  
  29. export class ZarinpalPaymentGatewayService
  30.     implements IPaymentService
  31. {
  32.     #device?: PaymentDevice;
  33.     #errorResponse?: PaymentError;
  34.     #redirectUrl?: string;
  35.  
  36.     set device(device: PaymentDevice) {
  37.         this.#device = device;
  38.     }
  39.  
  40.     get device() {
  41.         if (!this.#device) {
  42.             throw new Error('E_EMPTY_DEVICE')
  43.         }
  44.         return this.#device;
  45.     }
  46.  
  47.     set redirectUrl(redirectUrl: string) {
  48.         this.#redirectUrl = redirectUrl;
  49.     }
  50.  
  51.     get redirectUrl() {
  52.         if (!this.#redirectUrl) {
  53.             throw new Error('E_EMPTY_REDIRECT_URL')
  54.         }
  55.         return this.#redirectUrl;
  56.     }
  57.  
  58.     verifyPayment() {
  59.         return true;
  60.     }
  61.     // Why it does not show me an error for empty function parameter?
  62.     createPaymentGateway() {
  63.         const url =
  64.             'https://www.zarinpal.com/pg/StartPay/$Authority';
  65.         // const {} = payment;
  66.         return '';
  67.     }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement