Skip to content

Commit

Permalink
Added retry logic when mounting Stripe elements and extended timout t…
Browse files Browse the repository at this point in the history
…o 50 ms
  • Loading branch information
cturnbull-bitwarden committed Jan 29, 2025
1 parent ef38a96 commit 66966c5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions apps/web/src/app/billing/services/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,21 @@ export class StripeService {
* Re-mounts previously created Stripe credit card [elements]{@link https://docs.stripe.com/js/elements_object/create} into the HTML elements
* specified during the {@link loadStripe} call. This is useful for when those HTML elements are removed from the DOM by Angular.
*/
mountElements() {
mountElements(i: number = 0) {
setTimeout(() => {
if (!document.querySelector(this.elementIds.cardNumber) && i < 10) {
this.logService.warning("Stripe container missing, retrying...");
this.mountElements(i + 1);
return;

Check warning on line 77 in apps/web/src/app/billing/services/stripe.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/billing/services/stripe.service.ts#L75-L77

Added lines #L75 - L77 were not covered by tests
}

const cardNumber = this.elements.getElement("cardNumber");
const cardExpiry = this.elements.getElement("cardExpiry");
const cardCvc = this.elements.getElement("cardCvc");
cardNumber.mount(this.elementIds.cardNumber);
cardExpiry.mount(this.elementIds.cardExpiry);
cardCvc.mount(this.elementIds.cardCvc);
});
}, 50);
}

/**
Expand Down

0 comments on commit 66966c5

Please sign in to comment.