public async Task <IActionResult> Pay(string id)
        {
            try
            {
                var order = await this.ordersService.GetByIdAsync(id);

                if (order == null ||
                    order.UserName != this.User.Identity.Name ||
                    order.PaymentStatus != PaymentStatus.Pending)
                {
                    return(this.RedirectToAction("My", "Orders"));
                }

                var paymentInfo = new
                {
                    Amount      = order.ProductPrice,
                    Description = order.ProductName,
                    this.destinationBankAccountConfiguration.DestinationBankName,
                    this.destinationBankAccountConfiguration.DestinationBankCountry,
                    this.destinationBankAccountConfiguration.DestinationBankSwiftCode,
                    this.destinationBankAccountConfiguration.DestinationBankAccountUniqueId,
                    this.destinationBankAccountConfiguration.RecipientName,

                    // ! PaymentInfo can also contain custom properties
                    // ! that will be returned on payment completion

                    // ! OrderId is a custom property and is not required
                    OrderId = order.Id
                };

                // generate the returnUrl where the payment result will be received
                var returnUrl = this.directPaymentsConfiguration.SiteUrl + ReturnPath;

                // generate signed payment request
                var paymentRequest = DirectPaymentsHelper.GeneratePaymentRequest(
                    paymentInfo, this.directPaymentsConfiguration.SiteKey, returnUrl);

                // redirect the user to the CentralApi for payment processing
                var paymentPostRedirectModel = new PaymentPostRedirectModel
                {
                    Url = this.directPaymentsConfiguration.CentralApiPaymentUrl,
                    PaymentDataFormKey = PaymentDataFormKey,
                    PaymentData        = paymentRequest
                };

                return(this.View("PaymentPostRedirect", paymentPostRedirectModel));
            }
            catch
            {
                return(this.RedirectToAction("My", "Orders"));
            }
        }
Пример #2
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());
            }
        }