public async Task <ActionResult> Notify([FromQuery] string customKey, [FromHeader] string HMAC, [FromForm] PaymentNotifyRequest model) { try { logger.LogTrace("Start processing callback {Notify} ", nameof(Notify), customKey); logger.LogTrace(JsonConvert.SerializeObject(Request.Form)); if (ModelState.IsValid) { var calculatedHMAC = CalculateHMACSHA512Hex(Request.Form); if (!string.Equals(HMAC, calculatedHMAC)) { logger.LogError($"Invalid HMAC {HMAC} {calculatedHMAC}"); logger.LogError(JsonConvert.SerializeObject(Request.Form)); return(Content("ER")); } var request = new ProcessPaymentTransaction() { TransactionHash = model.TransactionHash, Address = model.Address, Amount = model.Amount, AmountBigInt = model.AmountBigInt, Currency = Enum.Parse <Currency>(model.Currency), // TODO IsConfirmed = model.IsConfirmed, VerificationCode = model.VerificationCode // TODO check }; var rs = await paymentService.ProcessCallback(request); if (rs.IsValid) { logger.LogInformation("End processing Notify"); return(Content("OK")); } else { logger.LogError("End processing Notify with Error"); return(Content("ER")); } } else { logger.LogError("ModelState Error", JsonConvert.SerializeObject(ModelState)); } } catch (Exception e) { logger.LogError("paymentTransactionService.ProcessCallback Exception {error}", e.ToString()); } logger.LogInformation("Finish processing callback {Notify} {CustomKey}", nameof(Notify), customKey); return(Content("ER")); }
public void PaymentsCallbackTest1() { var wallet = context.Wallets.First(w => w.UserId == user.Id && w.Currency == Currency.GVT); Assert.IsNull(wallet.WalletTransactions); var payment = new ProcessPaymentTransaction { Amount = 100, Address = "0x00", Status = PaymentTransactionStatus.ConfirmedAndValidated, Currency = Currency.GVT }; paymentService.ProcessCallback(payment); Assert.AreEqual(100, context.Wallets.First(w => w.UserId == user.Id && w.Currency == Currency.GVT).Amount); }