There was a problem loading the comments.

Appcell - Switch Customer Product status

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

With the development of AppCell, new functionalities come in use.

Now, the direct change of the Service status of a Customer Product in the Management Panel (by an Administrator) is an action completed in the system (and on the backend) by AppCell itself. This is done from the Billia Management Panel, in the Services tab of a specific user’s profile.

The code

The PHP code below incorporates all cases for the switch between Service statuses of Customer products. The statuses that can manually be set for a Customer product are active, suspended and terminated.

  1. $data['status'] - defines the new status preferred to be set up;
  2. $currentCustomerProduct['status'] - defines the current status of the Customer product - if it is in array or it’s a single status case.
switch ($data['status']) {
	case 'active':
		if (in_array($currentCustomerProduct['status'], ['pending', 'configure'])) {
			$action = 'create';
		} else if (in_array($currentCustomerProduct['status'], ['inactive', 'suspended', 'redemption'])) {
			$action = 'unsuspend';
		} else if ($currentCustomerProduct['status'] == 'terminated') {
			throw new \RuntimeException('Could not activate a terminated service. Use `save only` option if you are sure what you are doing.' . 422);
		}
		break;
	case 'suspended':
		if (in_array($currentCustomerProduct['status'], ['pending', 'configure'])) {
			throw new \RuntimeException('Could not suspend not created product. Use `save only` option if you are sure what you are doing.' . 422);
		} else if (in_array($currentCustomerProduct['status'], ['active', 'expired'])) {
			$action = 'suspend';
		} else if ($currentCustomerProduct['status'] == 'terminated') {
			throw new \RuntimeException('Could not suspend a terminated service. Use `save only` option if you are sure what you are doing.' . 422);
		}
		break;
	case 'terminated':
		if ($currentCustomerProduct['status'] !== 'suspended') {
			throw new \RuntimeException('You can terminate only a suspended service. Use `save only` option if you are sure what you are doing.' . 422);
		}
		$action = 'terminate';
		break;
}

When a switch is made to one of the three available statuses, the logic will include all the information from case ‘status’ to break. Various cases exist for the purpose. The action that AppCell would take depends on the status of the Customer product, prior to the change:

  • pending and configure - the product is created but not yet provisioned;
  • active - the product is created, provisioned and can be used;
  • expired - the product is no longer available for use as its active period has ended;
  • inactive and suspended - the product is created, provisioned and suspended from use;
  • redemption - the product is suspended from use and requires additional fee to be reactivated;
  • terminated - the product is terminated and cannot be reactivated any more.

Tip: To see all Service Statuses and their full definitions, please click here.

Example:

switch ($data['status']) {
	case 'active':
		if (in_array($currentCustomerProduct['status'], ['pending', 'configure'])) {
			$action = 'create';
		} else if (in_array($currentCustomerProduct['status'], ['inactive', 'suspended', 'redemption'])) {
			$action = 'unsuspend';
                }
}

This portion of the code defines that: AppCell is to change the Service Status of the Customer Product to active. If that product’s current Service Status is pending or configure, AppCell will need to make the action create, which will activate the Customer Product. If its current Service Status is inactive or suspended AppCell will need to make the action unsuspend which will on its end reactivate the product, etc._

In each of those cases, the system takes into account the current status of the Customer Product and, according to it, takes the appropriate action to complete the initial query. In this case - activate the Product.

The logic of switching Service statuses of Customer products can be ceased by using a specific header in the http request: AppCell-Mode: save_only.

Errors

The code also includes preset errors to be used in cases where the requested switch is illogical or not possible.

Example:

switch ($data['status']) {
	case 'active':
if ($currentCustomerProduct['status'] == 'terminated') {
			throw new \RuntimeException('Could not activate a terminated service. Use `save only` option if you are sure what you are doing.' . 422);
		}
}

A Customer product in the status terminated cannot be reactivated like that, it has to be repurchased. So the system will throw a \RuntimeException error 422.


Share via

Related Articles

© ApiHawk