Home > Enterprise >  Error: Uncaught (in promise): BraintreeError: options.authorization is required when instantiating a
Error: Uncaught (in promise): BraintreeError: options.authorization is required when instantiating a

Time:12-29

I am actually trying to implement braintree using Angular with asp.net core. But i am facing an issue, I don't understand how to solve it. I am follwing this enter image description here

I am a beginner. how to resolve this issue. or any alternative implementation? please help.

CodePudding user response:

It appears yu're not including your Braintree token in your request.

This is likely happening because you're making an asynchronous request before another completes.

A simple way to fix this would be to move the call to this.createBraintreeUI() inside the response to you token request.

Something like this:

  ngOnInit(): void {
    this.getToken();    
  }

  getToken() {
    this.http.get('https://localhost:5001/api/paypal').subscribe({
      next: response => { 
        console.log(this.CToken);
        this.CToken = response;
        this.createBraintreeUI(); 
      },
      error: error => console.log(error)
    })

  }

There may be more issues as this is a complex integration with Braintree, but if you see the console.log() statement showing your token, and the token looks correct, then you're on the right path.

(For instance, you might have another problem where you can't pass authorization: this.CToken there in the first line of your this.createBraintreeUI() function. You might have to set authorization to a property of this.CToken. So look at the console.log statement showing your token and see if it looks correct. )

  • Related