I'm using ngx-stripe , and the createToken returns an Observable which I've tried to convert to a promise so that I can use Async/await. However, it looks as though the promise dosen't resolve. Debugging doesn't reveal anything, and my try/Catch blocks doesn't capture any errors.
I wanted to know whether I'm using the toPromise correctly :
import {
Elements,
Element as StripeElement,
ElementsOptions,
BankAccountData,
StripeService
} from 'ngx-stripe';
constructor(
public stripeService: StripeService,
) {}
async next() {
let token: any;
let account: BankAccountData = {
country: this.country,
currency: this.currency,
account_holder_name: this.first_name + " " + this.last_name,
account_holder_type: this.type,
account_number: account_number,
routing_number: routing_number
};
console.log("--> Creating Bankaccount Token", account);
try {
token = await this.stripeService.createToken("bank_account", account).toPromise();
} catch (excep) {
console.log(excep);
}
console.log("-->Token Generated : ", token);
}
EDIT
Debugger - if it helps. This is the last console output:
Creating Bankaccount Token {country: "AU", currency: "aud", account_holder_name: "Someone Name", account_holder_type: "individual", account_number: "000123456", …}
*************************EDIT *********************** I'm not sure why, but the code worked when I created a stackblitz.
I then compared the libraries in stackblitz and updated my angular, rxjs, rxjs-compat to match what was in stackblitz and tried again and I was getting the same result as before.
I then removed the toPromise() and changed it to :
this.stripeService.createToken("bank_account", account).subscribe(data => {
console.log(data);
});
I'm not sure what is limiting what my project has compared to what's in stackblitz. I'm not sure how to work out what the problem is, and the only thing I can think of is rebuilding the project from scratch.