{
	"info": {
		"_postman_id": "06119990-1107-44c8-939f-a33070065f45",
		"name": "[SNAP] Top Up V2 Update",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
		"_exporter_id": "5512202"
	},
	"item": [
		{
			"name": "Top Up",
			"item": [
				{
					"name": "Get Access Token B2B",
					"event": [
						{
							"listen": "test",
							"script": {
								"type": "text/javascript",
								"exec": [
									"var jsonData = JSON.parse(responseBody);\r",
									"if (responseCode.code === 200) \r",
									"{    \r",
									"if(pm.environment.get(\"api\") == \"/OVOSNAP/v1.0/access-token/b2b\"){\r",
									"        pm.environment.set(\"b2b_accessToken\", jsonData.accessToken);\r",
									"        \r",
									"}\r",
									"}\r",
									""
								]
							}
						},
						{
							"listen": "prerequest",
							"script": {
								"type": "text/javascript",
								"exec": [
									"/*\r",
									"How to use:\r",
									"- Configure the client ID via request headers with key as x-client-key.\r",
									"- Configure the private key via environment variable with key as {clientID}_private_key.\r",
									"- Script will generate / replace environment variables listed in the Output section.\r",
									"\r",
									"Output (Environment variables):\r",
									"- gen_signature -> add to X-Signature headers\r",
									"- gen_timestamp -> add to X-Timestamp headers\r",
									"*/\r",
									"eval( pm.environment.get('pmlib_code') )\r",
									"\r",
									"var moment = require('moment')\r",
									"\r",
									"const clientID = pm.environment.get(\"clientID\")\r",
									"var privateKey = pm.environment.get(\"_private_key\")\r",
									"const timestamp = moment().format(\"YYYY-MM-DDThh:mm:ss.SSSZ\")\r",
									"\r",
									"const fullPath = pm.request.url.getPathWithQuery()\r",
									"\r",
									"console.log(\"clientID: \" + clientID)\r",
									"console.log(\"privateKey: \" + privateKey)\r",
									"console.log(\"timestamp: \" + timestamp)\r",
									"\r",
									"const msg = `${clientID}|${timestamp}`\r",
									"\r",
									"console.log(\"msg: \" + msg)\r",
									"\r",
									"var CryptoJS = require(\"crypto-js\")\r",
									"const hashedMsg = CryptoJS.SHA256(msg)\r",
									"console.log(\"hashedMsg: \" + hashedMsg)\r",
									"\r",
									"var sig = new pmlib.rs.KJUR.crypto.Signature({\"alg\": \"SHA256withRSA\"})\r",
									"privateKey = pmlib.rs.KEYUTIL.getKey(privateKey)\r",
									"sig.init(privateKey)\r",
									"const hash = sig.signString(msg)\r",
									"\r",
									"console.log(\"hash: \" + hash)\r",
									"\r",
									"function randomString(minValue, maxValue, dataSet = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {\r",
									"    if (!minValue) {\r",
									"        minValue = 20;\r",
									"        maxValue = 20;\r",
									"    }\r",
									"\r",
									"    if (!maxValue) {\r",
									"        maxValue = minValue;\r",
									"    }\r",
									"\r",
									"    let length = _.random(minValue, maxValue),\r",
									"        randomString = \"\";\r",
									"\r",
									"    for (let i = 0; i < length; i++)\r",
									"        randomString += dataSet.charAt(Math.floor(Math.random() * dataSet.length));\r",
									"    return randomString;\r",
									"}\r",
									"\r",
									"pm.environment.set('random_xternalid', randomString());\r",
									"pm.environment.set(\"gen_timestamp\", timestamp)\r",
									"pm.environment.set(\"gen_signature\", hash)\r",
									"\r",
									"pm.environment.set(\"api\",fullPath)\r",
									""
								]
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "x-client-key",
								"value": "{{clientID}}"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "X-Signature",
								"value": "{{gen_signature}}"
							},
							{
								"key": "x-Timestamp",
								"value": "{{gen_timestamp}}"
							},
							{
								"key": "X-EXTERNAL-ID",
								"value": "{{random_xternalid}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"grantType\" : \"client_credentials\"\n}"
						},
						"url": {
							"raw": "https://app.byte-stack.net/OVOSNAP/v1.0/access-token/b2b",
							"protocol": "https",
							"host": [
								"app",
								"byte-stack",
								"net"
							],
							"path": [
								"OVOSNAP",
								"v1.0",
								"access-token",
								"b2b"
							]
						}
					},
					"response": []
				},
				{
					"name": "Account Inquiry",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"/*\r",
									"How to use:\r",
									"- Configure the client ID via request headers with key as x-partner-id.\r",
									"- Configure the access token via request headers with key as Authorization and format of value as Bearer {access_token}.\r",
									"- Configure the secret key via environment variable with key as {clientID}_secret_key.\r",
									"- Script will generate / replace environment variables listed in the Output section.\r",
									"\r",
									"Output (Environment variables):\r",
									"- gen_signature -> add to X-Signature headers\r",
									"- gen_timestamp -> add to X-Timestamp headers\r",
									"*/\r",
									"eval( pm.globals.get('pmlib_code') )\r",
									"\r",
									"var moment = require('moment')\r",
									"var CryptoJS = require(\"crypto-js\")\r",
									"\r",
									"const clientID = pm.environment.get('clientID');\r",
									"const accessToken =pm.environment.get('b2b_accessToken');\r",
									"const timestamp = moment().format(\"YYYY-MM-DDThh:mm:ss.SSSZ\")\r",
									"const body = pm.request.body.raw\r",
									"const fullPath = pm.request.url.getPathWithQuery()\r",
									"const method = pm.request.method\r",
									"\r",
									"var secret_key = pm.environment.get(\"_secret_key\")\r",
									"\r",
									"console.log(\"clientID: \" + clientID)\r",
									"console.log(\"accessToken: \" + accessToken)\r",
									"console.log(\"timestamp: \" + timestamp)\r",
									"console.log(\"body: \" + body)\r",
									"console.log(\"fullPath: \" + fullPath)\r",
									"console.log(\"method: \" + method)\r",
									"console.log(\"secret_key: \" + secret_key)\r",
									"\r",
									"const hashedBody = CryptoJS.SHA256(body).toString()\r",
									"const finalBody = hashedBody.toLowerCase()\r",
									"\r",
									"console.log(\"hashedBody: \" + hashedBody)\r",
									"console.log(\"finalBody: \" + finalBody)\r",
									"\r",
									"const msg = `${method}:${fullPath}:${accessToken}:${finalBody}:${timestamp}`\r",
									"\r",
									"console.log(\"msg: \" + msg)\r",
									"\r",
									"const hash = CryptoJS.HmacSHA512(msg, secret_key).toString()\r",
									"\r",
									"console.log(\"hash: \" + hash)\r",
									"function randomString(minValue, maxValue, dataSet = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {\r",
									"    if (!minValue) {\r",
									"        minValue = 20;\r",
									"        maxValue = 20;\r",
									"    }\r",
									"\r",
									"    if (!maxValue) {\r",
									"        maxValue = minValue;\r",
									"    }\r",
									"\r",
									"    let length = _.random(minValue, maxValue),\r",
									"        randomString = \"\";\r",
									"\r",
									"    for (let i = 0; i < length; i++)\r",
									"        randomString += dataSet.charAt(Math.floor(Math.random() * dataSet.length));\r",
									"    return randomString;\r",
									"}\r",
									"var req = JSON.parse(pm.request.body.raw);\r",
									"pm.environment.set('random_xternalid', randomString());\r",
									"pm.environment.set(\"gen_timestamp\", timestamp)\r",
									"pm.environment.set(\"gen_signature\", hash)"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "X-PARTNER-ID",
								"value": "{{clientID}}"
							},
							{
								"key": "X-SIGNATURE",
								"value": "{{gen_signature}}"
							},
							{
								"key": "X-TIMESTAMP",
								"value": "{{gen_timestamp}}"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{b2b_accessToken}}"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "X-EXTERNAL-ID",
								"value": "{{random_xternalid}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"partnerReferenceNo\": \"Test12345678901\",\n    \"customerNumber\": \"081212345678\",\n    \"amount\": {\n        \"value\": \"10000.00\",\n        \"currency\": \"IDR\"\n    },\n    \"transactionDate\": \"2020-12-05T14:56:11+07:00\"\n}"
						},
						"url": {
							"raw": "https://app.byte-stack.net/OVOSNAP/v2.0/emoney/account-inquiry",
							"protocol": "https",
							"host": [
								"app",
								"byte-stack",
								"net"
							],
							"path": [
								"OVOSNAP",
								"v2.0",
								"emoney",
								"account-inquiry"
							]
						}
					},
					"response": []
				},
				{
					"name": "Payment Top Up",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"/*\r",
									"How to use:\r",
									"- Configure the client ID via request headers with key as x-partner-id.\r",
									"- Configure the access token via request headers with key as Authorization and format of value as Bearer {access_token}.\r",
									"- Configure the secret key via environment variable with key as {clientID}_secret_key.\r",
									"- Script will generate / replace environment variables listed in the Output section.\r",
									"\r",
									"Output (Environment variables):\r",
									"- gen_signature -> add to X-Signature headers\r",
									"- gen_timestamp -> add to X-Timestamp headers\r",
									"*/\r",
									"eval( pm.globals.get('pmlib_code') )\r",
									"\r",
									"var moment = require('moment')\r",
									"var CryptoJS = require(\"crypto-js\")\r",
									"\r",
									"const clientID = pm.environment.get('client-id');\r",
									"const accessToken =pm.environment.get('b2b_accessToken');\r",
									"const timestamp = moment().format(\"YYYY-MM-DDThh:mm:ss.SSSZ\")\r",
									"const body = pm.request.body.raw\r",
									"const fullPath = pm.request.url.getPathWithQuery()\r",
									"const method = pm.request.method\r",
									"\r",
									"var secret_key = pm.environment.get(\"_secret_key\")\r",
									"\r",
									"console.log(\"clientID: \" + clientID)\r",
									"console.log(\"accessToken: \" + accessToken)\r",
									"console.log(\"timestamp: \" + timestamp)\r",
									"console.log(\"body: \" + body)\r",
									"console.log(\"fullPath: \" + fullPath)\r",
									"console.log(\"method: \" + method)\r",
									"console.log(\"secret_key: \" + secret_key)\r",
									"\r",
									"const hashedBody = CryptoJS.SHA256(body).toString()\r",
									"const finalBody = hashedBody.toLowerCase()\r",
									"\r",
									"console.log(\"hashedBody: \" + hashedBody)\r",
									"console.log(\"finalBody: \" + finalBody)\r",
									"\r",
									"const msg = `${method}:${fullPath}:${accessToken}:${finalBody}:${timestamp}`\r",
									"\r",
									"console.log(\"msg: \" + msg)\r",
									"\r",
									"const hash = CryptoJS.HmacSHA512(msg, secret_key).toString()\r",
									"\r",
									"console.log(\"hash: \" + hash)\r",
									"\r",
									"function randomString(minValue, maxValue, dataSet = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {\r",
									"    if (!minValue) {\r",
									"        minValue = 20;\r",
									"        maxValue = 20;\r",
									"    }\r",
									"\r",
									"    if (!maxValue) {\r",
									"        maxValue = minValue;\r",
									"    }\r",
									"\r",
									"    let length = _.random(minValue, maxValue),\r",
									"        randomString = \"\";\r",
									"\r",
									"    for (let i = 0; i < length; i++)\r",
									"        randomString += dataSet.charAt(Math.floor(Math.random() * dataSet.length));\r",
									"    return randomString;\r",
									"}\r",
									"\r",
									"pm.environment.set('random_xternalid', randomString());\r",
									"pm.environment.set(\"gen_timestamp\", timestamp)\r",
									"pm.environment.set(\"gen_signature\", hash)"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "X-PARTNER-ID",
								"value": "{{clientID}}"
							},
							{
								"key": "X-SCOPE-ID",
								"value": "customer_topup"
							},
							{
								"key": "X-TIMESTAMP",
								"value": "{{gen_timestamp}}"
							},
							{
								"key": "X-SIGNATURE",
								"value": "{{gen_signature}}"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{b2b_accessToken}}"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "X-EXTERNAL-ID",
								"value": "{{random_xternalid}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"partnerReferenceNo\": \"Test12345678901\",\n    \"customerNumber\": \"081212345678\",\n    \"customerName\": \"Testing\",\n    \"amount\": {\n        \"value\": \"10000.00\",\n        \"currency\": \"IDR\"\n    },\n    \"feeAmount\": {\n        \"value\": \"1000.00\",\n        \"currency\": \"IDR\"\n    },\n    \"transactionDate\": \"2022-04-07T11:21:11+07:00\"\n}"
						},
						"url": {
							"raw": "https://app.byte-stack.net/OVOSNAP/v2.0/emoney/topup",
							"protocol": "https",
							"host": [
								"app",
								"byte-stack",
								"net"
							],
							"path": [
								"OVOSNAP",
								"v2.0",
								"emoney",
								"topup"
							]
						}
					},
					"response": []
				},
				{
					"name": "Top Up Status",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"exec": [
									"/*\r",
									"How to use:\r",
									"- Configure the client ID via request headers with key as x-partner-id.\r",
									"- Configure the access token via request headers with key as Authorization and format of value as Bearer {access_token}.\r",
									"- Configure the secret key via environment variable with key as {clientID}_secret_key.\r",
									"- Script will generate / replace environment variables listed in the Output section.\r",
									"\r",
									"Output (Environment variables):\r",
									"- gen_signature -> add to X-Signature headers\r",
									"- gen_timestamp -> add to X-Timestamp headers\r",
									"*/\r",
									"eval( pm.globals.get('pmlib_code') )\r",
									"\r",
									"var moment = require('moment')\r",
									"var CryptoJS = require(\"crypto-js\")\r",
									"\r",
									"const clientID = pm.environment.get('clientID');\r",
									"const accessToken =pm.environment.get('b2b_accessToken');\r",
									"const timestamp = moment().format(\"YYYY-MM-DDThh:mm:ss.SSSZ\")\r",
									"const body = pm.request.body.raw\r",
									"const fullPath = pm.request.url.getPathWithQuery()\r",
									"const method = pm.request.method\r",
									"\r",
									"var secret_key = pm.environment.get(\"_secret_key\")\r",
									"\r",
									"console.log(\"clientID: \" + clientID)\r",
									"console.log(\"accessToken: \" + accessToken)\r",
									"console.log(\"timestamp: \" + timestamp)\r",
									"console.log(\"body: \" + body)\r",
									"console.log(\"fullPath: \" + fullPath)\r",
									"console.log(\"method: \" + method)\r",
									"console.log(\"secret_key: \" + secret_key)\r",
									"\r",
									"const hashedBody = CryptoJS.SHA256(body).toString()\r",
									"const finalBody = hashedBody.toLowerCase()\r",
									"\r",
									"console.log(\"hashedBody: \" + hashedBody)\r",
									"console.log(\"finalBody: \" + finalBody)\r",
									"\r",
									"const msg = `${method}:${fullPath}:${accessToken}:${finalBody}:${timestamp}`\r",
									"\r",
									"console.log(\"msg: \" + msg)\r",
									"\r",
									"const hash = CryptoJS.HmacSHA512(msg, secret_key).toString()\r",
									"\r",
									"console.log(\"hash: \" + hash)\r",
									"function randomString(minValue, maxValue, dataSet = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {\r",
									"    if (!minValue) {\r",
									"        minValue = 20;\r",
									"        maxValue = 20;\r",
									"    }\r",
									"\r",
									"    if (!maxValue) {\r",
									"        maxValue = minValue;\r",
									"    }\r",
									"\r",
									"    let length = _.random(minValue, maxValue),\r",
									"        randomString = \"\";\r",
									"\r",
									"    for (let i = 0; i < length; i++)\r",
									"        randomString += dataSet.charAt(Math.floor(Math.random() * dataSet.length));\r",
									"    return randomString;\r",
									"}\r",
									"\r",
									"pm.environment.set('random_xternalid', randomString());\r",
									"\r",
									"pm.environment.set(\"gen_timestamp\", timestamp)\r",
									"pm.environment.set(\"gen_signature\", hash)"
								],
								"type": "text/javascript",
								"packages": {}
							}
						}
					],
					"request": {
						"method": "POST",
						"header": [
							{
								"key": "X-PARTNER-ID",
								"value": "{{clientID}}"
							},
							{
								"key": "X-SCOPE-ID",
								"value": "customer_topup"
							},
							{
								"key": "X-TIMESTAMP",
								"value": "{{gen_timestamp}}"
							},
							{
								"key": "X-SIGNATURE",
								"value": "{{gen_signature}}"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{b2b_accessToken}}"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "X-External-ID",
								"value": "{{random_xternalid}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": "{\n    \"originalPartnerReferenceNo\": \"Test12345678901\",\n    \"originalReferenceNo\": \"Test12345678901\",\n    \"serviceCode\": \"38\"\n}"
						},
						"url": {
							"raw": "https://app.byte-stack.net/OVOSNAP/v2.0/emoney/topup-status",
							"protocol": "https",
							"host": [
								"app",
								"byte-stack",
								"net"
							],
							"path": [
								"OVOSNAP",
								"v2.0",
								"emoney",
								"topup-status"
							]
						}
					},
					"response": []
				},
				{
					"name": "Balance",
					"event": [
						{
							"listen": "prerequest",
							"script": {
								"type": "text/javascript",
								"exec": [
									"/*\r",
									"How to use:\r",
									"- Configure the client ID via request headers with key as x-partner-id.\r",
									"- Configure the access token via request headers with key as Authorization and format of value as Bearer {access_token}.\r",
									"- Configure the secret key via environment variable with key as {clientID}_secret_key.\r",
									"- Script will generate / replace environment variables listed in the Output section.\r",
									"\r",
									"Output (Environment variables):\r",
									"- gen_signature -> add to X-Signature headers\r",
									"- gen_timestamp -> add to X-Timestamp headers\r",
									"*/\r",
									"eval( pm.globals.get('pmlib_code') )\r",
									"\r",
									"var moment = require('moment')\r",
									"var CryptoJS = require(\"crypto-js\")\r",
									"\r",
									"const clientID = pm.environment.get('client-id');\r",
									"const accessToken =pm.environment.get('b2b_accessToken');\r",
									"const timestamp = moment().format(\"YYYY-MM-DDThh:mm:ss.SSSZ\")\r",
									"const body = pm.request.body.raw\r",
									"const fullPath = pm.request.url.getPathWithQuery()\r",
									"const method = pm.request.method\r",
									"\r",
									"var secret_key = pm.environment.get(\"_secret_key\")\r",
									"\r",
									"console.log(\"clientID: \" + clientID)\r",
									"console.log(\"accessToken: \" + accessToken)\r",
									"console.log(\"timestamp: \" + timestamp)\r",
									"console.log(\"body: \" + body)\r",
									"console.log(\"fullPath: \" + fullPath)\r",
									"console.log(\"method: \" + method)\r",
									"console.log(\"secret_key: \" + secret_key)\r",
									"\r",
									"const hashedBody = CryptoJS.SHA256(body).toString()\r",
									"const finalBody = hashedBody.toLowerCase()\r",
									"\r",
									"console.log(\"hashedBody: \" + hashedBody)\r",
									"console.log(\"finalBody: \" + finalBody)\r",
									"\r",
									"const msg = `${method}:${fullPath}:${accessToken}:${finalBody}:${timestamp}`\r",
									"\r",
									"console.log(\"msg: \" + msg)\r",
									"\r",
									"const hash = CryptoJS.HmacSHA512(msg, secret_key).toString()\r",
									"\r",
									"console.log(\"hash: \" + hash)\r",
									"\r",
									"function randomString(minValue, maxValue, dataSet = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') {\r",
									"    if (!minValue) {\r",
									"        minValue = 20;\r",
									"        maxValue = 20;\r",
									"    }\r",
									"\r",
									"    if (!maxValue) {\r",
									"        maxValue = minValue;\r",
									"    }\r",
									"\r",
									"    let length = _.random(minValue, maxValue),\r",
									"        randomString = \"\";\r",
									"\r",
									"    for (let i = 0; i < length; i++)\r",
									"        randomString += dataSet.charAt(Math.floor(Math.random() * dataSet.length));\r",
									"    return randomString;\r",
									"}\r",
									"\r",
									"pm.environment.set('random_xternalid', randomString());\r",
									"pm.environment.set(\"gen_timestamp\", timestamp)\r",
									"pm.environment.set(\"gen_signature\", hash)"
								]
							}
						}
					],
					"protocolProfileBehavior": {
						"disableBodyPruning": true
					},
					"request": {
						"method": "GET",
						"header": [
							{
								"key": "X-PARTNER-ID",
								"value": "{{clientID}}"
							},
							{
								"key": "X-SCOPE-ID",
								"value": "customer_topup"
							},
							{
								"key": "X-TIMESTAMP",
								"value": "{{gen_timestamp}}"
							},
							{
								"key": "X-SIGNATURE",
								"value": "{{gen_signature}}"
							},
							{
								"key": "Authorization",
								"value": "Bearer {{b2b_accessToken}}"
							},
							{
								"key": "Content-Type",
								"value": "application/json"
							},
							{
								"key": "X-EXTERNAL-ID",
								"value": "{{random_xternalid}}"
							}
						],
						"body": {
							"mode": "raw",
							"raw": ""
						},
						"url": {
							"raw": "https://app.byte-stack.net/cashin/snap/v1.0/merchant/account/balance",
							"protocol": "https",
							"host": [
								"app",
								"byte-stack",
								"net"
							],
							"path": [
								"cashin",
								"snap",
								"v1.0",
								"merchant",
								"account",
								"balance"
							]
						}
					},
					"response": []
				}
			]
		}
	]
}