{
	"info": {
		"_postman_id": "fb30cbfe-07f1-4301-a9e7-13c45119b54c",
		"name": "PhonePe Online Integration",
		"description": "Debit and Check Status API's for PhonePe Integration",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "V3 Debit API",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"id": "0d2b26fe-00bb-4a67-a412-cb4efad3c36c",
						"exec": [
							"const currentIndex = 0",
							"",
							"//Configuration",
							"const url = \"https://mercury-uat.phonepe.com\"",
							"const mid = \"M2306160483220675579140\"",
							"const tid = \"testTxn01\"",
							"const saltKey = \"8289e078-be0b-484d-ae60-052f117f8deb\"",
							"const saltIndex = 1",
							"",
							"const paths = [",
							"    '/v3/debit'         // POST",
							"]",
							"",
							"const decodedRequests = [{",
							"    \"merchantId\": mid,",
							"    \"transactionId\": tid,",
							"    \"merchantUserId\" : \"user101\",",
							"    \"amount\": 200,",
							"    \"merchantOrderId\": \"testOrder_101\",",
							"    \"message\": \"PhonePe Payment\",",
							"    \"mobileNumber\" : \"9898989899\",",
							"    \"email\" : \"testuser@gmail.com\",",
							"    \"shortName\" : \"User\"",
							"}",
							"]",
							"",
							"const path = paths[currentIndex]",
							"const decodedRequest = decodedRequests[currentIndex]",
							"",
							"let encodedRequest = decodedRequest === \"\" ? \"\" : btoa(JSON.stringify(decodedRequest))",
							"",
							"// Postman variables",
							"pm.environment.set(\"endpoint\", url + path);",
							"if (encodedRequest === \"\")",
							"    pm.environment.set(\"base64Request\", \"\");",
							"else",
							"    pm.environment.set(\"base64Request\", `{\"request\": \"${encodedRequest}\"}`);",
							"",
							"generateChecksum(encodedRequest, path, saltKey, saltIndex)",
							"",
							"function generateChecksum(encodedRequest, path, saltKey, keyIndex) {",
							"    const cjs = require(\"crypto-js\");",
							"",
							"    const checksum = cjs.SHA256(encodedRequest + path + saltKey).toString(cjs.enc.Hex)",
							"    console.log(\"base64 request:\", encodedRequest, \"Api checksum: \", checksum);",
							"    pm.environment.set(\"xVerify\", checksum + \"###\" + keyIndex);",
							"}"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"type": "text",
						"value": "application/json"
					},
					{
						"key": "X-VERIFY",
						"type": "text",
						"value": "{{xVerify}}"
					},
					{
						"key": "X-CALLBACK-URL",
						"value": "https://webhook.site/a5b80715-2021-4eb0-8ffc-e2b31d683403",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{{base64Request}}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{endpoint}}",
					"host": [
						"{{endpoint}}"
					]
				}
			},
			"response": []
		},
		{
			"name": "V4 Debit API",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"id": "0d2b26fe-00bb-4a67-a412-cb4efad3c36c",
						"exec": [
							"const currentIndex = 0",
							"",
							"//Configuration",
							"const url = \"https://mercury-uat.phonepe.com\"",
							"const mid = \"M2306160483220675579140\"",
							"const tid = \"testTxn04\"",
							"const saltKey = \"8289e078-be0b-484d-ae60-052f117f8deb\"",
							"const saltIndex = 1",
							"",
							"const paths = [",
							"    '/v4/debit'         // POST",
							"]",
							"",
							"const decodedRequests = [{",
							"    \"merchantId\": mid,",
							"    \"transactionId\": tid,",
							"    \"merchantUserId\" : \"user101\",",
							"    \"amount\": 200,",
							"    \"merchantOrderId\": \"testOrder_101\",",
							"    \"message\": \"PhonePe Payment\",",
							"    \"mobileNumber\" : \"9898989899\",",
							"    \"email\" : \"testuser@gmail.com\",",
							"    \"shortName\" : \"User\"",
							"}",
							"]",
							"",
							"const path = paths[currentIndex]",
							"const decodedRequest = decodedRequests[currentIndex]",
							"",
							"let encodedRequest = decodedRequest === \"\" ? \"\" : btoa(JSON.stringify(decodedRequest))",
							"",
							"// Postman variables",
							"pm.environment.set(\"endpoint\", url + path);",
							"if (encodedRequest === \"\")",
							"    pm.environment.set(\"base64Request\", \"\");",
							"else",
							"    pm.environment.set(\"base64Request\", `{\"request\": \"${encodedRequest}\"}`);",
							"",
							"generateChecksum(encodedRequest, path, saltKey, saltIndex)",
							"",
							"function generateChecksum(encodedRequest, path, saltKey, keyIndex) {",
							"    const cjs = require(\"crypto-js\");",
							"",
							"    const checksum = cjs.SHA256(encodedRequest + path + saltKey).toString(cjs.enc.Hex)",
							"    console.log(\"base64 request:\", encodedRequest, \"Api checksum: \", checksum);",
							"    pm.environment.set(\"xVerify\", checksum + \"###\" + keyIndex);",
							"}"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"type": "text",
						"value": "application/json"
					},
					{
						"key": "X-VERIFY",
						"type": "text",
						"value": "{{xVerify}}"
					},
					{
						"key": "X-CALLBACK-URL",
						"value": "https://webhook.site/a5b80715-2021-4eb0-8ffc-e2b31d683403",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{{base64Request}}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{endpoint}}",
					"host": [
						"{{endpoint}}"
					]
				}
			},
			"response": []
		},
		{
			"name": "Check Status API",
			"event": [
				{
					"listen": "prerequest",
					"script": {
						"id": "0d2b26fe-00bb-4a67-a412-cb4efad3c36c",
						"exec": [
							"const currentIndex = 0",
							"",
							"//Configuration",
							"const url = \"https://mercury-uat.phonepe.com\"",
							"const mid = \"M2306160483220675579140\"",
							"const tid = \"testTxn01\"",
							"const saltKey = \"8289e078-be0b-484d-ae60-052f117f8deb\"",
							"const saltIndex = 1",
							"",
							"const paths = [",
							"    '/v3/transaction/' + mid + '/' + tid + '/status',         // GET",
							"]",
							"",
							"const decodedRequests = [",
							"    \"\"",
							"]",
							"",
							"const path = paths[currentIndex]",
							"const decodedRequest = decodedRequests[currentIndex]",
							"",
							"let encodedRequest = decodedRequest === \"\" ? \"\" : btoa(JSON.stringify(decodedRequest))",
							"",
							"// Postman variables",
							"pm.environment.set(\"endpoint\", url + path);",
							"if (encodedRequest === \"\")",
							"    pm.environment.set(\"base64Request\", \"\");",
							"else",
							"    pm.environment.set(\"base64Request\", `{\"request\": \"${encodedRequest}\"}`);",
							"",
							"generateChecksum(encodedRequest, path, saltKey, saltIndex)",
							"",
							"function generateChecksum(encodedRequest, path, saltKey, keyIndex) {",
							"    const cjs = require(\"crypto-js\");",
							"",
							"    const checksum = cjs.SHA256(encodedRequest + path + saltKey).toString(cjs.enc.Hex)",
							"    console.log(\"base64 request:\", encodedRequest, \"Api checksum: \", checksum);",
							"    pm.environment.set(\"xVerify\", checksum + \"###\" + keyIndex);",
							"}"
						],
						"type": "text/javascript"
					}
				}
			],
			"protocolProfileBehavior": {
				"disableBodyPruning": true
			},
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Content-Type",
						"name": "Content-Type",
						"type": "text",
						"value": "application/json"
					},
					{
						"key": "X-VERIFY",
						"type": "text",
						"value": "{{xVerify}}"
					},
					{
						"key": "X-CALLBACK-URL",
						"value": "https://webhook.site/a5b80715-2021-4eb0-8ffc-e2b31d683403",
						"type": "text"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "{{base64Request}}",
					"options": {
						"raw": {
							"language": "json"
						}
					}
				},
				"url": {
					"raw": "{{endpoint}}",
					"host": [
						"{{endpoint}}"
					]
				}
			},
			"response": []
		}
	],
	"protocolProfileBehavior": {}
}