public async Task <NewReservationSummary> NewAsync(IReservationCreation reservation) { var currProjection = await projectionRepo.GetProjectionByIdAsync(reservation.ProjectionId); var reservationExpiration = currProjection.StartDate - TimeSpan.FromMinutes(10); IReservation newReservation = await reservationRepo.InsertAsync( new Reservation( reservation.ProjectionId, reservation.Row, reservation.Column, reservationExpiration)); await projectionRepo.DecreaseAvailableSeatsAsync(reservation.ProjectionId); //prepearing for reservation ticket var currMovie = await movieRepo.GetByIdAsync(currProjection.MovieId); var currRoom = await roomRepo.GetByIdAsync(currProjection.RoomId); var currCinema = await cinemaRepo.GetByIdAsync(currRoom.CinemaId); ReservationTicket reservationTicket = new ReservationTicket( newReservation.Id, currProjection.StartDate, currMovie.Name, currCinema.Name, currRoom.Number, newReservation.Row, newReservation.Column); return(new NewReservationSummary(true, reservationTicket)); }
/// <summary> /// Processes the specified order. /// </summary> /// <typeparam name="T">The order type.</typeparam> /// <param name="order">The order instance.</param> /// <exception cref="InvalidTypeException">The provider doesn't implement IReservable interface.</exception> protected override void Process <T>(T order) { bool cancelSuccess = false; ReservationTicket reservationTicket = new ReservationTicket(order); PaymentArgs paymentArgs = new PaymentArgs(); PaymentProvider paymentProvider = Context.Entity.Resolve <PaymentProvider>(order.PaymentSystem.Code); IReservable reservableProvider = paymentProvider as IReservable; if (reservableProvider != null) { reservableProvider.CancelReservation(order.PaymentSystem, paymentArgs, reservationTicket); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); string result = transactionDataProvider.GetPersistentValue(order.OrderNumber) as string; if (string.Compare(result, "Canceled", StringComparison.OrdinalIgnoreCase) == 0) { cancelSuccess = true; } } if (!cancelSuccess) { order.Status = Context.Entity.Resolve <OrderStatus>("Processing"); IOrderManager <Order> orderManager = Context.Entity.Resolve <IOrderManager <Order> >(); orderManager.SaveOrder(order); } if (reservableProvider == null) { throw new InvalidTypeException("The provider doesn't implement IReservable interface."); } }
protected ProcessResponse Process([NotNull] PaymentSystem paymentSystem, [NotNull] ReservationTicket reservationTicket, [NotNull] string operation) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); Assert.ArgumentNotNull(operation, "operation"); return(this.Process(paymentSystem, reservationTicket, reservationTicket.Amount, operation)); }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); string autocapture = configuration.GetSetting("autocapture"); if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse) { string xmlReturn = this.CheckStatus(paymentSystem, paymentArgs); if (!string.IsNullOrEmpty(xmlReturn)) { var quickPayResponse = this.ParseResult(xmlReturn); string secret = paymentSystem.Password; string tohash = string.Join(string.Empty, quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) + secret; string md5Check = this.GetMD5Hash(tohash); if (md5Check.Equals(quickPayResponse["md5check"]) && quickPayResponse["qpstat"].Equals("000")) { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), quickPayResponse["transaction"], quickPayResponse["amount"], quickPayResponse["currency"], string.Empty, string.Empty, string.Empty, quickPayResponse["cardtype"]); if (string.Compare(autocapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0) { string transactionAmount = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TotalAmount) as string; string orderNumber = paymentArgs.ShoppingCart.OrderNumber; string transactionNumber = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TransactionNumber) as string; decimal amount = transactionAmount.FromCents(); ReservationTicket reservationTicket = new ReservationTicket { InvoiceNumber = orderNumber, AuthorizationCode = PaymentConstants.EmptyAuthorizationCode, TransactionNumber = transactionNumber, Amount = amount }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } } else { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
/// <summary> /// Performs the completion of the conversation with PayPal. /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="orderRef">The order ref.</param> /// <param name="accountNumber">The account number.</param> /// <param name="hash">The hash.</param> /// <param name="transactionDataProvider">The transaction data provider.</param> protected void CompleteCallback(PaymentSystem paymentSystem, string orderRef, long accountNumber, string hash, ITransactionData transactionDataProvider) { PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); string purchaseOperation = configuration.GetSetting("purchaseOperation"); PaymentStatus paymentStatusResult = PaymentStatus.Failure; PxOrder payexOrder = new PxOrder(); string xmlReturn = payexOrder.Complete(accountNumber, orderRef, hash); string transactionNumber = this.ParseRes(xmlReturn, "/payex/transactionNumber"); string orderNumber = this.ParseRes(xmlReturn, "/payex/orderId"); string transactionAmount = this.ParseRes(xmlReturn, "/payex/amount"); string errorCode = this.ParseRes(xmlReturn, "/payex/status/errorCode"); int transactionStatus = int.Parse(this.ParseRes(xmlReturn, "/payex/transactionStatus")); if (errorCode == "OK") { switch (transactionStatus) { case (int)TransactionStatus.Sale: case (int)TransactionStatus.Authorize: { paymentStatusResult = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(orderNumber, paymentStatusResult.ToString(), transactionNumber, transactionAmount, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty); if (string.Compare(purchaseOperation, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0) { decimal amount = transactionAmount.FromCents(); ReservationTicket reservationTicket = new ReservationTicket { InvoiceNumber = orderNumber, AuthorizationCode = PaymentConstants.EmptyAuthorizationCode, TransactionNumber = transactionNumber, Amount = amount }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } break; } default: { string transactionErrorCode = this.ParseRes(xmlReturn, "/payex/errorDetails/transactionErrorCode"); if (transactionErrorCode == OperationCanceledError) { paymentStatusResult = PaymentStatus.Canceled; } break; } } } this.PaymentStatus = paymentStatusResult; }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); string instantcapture = configuration.GetSetting("instantcapture"); if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse) { string transactionNumber = request.QueryString["tid"]; string cardid = request.QueryString["cardid"]; string currency = request.QueryString["cur"]; string orderid = request.QueryString["orderid"]; string amount = request.QueryString["amount"]; string hashString = request.QueryString["eKey"]; string date = request.QueryString["date"]; if (!this.CallBackIsvalid(paymentSystem, paymentArgs, currency, transactionNumber, amount, orderid, hashString, date)) { Log.Error("Callback parameters are invalid.", this); } else { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(orderid, this.PaymentStatus.ToString(), transactionNumber, amount, currency, string.Empty, string.Empty, string.Empty, cardid); if (string.Compare(instantcapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0) { ReservationTicket reservationTicket = new ReservationTicket { InvoiceNumber = orderid, AuthorizationCode = hashString, TransactionNumber = transactionNumber, Amount = amount.FromCents() }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } else { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); string transactionType = configuration.GetSetting("x_type"); if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse) { string transactionId = request.Form["x_split_tender_id"] ?? request.Form["x_trans_id"]; string invoiceNumber = request.Form["x_invoice_num"]; string authorizationCode = request.Form["x_auth_code"]; string totalPrice = request.Form["x_amount"]; string responseCode = request.Form["x_response_code"]; string responseReasonCode = request.Form["x_response_reason_code"]; string responseReasonText = request.Form["x_response_reason_text"]; string method = request.Form["x_method"]; string hash = request.Form["x_MD5_Hash"]; string hashMD5 = Crypto.GetMD5Hash(paymentSystem.Password + paymentSystem.Username + transactionId + totalPrice); if (!string.IsNullOrEmpty(hash) && !string.IsNullOrEmpty(hashMD5) && string.Equals(hashMD5, hash, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(responseCode) && responseCode.Equals("1")) { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, PaymentStatus.Succeeded.ToString(), transactionId, totalPrice, string.Empty, responseCode, responseReasonCode, responseReasonText, method); if (string.Compare(transactionType, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0) { ReservationTicket reservationTicket = new ReservationTicket { InvoiceNumber = invoiceNumber, AuthorizationCode = authorizationCode, TransactionNumber = transactionId, Amount = TypeUtil.TryParse(totalPrice, decimal.Zero) }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } else { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); bool capturenow = !string.IsNullOrEmpty(configuration.GetSetting("capturenow")); if (request[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse) { string transactionNumber = request["transact"]; string amount = request["amount"]; string merchant = request["merchant"]; string orderid = request["orderid"]; string authkey = request["authkey"]; string cardType = request["paytype"] ?? string.Empty; if (this.CallBackIsvalid(paymentSystem, paymentArgs, transactionNumber, amount, merchant, orderid)) { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(orderid, this.PaymentStatus.ToString(), transactionNumber, amount, string.Empty, string.Empty, string.Empty, string.Empty, cardType); if (!capturenow) { ReservationTicket reservationTicket = new ReservationTicket { InvoiceNumber = orderid, AuthorizationCode = authkey, TransactionNumber = transactionNumber, Amount = amount.FromCents() }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } else { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
public virtual OldOrder CreateOrder <TShoppingCart>([NotNull] TShoppingCart shoppingCart) where TShoppingCart : ShoppingCart { Assert.ArgumentNotNull(shoppingCart, "shoppingCart"); Assert.IsNotNull(this.transactionData, "TransactionData must be set."); Assert.IsNotNull(this.shopContext, "Unable to create the order. Shop context is not set."); this.InitializeInnerRepository(); OldOrder order = Context.Entity.Resolve <OldOrder>(); this.Map(shoppingCart, order); string transactionNumber = TypeUtil.TryParse(this.transactionData.GetPersistentValue(shoppingCart.OrderNumber, TransactionConstants.TransactionNumber), string.Empty); if (!string.IsNullOrEmpty(transactionNumber)) { order.TransactionNumber = transactionNumber; } order.OrderDate = DateTime.Now; order.Status = Context.Entity.Resolve <NewOrder>(); order.ProcessStatus(); string cardType = this.transactionData.GetPersistentValue(order.OrderNumber, TransactionConstants.CardType) as string; order.CustomerInfo.CustomProperties[TransactionConstants.CardType] = cardType; Ecommerce.OrderManagement.Orders.Order newOrder = this.Convert(order); ReservationTicket sourceTicket = this.transactionData.GetPersistentValue(order.OrderNumber, "ReservationTicket") as ReservationTicket; if (sourceTicket != null) { Ecommerce.OrderManagement.Orders.ReservationTicket destinationTicket = new Ecommerce.OrderManagement.Orders.ReservationTicket(); this.Map(sourceTicket, destinationTicket); newOrder.ReservationTicket = destinationTicket; } newOrder.ShopContext = this.shopContext.InnerSite.Name; this.innerRepository.Create(newOrder); return(order); }
public IReservationTicket MakeReservation(IReservationCreation reservation) { ReservationTicket reservationTicket = new ReservationTicket(reservation.ProjId, reservation.SeatRow, reservation.SeatCol); reservationTicket.Projection = db.Projections.FirstOrDefault((p) => p.Id == reservation.ProjId); reservationTicket.Projection.Movie = db.Movies.FirstOrDefault((m) => m.Id == reservationTicket.Projection.MovieId); reservationTicket.Projection.Room = db.Rooms.FirstOrDefault((r) => r.Id == reservationTicket.Projection.RoomId); reservationTicket.Projection.Room.Cinema = db.Cinemas.FirstOrDefault( (c) => c.Id == reservationTicket.Projection.Room.CinemaId); --reservationTicket.Projection.AvailableSeatsCount; db.ReservationTickets.Add(reservationTicket); db.SaveChanges(); return(new MakeReservationTicket(reservationTicket.Id, reservationTicket.Projection.StartDate, reservationTicket.Projection.Movie.Name, reservationTicket.Projection.Room.Cinema.Name, reservationTicket.Projection.Room.Number, reservationTicket.SeatRow, reservationTicket.SeatCol)); }
protected ProcessResponse Process([NotNull] PaymentSystem paymentSystem, [NotNull] ReservationTicket reservationTicket, decimal amount, [NotNull] string operation) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); Assert.ArgumentNotNull(operation, "operation"); string merchantId = paymentSystem.Username; string token = paymentSystem.Password; string transactionId = reservationTicket.TransactionNumber; string transactionAmount = amount.ToCents(); Netaxept client = new Netaxept(); ProcessRequest processRequest = new ProcessRequest { Operation = operation, TransactionId = transactionId, TransactionAmount = transactionAmount }; return(client.Process(merchantId, token, processRequest)); }
public virtual void Credit(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs, ReservationTicket reservationTicket) { var args = Assert.ResultNotNull(paymentArgs as ActiveCommerce.Payments.PaymentArgs, "PaymentArgs must be of type ActiveCommerce.Payments.PaymentArgs"); var card = Assert.ResultNotNull(args.PaymentDetails as GiftCardInfo, "PaymentDetails must be of type GiftCardInfo"); try { GiftCardManager.Credit(card, args.Amount); } catch (Exception e) { PaymentStatus = PaymentStatus.Failure; Log.Error(string.Format("Unable to credit gift card: TranactionID={0}; Customer={1}; OrderNumber={2}", reservationTicket.TransactionNumber, paymentArgs.ShoppingCart.GetCustomerNameForLog(), paymentArgs.ShoppingCart.OrderNumber), e, this); return; } PaymentStatus = PaymentStatus.Succeeded; }
/// <summary> /// Cancels the payment reservation /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); const string Operation = "ANNUL"; string orderNumber = reservationTicket.InvoiceNumber; ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); try { ProcessResponse processResponse = this.Process(paymentSystem, reservationTicket, reservationTicket.Amount, Operation); transactionDataProvider.SavePersistentValue(orderNumber, processResponse.ResponseCode == "OK" ? PaymentConstants.CancelSuccess : processResponse.ResponseText); } catch (Exception exception) { Log.Warn(exception.Message, exception, this); transactionDataProvider.SavePersistentValue(orderNumber, exception.Message); } }
/// <summary> /// Captures the payment /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> /// <param name="amount">The amount.</param> public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero"); Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one"); const string Operation = "CAPTURE"; string orderNumber = reservationTicket.InvoiceNumber; ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); try { ProcessResponse processResponse = this.Process(paymentSystem, reservationTicket, amount, Operation); transactionDataProvider.SavePersistentValue(orderNumber, processResponse.ResponseCode == "OK" ? PaymentConstants.CaptureSuccess : processResponse.ResponseText); } catch (Exception exception) { Log.Warn(exception.Message, exception, this); transactionDataProvider.SavePersistentValue(orderNumber, exception.Message); } }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); string operation = configuration.GetSetting("operation"); string transactionId = request.QueryString["transactionId"]; string responseCode = request.QueryString["responseCode"]; if (string.Compare(responseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0) { string merchantId = paymentSystem.Username; string token = paymentSystem.Password; string orderNumber = paymentArgs.ShoppingCart.OrderNumber; decimal amount = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat; string currency = this.Currency(paymentArgs.ShoppingCart.Currency.Code); Netaxept client = new Netaxept(); ProcessRequest processRequest = new ProcessRequest { Operation = operation, TransactionId = transactionId }; try { ProcessResponse processResponse = client.Process(merchantId, token, processRequest); if (string.Compare(processResponse.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0) { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), transactionId, amount.ToString(), currency, string.Empty, string.Empty, string.Empty, string.Empty); if (string.Compare(operation, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0) { ReservationTicket reservationTicket = new ReservationTicket { Amount = amount, AuthorizationCode = processResponse.AuthorizationId, InvoiceNumber = orderNumber, TransactionNumber = transactionId }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } catch (Exception exception) { Log.Error(exception.Message, exception, this); } } else if (string.Compare(responseCode, "CANCEL", StringComparison.OrdinalIgnoreCase) == 0) { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>(); string operation = configuration.GetSetting("operation"); string transactionId = request.QueryString["transactionId"]; string responseCode = request.QueryString["responseCode"]; if (string.Compare(responseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0) { string merchantId = paymentSystem.Username; string token = paymentSystem.Password; string orderNumber = paymentArgs.ShoppingCart.OrderNumber; decimal amount = paymentArgs.ShoppingCart.Totals.TotalPriceIncVat; string currency = this.Currency(paymentArgs.ShoppingCart.Currency.Code); Netaxept client = new Netaxept(); ProcessRequest processRequest = new ProcessRequest { Operation = operation, TransactionId = transactionId }; try { ProcessResponse processResponse = client.Process(merchantId, token, processRequest); if (string.Compare(processResponse.ResponseCode, "OK", StringComparison.OrdinalIgnoreCase) == 0) { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), transactionId, amount.ToString(), currency, string.Empty, string.Empty, string.Empty, string.Empty); if (string.Compare(operation, this.ReservableTransactionType, StringComparison.OrdinalIgnoreCase) == 0) { ReservationTicket reservationTicket = new ReservationTicket { Amount = amount, AuthorizationCode = processResponse.AuthorizationId, InvoiceNumber = orderNumber, TransactionNumber = transactionId }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } catch (Exception exception) { Log.Error(exception.Message, exception, this); } } else if (string.Compare(responseCode, "CANCEL", StringComparison.OrdinalIgnoreCase) == 0) { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
/// <summary> /// Captures the payment /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> /// <param name="amount">The amount.</param> public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero"); Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one"); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); string key1 = configuration.GetSetting("key1"); string key2 = configuration.GetSetting("key2"); string url = configuration.GetSetting("captureUrl"); string merchant = paymentSystem.Username; string password = paymentSystem.Password; string orderId = reservationTicket.InvoiceNumber; string transact = reservationTicket.TransactionNumber; string amountInput = amount.ToCents(); const string Textreply = "yes"; const string Fullreply = "yes"; string forHash = string.Format("merchant={0}&orderid={1}&transact={2}&amount={3}", merchant, orderId, transact, amountInput); string md5Key = this.CalculateMd5Key(key1, key2, forHash); NameValueCollection data = new NameValueCollection { { "merchant", merchant }, { "orderid", orderId }, { "transact", transact }, { "amount", amountInput }, { "md5key", md5Key }, { "textreply", Textreply }, { "fullreply", Fullreply }, }; NameValueCollection result = new NameValueCollection(); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); transactionDataProvider.SavePersistentValue(orderId, this.SendRequest(merchant, password, url, data, ref result) ? PaymentConstants.CaptureSuccess : string.Format("UnCaptured. Reason={0}", result["reason"])); }
public async Task <ReservationSummary> MakeReservation(CreateReservationBindingModel model) { var projection = this.DbContext.Projections.FirstOrDefault(p => p.Id == model.ProjectionId); if (projection == null) { return(new ReservationSummary(false, $"Projection with id {model.ProjectionId} does not exist")); } bool isStarted = projection.StartDate < DateTime.UtcNow; bool isToLate = projection.StartDate < DateTime.UtcNow.AddMinutes(10); if (isStarted || isToLate) { return(new ReservationSummary(false, $"Reservation for this projection are closed")); } var room = this.DbContext.Rooms.FirstOrDefault(r => r.Id == projection.RoomId); bool isValidRow = model.Row > 0 && model.Row <= room.Rows; bool isValidRColumn = model.Column > 0 && model.Column <= room.SeatsPerRow; if (!isValidRow || !isValidRColumn) { return(new ReservationSummary(false, $"Invalid seat place")); } bool isReserved = this.DbContext.Reservations.Where(r => r.ProjectionId == model.ProjectionId) .FirstOrDefault(r => r.Row == model.Row && r.Column == model.Column) .Equals(null); bool isSold = this.DbContext.Tickets.Where(t => t.ProjectionId == model.ProjectionId) .FirstOrDefault(r => r.Row == model.Row && r.Column == model.Column) .Equals(null); if (isReserved || isSold) { return(new ReservationSummary(false, $"The place is occupied")); } Reservation newReservation = new Reservation(); newReservation.ProjectionId = projection.Id; newReservation.Row = model.Row; newReservation.Column = model.Column; this.DbContext.Reservations.Add(newReservation); int rowsAffected = await this.DbContext.SaveChangesAsync(); if (rowsAffected == 0) { return(new ReservationSummary(false, $"Reservation server error")); } var movie = this.DbContext.Movies.First(m => m.Id == projection.MovieId); var cinema = this.DbContext.Cinemas.First(c => c.Id == room.CinemaId); ReservationTicket reservationTicket = new ReservationTicket(); reservationTicket.ReservationId = newReservation.Id; reservationTicket.StartDate = projection.StartDate; reservationTicket.MovieName = movie.Name; reservationTicket.CinemaName = cinema.Name; reservationTicket.RoomNumber = room.Number; reservationTicket.Row = newReservation.Row; reservationTicket.Column = newReservation.Column; return(new ReservationSummary(true, reservationTicket)); }
/// <summary> /// Captures the payment /// </summary> /// <param name="paymentSystem">The payment System.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> /// <param name="amount">The amount.</param> public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero"); Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one"); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); bool isTest; Boolean.TryParse(configuration.GetSetting("x_test_request"), out isTest); var request = new CaptureRequest(amount, reservationTicket.TransactionNumber, reservationTicket.AuthorizationCode); var gate = new Gateway(paymentSystem.Username, paymentSystem.Password, isTest); var response = gate.Send(request); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, response.Approved ? PaymentConstants.CaptureSuccess : response.Message); }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>(); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); string autocapture = configuration.GetSetting("autocapture"); if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse) { string xmlReturn = this.CheckStatus(paymentSystem, paymentArgs); if (!string.IsNullOrEmpty(xmlReturn)) { var quickPayResponse = this.ParseResult(xmlReturn); string secret = paymentSystem.Password; string tohash = string.Join(string.Empty, quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) + secret; string md5Check = this.GetMD5Hash(tohash); if (md5Check.Equals(quickPayResponse["md5check"]) && quickPayResponse["qpstat"].Equals("000")) { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(paymentArgs.ShoppingCart.OrderNumber, this.PaymentStatus.ToString(), quickPayResponse["transaction"], quickPayResponse["amount"], quickPayResponse["currency"], string.Empty, string.Empty, string.Empty, quickPayResponse["cardtype"]); if (string.Compare(autocapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0) { string transactionAmount = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TotalAmount) as string; string orderNumber = paymentArgs.ShoppingCart.OrderNumber; string transactionNumber = transactionDataProvider.GetPersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.TransactionNumber) as string; decimal amount = transactionAmount.FromCents(); ReservationTicket reservationTicket = new ReservationTicket { InvoiceNumber = orderNumber, AuthorizationCode = PaymentConstants.EmptyAuthorizationCode, TransactionNumber = transactionNumber, Amount = amount }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } } else { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
/// <summary> /// Cancels payment reservation /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); var configuration = new PaymentSettingsReader(paymentSystem); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); string protocolInput = configuration.GetSetting("protocol"); const string MsgtypeInput = "cancel"; string merchantInput = paymentSystem.Username; string transaction = reservationTicket.TransactionNumber; string secretInput = paymentSystem.Password; string apiUrl = configuration.GetSetting("apiURL"); string tohashInput = string.Concat(protocolInput, MsgtypeInput, merchantInput, transaction, secretInput); string hashInput = this.GetMD5Hash(tohashInput); string requestString = string.Format( "protocol={0}&msgtype={1}&merchant={2}&transaction={3}&md5check={4}", protocolInput, MsgtypeInput, paymentSystem.Username, transaction, hashInput); string message = "UnCanceled: "; string information = string.Empty; string xmlReturn = this.SendRequest(apiUrl, requestString, ref information); if (!string.IsNullOrEmpty(xmlReturn)) { var quickPayResponse = this.ParseResult(xmlReturn); string secret = paymentSystem.Password; string tohash = string.Join(string.Empty, quickPayResponse.Where(x => x.Key != "md5check").Select(x => x.Value).ToArray()) + secret; string md5Check = this.GetMD5Hash(tohash); if (md5Check.Equals(quickPayResponse["md5check"]) && quickPayResponse["qpstat"].Equals("000")) { transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.CancelSuccess); return; } message += string.Format("qpstat={0}", quickPayResponse["qpstat"]); } else { message += information; } transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, message); }
/// <summary> /// Captures the payment /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> /// <param name="amount">The amount.</param> public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero"); Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one"); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); long accountNumber = TypeUtil.TryParse <long>(paymentSystem.Username, 0); int transactionNumber = int.Parse(reservationTicket.TransactionNumber); int amountInput = int.Parse(amount.ToCents()); string encryptionKey = paymentSystem.Password; ArrayList param = new ArrayList { accountNumber, transactionNumber, amountInput, encryptionKey }; string hash = this.CreateMD5Hash(param); PxOrder order = new PxOrder(); string xmlReturn = order.Capture2(accountNumber, transactionNumber, amountInput, hash); string errorCode = this.ParseRes(xmlReturn, "/payex/status/errorCode"); string description = this.ParseRes(xmlReturn, "/payex/status/description"); if (errorCode == "OK" && description == "OK") { transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.CaptureSuccess); } else { transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, string.Format("errorCode={0} description={1}", errorCode, description)); } }
/// <summary> /// Allows the issue of a credit to a card after a captured transaction. Used in particular /// when order processing fails if a payment gateway is configured for authorize-and-capture. /// </summary> public virtual void Credit(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs, ReservationTicket reservationTicket) { var paymentService = new MockPaymentService { EndpointUrl = paymentSystem.PaymentUrl, Username = paymentSystem.Username, Password = paymentSystem.Password }; //amount to credit can be found on the reservation ticket var request = new Request { RequestType = RequestType.Credit, MerchantOrderNumber = reservationTicket.InvoiceNumber, TransactionId = reservationTicket.TransactionNumber, Amount = reservationTicket.Amount }; var response = paymentService.ExecuteRequest(request); //IMPORTANT: Set PaymentStatus based on response from gateway this.PaymentStatus = response.ResponseStatus == ResponseStatus.Success ? PaymentStatus.Succeeded : PaymentStatus.Failure; }
/// <summary> /// Allows for capturing of a payment reservation. Not used by Active Commerce /// out of the box, but would be useful if you wish to automate capture in your /// Active Commerce implementation. /// </summary> public virtual void Capture(Sitecore.Ecommerce.DomainModel.Payments.PaymentSystem paymentSystem, Sitecore.Ecommerce.DomainModel.Payments.PaymentArgs paymentArgs, ReservationTicket reservationTicket, decimal amount) { var paymentService = new MockPaymentService { EndpointUrl = paymentSystem.PaymentUrl, Username = paymentSystem.Username, Password = paymentSystem.Password }; //Capture usually requires confirmation of amount to capture, //which can be found on the reservation ticket var request = new Request { RequestType = RequestType.CaptureReservation, MerchantOrderNumber = reservationTicket.InvoiceNumber, TransactionId = reservationTicket.TransactionNumber, Currency = paymentArgs.ShoppingCart.Currency.Code, Amount = reservationTicket.Amount }; var response = paymentService.ExecuteRequest(request); //IMPORTANT: Set PaymentStatus based on response from gateway this.PaymentStatus = response.ResponseStatus == ResponseStatus.Success ? PaymentStatus.Succeeded : PaymentStatus.Failure; }
/// <summary> /// Cancels the payment reservation /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); Payment payment = new Payment(); int pbsResponse = 0; bool deleteResult = payment.delete(int.Parse(paymentSystem.Username), long.Parse(reservationTicket.TransactionNumber), string.Empty, paymentSystem.Password, ref pbsResponse); transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, deleteResult ? PaymentConstants.CancelSuccess : string.Format("pbsResponse={0}", pbsResponse)); }
public NewReservationSummary(bool status, ReservationTicket reservationTicket) : this(status) { this.ReservationTicket = reservationTicket; }
public ReservationSummary(bool isSuccesfull, ReservationTicket reservationTicket) : base(isSuccesfull) { this.ReservationTicket = reservationTicket; }
/// <summary> /// Cancels the payment reservation. /// </summary> /// <param name="paymentSystem">The payment System.</param> /// <param name="paymentArgs">The payment arguments.</param> /// <param name="reservationTicket">The reservation ticket.</param> public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); bool isTest; Boolean.TryParse(configuration.GetSetting("x_test_request"), out isTest); var request = new VoidRequest(reservationTicket.TransactionNumber); var gate = new Gateway(paymentSystem.Username, paymentSystem.Password, isTest); var response = gate.Send(request); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, response.Approved ? PaymentConstants.CancelSuccess : response.Message); }
/// <summary> /// Cancels the payment /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); string key1 = configuration.GetSetting("key1"); string key2 = configuration.GetSetting("key2"); string url = configuration.GetSetting("cancelReservationUrl"); string merchant = paymentSystem.Username; string password = paymentSystem.Password; string orderId = reservationTicket.InvoiceNumber; string transact = reservationTicket.TransactionNumber; const string Textreply = "yes"; const string Fullreply = "yes"; string forHash = string.Format("merchant={0}&orderid={1}&transact={2}", merchant, orderId, transact); string md5Key = this.CalculateMd5Key(key1, key2, forHash); NameValueCollection data = new NameValueCollection { { "merchant", merchant }, { "orderid", orderId }, { "transact", transact }, { "md5key", md5Key }, { "textreply", Textreply }, { "fullreply", Fullreply }, }; NameValueCollection result = new NameValueCollection(); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); transactionDataProvider.SavePersistentValue(orderId, this.SendRequest(merchant, password, url, data, ref result) ? PaymentConstants.CancelSuccess : string.Format("UnCanceled. Reason={0}", result["reason"])); }
/// <summary> /// Captures the payment /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> /// <param name="amount">The amount.</param> public void Capture([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket, decimal amount) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); Assert.ArgumentCondition((amount > 0), "amount", "An amount should be greater than zero"); Assert.ArgumentCondition((amount <= reservationTicket.Amount), "amount", "An amount should not be greater than the original reserved one"); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); Payment payment = new Payment(); int pbsResponse = 0; int epayresponse = 0; bool captureResult = payment.capture(int.Parse(paymentSystem.Username), long.Parse(reservationTicket.TransactionNumber), int.Parse(amount.ToCents()), string.Empty, paymentSystem.Password, ref pbsResponse, ref epayresponse); transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, captureResult ? PaymentConstants.CaptureSuccess : string.Format("pbsResponse={0} epayresponse={1}", pbsResponse, epayresponse)); }
/// <summary> /// Processes the callback in terms of the HttpRequest and extracts either hidden form fields, or querystring parameters /// that is returned from the payment provider. /// Determines the payment status and saves that indication for later, could be in session, in db, or other storage. /// This information is important and used in the GetPaymentStatus(). /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> public override void ProcessCallback([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.IsNotNull(paymentArgs.ShoppingCart, "Shopping cart is null"); this.PaymentStatus = PaymentStatus.Failure; HttpRequest request = HttpContext.Current.Request; PaymentSettingsReader configuration = new PaymentSettingsReader(paymentSystem); ITransactionData transactionDataProvider = Context.Entity.Resolve<ITransactionData>(); string instantcapture = configuration.GetSetting("instantcapture"); if (request.QueryString[PaymentConstants.ActionKey] != PaymentConstants.CancelResponse) { string transactionNumber = request.QueryString["tid"]; string cardid = request.QueryString["cardid"]; string currency = request.QueryString["cur"]; string orderid = request.QueryString["orderid"]; string amount = request.QueryString["amount"]; string hashString = request.QueryString["eKey"]; string date = request.QueryString["date"]; if (!this.CallBackIsvalid(paymentSystem, paymentArgs, currency, transactionNumber, amount, orderid, hashString, date)) { Log.Error("Callback parameters are invalid.", this); } else { this.PaymentStatus = PaymentStatus.Succeeded; transactionDataProvider.SaveCallBackValues(orderid, this.PaymentStatus.ToString(), transactionNumber, amount, currency, string.Empty, string.Empty, string.Empty, cardid); if (string.Compare(instantcapture, this.ReservableBehavior, StringComparison.OrdinalIgnoreCase) == 0) { ReservationTicket reservationTicket = new ReservationTicket { InvoiceNumber = orderid, AuthorizationCode = hashString, TransactionNumber = transactionNumber, Amount = amount.FromCents() }; transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.ReservationTicket, reservationTicket); } } } else { this.PaymentStatus = PaymentStatus.Canceled; } if (this.PaymentStatus != PaymentStatus.Succeeded) { transactionDataProvider.SavePersistentValue(paymentArgs.ShoppingCart.OrderNumber, TransactionConstants.PaymentStatus, this.PaymentStatus.ToString()); } }
/// <summary> /// Cancels payment reservation /// </summary> /// <param name="paymentSystem">The payment system.</param> /// <param name="paymentArgs">The payment args.</param> /// <param name="reservationTicket">The reservation ticket.</param> public void CancelReservation([NotNull] PaymentSystem paymentSystem, [NotNull] PaymentArgs paymentArgs, [NotNull] ReservationTicket reservationTicket) { Assert.ArgumentNotNull(paymentSystem, "paymentSystem"); Assert.ArgumentNotNull(paymentArgs, "paymentArgs"); Assert.ArgumentNotNull(reservationTicket, "reservationTicket"); ITransactionData transactionDataProvider = Context.Entity.Resolve <ITransactionData>(); long accountNumber = TypeUtil.TryParse <long>(paymentSystem.Username, 0); int transactionNumber = int.Parse(reservationTicket.TransactionNumber); string encryptionKey = paymentSystem.Password; ArrayList param = new ArrayList { accountNumber, transactionNumber, encryptionKey }; string hash = this.CreateMD5Hash(param); PxOrder order = new PxOrder(); string xmlReturn = order.Cancel2(accountNumber, transactionNumber, hash); string errorCode = this.ParseRes(xmlReturn, "/payex/status/errorCode"); string description = this.ParseRes(xmlReturn, "/payex/status/description"); if (errorCode == "OK" && description == "OK") { transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, PaymentConstants.CancelSuccess); } else { transactionDataProvider.SavePersistentValue(reservationTicket.InvoiceNumber, string.Format("errorCode={0} description={1}", errorCode, description)); } }