Property Razorpay does not exist on type window

Discussão em 'Angular' iniciado por pufaxeh, Março 14, 2025.

  1. pufaxeh

    pufaxeh Guest

    In the second last line i get the eror Property Razorpay does not exist on type window. The app runs without any problem with this error and the payment gateway works. The vsCode highlights the file as red due to error but It complies successfully and then prints the error message below in the command line interface. How to get rid of this error.

    export class InvoiceDetailComponent implements OnInit {
    _id: Number;
    singleInvoiceDetail: any;

    rzp1: any;
    title = 'app';
    options = {
    'key': 'dsewweewew',
    'amount': '2000',
    'name': 'Merchant Name',
    'description': 'Purchase Description',
    'image': 'http://localhost:4200/theme/images/logo.svg',
    'handler': function(response: any) {
    alert(response.razorpay_payment_id);
    },
    'prefill': {
    'name': 'dsdsdsds',
    'email': 'dshil@razorpay.com'
    },
    'notes': {
    'address': 'Hello World'
    },
    'theme': {
    'color': '#F37254'
    }
    };

    constructor(
    private activatedRoute: ActivatedRoute,
    private auth: AuthService, private router: Router,
    @Inject(WINDOW)private window: Window) { }

    ngOnInit() {

    }

    public initPay(): void {
    console.log(window);
    this.rzp1 = window.Razorpay(this.options);
    this.rzp1.open();
    }
    }


    Window service file which is being imported

    import { isPlatformBrowser } from "@angular/common";
    import { Injectable } from '@angular/core';
    import { ClassProvider, FactoryProvider, InjectionToken, PLATFORM_ID } from '@angular/core';

    /* Create a new injection token for injecting the window into a component. */
    export const WINDOW = new InjectionToken('WindowToken');

    /* Define abstract class for obtaining reference to the global window object. */
    export abstract class WindowRef {

    get nativeWindow(): Window | Object {
    throw new Error('Not implemented.');
    }

    }

    /* Define class that implements the abstract class and returns the native window object. */
    export class BrowserWindowRef extends WindowRef {

    constructor() {
    super();
    }

    get nativeWindow(): Window | Object {
    return window;
    }

    }

    /* Create an factory function that returns the native window object. */
    export function windowFactory(browserWindowRef: BrowserWindowRef, platformId: Object): Window | Object {
    if (isPlatformBrowser(platformId)) {
    return browserWindowRef.nativeWindow;
    }
    return new Object();
    }

    /* Create a injectable provider for the WindowRef token that uses the BrowserWindowRef class. */
    const browserWindowProvider: ClassProvider = {
    provide: WindowRef,
    useClass: BrowserWindowRef
    };

    /* Create an injectable provider that uses the windowFactory function for returning the native window object. */
    const windowProvider: FactoryProvider = {
    provide: WINDOW,
    useFactory: windowFactory,
    deps: [ WindowRef, PLATFORM_ID ]
    };

    /* Create an array of providers. */
    export const WINDOW_PROVIDERS = [
    browserWindowProvider,
    windowProvider
    ];

    Continue reading...

Compartilhe esta Página