public async Task <string> MakeOrder(PayUOrder order)
        {
            var token = await GetAccessToken();

            var jsonOrder = JsonConvert.SerializeObject(order, Formatting.Indented,
                                                        new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            var baseAddress = new Uri("https://secure.snd.payu.com/api/v2_1/orders");

            using (var httpClient = new HttpClient(new WebRequestHandler()
            {
                AllowAutoRedirect = false
            })
            {
                BaseAddress = baseAddress
            })
            {
                httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                using (var content = new StringContent(jsonOrder, System.Text.Encoding.Default, "application/json"))
                {
                    using (var response = await httpClient.PostAsync(baseAddress, content))
                    {
                        if (response.StatusCode == HttpStatusCode.Redirect ||
                            response.StatusCode == HttpStatusCode.MovedPermanently)
                        {
                            return(response.Headers.Location.AbsoluteUri);
                        }
                    }
                }
            }
            return(null);
        }
 public CommonPaymentRequest()
 {
     Order    = new PayUOrder();
     Config   = new PayUConfig();
     Customer = new PayUCustomer();
     Delivery = new PayUDelivery();
 }
Пример #3
0
 public ApiPaymentRequest()
 {
     Order      = new PayUOrder();
     Config     = new PayUConfig();
     CreditCard = new PayUCreditCard();
     Customer   = new PayUCustomer();
     Delivery   = new PayUDelivery();
 }
Пример #4
0
        public async Task <IActionResult> PayForOrder([FromBody] PayUOrder payment,
                                                      [FromHeader(Name = "operationid")] string operationId)
        {
            if (!Guid.TryParse(operationId, out Guid operation))
            {
                return(BadRequest("Operation id should be Guid type."));
            }

            await busControl.Publish <IPaymentProcessBegin>(
                new { PaymentId = Guid.NewGuid(), OrderId = payment.ExtOrderId }, context =>
            {
                context.Headers.Set(LogConstansts.Common.OperationId, operation.ToString());
                context.Headers.Set(LogConstansts.QueueMessageHeaderNames.Publisher, Request.Path.Value);
            });

            var paymentServiceUrl = await payUClient.GetPayUOrderUrl(payment);

            return(Ok(paymentServiceUrl));
        }
        private PayUOrder PreparePayUOrder(OrderDto order)
        {
            var product      = productService.GetProductById(Guid.Parse(order.ProductId));
            var payUProducts = new List <PayUProduct>
            {
                new PayUProduct
                {
                    Name      = product.Name,
                    UnitPrice = product.Price,
                    Quantity  = order.Quantity.ToString()
                }
            };
            var totalAmount = payUProducts.Sum(x => (int.Parse(x.UnitPrice) * int.Parse(x.Quantity)))
                              .ToString(CultureInfo.InvariantCulture);

            var payUOrder = new PayUOrder
            {
                ContinueUrl   = "http://*****:*****@wp.pl",
                    FirstName = "Daniel",
                    LastName  = "Dziubecki",
                    Phone     = "12332111"
                }
            };

            var test = JsonConvert.SerializeObject(payUOrder);

            return(payUOrder);
        }
        public static async Task <Result <PayUOrderRequestResult> > OrderPayU(Order order, string notifyUrl, string customerIp = "127.0.0.1")
        {
            var result = new Result <PayUOrderRequestResult>();

            result.status = false;
            result.info   = "";
            var body = "grant_type=client_credentials&client_id=" + client_id + "&client_secret=" + client_secret;
            //Needed to setup the body of the request
            StringContent authoriseData = new StringContent(body, System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
            //data.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
            var handler = new HttpClientHandler()
            {
                AllowAutoRedirect = false
            };
            HttpClient client   = new HttpClient(handler);
            var        response = await client.PostAsync(urlAuthorize, authoriseData);

            var statusCode = response.StatusCode;

            if (statusCode == HttpStatusCode.OK)
            {
                PayUAuthorizeModel authorizeRezult = await response.Content.ReadAsAsync <PayUAuthorizeModel>();

                //
                var orderP = new PayUOrder()
                {
                    notifyUrl     = notifyUrl,
                    continueUrl   = "http://*****:*****@gmail.com", firstName = "FirstName", lastName = "lastName", language = "pl", phone = "123123123"
                };



                //Converting the object to a json string. NOTE: Make sure the object doesn't contain circular references.
                string        json      = JsonConvert.SerializeObject(orderP);
                StringContent orderData = new StringContent(json, System.Text.Encoding.UTF8, "application/json"); //"
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authorizeRezult.access_token);
                var orderResult = await client.PostAsync(urlOrder, orderData);

                var statusCodeOrder = orderResult.StatusCode;
                if (HttpStatusCode.Found == statusCodeOrder)
                {
                    var rV = await orderResult.Content.ReadAsAsync <PayUOrderRequestResult>();

                    result.status = true;
                    result.info   = rV.redirectUri;
                    result.value  = rV;
                }
                else
                {
                    result.info = await orderResult.Content.ReadAsStringAsync();
                }
            }
            else
            {
                result.info = await response.Content.ReadAsStringAsync();
            }
            //It would be better to make sure this request actually made it through



            //close out the client
            client.Dispose();

            return(result);
        }
        public async Task <string> MakeOrder(PayUOrder order)
        {
            var orderUrl = await payUClient.MakeOrder(order);

            return(orderUrl);
        }