private StartPaymentOperation PreparePaymentOperation(Order order, BarionSettings storeSetting)
        {
            PaymentType paymentType = PaymentType.Immediate;

            if (storeSetting.UseReservationPaymentType)
            {
                paymentType = PaymentType.Reservation;
            }

            var operation = new StartPaymentOperation
            {
                PayerHint        = order.BillingAddress.Email,
                GuestCheckOut    = true,
                PaymentType      = paymentType,
                FundingSources   = new[] { FundingSourceType.All },
                PaymentRequestId = Guid.NewGuid().ToString(),
                OrderNumber      = order.CustomOrderNumber,
                Currency         = GetCurrency(order.CustomerCurrencyCode),
                CallbackUrl      = storeSetting.CallbackUrl,
                Locale           = CultureInfo.GetCultureInfo(_workContext.WorkingLanguage.LanguageCulture),
                RedirectUrl      = storeSetting.RedirectUrl
            };

            if (storeSetting.UseReservationPaymentType)
            {
                operation.ReservationPeriod = TimeSpan.FromHours(storeSetting.ReservationPeriod);
            }

            return(operation);
        }
Exemplo n.º 2
0
        public static StartPaymentOperationResult StartPayment(BarionClient barionClient, BarionSettings settings, PaymentType paymentType, TimeSpan?reservationPeriod = null, bool initiateRecurrence = false, string recurrenceId = null)
        {
            var startPaymentOperation = new StartPaymentOperation
            {
                GuestCheckOut      = true,
                PaymentType        = paymentType,
                ReservationPeriod  = reservationPeriod,
                FundingSources     = new[] { FundingSourceType.All },
                PaymentRequestId   = "P1",
                OrderNumber        = "1_0",
                Currency           = Currency.EUR,
                CallbackUrl        = "http://index.sk",
                Locale             = CultureInfo.CurrentCulture,
                RedirectUrl        = "http://index.sk",
                InitiateRecurrence = initiateRecurrence,
                RecurrenceId       = recurrenceId
            };

            var transaction = new PaymentTransaction
            {
                Payee            = settings.Payee,
                POSTransactionId = POSTransactionId,
                Total            = new decimal(1000),
                Comment          = "comment"
            };

            var item = new Item
            {
                Name        = "Test",
                Description = "Test",
                ItemTotal   = new decimal(1000),
                Quantity    = 1,
                Unit        = "piece",
                UnitPrice   = new decimal(1000),
                SKU         = "SKU"
            };

            transaction.Items = new[] { item };
            startPaymentOperation.Transactions = new[] { transaction };

            Console.WriteLine("Sending StartPayment...");
            var result = barionClient.ExecuteAsync <StartPaymentOperationResult>(startPaymentOperation).Result;

            if (!result.IsOperationSuccessful)
            {
                throw new Exception("Start payment operation was not successful.");
            }

            return(result);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> StartPayment(Product product)
        {
            var item = new Item
            {
                Name        = product.Name,
                Description = product.Name,
                Quantity    = 1,
                UnitPrice   = product.Price,
                ItemTotal   = product.Price,
                Unit        = "piece",
                SKU         = "SKU"
            };

            var transaction = new PaymentTransaction
            {
                Items            = new[] { item },
                POSTransactionId = "T1",
                Payee            = _barionSettings.Payee,
                Total            = product.Price
            };

            var startPayment = new StartPaymentOperation
            {
                Transactions     = new[] { transaction },
                PaymentType      = PaymentType.Immediate,
                Currency         = Currency.HUF,
                FundingSources   = new[] { FundingSourceType.All },
                GuestCheckOut    = true,
                Locale           = CultureInfo.CurrentCulture,
                OrderNumber      = "Order1",
                PaymentRequestId = "R1",
                CallbackUrl      = UriHelper.BuildAbsolute(Request.Scheme, Request.Host, Url.Action("Callback", "Barion")),
                RedirectUrl      = UriHelper.BuildAbsolute(Request.Scheme, Request.Host, Url.Action("PaymentFinished", "Home"))
            };

            var result = await _barionClient.ExecuteAsync(startPayment);

            if (result.IsOperationSuccessful)
            {
                var startPaymentReult = result as StartPaymentOperationResult;
                return(Redirect(startPaymentReult.GatewayUrl));
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 4
0
        public static void Run()
        {
            var settings = new BarionSettings
            {
                BaseUrl = new Uri(AppSettings.BarionBaseAddress),
                POSKey  = Guid.Parse(AppSettings.BarionPOSKey),
                Payee   = AppSettings.BarionPayee
            };

            using (var barionClient = new BarionClient(settings))
            {
                var startPaymentOperation = new StartPaymentOperation
                {
                    GuestCheckOut     = true,
                    PaymentType       = PaymentType.Reservation,
                    ReservationPeriod = TimeSpan.FromDays(1),
                    FundingSources    = new[] { FundingSourceType.All },
                    PaymentRequestId  = "P1",
                    OrderNumber       = "1_0",
                    Currency          = Currency.HUF,
                    CallbackUrl       = "http://index.hu",
                    Locale            = CultureInfo.CurrentCulture,
                    RedirectUrl       = "http://index.hu"
                };

                var transaction = new PaymentTransaction
                {
                    Payee            = settings.Payee,
                    POSTransactionId = "T1",
                    Total            = new decimal(1000),
                    Comment          = "comment"
                };

                var item = new Item
                {
                    Name        = "Test",
                    Description = "Test",
                    ItemTotal   = new decimal(1000),
                    Quantity    = 1,
                    Unit        = "piece",
                    UnitPrice   = new decimal(1000),
                    SKU         = "SKU"
                };

                transaction.Items = new[] { item };
                startPaymentOperation.Transactions = new[] { transaction };

                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Sending StartPayment...");
                var result = barionClient.ExecuteAsync <StartPaymentOperationResult>(startPaymentOperation).Result;
                Console.ResetColor();
                Console.WriteLine("StartPayment result:");
                if (result.IsOperationSuccessful)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                Console.WriteLine($"\tSuccess: {result.IsOperationSuccessful}");
                Console.WriteLine($"\tPaymentId: {result.PaymentId}");
                Console.WriteLine($"\tStatus: {result.Status}");

                Console.ResetColor();
                Console.WriteLine();
                Console.WriteLine("Starting the browser with the barion pay page.");

                System.Diagnostics.Process.Start(result.GatewayUrl);

                Console.WriteLine("Press any key to continue the flow...");
                Console.ReadKey();

                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Sending GetPaymentState...");

                var statusOperation = new GetPaymentStateOperation();
                statusOperation.PaymentId = result.PaymentId;

                var result2 = barionClient.ExecuteAsync <GetPaymentStateOperationResult>(statusOperation).Result;

                Console.ResetColor();
                Console.WriteLine("GetPaymentState result:");
                if (result.IsOperationSuccessful)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                Console.WriteLine($"\tSuccess: {result2.IsOperationSuccessful}");
                Console.WriteLine($"\tPaymentId: {result2.PaymentId}");
                Console.WriteLine($"\tStatus: {result2.Status}");

                var finishReservation = new FinishReservationOperation();

                finishReservation.PaymentId = result2.PaymentId;

                var transactionToFinish = new TransactionToFinish();
                transactionToFinish.TransactionId = result2.Transactions.Single(t => t.POSTransactionId == "T1").TransactionId;
                transactionToFinish.Total         = 500;

                finishReservation.Transactions = new[] { transactionToFinish };

                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Sending FinishReservation...");

                var result3 = barionClient.ExecuteAsync <FinishReservationOperationResult>(finishReservation).Result;

                Console.ResetColor();
                Console.WriteLine("FinishReservation result:");
                if (result.IsOperationSuccessful)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                Console.WriteLine($"\tSuscess: {result3.IsOperationSuccessful}");
                Console.WriteLine($"\tPaymentId: {result3.PaymentId}");
                Console.WriteLine($"\tStatus: {result3.Status}");
            }
        }