event subscribers – How to remove a role after a user adds a payment method in Commerce?


I am trying to set up a subscription-based site in Drupal 8/Commerce 2.

I’m using Commerce Stripe to process payments. I want to remove a role from a user (“needs to add new card” role) when the user adds a new payment method (credit card via Stripe) on the payment method page (user/UID/payment-methods).

I assume I need to write an event subscriber, but I don’t know which event to use for adding a payment method.

I tried to read through the code in commerce/modules/payment/src/EventSubscriber, but I couldn’t find the event I need to hook into to remove the role.

Background

When a user’s credit card has expired, they need to add a new card (add a new payment method). In this case, I have flagged the users with a role, Add new card role.

Then I show a block to users with the Add new card role that says “Please update your card info.” with a link to add a card.

However, when the user adds a new card, they still see the block asking them to add a new card, which is confusing. So I want to immediately remove the Add new card role (to hide the block) as soon as the user adds a new card.