You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

406 lines
14 KiB

1 year ago
  1. SET QUOTED_IDENTIFIER ON
  2. SET ANSI_NULLS ON
  3. GO
  4. CREATE PROC [dbo].[ws_proc_PayTXNCheck] (
  5. @ACCESSCODE VARCHAR(50),
  6. @USERNAME VARCHAR(50),
  7. @PASSWORD VARCHAR(50),
  8. @REFNO VARCHAR(50),
  9. @AGENT_SESSION_ID VARCHAR(150)
  10. )
  11. AS
  12. SET NOCOUNT ON;
  13. SET XACT_ABORT ON;
  14. BEGIN TRY
  15. DECLARE @apiRequestId BIGINT
  16. IF @AGENT_SESSION_ID IS NULL
  17. BEGIN
  18. SELECT '1001' CODE,'AGENT SESSION ID Field is Empty' MESSAGE
  19. ,AGENT_SESSION_ID = @AGENT_SESSION_ID
  20. RETURN;
  21. END
  22. INSERT INTO apiRequestLogPay(ACCESSCODE,USERNAME,PASSWORD,REFNO,AGENT_SESSION_ID,requestedDate)
  23. SELECT @ACCESSCODE,@USERNAME,@PASSWORD,@REFNO,@AGENT_SESSION_ID,GETDATE()
  24. SET @apiRequestId = SCOPE_IDENTITY()
  25. DECLARE @errCode INT, @controlNoEnc VARCHAR(50) = dbo.FNAENcryptString(@REFNO)
  26. DECLARE @autMsg VARCHAR(500), @errorCode VARCHAR(10), @errorMsg VARCHAR(MAX), @remarks VARCHAR(30) = 'Pay Search'
  27. EXEC ws_proc_checkAuthntication @USERNAME, @PASSWORD, @ACCESSCODE, @errCode OUT, @autMsg OUT
  28. -- EXEC ws_proc_checkAuthntication @USERNAME, @PASSWORD, @ACCESSCODE, @errCode OUT
  29. DECLARE @errorTable TABLE(
  30. AGENT_SESSION_ID VARCHAR(150)
  31. ,REFNO VARCHAR(50)
  32. ,SEND_AGENT VARCHAR(50)
  33. ,SENDER_NAME VARCHAR(200)
  34. ,SENDER_MOBILE VARCHAR(50)
  35. ,SENDER_CITY VARCHAR(100)
  36. ,SENDER_COUNTRY VARCHAR(100)
  37. ,RECEIVER_NAME VARCHAR(200)
  38. ,RECEIVER_ADDRESS VARCHAR(200)
  39. ,RECEIVER_PHONE VARCHAR(50)
  40. ,RECEIVER_CITY VARCHAR(100)
  41. ,RECEIVER_COUNTRY VARCHAR(100)
  42. ,PAYOUT_AMT MONEY
  43. ,SENDING_AMT MONEY
  44. ,PAYOUT_CURRENCY VARCHAR(3)
  45. ,PAYMENT_TYPE VARCHAR(100)
  46. ,TXN_DATE VARCHAR(50)
  47. ,PAY_TOKEN_ID VARCHAR(50)
  48. ,ISLOCAL VARCHAR(5)
  49. ,TRANID VARCHAR(50)
  50. ,RECEIVERMOBILE VARCHAR(50)
  51. )
  52. INSERT INTO @errorTable(AGENT_SESSION_ID, REFNO)
  53. SELECT @AGENT_SESSION_ID, @REFNO
  54. IF @errCode = 1
  55. BEGIN
  56. SELECT @errorCode = '1002', @errorMsg = ISNULL(@autMsg,'Authentication Fail')
  57. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  58. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  59. RETURN
  60. END
  61. IF EXISTS(SELECT 'x' FROM applicationUsers WITH (NOLOCK) WHERE userName = @USERNAME AND forceChangePwd = 'Y' )
  62. BEGIN
  63. SELECT @errorCode = '1002', @errorMsg = 'You are required to change your password.'
  64. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  65. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  66. RETURN
  67. END
  68. ------------------VALIDATION-------------------------------
  69. /*
  70. IF @AGENT_SESSION_ID IS NULL
  71. BEGIN
  72. SELECT '1001' CODE,'AGENT SESSION ID Field is Empty' MESSAGE,* FROM @errorTable
  73. RETURN
  74. END
  75. */
  76. IF @REFNO IS NULL
  77. BEGIN
  78. SELECT @errorCode = '1001', @errorMsg = 'Control Number Field is Required'
  79. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  80. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  81. RETURN;
  82. END
  83. --IF @REFNO IS NOT NULL AND ISNUMERIC(@REFNO)=0
  84. --BEGIN
  85. -- SELECT @errorCode = '2003', @errorMsg = 'Technical Error: PINNO must be numeric'
  86. -- EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  87. -- SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  88. -- RETURN;
  89. --END
  90. -- GET AGENT DETAIL
  91. DECLARE
  92. @pAgent INT,
  93. @pAgentTran INT,
  94. @tranId BIGINT,
  95. @tranStatus VARCHAR(50),
  96. @pCountry VARCHAR(50),
  97. @userCountry VARCHAR(50),
  98. @paymentMethod VARCHAR(100),
  99. @lock_status VARCHAR(50),
  100. @MESSAGE VARCHAR(50),
  101. @SEND_AGENT VARCHAR(50),
  102. @SENDER_NAME VARCHAR(200),
  103. @SENDER_ADDRESS VARCHAR(200),
  104. @SENDER_MOBILE VARCHAR(50),
  105. @SENDER_CITY VARCHAR(100),
  106. @SENDER_COUNTRY VARCHAR(100),
  107. @RECEIVER_NAME VARCHAR(200),
  108. @RECEIVER_ADDRESS VARCHAR(200),
  109. @RECEIVER_PHONE VARCHAR(50),
  110. @RECEIVER_CITY VARCHAR(100),
  111. @RECEIVER_COUNTRY VARCHAR(100),
  112. @PAYOUT_AMT VARCHAR(50),
  113. @SENDING_AMT VARCHAR(50),
  114. @PAYOUT_COMM VARCHAR(50),
  115. @PAYOUT_CURRENCY VARCHAR(3),
  116. @PAYMENT_TYPE VARCHAR(100),
  117. @TXN_DATE VARCHAR(50),
  118. @PAY_TOKEN_ID VARCHAR(50),
  119. @Status VARCHAR(50),
  120. @lockedBy VARCHAR(100),
  121. @pAgentName VARCHAR(200),
  122. @isLocal VARCHAR(100),
  123. @Occupation VARCHAR(100),
  124. @IncomeSource VARCHAR(100),
  125. @Relationship VARCHAR(100),
  126. @PurposeOfRemittance VARCHAR(100),
  127. @sCurrCostRate VARCHAR(100),
  128. @pCurrCostRate VARCHAR(100)
  129. -- PICK AGENTID ,COUNTRY FROM USER
  130. SELECT
  131. @pAgent = am.agentId
  132. ,@userCountry = cm.countryName
  133. FROM applicationUsers au WITH(NOLOCK)
  134. INNER JOIN countryMaster cm WITH(NOLOCK) ON au.countryId = cm.countryId
  135. INNER JOIN agentMaster am WITH(NOLOCK) ON au.agentId = am.agentId
  136. WHERE userName = @USERNAME
  137. SELECT @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  138. --------------------------------------------------------------------------------------------------
  139. SELECT
  140. @tranId = rt.id
  141. ,@tranStatus = rt.tranStatus
  142. ,@pCountry = rt.pCountry
  143. ,@pAgentTran = rt.pAgent
  144. ,@paymentMethod = rt.paymentMethod
  145. ,@lock_status = rt.lockStatus
  146. ,@lockedBy = rt.lockedBy
  147. ,@MESSAGE = @REFNO
  148. ,@SEND_AGENT = rt.sAgentName
  149. ,@SENDER_NAME = rt.SenderName
  150. ,@SENDER_ADDRESS = sen.Address
  151. ,@SENDER_MOBILE = sen.mobile
  152. ,@SENDER_CITY = sen.city
  153. ,@SENDER_COUNTRY = rt.sCountry
  154. ,@RECEIVER_NAME = rt.ReceiverName
  155. ,@RECEIVER_ADDRESS = rec.address
  156. ,@RECEIVER_PHONE = rec.mobile
  157. ,@RECEIVER_CITY = rec.city
  158. ,@RECEIVER_COUNTRY = rt.pCountry
  159. ,@PAYOUT_AMT = rt.pAmt
  160. ,@SENDING_AMT = rt.tAmt
  161. ,@PAYOUT_CURRENCY = rt.payoutCurr
  162. ,@PAYMENT_TYPE = rt.paymentMethod
  163. ,@TXN_DATE = RT.createdDate
  164. ,@Status = rt.payStatus
  165. ,@isLocal = CASE WHEN tranType ='D' THEN 'P' ELSE 'R' END
  166. ,@Occupation = sen.occupation
  167. ,@IncomeSource = rt.sourceOfFund
  168. ,@Relationship = rt.relWithSender
  169. ,@PurposeOfRemittance = rt.purposeOfRemit
  170. ,@sCurrCostRate = (sCurrCostRate+isnull(sCurrHoMargin,0))
  171. ,@pCurrCostRate = (pCurrCostRate+isnull(pCurrHoMargin,0))
  172. ,@pAgent = rt.pAgent
  173. FROM RemitTran rt WITH(NOLOCK)
  174. INNER JOIN TranSenders sen WITH(NOLOCK) ON rt.id = sen.tranId
  175. INNER JOIN TranReceivers rec WITH(NOLOCK) ON rt.id = rec.tranId
  176. WHERE controlNo = @controlNoEnc
  177. --AND rt.pAgent IS NULL
  178. IF @tranId IS NULL
  179. BEGIN
  180. SELECT @errorCode = '2003', @errorMsg = 'Transaction does not exist. Please check your GME No(GME NUMBER).'
  181. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  182. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  183. RETURN
  184. END
  185. IF @pAgent IS NOT NULL AND @pCountry='Nepal'
  186. BEGIN
  187. SELECT @errorCode = '2003', @errorMsg = 'Transaction is locked,Please try after 5 minute.'
  188. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  189. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  190. RETURN
  191. END
  192. IF @tranStatus IS NULL
  193. BEGIN
  194. SELECT @errorCode = '2003', @errorMsg = 'Transaction does not exist. Please check your GME No(GME NUMBER).'
  195. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  196. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  197. RETURN
  198. END
  199. IF @pCountry <> @userCountry
  200. BEGIN
  201. SELECT @errorCode = '2003', @errorMsg = 'You are not allow to request other countries transaction. Please check your GME No(GME NUMBER).'
  202. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  203. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  204. RETURN
  205. END
  206. IF @paymentMethod <> 'Cash Payment'
  207. BEGIN
  208. SELECT @errorCode = '2005', @errorMsg = 'This transaction is not Cash Pay Transaction'
  209. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  210. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  211. RETURN
  212. END
  213. IF (@tranStatus LIKE '%Hold%')
  214. BEGIN
  215. SELECT @errorCode = '2006', @errorMsg = 'The Transaction is not approved. Kindly contact info@gmeremit.com.np to approve the transction.'
  216. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  217. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  218. RETURN
  219. END
  220. IF (ISNULL(@Status,'') = 'Paid')
  221. BEGIN
  222. SELECT @errorCode = '2007', @errorMsg = 'Transaction ' + @REFNO + ' is already PAID'
  223. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  224. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  225. RETURN
  226. END
  227. -- IF (@pAgentTran IS NOT NULL AND @pAgentTran <> @pAgent)
  228. --BEGIN
  229. -- SELECT @errorCode = '2007', @errorMsg = 'This transaction belongs to : ' + @pAgentName
  230. -- EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  231. -- SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  232. -- RETURN
  233. --END
  234. IF (ISNULL(@tranStatus,'') <> 'Payment')
  235. BEGIN
  236. SELECT @errorCode = '2006', @errorMsg = 'This transaction is not currently available for payment. Kindly contact info@gmeremit.com.np for the details.'
  237. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  238. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  239. RETURN
  240. END
  241. IF @Status = 'Post'
  242. BEGIN
  243. SELECT @errorCode = '2006', @errorMsg = 'This transaction is not currently available for payment. Kindly contact info@gmeremit.com.np for the details.'
  244. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  245. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  246. RETURN
  247. END
  248. IF (ISNULL(@Status,'') <> 'Unpaid')
  249. BEGIN
  250. SELECT @errorCode = '2006', @errorMsg = 'This transaction is not currently available for payment. Kindly contact info@gmeremit.com.np for the details.'
  251. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  252. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  253. RETURN
  254. END
  255. IF (@lock_status = 'locked' and @USERNAME <> @lockedBy)
  256. BEGIN
  257. SELECT @errorCode = '2005', @errorMsg = 'Transaction is locked, Please Contact Head Office'
  258. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  259. SELECT @errorCode CODE, @errorMsg MESSAGE, * FROM @errorTable
  260. RETURN
  261. END
  262. -->>Pay Search Log
  263. INSERT INTO tranViewHistory(
  264. controlNumber, tranViewType, agentId
  265. ,createdBy, createdDate
  266. ,tranId, dcInfo
  267. )
  268. SELECT
  269. @controlNoEnc, 'PAY', @pAgent
  270. ,@USERNAME, GETDATE()
  271. ,@tranId, 'API : ' + @USERNAME + '(' + @pAgentName + ')'
  272. --<<Pay Search Log
  273. DECLARE @tokenId INT
  274. SELECT @tokenId = CAST(RAND() * 100000000 AS INT)
  275. SELECT
  276. @pAgent = am.agentId
  277. ,@userCountry = cm.countryName
  278. FROM applicationUsers au WITH(NOLOCK)
  279. INNER JOIN countryMaster cm WITH(NOLOCK) ON au.countryId = cm.countryId
  280. INNER JOIN agentMaster am WITH(NOLOCK) ON au.agentId = am.agentId
  281. WHERE userName = @USERNAME
  282. SELECT @pAgentName = agentName FROM agentMaster WITH(NOLOCK) WHERE agentId = @pAgent
  283. UPDATE remitTran SET
  284. lockStatus = 'locked'
  285. ,lockedBy = @USERNAME
  286. ,lockedDate = GETDATE()
  287. ,payTokenId = @tokenId
  288. ,pAgent = @pAgent
  289. ,pAgentName = @pAgentName
  290. WHERE controlNo = @controlNoEnc
  291. UPDATE apiRequestLogPay SET
  292. errorCode = '0'
  293. ,errorMsg = 'Search Success'
  294. ,PAY_TOKEN_ID = @tokenId
  295. ,remarks = @remarks
  296. WHERE rowId = @apiRequestId
  297. SELECT
  298. CODE = '0',
  299. REFNO = @REFNO,
  300. AGENT_SESSION_ID = @AGENT_SESSION_ID,
  301. MESSAGE = 'Success',
  302. SEND_AGENT = @SEND_AGENT,
  303. SENDER_NAME = @SENDER_NAME ,
  304. SENDER_ADDRESS = @SENDER_ADDRESS,
  305. SENDER_MOBILE = @SENDER_MOBILE,
  306. SENDER_CITY = @SENDER_CITY,
  307. SENDER_COUNTRY = @SENDER_COUNTRY,
  308. RECEIVER_NAME = @RECEIVER_NAME,
  309. RECEIVER_ADDRESS = @RECEIVER_ADDRESS,
  310. RECEIVER_PHONE = @RECEIVER_PHONE,
  311. RECEIVER_CITY = @RECEIVER_CITY,
  312. RECEIVER_COUNTRY = @RECEIVER_COUNTRY,
  313. PAYOUT_AMT = @PAYOUT_AMT,
  314. SENDING_AMT = @SENDING_AMT,
  315. PAYOUT_CURRENCY = @PAYOUT_CURRENCY,
  316. PAYMENT_TYPE = CASE WHEN @PAYMENT_TYPE = 'Cash Payment' THEN 'Cash Pay' ELSE @PAYMENT_TYPE END,
  317. TXN_DATE = @TXN_DATE,
  318. PAY_TOKEN_ID = @tokenId,
  319. TRANID = @tranId,
  320. RECEIVERMOBILE = @RECEIVER_PHONE
  321. ,Occupation = @Occupation
  322. ,IncomeSource = @IncomeSource
  323. ,Relationship = @Relationship
  324. ,PurposeOfRemittance = @PurposeOfRemittance
  325. ,CalculateBy = 'C'
  326. ,pCurrCostRate = @pCurrCostRate
  327. ,sCurrCostRate = @sCurrCostRate
  328. END TRY
  329. BEGIN CATCH
  330. DECLARE @errorLogId BIGINT
  331. INSERT INTO Logs (errorPage, errorMsg, errorDetails, createdBy, createdDate)
  332. SELECT 'API SP Error',@errorMsg MESSAGE, 'ws_proc_PayTXNCheck', @USERNAME, GETDATE()
  333. SET @errorLogId = SCOPE_IDENTITY()
  334. SELECT @errorCode = '9001', @errorMsg = 'Technical Error : ' + ERROR_MESSAGE() + ', Error Log Id : ' + CAST(@errorLogId AS VARCHAR)
  335. EXEC ws_proc_responseLog @flag = 'p', @requestId = @apiRequestId, @errorCode = @errorCode, @errorMsg = @errorMsg, @remarks = @remarks
  336. SELECT @errorCode CODE, 'Technical Error occurred, Error Log Id : ' + CAST(@errorLogId AS VARCHAR) MESSAGE, * FROM @errorTable
  337. END CATCH
  338. /*
  339. EXEC ws_proc_PayTXNCheck
  340. @ACCESSCODE='IMEBGUBL085',
  341. @USERNAME='apitest02',@PASSWORD='ime@9999',
  342. @AGENT_SESSION_ID='1234567',
  343. @REFNO='90407878675'
  344. */
  345. --EXEC ws_proc_PayTXNCheck @ACCESSCODE='GMKOR393965',@USERNAME='IMENepal',@PASSWORD='123456',@AGENT_SESSION_ID='1231',@REFNO='80175977055'
  346. GO