Exemple #1
0
        private bool IsSignatureValid(FomoPayResponse fomoPayResponse)
        {
            var param = new SortedDictionary <string, string>
            {
                { "transaction", fomoPayResponse.transaction },
                { "result", fomoPayResponse.result },
                { "upstream", fomoPayResponse.upstream },
                { "nonce", fomoPayResponse.nonce },
                { "payment_id", fomoPayResponse.payment_id }
            };
            var strArray = new StringBuilder();

            foreach (var(key, value) in param)
            {
                strArray.Append(key + "=" + value + "&");
            }

            var nLen = strArray.Length;

            strArray.Remove(nLen - 1, 1);
            var computeSha256Hash = ComputeSha256Hash(strArray.ToString());

            _logger.LogInformation(
                $"computedSignature:{computeSha256Hash},originalSignature:{fomoPayResponse.signature}");
            return(computeSha256Hash == fomoPayResponse.signature);
        }
Exemple #2
0
 public void ProcessPaymentCallback([FromForm] FomoPayResponse fomoPayResponse)
 {
     _logger.LogInformation("processPaymentCallback Request:" + JsonConvert.SerializeObject(fomoPayResponse));
     if (!IsSignatureValid(fomoPayResponse))
     {
         return;
     }
     SaveFomoPayResponse(fomoPayResponse).GetAwaiter().GetResult();
 }
Exemple #3
0
        private async Task SaveFomoPayResponse(FomoPayResponse fomoPayResponse)
        {
            var topUpHistory = await _eWalletService.FindByTopUpTransactionIdAsync(fomoPayResponse.transaction);

            var initTransaction = topUpHistory.First(x => x.Status == Status.Init);

            if (initTransaction != null)
            {
                TopUpResource topUpResource = new TopUpResource
                {
                    TransactionId      = fomoPayResponse.transaction,
                    ActionDate         = DateTime.Now,
                    Status             = fomoPayResponse.result == "0" ? Status.Success : Status.Fail,
                    PaymentReferenceNo = fomoPayResponse.payment_id + '|' + fomoPayResponse.upstream + '|' +
                                         fomoPayResponse.nonce + '|' +
                                         fomoPayResponse.signature,
                    Amount          = initTransaction.Amount,
                    PaymentMerchant = initTransaction.PaymentMerchant
                };
                await _eWalletService.SaveTopUpAsync(topUpResource, initTransaction.UserId);
            }
        }