public Task <ObjectResult> Pay(StartPaymentMessage message) { var task = new Task <ObjectResult>(() => OnPayment(message)); task.Start(); return(task); }
public IActionResult Payment([FromBody] StartPaymentMessage dto) { var task = GetSuccessResponseTask(dto); task.Start(); return(Ok()); }
public Task GetSuccessResponseTask(StartPaymentMessage dto) { var paymentResponse = new PaymentResponse { Code = 200, Message = "", OperationId = dto.OperationId, Timestamp = DateTime.Now }; return(new Task(() => { Thread.Sleep(2000); var api = RestService.For <ISuperpagosApi>(dto.ResponseEndpoint); api.PaymentEnded(paymentResponse); })); }
// todo: hacer async public bool Start(ProviderApiFactory providerApiFactory, AppDbContext context, string responseEndpoint) { InProcess = true; Started = true; var couldTriggerPayment = false; var api = providerApiFactory.Create(Account.Provider.PaymentEndpoint); try { api.Pay(StartPaymentMessage.Build(Account, OperationType, Amount, responseEndpoint, OperationId)).Wait(); couldTriggerPayment = true; } catch (Exception e) { Debug.Print(e.ToString()); IsSuccesfull = false; InProcess = false; } context.Movements.Update(this); return(couldTriggerPayment); }
public Task <ObjectResult> Pay(StartPaymentMessage message) { throw new NotImplementedException(); }
/// <summary> /// Computes the url of CartaSì's web service to which the buyer has to be redirected. /// </summary> /// <param name="paymentId">The id of the PaymentRecord for the transaction we are trying to complete.</param> /// <returns>The url where we should redirct the buyer.</returns> public string StartCartaSiTransactionURL(int paymentId) { var settings = _orchardServices.WorkContext.CurrentSite.As <PaymentCartaSiSettingsPart>(); string pURL = settings.UseTestEnvironment ? EndPoints.TestPaymentURL : EndPoints.PaymentURL; var pRecord = GetPaymentInfo(paymentId); if (pRecord.PaymentTransactionComplete) { //this avoids repeat payments when the user is dumb and goes back in the browser to try and pay again return(GetPaymentInfoUrl(paymentId)); } var user = _orchardServices.WorkContext.CurrentUser; if (pRecord.UserId > 0 && pRecord.UserId != user.Id) { //not the same user who started the payment throw new Exception(); } StartPaymentMessage spMsg = new StartPaymentMessage(settings.CartaSiShopAlias, settings.CartaSiSecretKey, pRecord); spMsg.url = ActionUrl("CartaSiOutcome"); spMsg.url_back = ActionUrl("CartaSiUndo"); spMsg.urlpost = ActionUrl("CartaSiS2S"); #if DEBUG spMsg.urlpost = RemoteActionUrl("CartaSiS2S"); #endif spMsg.mac = spMsg.TransactionStartMAC; try { Validator.ValidateObject(spMsg, new ValidationContext(spMsg), true); } catch (Exception ex) { //Log the error Logger.Error(T("Transaction information not valid: {0}", ex.Message).Text); //update the PaymentRecord for this transaction EndPayment(paymentId, false, null, T("Transaction information not valid: {0}", ex.Message).Text); //return the URL of a suitable error page (call this.GetPaymentInfoUrl after inserting the error in the PaymentRecord) return(GetPaymentInfoUrl(paymentId)); } //from the parameters, make the query string for the payment request string qString = ""; try { qString = spMsg.MakeQueryString(); if (string.IsNullOrWhiteSpace(qString)) { throw new Exception(T("Errors while creating the query string. The query string cannot be empty.").Text); } } catch (Exception ex) { //Log the error Logger.Error(ex.Message); //update the PaymentRecord for this transaction EndPayment(paymentId, false, null, ex.Message); //return the URL of a suitable error page (call this.GetPaymentInfoUrl after inserting the error in the PaymentRecord) return(GetPaymentInfoUrl(paymentId)); } pURL = string.Format("{0}?{1}", pURL, qString); return(pURL); // return null; }