Apply Min/Max Order Quantity

Requirement

Minimum/Maximum quantity of a product should be enforced during the initial purchase of a product.

Target end point(s)

  • Subscription Create

Example Flow

Precheck Request

POST http://localhost/examplenew/api/example/subscriptions/create HTTP/1.1
X-CloudPlatform-ApplicationId: 9C292077-6907-4A95-BDE0-681B36CC7E86
X-CloudPlatform-APIKey: d3RzbXhNdmsrZGVZQzdleVV1dnV4ekZhT3VCSzRWemFVVXVHTDNGT2ViST0=
Accept-Language: en
X-CloudPlatform-Setting-FieldUsername: test
X-CloudPlatform-Setting-FieldPassword: test
X-CloudPlatform-Setting-FieldUri: http://google.com
X-CloudPlatform-Setting-FieldRegion: http://google.com
X-CloudPlatform-TrackId: 30619dec-560b-432c-a6fd-ebf0b7768ecd
Content-Type: application/json; charset=UTF-8
Accept: Accept=application/json
Host: localhost
Content-Length: 1446
{
 -----------------
 "Quantity": 1,
 -----------------
 "CheckOnly": true,
 -----------------
}

Key points:

Line 16Quantity” property contains the quantity requested for new service activation
Line 18CheckOnly” property is set to true in case the call is performed just for pre-provisioning validation purposes

Example of precheck code

Using .NET Service Manager SDK

[Route("Subscriptions/Create")]
public override IHttpActionResult SubscriptionsCreate(ServiceDefinition definition)
{
  int minimumQuantity = 3;
  int minimumQuantityErrorCode = -105;
  string minimumQuantityErrorMessage = "Purchase of product could not be made with quantity less that 3";

  using (var tracer = new LogTracer(LogActionInput, 
                                              Logging, 
                                              ActionName, 
                                              ActionLogUUID, 
                                              new List<object>() { definition }))
  {
	ServiceResultDefinition result = new ServiceResultDefinition();

    //Check minimum quantity requirement
    if (definition.Quantity < minimumQuantity)
		return ErrorResult(ActionLogUUID, minimumQuantityErrorCode, minimumQuantityErrorMessage);
                
    if (definition.CheckOnly)
		return SuccessResult(ActionLogUUID, result);
                
    //Continue provisioning actions here

    return SuccessResult(ActionLogUUID, result);
  }
}

Variables

VariableDescription
minimumQuantitythe minimum quantity that should be enforced for new purchases
minimumQuantityErrorCodethe error code that will be used in case minimum quantity validation fails
minimumQuantityErrorMessagethe error message that will be used in case minimum quantity validation fails

Key points

LinesNotes
Lines 17-18compares minimum quantity with the quantity requested for the new purchase (definition.Quantity) and returns a failed response in case quantity validation fails.
Failed response is returned using error code (minimumQuantityErrorCode) and error message (minimumQuantityErrorMessage) variables.
Lines 20-21evaluates definition.CheckOnly property and terminates method’s execution before actual provisioning actions. A successful response is returned.

Successful Validation Response

HTTP/1.1 200 OK
Pragma: no-cache
Content-Length: 124
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Wed, 16 Jun 2021 15:55:03 GMT
{
  "AccountExtraInfo": null,
  "CustomFieldValues": null,
  "SendNotification": false,
  "ExtraInfo": {},
  "Code": 0,
  "Message": "",
  "Result": ""
}

Failed Validation Response

HTTP/1.1 200 OK
Pragma: no-cache
Content-Length: 103
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Wed, 16 Jun 2021 15:50:58 GMT
{
  "Code": -105,
  "Message": "Purchase of product could not be made with quantity less that 3",
  "Result": null
}