public async Task <ActionResult> Pay(RequestViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var verifyUrl = Url.Action("Verify", "Payment", null, Request.Url.Scheme); var result = await _onlinePayment.RequestAsync(invoice => { invoice .SetAmount(viewModel.Amount) .SetCallbackUrl(verifyUrl) .SetGateway(viewModel.Gateway.ToString()); if (viewModel.GenerateTrackingNumberAutomatically) { invoice.UseAutoIncrementTrackingNumber(); } else { invoice.SetTrackingNumber(viewModel.TrackingNumber); } }); // Save the result.TrackingNumber in your database. if (result.IsSucceed) { return(result.GatewayTransporter.TransportToGateway()); } return(View("PayRequestError", result)); }
public async Task <ActionResult> PayRequest(RequestViewModel payViewModel) { if (!ModelState.IsValid) { return(View(payViewModel)); } var verifyUrl = Url.Action("Verify", "Payment", null, Request.Url.Scheme); var result = await _onlinePayment.RequestAsync(invoice => { invoice .UseAutoIncrementTrackingNumber() .SetAmount(payViewModel.Amount) .SetCallbackUrl(verifyUrl) .UseGateway(payViewModel.Gateway); }); if (result.IsSucceed) { return(result.GatewayTransporter.TransportToGateway()); } // Note: This is just for development and testing. // Don't show the actual result object to clients in production environment. // Instead, show only the important information such as IsSucceed, Tracking Number and Transaction Code. return(View("PayRequestError", result)); }
public async Task <IActionResult> Pay(PayViewModel viewModel) { var verifyUrl = Url.Action("Verify", "Payment", null, Request.Scheme); var result = await _onlinePayment.RequestAsync(invoice => { invoice .SetAmount(viewModel.Amount) .SetCallbackUrl(verifyUrl) .SetGateway(viewModel.SelectedGateway.ToString()); if (viewModel.GenerateTrackingNumberAutomatically) { invoice.UseAutoIncrementTrackingNumber(); } else { invoice.SetTrackingNumber(viewModel.TrackingNumber); } }); if (result.IsSucceed) { return(result.GatewayTransporter.TransportToGateway()); } // Note: This is just for development and testing. // Don't show the actual result object to clients in production environment. // Instead, show only the important information such as IsSucceed, Tracking Number and Transaction Code. return(View("PayRequestError", result)); }
/// <summary> /// Performs a new payment request with the given data. /// </summary> /// <param name="onlinePayment"></param> /// <param name="gatewayName">The gateway which the client must pay the invoice in.</param> /// <param name="trackingNumber"> /// A tracking number for this request. It will be sent to the gateway. /// <para>Note: It must be unique for each requests.</para> /// </param> /// <param name="amount">The amount of the payment request.</param> /// <param name="callbackUrl"> /// A complete URL of your website. It will be used by the gateway for redirecting the client again to your website. /// <para>A complete URL would be like: "http://www.mywebsite.com/foo/bar/"</para> /// </param> public static IPaymentRequestResult Request( this IOnlinePayment onlinePayment, string gatewayName, long trackingNumber, decimal amount, string callbackUrl) => onlinePayment.RequestAsync(gatewayName, trackingNumber, amount, callbackUrl) .GetAwaiter() .GetResult();
public async Task <IActionResult> Pay(string id) { var factorFromRepo = await _dbFinancial.FactorRepository.GetByIdAsync(id); if (factorFromRepo == null) { return(RedirectToAction("Verify", new { error = "تراکنش مورد نظر وجود ندارد" })); } // if (factorFromRepo.Status) { return(RedirectToAction("Verify", new { token = factorFromRepo.Id, error = "پرداخت قبلا به صورت موفق انجام شده است" })); } var callbackUrl = Url.Action("Verify", "Bank", null, Request.Scheme); var result = await _onlinePayment.RequestAsync(invoice => { invoice .UseAutoIncrementTrackingNumber() .SetAmount(factorFromRepo.EndPrice) .SetCallbackUrl(callbackUrl) //.UseParbadVirtual(); .UseZarinPal("پرداخت از سایت مادپی"); }); if (result.IsSucceed) { factorFromRepo.RefBank = result.TrackingNumber.ToString(); factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Bank = result.GatewayName.ToBank(); _dbFinancial.FactorRepository.Update(factorFromRepo); if (await _dbFinancial.SaveAsync()) { await result.GatewayTransporter.TransportAsync(); return(new EmptyResult()); } else { return(RedirectToAction("Verify", new { token = factorFromRepo.Id, error = "خطا در ثبت " })); } } else { return(RedirectToAction("Verify", new { token = factorFromRepo.Id, error = result.Message })); } }
/// <summary> /// Performs a new payment request with the given data. /// </summary> /// <param name="onlinePayment"></param> /// <param name="gatewayName">The gateway which the client must pay the invoice in.</param> /// <param name="trackingNumber"> /// A tracking number for this request. It will be sent to the gateway. /// <para>Note: It must be unique for each requests.</para> /// </param> /// <param name="amount">The amount of the payment request.</param> /// <param name="callbackUrl"> /// A complete URL of your website. It will be used by the gateway for redirecting the client again to your website. /// <para>A complete URL would be like: "http://www.mywebsite.com/foo/bar/"</para> /// </param> /// <param name="cancellationToken"></param> public static Task <IPaymentRequestResult> RequestAsync( this IOnlinePayment onlinePayment, string gatewayName, long trackingNumber, decimal amount, string callbackUrl, CancellationToken cancellationToken = default) { return(onlinePayment.RequestAsync(builder => { builder .SetTrackingNumber(trackingNumber) .SetAmount(amount) .SetCallbackUrl(callbackUrl) .SetGateway(gatewayName); }, cancellationToken)); }
/// <summary> /// Performs a new payment request by using an invoice builder. /// </summary> /// <param name="onlinePayment"></param> /// <param name="configureInvoice">A builder which helps to build an invoice.</param> /// <param name="cancellationToken"></param> public static async Task <IPaymentRequestResult> RequestAsync( this IOnlinePayment onlinePayment, Action <IInvoiceBuilder> configureInvoice, CancellationToken cancellationToken = default) { if (onlinePayment == null) { throw new ArgumentNullException(nameof(onlinePayment)); } if (configureInvoice == null) { throw new ArgumentNullException(nameof(configureInvoice)); } IInvoiceBuilder invoiceBuilder = new DefaultInvoiceBuilder(onlinePayment.Services); configureInvoice(invoiceBuilder); var invoice = await invoiceBuilder.BuildAsync(cancellationToken).ConfigureAwaitFalse(); return(await onlinePayment.RequestAsync(invoice, cancellationToken)); }
public async Task <IActionResult> Pay([FromBody] PayViewModel viewModel) { var callbackUrl = Url.Action("Verify", "Payment", null, Request.Scheme); var result = await _onlinePayment.RequestAsync(invoice => { invoice .SetAmount(viewModel.Amount) .SetCallbackUrl(callbackUrl) .SetGateway(viewModel.SelectedGateway.ToString()); if (viewModel.GenerateTrackingNumberAutomatically) { invoice.UseAutoIncrementTrackingNumber(); } else { invoice.SetTrackingNumber(viewModel.TrackingNumber); } }); _orderRepository.AddOrder(new Order { PaymentTrackingNumber = result.TrackingNumber, Amount = result.Amount, GatewayName = result.GatewayName, GatewayAccountName = result.GatewayAccountName }); return(Ok(new { result.IsSucceed, result.Message, Transporter = CreateTransporterForClientApp(result.GatewayTransporter) })); }
/// <summary> /// Performs a new payment request with the given invoice. /// </summary> /// <param name="onlinePayment"></param> /// <param name="invoice">The invoice that must be paid.</param> public static IPaymentRequestResult Request(this IOnlinePayment onlinePayment, Invoice invoice) => onlinePayment.RequestAsync(invoice) .GetAwaiter() .GetResult();
/// <summary> /// Performs a new payment request with the given data. /// </summary> /// <param name="onlinePayment"></param> /// <param name="configureInvoice">A builder which helps to build an invoice.</param> public static IPaymentRequestResult Request(this IOnlinePayment onlinePayment, Action <IInvoiceBuilder> configureInvoice) => onlinePayment.RequestAsync(configureInvoice) .GetAwaiter() .GetResult();
public async Task <IActionResult> Pay(string token) { var factorFromRepo = await _dbFinancial.FactorRepository.GetByIdAsync(token); if (factorFromRepo == null) { model.Status = false; model.Messages.Clear(); model.Messages = new string[] { "token-error" }; model.Result = null; return(View(model)); } // model.Result.Factor = factorFromRepo; model.Result.Gate = await _db._GateRepository.GetByIdAsync(factorFromRepo.GateId); // if (factorFromRepo.DateCreated.AddMinutes(10) < DateTime.Now) { model.Status = false; model.Messages.Clear(); model.Messages = new string[] { "زمان تکمیل عملیات پرداخت تمام شده است" }; return(View(model)); } if (factorFromRepo.Status) { model.Status = false; model.Messages.Clear(); model.Messages = new string[] { "پرداخت قبلا به صورت موفق انجام شده است" }; return(View(model)); } if (model.Result.Gate.IsDirect) { var callbackUrl = Url.Action("Verify", "Bank", null, Request.Scheme); var result = await _onlinePayment.RequestAsync(invoice => { decimal amount = Convert.ToDecimal(factorFromRepo.EndPrice); invoice .UseAutoIncrementTrackingNumber() .SetAmount(amount) .SetCallbackUrl(callbackUrl) //.UseParbadVirtual(); .UseZarinPal("پرداخت از سایت مادپی", "*****@*****.**", "09361234567"); }); if (result.IsSucceed) { factorFromRepo.RefBank = result.TrackingNumber.ToString(); factorFromRepo.DateModified = DateTime.Now; factorFromRepo.Bank = result.GatewayName.ToBank(); _dbFinancial.FactorRepository.Update(factorFromRepo); if (await _dbFinancial.SaveAcync() > 0) { await result.GatewayTransporter.TransportAsync(); return(new EmptyResult()); } else { model.Status = false; model.Messages.Clear(); model.Messages = new string[] { "خطا در ثبت " }; return(View(model)); } } else { model.Status = false; model.Messages.Clear(); model.Messages = new string[] { result.Message }; return(View(model)); } } else { model.Status = true; model.Messages.Clear(); return(View(model)); } }