{
	"info": {
		"_postman_id": "9366335d-9af3-4033-a9d6-4e05bbb92e7a",
		"name": "Order Revision",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "Authenticate FC_FASHION Retailer",
			"item": [
				{
					"name": "Fluent Auth - Retailer FC_FASHION",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"const jsonData = pm.response.json();",
									"var currentRetailerRef = pm.environment.get(\"fluent.retailer.current.ref\");",
									"",
									"pm.environment.set(\"fluent.retailer.current.token\", jsonData.access_token);",
									"pm.environment.set(\"fluent.retailer.\" + currentRetailerRef + \".token\", jsonData.access_token);",
									"",
									"var expiryTime = new Date(Date.now() + (jsonData.expires_in * 1000));",
									"console.log(\"Token will expire at: \" + expiryTime);",
									"pm.environment.set(\"fluent.retailer.current.token.expiry_time\", expiryTime);",
									"pm.environment.set(\"fluent.retailer.\" + currentRetailerRef + \".token.expiry_time\", expiryTime);",
									"pm.environment.set(\"fluent.retailer.current.customer.id\", pm.environment.get(\"fluent.retailer.\" + currentRetailerRef + \".customer.id\"));",
									"",
									"console.log(\"Setting current retailer token: \" + pm.environment.get(\"fluent.retailer.current.token\") + \", RetailerRef: \" + pm.environment.get(\"fluent.retailer.current.ref\") + \", RetailerId: \" + pm.environment.get(\"fluent.retailer.current.id\"));",
									""
								],
								"type": "text/javascript"
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"",
									"let use_unique_suffix = (pm.environment.has(\"fluent.data.use_unique_suffix\") && pm.environment.get(\"fluent.data.use_unique_suffix\") == true) ? true : false;",
									"",
									"let currentRetailerRef = \"fc_fashion\";",
									"if (use_unique_suffix) {",
									"    currentRetailerRef = currentRetailerRef + \"_\" + pm.environment.get(\"fluent.data.unique_suffix\");",
									"}",
									"",
									"pm.variables.set(\"fc_fashion_username\", pm.environment.get(\"fluent.retailer.\" + currentRetailerRef + \".user.username\"));",
									"pm.variables.set(\"fc_fashion_password\", pm.environment.get(\"fluent.retailer.\" + currentRetailerRef + \".user.password\"));",
									"",
									"pm.environment.set(\"fluent.retailer.current.id\", pm.environment.get(\"fluent.retailer.\" + currentRetailerRef + \".id\"));",
									"pm.environment.set(\"fluent.retailer.current.ref\", pm.environment.get(\"fluent.retailer.\" + currentRetailerRef + \".ref\"));",
									"pm.environment.set(\"fluent.retailer.current.user.username\", pm.environment.get(\"fluent.retailer.\" + currentRetailerRef + \".user.username\"));",
									"pm.environment.set(\"fluent.retailer.current.user.password\", pm.environment.get(\"fluent.retailer.\" + currentRetailerRef + \".user.password\"));",
									"",
									"",
									"",
									"console.log(\"Setting Current Retailer: \" + pm.environment.get(\"fluent.retailer.current.ref\") + \", Id: \" + pm.environment.get(\"fluent.retailer.current.id\"));",
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "noauth"
						},
						"method": "POST",
						"header": [],
						"url": {
							"raw": "{{fluent.account.host}}/oauth/token?username={{fc_fashion_username}}&password={{fc_fashion_password}}&client_id={{fluent.account.client_id}}&client_secret={{fluent.account.client_secret}}&scope=api&grant_type=password",
							"host": [
								"{{fluent.account.host}}"
							],
							"path": [
								"oauth",
								"token"
							],
							"query": [
								{
									"key": "username",
									"value": "{{fc_fashion_username}}",
									"description": "FC Fashion Admin User Username"
								},
								{
									"key": "password",
									"value": "{{fc_fashion_password}}",
									"description": "FC Fashion Admin User Password"
								},
								{
									"key": "client_id",
									"value": "{{fluent.account.client_id}}",
									"description": "Fluent Account Id / Client Id"
								},
								{
									"key": "client_secret",
									"value": "{{fluent.account.client_secret}}",
									"description": "Fluent Account Client Secret"
								},
								{
									"key": "scope",
									"value": "api"
								},
								{
									"key": "grant_type",
									"value": "password"
								}
							]
						},
						"description": "## Authenticate the FC FASHION Retailer Admin User\n\nUse this request to Authenticate your FC FASHION Retailer Admin User.\n\nThe response `access_token` will be saved into the `fluent.retailer.current.token` and the `fluent.retailer.<retailer_ref>.token` environment variable for use in future requests.\n\nFor more information: [Fluent API Authentication](https://lingo.fluentcommerce.com/DEVELOPERS/authentication/)"
					},
					"response": [
						{
							"name": "Fluent Auth - Account: SUCCESS",
							"originalRequest": {
								"method": "POST",
								"header": [],
								"url": {
									"raw": "{{fluent.account.host}}/oauth/token?username={{fluent.account.username}}&password={{fluent.account.password}}&client_id={{fluent.account.client_id}}&client_secret={{fluent.account.client_secret}}&scope=api&grant_type=password",
									"host": [
										"{{fluent.account.host}}"
									],
									"path": [
										"oauth",
										"token"
									],
									"query": [
										{
											"key": "username",
											"value": "{{fluent.account.username}}",
											"description": "Fluent Account Admin User Username"
										},
										{
											"key": "password",
											"value": "{{fluent.account.password}}",
											"description": "Fluent Account Admin User Password"
										},
										{
											"key": "client_id",
											"value": "{{fluent.account.client_id}}",
											"description": "Fluent Account Id / Client Id"
										},
										{
											"key": "client_secret",
											"value": "{{fluent.account.client_secret}}",
											"description": "Fluent Account Client Secret"
										},
										{
											"key": "scope",
											"value": "api"
										},
										{
											"key": "grant_type",
											"value": "password"
										}
									]
								}
							},
							"status": "OK",
							"code": 200,
							"_postman_previewlanguage": "json",
							"header": [
								{
									"key": "Date",
									"value": "Tue, 29 Oct 2019 00:45:57 GMT"
								},
								{
									"key": "Content-Type",
									"value": "application/json;charset=UTF-8"
								},
								{
									"key": "Transfer-Encoding",
									"value": "chunked"
								},
								{
									"key": "Connection",
									"value": "keep-alive"
								},
								{
									"key": "Server",
									"value": "nginx/1.10.3 (Ubuntu)"
								},
								{
									"key": "Access-Control-Allow-Origin",
									"value": "*"
								},
								{
									"key": "Access-Control-Allow-Methods",
									"value": "POST, PUT, GET, OPTIONS, DELETE"
								},
								{
									"key": "Access-Control-Max-Age",
									"value": "3600"
								},
								{
									"key": "Access-Control-Allow-Headers",
									"value": "Authorization, Content-Type, fluent.account"
								},
								{
									"key": "Access-Control-Expose-Headers",
									"value": "flex.type, flex.version"
								},
								{
									"key": "Access-Control-Allow-Credentials",
									"value": "true"
								},
								{
									"key": "X-Content-Type-Options",
									"value": "nosniff"
								},
								{
									"key": "X-XSS-Protection",
									"value": "1; mode=block"
								},
								{
									"key": "Cache-Control",
									"value": "no-cache, no-store, max-age=0, must-revalidate"
								},
								{
									"key": "Cache-Control",
									"value": "no-store"
								},
								{
									"key": "Pragma",
									"value": "no-cache"
								},
								{
									"key": "Pragma",
									"value": "no-cache"
								},
								{
									"key": "Expires",
									"value": "0"
								},
								{
									"key": "X-Frame-Options",
									"value": "DENY"
								}
							],
							"cookie": [],
							"body": "{\n    \"access_token\": \"4b5eb7aa-5714-4c73-8813-4e4aae0a3e0f\",\n    \"token_type\": \"bearer\",\n    \"expires_in\": 2579,\n    \"scope\": \"api\",\n    \"Roles\": [],\n    \"FirstName\": \"Bob\",\n    \"LastName\": \"Smith\"\n}"
						}
					]
				}
			],
			"description": "This Authentication Request is set to authenticate the FC FASHION Retailer Admin User.\n\nThis request will set the `fluent.retailer.current.token` which is used by the following requests.\n\nThis effectively activates the current Retailer for the given Lab steps to be executed."
		},
		{
			"name": "Get Setting/Workflow",
			"item": [
				{
					"name": "Get the Retailer settings",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"tests[\"HTTP response code is 200\"] = responseCode.code === 200;"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{fluent.retailer.current.token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							}
						],
						"url": {
							"raw": "{{fluentApiHost}}/api/v4.1/settings/retailer/1/DEFAULT_TAX_TYPE",
							"host": [
								"{{fluentApiHost}}"
							],
							"path": [
								"api",
								"v4.1",
								"settings",
								"retailer",
								"1",
								"DEFAULT_TAX_TYPE"
							]
						}
					},
					"response": []
				},
				{
					"name": "Get workflow by Retailer Id and Workflow Name",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									"tests[\"HTTP response code is 200\"] = responseCode.code === 200;"
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{fluent.retailer.current.token}}",
									"type": "string"
								}
							]
						},
						"method": "GET",
						"header": [
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{access_token}}"
							},
							{
								"key": "fluent.account",
								"value": "{{account.id}}",
								"type": "text",
								"disabled": true
							}
						],
						"url": {
							"raw": "{{fluentApiHost}}/api/v4.1/workflow/1/BILLING_ACCOUNT::CUSTOMER",
							"host": [
								"{{fluentApiHost}}"
							],
							"path": [
								"api",
								"v4.1",
								"workflow",
								"1",
								"BILLING_ACCOUNT::CUSTOMER"
							]
						}
					},
					"response": []
				}
			],
			"description": "This Authentication Request is set to authenticate the FC FASHION Retailer Admin User.\n\nThis request will set the `fluent.retailer.current.token` which is used by the following requests.\n\nThis effectively activates the current Retailer for the given Lab steps to be executed."
		},
		{
			"name": "Create Settings",
			"item": [
				{
					"name": "Create EXCHANGE_REASON setting",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{fluent.retailer.current.token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [],
						"body": {
							"mode": "graphql",
							"graphql": {
								"query": "mutation {\n    createSetting(input: {\n        name: \"EXCHANGE_REASON\",\n        valueType: \"JSON\",\n        context: \"RETAILER\",\n        contextId: 1,\n        lobValue: [{label:\"Wrong Size\", value:\"WRONGSIZE\"}, {label:\"Change of mind\", value:\"CHANGEOFMIND\"}, {label:\"Change variant\", value:\"CHANGEVARIANT\"}] \n    }) {\n        id\n    }\n}\n",
								"variables": ""
							}
						},
						"url": {
							"raw": "{{fluent.account.host}}/graphql",
							"host": [
								"{{fluent.account.host}}"
							],
							"path": [
								"graphql"
							]
						}
					},
					"response": []
				},
				{
					"name": "Create DEFAULT_TAX_TYPE setting",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{fluent.retailer.current.token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [],
						"body": {
							"mode": "graphql",
							"graphql": {
								"query": "mutation taxType ($taxTypeValue: Json) {\n    createSetting(input: {\n        name: \"DEFAULT_TAX_TYPE\",\n        valueType: \"JSON\",\n        context: \"RETAILER\",\n        contextId: 1,\n        lobValue: $taxTypeValue\n    }) {\n        id\n    }\n}\n",
								"variables": "{\n    \"taxTypeValue\": {\n        \"country\": \"UK\",\n        \"group\": \"STANDARD\",\n        \"tariff\": \"GST\"\n    }\n}\n"
							}
						},
						"url": {
							"raw": "{{fluent.account.host}}/graphql",
							"host": [
								"{{fluent.account.host}}"
							],
							"path": [
								"graphql"
							]
						}
					},
					"response": []
				},
				{
					"name": "Create GST setting",
					"event": [
						{
							"listen": "test",
							"script": {
								"exec": [
									""
								],
								"type": "text/javascript"
							}
						}
					],
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{fluent.retailer.current.token}}",
									"type": "string"
								}
							]
						},
						"method": "POST",
						"header": [],
						"body": {
							"mode": "graphql",
							"graphql": {
								"query": "mutation GST ($GSTValue: String) {\n    createSetting(input: {\n        name: \"GST\",\n        valueType: \"STRING\",\n        context: \"RETAILER\",\n        contextId: 1,\n        value: $GSTValue\n    }) {\n        id\n    }\n}\n",
								"variables": "{\n\t\"GSTValue\": \"0.0\"\n}"
							}
						},
						"url": {
							"raw": "{{fluent.account.host}}/graphql",
							"host": [
								"{{fluent.account.host}}"
							],
							"path": [
								"graphql"
							]
						}
					},
					"response": []
				}
			],
			"description": "This Authentication Request is set to authenticate the FC FASHION Retailer Admin User.\n\nThis request will set the `fluent.retailer.current.token` which is used by the following requests.\n\nThis effectively activates the current Retailer for the given Lab steps to be executed."
		},
		{
			"name": "Post a basic Billing Account workflow",
			"item": [
				{
					"name": "Post a a basic Billing Account workflow",
					"request": {
						"auth": {
							"type": "bearer",
							"bearer": [
								{
									"key": "token",
									"value": "{{fluent.retailer.current.token}}",
									"type": "string"
								}
							]
						},
						"method": "PUT",
						"header": [],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"retailerId\": \"1\",\n    \"version\": \"1.0\",\n    \"entityType\": \"BILLING_ACCOUNT\",\n    \"entitySubtype\": \"CUSTOMER\",\n    \"description\": \"Basic Billing Account workflow template\",\n    \"name\": \"BILLING_ACCOUNT::CUSTOMER\",\n    \"rulesets\": [\n        {\n            \"name\": \"CREATE\",\n            \"description\": \"CREATE BILLING_ACCOUNT\",\n            \"type\": \"BILLING_ACCOUNT\",\n            \"subtype\": \"CUSTOMER\",\n            \"eventType\": \"NORMAL\",\n            \"rules\": [\n                {\n                    \"name\": \"{{fluent.account.client_id}}.core.SetState\",\n                    \"props\": {\n                        \"status\": \"ACTIVE\"\n                    }\n                }\n            ],\n            \"triggers\": [\n                {\n                    \"status\": \"CREATED\"\n                }\n            ],\n            \"userActions\": []\n        },\n        {\n            \"name\": \"ProcessCredit\",\n            \"description\": \"ProcessCredit\",\n            \"type\": \"BILLING_ACCOUNT\",\n            \"subtype\": \"CUSTOMER\",\n            \"eventType\": \"NORMAL\",\n            \"rules\": [\n                {\n                    \"name\": \"FLUENTRETAIL.base.CreateCreditMemoFromReturnOrder\",\n                    \"props\": {\n                        \"creditMemoType\": \"TYPE_MEMO\",\n                        \"creditMemoItemType\": \"TYPE_MEMO_ITEM\"\n                    }\n                }\n            ],\n            \"triggers\": [\n                {\n                    \"status\": \"ACTIVE\"\n                }\n            ],\n            \"userActions\": []\n        },\n        {\n            \"name\": \"CREATE\",\n            \"description\": \"CREATE CREDIT MEMO\",\n            \"type\": \"CREDIT_MEMO\",\n            \"eventType\": \"NORMAL\",\n            \"rules\": [\n                {\n                    \"name\": \"{{fluent.account.client_id}}.core.SetState\",\n                    \"props\": {\n                        \"status\": \"PENDING_REFUND\"\n                    }\n                }\n            ],\n            \"triggers\": [\n                {\n                    \"status\": \"CREATED\"\n                }\n            ],\n            \"userActions\": []\n        },\n        {\n            \"name\": \"PaymentFailed\",\n            \"description\": \"PaymentFailed\",\n            \"type\": \"CREDIT_MEMO\",\n            \"subtype\": \"DEFAULT\",\n            \"eventType\": \"NORMAL\",\n            \"rules\": [\n                {\n                    \"name\": \"{{fluent.account.client_id}}.core.SetState\",\n                    \"props\": {\n                        \"status\": \"REFUND_FAILED\"\n                    }\n                },\n                {\n                    \"name\": \"FLUENTRETAIL.base.SendEventForCreditMemoToReturn\",\n                    \"props\": {\n                        \"eventName\": \"RefundRejected\"\n                    }\n                }\n            ],\n            \"triggers\": [\n                {\n                    \"status\": \"PENDING_REFUND\"\n                },\n                {\n                    \"status\": \"CREATED\"\n                }\n            ],\n            \"userActions\": []\n        },\n        {\n            \"name\": \"PaymentComplete\",\n            \"description\": \"PaymentComplete\",\n            \"type\": \"CREDIT_MEMO\",\n            \"subtype\": \"DEFAULT\",\n            \"eventType\": \"NORMAL\",\n            \"rules\": [\n                {\n                    \"name\": \"{{fluent.account.client_id}}.core.SetState\",\n                    \"props\": {\n                        \"status\": \"REFUND_COMPLETE\"\n                    }\n                },\n                {\n                    \"name\": \"FLUENTRETAIL.base.SendEventForCreditMemoToReturn\",\n                    \"props\": {\n                        \"eventName\": \"RefundComplete\"\n                    }\n                }\n            ],\n            \"triggers\": [\n                {\n                    \"status\": \"PENDING_REFUND\"\n                },\n                {\n                    \"status\": \"CREATED\"\n                }\n            ],\n            \"userActions\": []\n        },\n        {\n            \"name\": \"ProcessCreditForRevisedOrder\",\n            \"description\": \"Start the processing of the creditMemo\",\n            \"type\": \"BILLING_ACCOUNT\",\n            \"subtype\": \"CUSTOMER\",\n            \"eventType\": \"NORMAL\",\n            \"rules\": [\n                {\n                    \"name\": \"FLUENTRETAIL.base.CreateCreditMemoForRevisedOrder\",\n                    \"props\": {\n                        \"creditMemoType\": \"EXCHANGE\",\n                        \"creditMemoItemType\": \"EXCHANGE_ITEM\"\n                    }\n                }\n            ],\n            \"triggers\": [\n                {\n                    \"status\": \"ACTIVE\"\n                }\n            ],\n            \"userActions\": []\n        }\n    ],\n    \"statuses\": [\n        {\n            \"name\": \"CREATED\",\n            \"entityType\": \"BILLING_ACCOUNT\",\n            \"category\": \"BOOKING\"\n        },\n        {\n            \"name\": \"ACTIVE\",\n            \"entityType\": \"BILLING_ACCOUNT\",\n            \"category\": \"BOOKING\"\n        },\n        {\n            \"name\": \"REFUND_COMPLETE\",\n            \"entityType\": \"CREDIT_MEMO\",\n            \"category\": \"DONE\"\n        },\n        {\n            \"name\": \"REFUND_FAILED\",\n            \"entityType\": \"CREDIT_MEMO\",\n            \"category\": \"DONE\"\n        },\n        {\n            \"name\": \"CREATED\",\n            \"entityType\": \"CREDIT_MEMO\",\n            \"category\": \"BOOKING\"\n        },\n        {\n            \"name\": \"PENDING_REFUND\",\n            \"entityType\": \"CREDIT_MEMO\",\n            \"category\": \"BOOKING\"\n        }\n    ]\n}",
							"options": {
								"raw": {
									"language": "json"
								}
							}
						},
						"url": {
							"raw": "{{fluent.account.host}}/api/v4.1/workflow",
							"host": [
								"{{fluent.account.host}}"
							],
							"path": [
								"api",
								"v4.1",
								"workflow"
							]
						}
					},
					"response": []
				}
			],
			"description": "This Authentication Request is set to authenticate the FC FASHION Retailer Admin User.\n\nThis request will set the `fluent.retailer.current.token` which is used by the following requests.\n\nThis effectively activates the current Retailer for the given Lab steps to be executed."
		}
	]
}