Preventing Duplicate Subscriptions for API Consumers
2023-10-5 20:35:35 Author: blogs.sap.com(查看原文) 阅读量:4 收藏

SAP Subscription Billing is a cloud solution for the management and billing of subscriptions. Subscriptions are created mainly via the user interface or via integrations, which can be enabled by predefined packages from SAP or by building custom integrations with the SAP Subscription Billing APIs and Business Events.

If you have a custom integration, this blog post will provide you with a handy trick that will help you preventing duplicate subscriptions from being created by your frontend system. When could this happen? For example, if the same data is sent twice due to a temporary interruption in the network connection.

Example Use Case

Via their online shop, a provider of coffee solutions for businesses and private consumers offers subscription-based deliveries. When a customer signs up for a new subscription, the data required to start billing the subscription is sent from the online shop to SAP Subscription Billing via a custom integration built with the Subscriptions API.

Procedure

To create subscriptions as triggered by an integrated system, you need the API operation POST on /subscriptions. In the request, apart from the usual data required for the creation (customer, market, product, rate plan, and so on), add the attribute externalUniqueID.

The external unique ID is a string that allows you to uniquely identify subscription data that is sent from an external system. In turn, this allows you to prevent the creation of duplicates. In our example, the string is the subscription order ID from the online shop.

A very basic request containing the external unique ID could look like this:

{
  "customer": {
    "id": "608827985",
    "structureElement": "S-001"
  },
  "market": {
    "id": "A1"
  },
  "validFrom": "2024-01-01T05:00:00.000Z",
  "snapshots": [
    {
      "effectiveDate": "2024-01-01T05:00:00.000Z",
      "items": [
        {
          "itemId": "10",
          "product": {
            "id": "14c3240a-04a5-4bdb-8b55-e3d6a56e3c69"
          }
          ],
          "subscriptionType": "Commercial",
          "ratePlan": {
            "id": "50bb0865-9607-4966-82a4-9aa08925ded2",
            "source": "product"
          }
        }
      ],

}
  "externalUniqueId": "f0239ce75f8e528814618638c4a6caed"
}

Every time that you send a request with an external unique ID, the system checks whether a subscription already exists with that ID. If so, the system rejects the request, which prevents the creation of a duplicate subscription for the same order.

Additional Reading Materials

If you’re just getting started with our APIs and business events, the following blog posts are a good starting point:

And did you like our example use case about offering coffee as a service? If you want to learn more about modelling subscriptions of consumables, see our blog post Modelling the Replenishment of Consumables with Subscription Notifications.

More Information About SAP Subscription Billing


文章来源: https://blogs.sap.com/2023/10/05/preventing-duplicate-subscriptions-for-api-consumers/
如有侵权请联系:admin#unsafe.sh