Appearance
Get All Order
Navigate to the Workflow Definitions page and click the Create Workflow button.
We are now on the workflow designer canvas. Click the green Start button to open the Activity Picker
Search for the HTTP Endpoint activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
Path:
/get-all-orders
Methods:
GET
And click the Save button.We are now back in the designer which shows the HTTP Endpoint activity we just added.
The activity has a single outcome called Done. Click on the plus button below it to add and connect another activity to this outcome. The activity picker shows up again. This time, search for the SendQsPayRequest activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
Qspay Job:
Get All Orders
Supported Status Codes:
200,401
Name :
getAllOrders
Display Name :
Get All Orders
And click the Save button.
We are now back in the designer which shows the Get All Orders
activity we just added.
Click on the plus button below it to add and connect another activity to 401 outcome. The activity picker shows up again. Search for the SendQsPayRequest activity again and select it.
The next screen presents the available settings for the activity. Specify the following values:
Qspay Job:
User Authenticate
Content :
{'userName':'erp@****.com','password':'Test123!'}
Name :
userAuthenticate
Display Name :
User Authenticate
And click the Save button. We are now back in the designer which shows the User Authenticate
activity we just added. Mouse right click on the plus button below it to connect 200 outcome to previous activity.
Click on the plus button below it to add and connect another activity to Get All Orders
activity's 200 outcome. The activity picker shows up again. This time, search for the If/Else activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
- Condition :
return activities.getAllOrders.ResponseResultContent().Count>0
And click the Save button. We are now back in the designer which shows the If/Else activity we just added.
This activity will check if there are import orders from Qs-Pay to ERP. Click on the plus button below it to add and connect another activity to True outcome. The activity picker shows up again. This time, search for the For Each activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
- Items:
activities.getAllOrders.ResponseResultContent()
And click the Save button. We are now back in the designer which shows the For Each activity we just added.
Click on the plus button below it to add and connect another activity to Iterate outcome. The activity picker shows up again. This time, search for the Set Variable activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
Variable Name :
CurrentOrder
Value:
input
And click the Save button. We are now back in the designer which shows the Set Variable activity we just added.
Click on the plus button below it to add and connect another activity to Done outcome. The activity picker shows up again. This time, search for the If/Else activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
Condition :
var currentOrder = getVariable("CurrentOrder"); if(isEmpty(currentOrder.products)==true || (currentOrder.storePaymentDefinition.erpReferenceId==11 && isEmpty(currentOrder.transactions)==true)) { return false; } else { return true; }
And click the Save button. We are now back in the designer which shows the If/Else activity we just added.
Click on the plus button below it to add and connect another activity to True outcome. The activity picker shows up again. This time, search for the SendHttpRequest activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
- Url :
http://localhost:47690/order/add
The URL should be the API endpoint information that we will use to add the order on the merchant side.
Method :
POST
Content :
return getVariable("CurrentOrder");
In the example, we assume that the Merchant endpoint use the order data model at Qs-Pay.
If the EP model was different, we had to convert the order data model in Qs-Pay to EP model with the objectmapper.
Content Type :
application/json
ReadContent :
checked
Supported Status Codes:
200
Name :
addOrder
Display Name :
Add Order
And click the Save button.We are now back in the designer which shows the Add Order
activity we just added.
Click on the plus button below it to add and connect another activity to 200 outcome. The activity picker shows up again. This time, search for the SendQsPayRequest activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
Qspay Job:
Set Order ERP Reference
Content :
var response = jsonDecode(activities.addOrder.ResponseContent()); setVariable("MerchantTask",response.result); return jsonEncode(response.result.request);
Supported Status Codes:
200
Name :
setOrderErpReference
DisplayName :
Set Order Erp Reference
And click the Save button. We are now back in the designer which shows the Set Order Erp Reference
activity we just added.
Click on the plus button below it to add and connect another activity to 200 outcome. The activity picker shows up again. This time, search for the SendHttpRequest activity and select it.
The next screen presents the available settings for the activity. Specify the following values:
- Url :
http://localhost:47690/QspayTask/updateImportTask
In the example, we assume that the order transfer process is logged on the merchant side. So the URL should be the API endpoint information that we will use to update log status on the merchant side.
Method :
POST
Content :
var item = getVariable("MerchantTask"); var response = activities.setOrderErpReference.ResponseContent(); var request = {TaskId: item.taskId, Result:response }; return jsonEncode(request);
Content Type :
application/json
ReadContent :
checked
Supported Status Codes:
200
Name :
updateMerchantTask
And click the Save button.
Finally, let's give our workflow a name. From the designer, you'll find a cog-wheel button at the top-right of the screen. Click it to open the workflow settings and provide the following values:
Name: GetAllOrders
Display Name: Get All Orders
Leave the rest to their defaults and click the Save button.
Back on the designer, click the Publish button on the bottom-right of the screen. The workflow is now published and ready to be invoked!
We'll try out the workflow in a second. Here's an video that shows the above steps: