public async Task <IActionResult> Continue([FromForm] string bankId) { bool cookieExists = this.Request.Cookies.TryGetValue(PaymentDataCookie, out string data); if (!cookieExists) { return(this.BadRequest()); } try { var request = DirectPaymentsHelper.ParsePaymentRequest(data); if (request == null) { return(this.BadRequest()); } var bank = await this.bankService.GetBankByIdAsync <BankPaymentServiceModel>(bankId); if (bank?.PaymentUrl == null) { return(this.BadRequest()); } // generate PaymentProof containing the bank's public key // and merchant's original PaymentInfo signature string proofRequest = DirectPaymentsHelper.GeneratePaymentRequestWithProof(request, bank.ApiKey, this.configuration.Key); // redirect the user to their bank for payment completion var paymentPostRedirectModel = new PaymentPostRedirectModel { Url = bank.PaymentUrl, PaymentDataFormKey = PaymentDataFormKey, PaymentData = proofRequest }; return(this.View("PaymentPostRedirect", paymentPostRedirectModel)); } catch { return(this.BadRequest()); } }
public async Task <IActionResult> Process() { bool cookieExists = this.Request.Cookies.TryGetValue(PaymentDataCookie, out var data); if (!cookieExists) { return(this.RedirectToHome()); } try { dynamic paymentRequest = DirectPaymentsHelper.ParsePaymentRequest(data, this.bankConfiguration.CentralApiPublicKey); if (paymentRequest == null) { return(this.BadRequest()); } dynamic paymentInfo = DirectPaymentsHelper.GetPaymentInfo(paymentRequest); var userId = await this.userService.GetUserIdByUsernameAsync(this.User.Identity.Name); var model = new PaymentConfirmBindingModel { Amount = paymentInfo.Amount, Description = paymentInfo.Description, DestinationBankName = paymentInfo.DestinationBankName, DestinationBankCountry = paymentInfo.DestinationBankCountry, DestinationBankAccountUniqueId = paymentInfo.DestinationBankAccountUniqueId, RecipientName = paymentInfo.RecipientName, OwnAccounts = await this.GetAllAccountsAsync(userId), DataHash = DirectPaymentsHelper.Sha256Hash(data) }; return(this.View(model)); } catch { return(this.BadRequest()); } }
public async Task <IActionResult> Process() { bool cookieExists = this.Request.Cookies.TryGetValue(PaymentDataCookie, out string data); if (!cookieExists) { return(this.BadRequest()); } try { var request = DirectPaymentsHelper.ParsePaymentRequest(data); if (request == null) { return(this.BadRequest()); } var paymentInfo = DirectPaymentsHelper.GetPaymentInfo(request); var banks = (await this.bankService.GetAllBanksSupportingPaymentsAsync <BankListingServiceModel>()) .Select(Mapper.Map <BankListingViewModel>) .ToArray(); var viewModel = new PaymentSelectBankViewModel { Amount = paymentInfo.Amount, Description = paymentInfo.Description, Banks = banks }; return(this.View(viewModel)); } catch { return(this.BadRequest()); } }
public async Task <IActionResult> PayAsync(PaymentConfirmBindingModel model) { bool cookieExists = this.Request.Cookies.TryGetValue(PaymentDataCookie, out var data); if (!this.ModelState.IsValid || !cookieExists || model.DataHash != DirectPaymentsHelper.Sha256Hash(data)) { return(this.PaymentFailed(NotificationMessages.PaymentStateInvalid)); } var account = await this.bankAccountService.GetByIdAsync <BankAccountDetailsServiceModel>(model.AccountId); if (account == null || account.UserUserName != this.User.Identity.Name) { return(this.Forbid()); } try { // read and validate payment data dynamic paymentRequest = DirectPaymentsHelper.ParsePaymentRequest(data, this.bankConfiguration.CentralApiPublicKey); if (paymentRequest == null) { return(this.PaymentFailed(NotificationMessages.PaymentStateInvalid)); } dynamic paymentInfo = DirectPaymentsHelper.GetPaymentInfo(paymentRequest); string returnUrl = paymentRequest.ReturnUrl; // transfer money to destination account var serviceModel = new GlobalTransferDto { Amount = paymentInfo.Amount, Description = paymentInfo.Description, DestinationBankName = paymentInfo.DestinationBankName, DestinationBankCountry = paymentInfo.DestinationBankCountry, DestinationBankSwiftCode = paymentInfo.DestinationBankSwiftCode, DestinationBankAccountUniqueId = paymentInfo.DestinationBankAccountUniqueId, RecipientName = paymentInfo.RecipientName, SourceAccountId = model.AccountId }; var result = await this.globalTransferHelper.TransferMoneyAsync(serviceModel); if (result != GlobalTransferResult.Succeeded) { return(this.PaymentFailed(result == GlobalTransferResult.InsufficientFunds ? NotificationMessages.InsufficientFunds : NotificationMessages.TryAgainLaterError)); } // delete cookie to prevent accidental duplicate payments this.Response.Cookies.Delete(PaymentDataCookie); // return signed success response var response = DirectPaymentsHelper.GenerateSuccessResponse(paymentRequest, this.bankConfiguration.Key); return(this.Ok(new { success = true, returnUrl = HttpUtility.HtmlEncode(returnUrl), data = response })); } catch { return(this.PaymentFailed(NotificationMessages.PaymentStateInvalid)); } }