Ejemplo n.º 1
0
        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());
            }
        }