Pages

Sunday, October 15, 2017

Episode 557: Fully Automatic Billing Flow that Communicates with Various APIs


Operation: A Large Amount of the End of the Month Billing

The monthly billing business at the end of the month has become to be conducted without missing!

With regard to "charged amount" to each customer, it became possible to catch in real time that who has input or who approved and when. Moreover, thanks to the "Automatic Step" which accesses the credit company API (Stripe API), charging to credit cards are directly performed from the Workflow system. In other words, it eliminates "dual entry" into the accounting system.

Challenge: Reduce Dependence on Human

However, this Business Process is still depending on "data input by human". That is, a human (sales representative) is in charge of input of "billing amount" that is crucial.

Certainly, "customer information" is set automatically, and "card billing code" (Stripe CustomerID) is also preset. Furthermore, "list of billing work" also appears on the list of Offered without missing, so it is easy to do the billing work by multiple people cooperating. So, I think that "labor saving of inputting" has been realized at a fairly high level, but...

However, the information on "charge amount" (billing amount) is in the "Sales management system" which is an "external system" from the viewpoint of the Workflow system. I wonder if there is a measure to automatically acquire sales summary somehow? (Today, "API economy" is urged out, and I think that where Business Process Improvement is heading to is "unmanned"...)

[Credit Card Charging - Recursive call-Full automation]


Solution: Automatic Cooperation with Sales Aggregation System

After a year of working on business process management activities (BPM activities), we want to sublimate the goal of "labor saving of input work" into "unattended input work" (human excluding).

That is, if you can replace "Human Task" (light blue rectangular icon) on the defined Workflow chart (Process diagram) with "Service Task" (gray rectangular icon: auto-Step), it will be no longer necessary to consider "human error" or "human processing speed. As a result, double check process such as approval and confirmation, for example, will become unnecessary, and it will not stagnate on holiday or even off business hours. In addition, you will not have to worry about falling into "talent shortage" in the rapid expansion phase (scale out period) of business.

The Business Process Definition introduced here is one that I made some arrangements to make all Steps unmanned, into the "Credit Card Charging process" (Stripe card billing) in the Episode 556.

Basically
  • The human Task of [1. Charge amount entry] has been divided into an auto-Step of [Acquisition of Sales Results] and a human Task of [1. Billing info edit], and,
  • the human Task of [2. Approval] has been substituted with [2. Monitoring], a human Task.

At first glance it seems that the "human Tasks" has not decreased, but the deadline time is set for the newly placed human Task, and it is set to automatically advance to the next Step when the deadline time comes. In other words, it is a human Task that is to be operated only when there is a change in information, so human beings are not involved in normal times. (A Human Task with Timer Boundary Event)

Discussion: Things to be Careful in Fully Automation

Automatic processing (auto-Step) in the BPM system / Workflow system is realized by a Workflow engine (server side) that controls instance progress.

In this example, the monthly "Billing amount" (invoiced amount) is automatically acquired at the auto-Step (Acquisition of Sales Results). As a disadvantage, you will need a script to communicate with the sales management system. In other words, programming knowledge is required. In other words, programming knowledge is required. Also for the sales management system side, it is necessary that an "API for returning the amount as response" has been implemented.
* As a "sales management system", not only the so-called "sales management cloud service" but also a commercial transaction platform such as "EDI system", and a simple database such as "Google Sheets" and "Cybozu kintone" are assumed. (EDI: Electronic Data Interchange)


Human involvement is still important even when all Steps has been automated and the entire Business Process has become unmanned. That is, it is important to 1) to be properly monitored by humans, and 2) to prepare a flow to recover by humans when an error occurred automatic processing. In this example, you can operate "2. Billing Monitor" during the time from "acquisition date and time of accounting actual" until "Schedule notification date and time". In this, it is supposed to take measures such as "discontinue processing" when some kind of error is detected.

[Setting example of Script Task "Acquisition of Sales results" (Server side JavaScript) ]
/// Sum of a series of numbers in a Google Spreadsheet (ver. 20171011)
/// (c) 2017, Questetra, Inc. (the MIT License)

//// == OAuth2 config ==
// Authorization Endpoint URL: https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force
// Token Endpoint URL: https://accounts.google.com/o/oauth2/token
// Scope: https://www.googleapis.com/auth/spreadsheets
// Consumer Key: (via Google Developers Console)
// Consumer Secret: (via Google Developers Console)

var token = httpClient.getOAuth2Token( "Google-Sheets" );


//// == Data Retrieving ==
var driveFileId = "zxcv123EXAMPLE321vnm";
var monthYear = engine.findDataByName( "Date and time of Sales results acquisition" ).toString() + ""; // "2017-12-30 12:34"
    monthYear = monthYear.slice(0,7); // "2017-12"
var customerEmail = engine.findDataByName( "Email" ) + ""; // "bill@example.com"
var sheetRange = "A:C"; // A:customerEmail, B:amount, C:description


//// == Calculating ==
// preparing for API Request
var apiRequest = httpClient.begin(); // HttpRequestWrapper
// com.questetra.bpms.core.event.scripttask.HttpClientWrapper

// preparing for API Request (OAuth2 Token)
apiRequest = apiRequest.bearer( token );

// preparing for API Request (Path parameters)
var apiUri = "https://sheets.googleapis.com/v4/spreadsheets/";
    apiUri += driveFileId;
    apiUri += "/values/";
    apiUri += monthYear;
    apiUri += "!";
    apiUri += sheetRange;

// preparing for API Request (Query parameters)
// (no set)

// preparing for API Request (JSON Body, Form Parameters)
// (no set)

// Request to the API (GET)
var response = apiRequest.get( apiUri ); // HttpResponseWrapper
var httpStatus = response.getStatusCode() + "";
var accessLog = "---GET request--- " + httpStatus + "\n";
accessLog += response.getResponseAsString() + "\n";
var responseObj = JSON.parse( response.getResponseAsString() );

// Retrieve Properties from Response-JSON
var sumOfSales = 0;
var listOfCharge = "";
if( httpStatus === "200" ){
  for( var i = 0; i < responseObj.values.length; i++ ){
    if( responseObj.values[i][0] === customerEmail ){
      sumOfSales += parseFloat( responseObj.values[i][1] );
      listOfCharge += responseObj.values[i][2] + ", ";
    }
  }
}

// Error Handling
// (no action)


//// == Data Updating ==
engine.setDataByNumber( "28", listOfCharge );
engine.setDataByNumber( "8", java.math.BigDecimal( sumOfSales ) );
[Credit Card Charging - Recursive call-Full automation:"2. Billing monitor" screen]
[Data Items list]
[Free download] &lt;Similar Models&gt; &lt;&lt;Related Articles&gt;&gt; [Japanese Entry (ε’Œζ–‡θ¨˜δΊ‹)]