Beispiel #1
0
        protected virtual void PlaceOrderButton_Click(object sender, EventArgs e)
        {
            if (ValidateInput())
            {
                CheckoutState    checkoutState = GetCheckoutState();
                Guid             cartId        = this.GetShoppingCartId();
                IPaymentResponse response      = OrderHelper.PlaceOrder(this.OrdersManager, this.CatalogManager, this.UserManager, this.RoleManager, this.UserProfileManager, checkoutState, cartId);

                if (!response.IsOffsitePayment)
                {
                    if (!response.IsSuccess) // in case of unsuccessful direct payment
                    {
                        // Order was declined
                        this.PaymentProblemPanel.Visible = true;
                        this.MessageControl.ShowNegativeMessage(response.GatewayResponse);
                        return;
                    }
                    CleanUp();
                }
                //leave the cart for offsite payments ones a notification came it will become paid.

                PageNode pageNode = App.WorkWith().Page(this.ReceiptPageId).Get();

                string fullUrl = this.GetPageNodeUrlForCurrentPageCulture(pageNode);

                fullUrl += "/order/" + cartId;
                this.Page.Response.Redirect(fullUrl);
            }
        }
Beispiel #2
0
        public void GetResponse_ResponseDataIsNull_ReturnsNull()
        {
            Kassa kassa = new Kassa(_configuration);

            IPaymentResponse response = kassa.GetResponse((NameValueCollection)null);

            Assert.IsNull(response);
        }
Beispiel #3
0
        internal IPaymentResponse GetResponse(IPaymentPostData response)
        {
            PaymentPostDataValidator.Validate(Configuration, response);

            IPaymentResponse result = PaymentResponse.Create(response.Data);

            PaymentResponseValidator.Validate(Configuration, result);

            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// Submits a sale request to the payment processor
        /// </summary>
        /// <param name="data">An instance of type <see cref="IPaymentRequest" /></param>
        /// <returns>An instance of type <see cref="IPaymentResponse" /></returns>
        public IPaymentResponse Sale(IPaymentRequest data)
        {
            BitPayServerResponse bitpayServerResponce = CreateInvoiceRequest(data);

            NameValueCollection createPaymentPostValues = new NameValueCollection();

            createPaymentPostValues.Add("id", bitpayServerResponce.Id);

            IPaymentResponse response = CreatePaymentResponse(data.OrderNumber, createPaymentPostValues);

            return(response);
        }
Beispiel #5
0
        public void GetResponse_ResponseValid_ReturnsResult()
        {
            Kassa           kassa    = new Kassa(_configuration);
            PaymentPostData postData = new PaymentPostData()
            {
                Data = $"merchantId={_configuration.MerchantId}|amount=4200",
                Seal = "0e14ed66182e64d1eed8623d946032648dafa6043f87fc7e4fb8eb2e40469781",
            };

            IPaymentResponse response = kassa.GetResponse(postData);

            Assert.IsNotNull(response);
            Assert.AreEqual(42.0m, response.Amount);
        }
Beispiel #6
0
        public void GetResponse_ResponseDataIsValid_ReturnsResponse()
        {
            Kassa kassa = new Kassa(_configuration);

            NameValueCollection responseData = new NameValueCollection()
            {
                { "Data", $"merchantId={_configuration.MerchantId}|amount=4200" },
                { "InterfaceVersion", "HP_1.0" },
                { "Seal", "0e14ed66182e64d1eed8623d946032648dafa6043f87fc7e4fb8eb2e40469781" }
            };

            IPaymentResponse response = kassa.GetResponse(responseData);

            Assert.IsNotNull(response);
            Assert.AreEqual(42m, response.Amount);
        }
Beispiel #7
0
        public void GetResponse_ResponseDataIsValid_ReturnsResponse()
        {
            Kassa kassa = new Kassa(_configuration);

            FormCollection responseData = new FormCollection(new Dictionary <string, StringValues>
            {
                { "Data", new StringValues($"merchantId={_configuration.MerchantId}|amount=4200") },
                { "InterfaceVersion", new StringValues("HP_1.0") },
                { "Seal", new StringValues("0e14ed66182e64d1eed8623d946032648dafa6043f87fc7e4fb8eb2e40469781") }
            });

            IPaymentResponse response = kassa.GetResponse(responseData);

            Assert.IsNotNull(response);
            Assert.AreEqual(42m, response.Amount);
        }
        public static void Validate(IKassaConfiguration configuration, IPaymentResponse response)
        {
            PaymentResponseValidator validator = new PaymentResponseValidator(configuration, response);

            validator.Validate();
        }
 private PaymentResponseValidator(IKassaConfiguration configuration, IPaymentResponse response)
 {
     _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
     _response      = response ?? throw new ArgumentNullException(nameof(response));
 }
Beispiel #10
0
        public IActionResult Post([FromBody] PaymentRequest paymentDetails, [FromServices] IBankRequest bank_request, [FromServices] IApiClient client, [FromServices] IPaymentResponse res, [FromServices] IHttpContextAccessor context)
        {
            this.logger.LogDebug("POST request : {PaymentRequest}", paymentDetails);

            /*
             * Step 1 - Make a POST request to the acquring Bank to valid the payment
             */
            string bank_response_json = null;

            bank_request.request = paymentDetails;
            try
            {
                bank_response_json = client.Post("https://httpbin.org/post", JsonConvert.SerializeObject(bank_request), "application/json");
            }
            catch (Exception ex)
            {
                this.logger.LogError("Could not send the post.Details : {Exception}", ex);
            }


            /*
             * Step 2 - Deserialize the response from bank
             */
            var bank_response      = JsonConvert.DeserializeObject <BankResponse>(bank_response_json);
            var bank_response_data = JsonConvert.DeserializeObject <BankResponseData>(bank_response.Data);

            this.logger.LogDebug("bank_response : {BankResponse}", bank_response);

            this.logger.LogDebug("bank_response_data : {BankResponseData}", bank_response_data);


            /*
             * Step 3 - Create the response
             */
            res.Id            = Guid.NewGuid().ToString();
            res.cardNo        = bank_response_data.Request.CardNo;
            res.expiry        = bank_response_data.Request.Expiry;
            res.amount        = bank_response_data.Request.Amount;
            res.currency      = bank_response_data.Request.Currency;
            res.cvv           = bank_response_data.Request.Cvv;
            res.response_code = 201;

            /*
             * Add to payments collections
             */
            _payments.Add(res);

            /*
             * Send created response
             */
            string baseurl     = $"{context.HttpContext.Request.Scheme}://{context.HttpContext.Request.Host.ToUriComponent()}";
            string locationUri = baseurl + '/' + "api/v1/Payment" + '/' + res.Id;

            return(Created(locationUri, res));
        }
Beispiel #11
0
        internal static IPaymentResponse PlaceOrder(OrdersManager ordersManager, CatalogManager catalogManager, UserManager userManager, RoleManager roleManager, UserProfileManager userProfileManager, CheckoutState checkoutState, Guid cartOrderId)
        {
            CartOrder cartOrder = ordersManager.GetCartOrder(cartOrderId);

            cartOrder.Addresses.Clear();
            cartOrder.Payments.Clear();

            //set the default currency of the order
            string defaultCurrency = Config.Get <EcommerceConfig>().DefaultCurrency;

            cartOrder.Currency = defaultCurrency;

            // set the shipping address
            CartAddress shippingAddress = CartHelper.GetShippingAddressFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Addresses.Add(shippingAddress);

            // set the billing address
            CartAddress billingAddress = CartHelper.GetBillingAddressFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Addresses.Add(billingAddress);

            //Get the first payment method in the shop

            // set the payment
            CartPayment payment = CartHelper.GetCartPaymentFromCheckoutState(ordersManager, checkoutState);

            cartOrder.Payments.Add(payment);

            ordersManager.SaveChanges();


            // Get current customer or create new one

            Customer customer = UserProfileHelper.GetCustomerInfoOrCreateOneIfDoesntExsist(userProfileManager, ordersManager, checkoutState);

            // Save the customer address
            CustomerAddressHelper.SaveCustomerAddressOfCurrentUser(checkoutState, customer);

            //Use the API to checkout
            IPaymentResponse paymentResponse = ordersManager.Checkout(cartOrderId, checkoutState, customer);

            // record the "success" state of the checkout
            checkoutState.IsPaymentSuccessful = paymentResponse.IsSuccess;

            Order order = ordersManager.GetOrder(cartOrderId);

            //Increment the order
            IncrementOrderNumber(ordersManager, order);

            // add the order to customer
            customer.Orders.Add(order);

            // Update the order
            order.Customer = customer;

            ordersManager.SaveChanges();

            if (order.OrderStatus == OrderStatus.Paid)
            {
                UserProfileHelper.AssignCustomerToRoles(userManager, roleManager, catalogManager, SecurityManager.GetCurrentUserId(), order);
                EmailHelper.SendOrderPlacedEmailToClientAndMerchant(cartOrder, checkoutState, order.OrderNumber);
            }

            return(paymentResponse);
        }