Change subscription credit card

PATCH/subscriptions/{subscriptionId}/credit-card

Replaces the credit card of a subscription of the business.

  • Tokenize the new card with the Easyflow JavaScript SDK and send the token in creditCard.token. The token goes only in this request: no response and no webhook returns it. The next recurrences are charged to the new card saved in the subscription, without a new token.
  • The API key must have write access to subscriptions, and its user must be a collaborator of the business sent in business-id. Only the business that owns the subscription can change its card.
  • Recurrences after the first one that are delayed or failed, and whose payments all failed, are sent to be charged on the new card. Their IDs come in retriedRecurrenceIds, and the result of each charge arrives by webhook.
  • A recurrence is left out of retriedRecurrenceIds, and is not charged by this request, when the subscription is active and the next automatic retry of the recurrence is already due (the automatic retry charges it), or when the recurrence was retried in the last 10 minutes.
  • When a recurrence is sent to be charged and the subscription is inactive, it becomes active again.
  • Easyflow sends the subscription.updated webhook.
  • A subscription that is canceled or expired cannot have its card changed.
  • Up to 30 requests per minute for each user (all API keys of the same user share the limit). Above that, the API returns 429 with the Retry-After header.

Headers

  • x-api-keystringrequired

    Api key provided on integrations tab in Easyflow platform.

  • x-api-secretstringrequired

    Api Secret provided on integrations tab in Easyflow platform.

  • business-idstringrequired

    Identifier of the business the request refers to. The user of your API key must be linked to this business, as explained in The business identifier. A value that is not a business identifier returns 400 with Invalid param: [businessId], and a business that the user is not linked to returns 403.

Path parameters

  • subscriptionIdstring · uuidrequired

    ID of the subscription.

Request bodyrequired

Content typeapplication/jsonobject

  • creditCardobjectrequired

    Credit card of the buyer. The card number is sent only inside token, created with the Easyflow JavaScript SDK.

    Show child attributesHide child attributes
    • tokenstringrequired

      Encrypted card token returned by the Easyflow JavaScript SDK. Sent only in this request. No response and no webhook returns it.

    • last4Numbersstringrequired

      Last 4 digits of the card.

    • holderNamestringrequired

      Name printed on the card.

    • expiresAtMonthintegerrequired

      Expiration month of the card.

    • expiresAtYearintegerrequired

      Expiration year of the card.

    • flagstringrequired

      Card brand.

      Possible values:visamastercardamerican-expressdiners-clubdiscoverjcbunionpaymaestromirelohiperhipercard

  • buyerobjectrequired
    Show child attributesHide child attributes
    • deviceobjectrequired

      Device of the buyer, sent with the card. When the subscription is created, it is also written to the metadata of the first order.

      Show child attributesHide child attributes
      • ipstringrequired

        IP address of the buyer. Never send the IP address of your server.

      • fingerprintIdstringrequired

        Fingerprint of the device of the buyer.

      • userAgentstringrequired

        User agent of the browser of the buyer.

Responses

200The card was changed.

The card was changed.

Content typeapplication/jsonobject

  • statusCodeinteger

    Example:200

  • dataobject
    Show child attributesHide child attributes
    • subscriptionIdstring · uuid

      ID of the subscription.

    • statusstring

      Status of the subscription after the change.

      Possible values:activeinactivecanceledexpired

    • creditCardobject

      The new card.

      Show child attributesHide child attributes
      • last4Numbersstring
      • holderNamestring
      • expiresAtMonthinteger
      • expiresAtYearinteger
      • flagstring

        Possible values:visamastercardamerican-expressdiners-clubdiscoverjcbunionpaymaestromirelohiperhipercard

    • retriedRecurrenceIdsarray of strings · uuid

      IDs of the recurrences sent to be charged on the new card. Empty when there was none.

400A field is missing or invalid; or the subscription does not exist, is not a valid ID or belongs to another business (message Invalid param: [subscriptionId]); or the subscription is canceled or expired (errorCode SUBSCRIPTIONCARDSUBSCRIPTIONFINISHED); or the subscription has no card registered (errorCode SUBSCRIPTIONCARDSUBSCRIPTIONWITHOUTCARD).

A field is missing or invalid; or the subscription does not exist, is not a valid ID or belongs to another business (message Invalid param: [subscriptionId]); or the subscription is canceled or expired (errorCode SUBSCRIPTION_CARD_SUBSCRIPTION_FINISHED); or the subscription has no card registered (errorCode SUBSCRIPTION_CARD_SUBSCRIPTION_WITHOUT_CARD).

Content typeapplication/jsonobject

  • messagestring

    Invalid param: []

    Example:Invalid param: []

  • errorstring

    Bad Request

    Example:Bad Request

  • statusCodeinteger

    400

    Example:400

  • errorCodestring

    Code that identifies the error. Present only on some errors.

401The credential is missing or invalid, or the business-id header is missing (message BusinessId is required).

The credential is missing or invalid, or the business-id header is missing (message BusinessId is required).

Content typeapplication/jsonobject

  • messagestring

    Invalid field

    Example:Unauthorized

  • errorstring

    Unauthorized

    Example:Unauthorized

  • statusCodeinteger

    401

    Example:401

403The API key has no write access to subscriptions, or its user is not a collaborator of the business sent in business-id.

The API key has no write access to subscriptions, or its user is not a collaborator of the business sent in business-id.

Content typeapplication/jsonobject

  • messagestring

    Forbidden resource

    Example:Forbidden resource

  • errorstring

    Forbidden

    Example:Forbidden

  • statusCodeinteger

    403

    Example:403

422The card could not be used. The errorCode field tells why: SUBSCRIPTIONCARDINVALIDCARDTOKEN, SUBSCRIPTIONCARDCUSTOMERNOTFOUND, SUBSCRIPTIONCARDDATAUNREADABLE, SUBSCRIPTIONCARDREJECTED or SUBSCRIPTIONCARDPAYMENTSERVICEUNAVAILABLE (temporary failure; try again later).

The card could not be used. The errorCode field tells why: SUBSCRIPTION_CARD_INVALID_CARD_TOKEN, SUBSCRIPTION_CARD_CUSTOMER_NOT_FOUND, SUBSCRIPTION_CARD_DATA_UNREADABLE, SUBSCRIPTION_CARD_REJECTED or SUBSCRIPTION_CARD_PAYMENT_SERVICE_UNAVAILABLE (temporary failure; try again later).

Content typeapplication/jsonobject

  • statusCodeintegerrequired

    HTTP status code.

  • messagestringrequired

    Explanation of the error.

  • errorstring

    Name of the HTTP status, such as Bad Request or Conflict.

  • errorCodestring

    Code that identifies the error. Present only on some errors.

429More than 30 requests in a minute for the user (all API keys of the same user share the limit). The message is Too many requests, retry after the Retry-After seconds. Wait the number of seconds in the Retry-After header before sending a new request.

More than 30 requests in a minute for the user (all API keys of the same user share the limit). The message is Too many requests, retry after the Retry-After seconds. Wait the number of seconds in the Retry-After header before sending a new request.

Content typeapplication/jsonobject

  • statusCodeinteger

    HTTP status code.

    Example:429

  • messagestring

    Explanation of the error.

    Example:Too many requests, retry after the Retry-After seconds

500If an unexpected condition occurs and the server cannot process the request, the API will return the following error response. This response has no error field.

If an unexpected condition occurs and the server cannot process the request, the API will return the following error response. This response has no error field.

Content typeapplication/jsonobject

  • statusCodeinteger

    HTTP status code.

    Example:500

  • messagestring

    Explanation of the error.

    Example:Internal Server Error