Java | Stripe – Handling expired credit cards

| By Webner


We are registering our customers using Stripe payment gateway where we are storing customer card details. We are doing recurring payment for customers periodic billing cycle. But if customer’s card expires or card number changes, we will not get any information about that and our billing cycle will stop there. We need to inform customer to provide new card details to us in case of card expiry. But, if customers have to update those details for the services they are using, it could be frustrating for them and we may lose paying customers.


If you are using Stripe payment gateway then we don’t need to worry about this issue. Stripe gateway provides a wonderful feature to handle expired cards. Stripe gateway directly interacts with Card update networks and provides every update related to the cards periodically and your customer can use your services without any obstacles. Whenever Stripe gateway receives card update associated with your Stripe customer account, it will fire “Customer.source.updated” web-hook event. It will send the complete request specifying modified card details in the request. The request will be similar to the one mentioned below:

Card Update Request:

  "id": "evt_1AXBfSKU9sddfgojRLUDxGcw2ba",
  "object": "event",
  "api_version": "2017-04-06",
  "created": 1498062418,
  "data": {
    "object": {
      "id": "stripe_card_id",
      "object": "card",
      "address_city": null,
      "address_country": null,
      "address_line1": null,
      "address_line1_check": null,
      "address_line2": null,
      "address_state": null,
      "address_zip": null,
      "address_zip_check": null,
      "brand": "MasterCard",
      "country": "IE",
      "customer": "stripe_test_customer_id",
      "cvc_check": null,
      "dynamic_last4": null,
      "exp_month": 6,
      "exp_year": 2020,
      "fingerprint": "z56KA47dfvKPS3sKrA",
      "funding": "credit",
      "last4": "7073",
      "metadata": {
      "name": null,
      "tokenization_method": null
    "previous_attributes": {
      "exp_year": 2017
  "livemode": true,
  "pending_webhooks": 1,
  "request": null,
  "type": "customer.source.updated"

This is the example of a dummy request which we will receive on card update. In the above request you can see:

"previous_attributes": {
      "exp_year": 2017

The above request has changed the customer card expiry date. With the new details typed below:

“exp_month”: 6,
“exp_year”: 2020,

The card expiry year has been updated from “2017” to “2020”.

What you have to do now is, to capture the request and write some custom code to update these details in your database where you are storing them and this way your billing cycle will go smoothly. Your clients have no need to update their card details manually.

Leave a Reply

Your email address will not be published. Required fields are marked *