Example #1
0
        public async Task <PendingPayment> HandlePaymentCallback(PaymentConfirmDto dto)
        {
            SignedPaymentInfo signed = new SignedPaymentInfo(dto.data, dto.signature);
            string            id     = LiqPay.GetOrderId(signed);

            if (!PendingPayments.ContainsKey(id))
            {
                throw new NotFoundException("payment with such id");
            }

            if (!LiqPay.IsSucceed(signed))
            {
                throw new ValidationException();
            }

            PendingPayment payment = PendingPayments[id];

            if (!LiqPay.IsPaymentAuthorized(signed, payment.PaymentInfo))
            {
                throw new UnauthorizedAccessException();
            }

            foreach (OrderEntity order in payment.PaidOrders)
            {
                await OrderRepo.MarkPaid(order.Id);
            }

            return(payment);
        }
        private async void InitPreload()
        {
            string preloadHTML = "<html>" +
                                 "<style>" +
                                 "#loader {" +
                                 "border: 1.5vh solid #67A93D;" +
                                 "border-left : 1.5vh solid #FFFFFF;" +
                                 "border-radius: 50%;" +
                                 "margin-top : 45vh;" +
                                 "width: 10vh;" +
                                 "height: 10vh;" +
                                 "animation: spin 2s linear infinite;" +
                                 "}" +
                                 "@keyframes spin {" +
                                 "0% { transform: rotate(0deg); }" +
                                 "100% { transform: rotate(360deg); }" +
                                 "}" +
                                 "</style>" +
                                 "<body><center><div id='loader'></div></center></body>" +
                                 "</html>";

            LoadData(preloadHTML, "text/html", "UTF-8");

            RestClient  client  = new RestClient(Constants.BASE_SERVER_ADDRESS + GET_PAYMENT_FORM_ENDPOINT);
            RestRequest request = new RestRequest(Method.GET);

            request.AddParameter(LOGIN_PARAMETER_NAME, BotService.CredentialsService.Credentials.Login);

            IRestResponse response = await client.ExecuteAsync(request);

            SignedPaymentInfo paymentInfo = JsonConvert.DeserializeObject <SignedPaymentInfo>(response.Content);

            LoadForm(paymentInfo);
        }
Example #3
0
        public bool IsSucceed(SignedPaymentInfo payment)
        {
            byte[]           dataBytes = Convert.FromBase64String(payment.Data);
            string           data      = Encoding.UTF8.GetString(dataBytes);
            PaymentStatusDto result    = JsonConvert.DeserializeObject <PaymentStatusDto>(data);

            return(result.Status == SUCCESS_STATUS_VALUE);
        }
Example #4
0
        public string GetOrderId(SignedPaymentInfo payment)
        {
            byte[] jsonBytes = Convert.FromBase64String(payment.Data);
            string json      = Encoding.UTF8.GetString(jsonBytes);

            LiqPayPaymentInfo liqPayPayment = JsonConvert.DeserializeObject <LiqPayPaymentInfo>(json);

            return(liqPayPayment.OrderId);
        }
Example #5
0
        public bool IsPaymentAuthorized(SignedPaymentInfo payment, SignedPaymentInfo stored)
        {
            string calculatedSignature = GetSignature(payment.Data);
            string storedSignature     = GetSignature(payment.Data);

            string            data = Encoding.UTF8.GetString(Convert.FromBase64String(stored.Data));
            LiqPayPaymentInfo info = JsonConvert.DeserializeObject <LiqPayPaymentInfo>(data);

            //DateTime exp = DateTime.Parse(info.Expired);

            return(calculatedSignature == payment.Signature && calculatedSignature == storedSignature); // && exp > DateTime.UtcNow;
        }
        private void LoadForm(SignedPaymentInfo paymentInfo)
        {
            string html = "<html>" +
                          "<style> #form { margin-top : 40vh; } </style>" +
                          "<body><center>" +
                          "<form id='form' method='POST' action='https://www.liqpay.ua/api/3/checkout' accept-charset='utf-8'>" +
                          $"<input type='hidden' id='data' name='data' value='{paymentInfo.Data}'/>" +
                          $"<input type='hidden' id='sign' name='signature' value='{paymentInfo.Signature}'/>" +
                          "<input type='image' src='http://static.liqpay.ua/buttons/p1ru.radius.png'/>" +
                          "</form>" +
                          "</center></body>" +
                          "</html>";

            LoadData(html, "text/html", "UTF-8");
        }
Example #7
0
        public async Task <SignedPaymentInfo> GetPaymentForm(string login)
        {
            IEnumerable <OrderEntity> oldUnpayedOrders = await GetOldUnpayedOrders(login);

            if (oldUnpayedOrders.Count() == 0)
            {
                throw new NotFoundException("orders to pay for");
            }

            int    tax = GetTaxAmount(oldUnpayedOrders);
            string id  = Guid.NewGuid().ToString();

            PaymentPrepareModel paymentPrepare = new PaymentPrepareModel(id, tax, CALLBACK_URL);
            SignedPaymentInfo   signedPayment  = LiqPay.CreatePayment(paymentPrepare);
            PendingPayment      pending        = new PendingPayment(id, signedPayment, oldUnpayedOrders);

            PendingPayments.Add(id, pending);
            return(signedPayment);
        }
Example #8
0
 public PendingPayment(string id, SignedPaymentInfo paymentInfo, IEnumerable <OrderEntity> paidOrders)
 {
     Id          = id;
     PaymentInfo = paymentInfo;
     PaidOrders  = paidOrders;
 }