Пример #1
0
        public async Task Should_Answer_PreCheckout_Query_With_Ok_And_Shipment_Option()
        {
            Update preCheckoutUpdate = await GetPreCheckoutQueryUpdate();

            PreCheckoutQuery query = preCheckoutUpdate.PreCheckoutQuery;

            await _fixture.BotClient.AnswerPreCheckoutQueryAsync(
                preCheckoutQueryId : query.Id
                );

            int totalAmount = _classFixture.Invoice.TotalAmount +
                              _classFixture.ShippingOption.Prices.Sum(p => p.Amount);

            Assert.Equal(UpdateType.PreCheckoutQuery, preCheckoutUpdate.Type);
            Assert.NotNull(query.Id);
            Assert.Equal(_classFixture.Payload, query.InvoicePayload);
            Assert.Equal(totalAmount, query.TotalAmount);
            Assert.Equal(_classFixture.Invoice.Currency, query.Currency);
            Assert.Contains(query.From.Username, _fixture.UpdateReceiver.AllowedUsernames);
            Assert.NotNull(query.OrderInfo);
            Assert.NotNull(query.OrderInfo.Email);
            Assert.NotNull(query.OrderInfo.Name);
            Assert.NotNull(query.OrderInfo.PhoneNumber);
            Assert.Equal(_classFixture.ShippingOption.Id, query.ShippingOptionId);
        }
Пример #2
0
        public async Task Should_Answer_PreCheckout_Query_With_Ok_For_No_Shipment_Option()
        {
            await _classFixture.SendTestCaseNotificationAsync(
                FactTitles.ShouldAnswerPreCheckoutQueryWithOkForNoShipmentOption,
                "Click on *Pay <amount>* and confirm payment. Transaction should be completed.");

            const string payload = "precheckout-ok-payload";

            LabeledPrice[] productPrices =
            {
                new LabeledPrice {
                    Amount = 150, Label = "One dollar 50 cents"
                },
                new LabeledPrice {
                    Amount = 2029, Label = "20 dollars 29 cents"
                },
            };
            Invoice invoice = new Invoice
            {
                Title          = "PRODUCT_TITLE",
                Currency       = "USD",
                StartParameter = "start_param",
                TotalAmount    = productPrices.Sum(p => p.Amount),
                Description    = "PRODUCT_DESCRIPTION",
            };

            Message message = await _fixture.BotClient.SendInvoiceAsync(_classFixture.TesterPrivateChatId,
                                                                        title : invoice.Title,
                                                                        description : invoice.Description,
                                                                        payload : payload,
                                                                        providerToken : _classFixture.PaymentProviderToken,
                                                                        startParameter : invoice.StartParameter,
                                                                        currency : invoice.Currency,
                                                                        prices : productPrices
                                                                        );

            Update precheckoutUpdate = await GetPreCheckoutQueryUpdate();

            PreCheckoutQuery query = precheckoutUpdate.PreCheckoutQuery;

            bool result = await _fixture.BotClient.AnswerPreCheckoutQueryAsync(
                query.Id,
                true
                );

            Assert.Equal(UpdateType.PreCheckoutQueryUpdate, precheckoutUpdate.Type);
            Assert.NotNull(query.Id);
            Assert.Equal(payload, query.InvoicePayload);
            Assert.Equal(invoice.TotalAmount, query.TotalAmount);
            Assert.Equal(invoice.Currency, query.Currency);
            Assert.Contains(query.From.Username, _fixture.AllowedUserNames);
            Assert.Null(query.OrderInfo);
            Assert.True(result);
        }
Пример #3
0
        public async Task Should_Receive_Successful_Payment_With_A_Tip()
        {
            PaymentsBuilder paymentsBuilder = new PaymentsBuilder()
                                              .WithProduct(_ => _
                                                           .WithTitle(title: "Three tasty donuts")
                                                           .WithDescription(description: "Donuts with special glaze")
                                                           .WithProductPrice(label: "Donut with chocolate glaze", amount: 550)
                                                           .WithProductPrice(label: "Donut with vanilla glaze", amount: 500)
                                                           .WithProductPrice(label: "Donut with glaze", amount: 500)
                                                           .WithPhoto(
                                                               url: "https://cdn.pixabay.com/photo/2017/11/22/00/18/donuts-2969490_960_720.jpg",
                                                               width: 960,
                                                               height: 640
                                                               ))
                                              .WithCurrency("USD")
                                              .WithPayload("<my-payload>")
                                              .WithSuggestedTips(100, 150, 200)
                                              .WithMaxTip(maxTipAmount: 300)
                                              .WithPaymentProviderToken(_classFixture.PaymentProviderToken)
                                              .ToChat(_classFixture.PrivateChat.Id);

            double totalCostWithoutShippingCost = paymentsBuilder
                                                  .GetTotalAmountWithoutShippingCost()
                                                  .CurrencyFormat();

            string instruction = FormatInstructionWithCurrency(
                $"Click on *Pay {totalCostWithoutShippingCost:C}*, select a tip from given options and confirm payment. Transaction should be completed."
                );
            await _fixture.SendTestInstructionsAsync(instruction, chatId : _classFixture.PrivateChat.Id);

            SendInvoiceRequest requestRequest = paymentsBuilder.BuildInvoiceRequest();
            Message            invoiceMessage = await BotClient.MakeRequestAsync(requestRequest);

            Update preCheckoutUpdate = await GetPreCheckoutQueryUpdate();

            PreCheckoutQuery query = preCheckoutUpdate.PreCheckoutQuery;

            await _fixture.BotClient.AnswerPreCheckoutQueryAsync(
                preCheckoutQueryId : query.Id
                );

            Update successfulPaymentUpdate = await GetSuccessfulPaymentUpdate();

            SuccessfulPayment successfulPayment = successfulPaymentUpdate.Message.SuccessfulPayment;
            int totalAmount = paymentsBuilder.GetTotalAmount();

            int[] suggestedTips      = { 100, 150, 200 };
            int[] totalAmountWithTip = suggestedTips.Select(_ => _ + totalAmount).ToArray();

            Assert.Contains(totalAmountWithTip, _ => _ == successfulPayment.TotalAmount);
            Assert.Equal("<my-payload>", successfulPayment.InvoicePayload);
            Assert.Equal(invoiceMessage.Invoice.Currency, successfulPayment.Currency);
        }
Пример #4
0
        public async Task Should_Answer_PreCheckout_Query_With_Error_For_No_Shipment_Option()
        {
            await _fixture.SendTestInstructionsAsync(
                "Click on *Pay <amount>* and confirm payment.",
                chatid : _classFixture.PrivateChat.Id
                );

            const string payload = "pre_checkout-error-payload";

            LabeledPrice[] productPrices =
            {
                new LabeledPrice("PART_OF_PRODUCT_PRICE_1",  150),
                new LabeledPrice("PART_OF_PRODUCT_PRICE_2", 2029),
            };
            Invoice invoice = new Invoice
            {
                Title          = "PRODUCT_TITLE",
                Currency       = "USD",
                StartParameter = "start_param",
                TotalAmount    = productPrices.Sum(p => p.Amount),
                Description    = "PRODUCT_DESCRIPTION",
            };

            await _fixture.BotClient.SendInvoiceAsync(
                chatId : (int)_classFixture.PrivateChat.Id,
                title : invoice.Title,
                description : invoice.Description,
                payload : payload,
                providerToken : _classFixture.PaymentProviderToken,
                startParameter : invoice.StartParameter,
                currency : invoice.Currency,
                prices : productPrices
                );

            Update preCheckoutUpdate = await GetPreCheckoutQueryUpdate();

            PreCheckoutQuery query = preCheckoutUpdate.PreCheckoutQuery;

            await _fixture.BotClient.AnswerPreCheckoutQueryAsync(
                preCheckoutQueryId : query.Id,
                errorMessage : "HUMAN_FRIENDLY_ERROR_MESSAGE"
                );
        }
Пример #5
0
        public async Task Should_Answer_PreCheckout_Query_With_Error_For_No_Shipment_Option()
        {
            PaymentsBuilder paymentsBuilder = new PaymentsBuilder()
                                              .WithProduct(_ => _
                                                           .WithTitle(title: "Reproduction of \"La nascita di Venere\"")
                                                           .WithDescription(description:
                                                                            "Sandro Botticelli`s the Birth of Venus depicts the goddess Venus arriving at the shore" +
                                                                            " after her birth, when she had emerged from the sea fully-grown ")
                                                           .WithProductPrice(label: "Price of the painting", amount: 500_000)
                                                           .WithProductPrice(label: "Wooden frame", amount: 100_000)
                                                           .WithPhoto(
                                                               url: "https://cdn.pixabay.com/photo/2012/10/26/03/16/painting-63186_1280.jpg",
                                                               width: 1280,
                                                               height: 820
                                                               ))
                                              .WithCurrency("USD")
                                              .WithPayload("<my-payload>")
                                              .WithPaymentProviderToken(_classFixture.PaymentProviderToken)
                                              .ToChat(_classFixture.PrivateChat.Id);

            double totalCostWithoutShippingCost = paymentsBuilder
                                                  .GetTotalAmountWithoutShippingCost()
                                                  .CurrencyFormat();

            string instruction = FormatInstructionWithCurrency(
                $"Click on *Pay {totalCostWithoutShippingCost:C}* and confirm payment. You should receive an error. Close payment window after that."
                );
            await _fixture.SendTestInstructionsAsync(instruction, chatId : _classFixture.PrivateChat.Id);

            SendInvoiceRequest requestRequest = paymentsBuilder.BuildInvoiceRequest();

            await BotClient.MakeRequestAsync(requestRequest);

            Update preCheckoutUpdate = await GetPreCheckoutQueryUpdate();

            PreCheckoutQuery query = preCheckoutUpdate.PreCheckoutQuery;

            await _fixture.BotClient.AnswerPreCheckoutQueryAsync(
                preCheckoutQueryId : query.Id,
                errorMessage : "Sorry, we couldn't process the transaction. Please, contact our support."
                );
        }
Пример #6
0
 private static async Task AnswerPreCheckoutQuetry(TelegramFSMBot botClient, PreCheckoutQuery preCheckoutQuery)
 {
     try
     {
         string OopsAnswer = "";
         bool   result     = botClient.PerformPreCheckoutQuery(preCheckoutQuery.InvoicePayload, ref OopsAnswer);
         if (result)
         {
             await botClient.AnswerPreCheckoutQueryAsync(preCheckoutQuery.Id);
         }
         else
         {
             await botClient.AnswerPreCheckoutQueryAsync(preCheckoutQuery.Id, OopsAnswer);
         }
     }
     catch (Exception err)
     {
         BotUtils.LogException(err);
     }
 }
Пример #7
0
        public async Task Should_Receive_Successful_Payment_With_Shipment_Option()
        {
            PaymentsBuilder paymentsBuilder = new PaymentsBuilder()
                                              .WithProduct(_ => _
                                                           .WithTitle(title: "Reproduction of \"La nascita di Venere\"")
                                                           .WithDescription(description:
                                                                            "Sandro Botticelli`s the Birth of Venus depicts the goddess Venus arriving at the shore" +
                                                                            " after her birth, when she had emerged from the sea fully-grown ")
                                                           .WithProductPrice(label: "Price of the painting", amount: 500_000)
                                                           .WithProductPrice(label: "Wooden frame", amount: 100_000)
                                                           .WithPhoto(
                                                               url: "https://cdn.pixabay.com/photo/2012/10/26/03/16/painting-63186_1280.jpg",
                                                               width: 1280,
                                                               height: 820
                                                               ))
                                              .WithShipping(_ => _
                                                            .WithTitle(title: "DHL Express")
                                                            .WithId(id: "dhl-express")
                                                            .WithPrice(label: "Packaging", amount: 400_000)
                                                            .WithPrice(label: "Shipping price", amount: 337_600))
                                              .WithCurrency("USD")
                                              .WithPayload("<my-payload>")
                                              .RequireEmail()
                                              .RequireName()
                                              .RequirePhoneNumber()
                                              .WithFlexible()
                                              .RequireShippingAddress()
                                              .SendEmailToProvider()
                                              .SendPhoneNumberToProvider()
                                              .WithPaymentProviderToken(_classFixture.PaymentProviderToken)
                                              .ToChat(_classFixture.PrivateChat.Id);

            double totalCostWithoutShippingCost = paymentsBuilder
                                                  .GetTotalAmountWithoutShippingCost()
                                                  .CurrencyFormat();

            string instruction = FormatInstructionWithCurrency(
                $"Click on *Pay {totalCostWithoutShippingCost:C}*, send your shipping address and confirm payment. Transaction should be completed."
                );
            await _fixture.SendTestInstructionsAsync(instruction, chatId : _classFixture.PrivateChat.Id);

            SendInvoiceRequest requestRequest = paymentsBuilder.BuildInvoiceRequest();

            Message invoiceMessage = await BotClient.MakeRequestAsync(requestRequest);

            Update shippingUpdate = await GetShippingQueryUpdate();

            AnswerShippingQueryRequest shippingQueryRequest = paymentsBuilder.BuildShippingQueryRequest(
                shippingQueryId: shippingUpdate.ShippingQuery.Id
                );

            await BotClient.MakeRequestAsync(shippingQueryRequest);

            Update preCheckoutUpdate = await GetPreCheckoutQueryUpdate();

            PreCheckoutQuery query = preCheckoutUpdate.PreCheckoutQuery;

            await _fixture.BotClient.AnswerPreCheckoutQueryAsync(
                preCheckoutQueryId : query.Id
                );

            Update successfulPaymentUpdate = await GetSuccessfulPaymentUpdate();

            SuccessfulPayment successfulPayment = successfulPaymentUpdate.Message.SuccessfulPayment;
            int totalAmount = paymentsBuilder.GetTotalAmount();

            Assert.Equal(totalAmount, successfulPayment.TotalAmount);
            Assert.Equal("<my-payload>", successfulPayment.InvoicePayload);
            Assert.Equal(invoiceMessage.Invoice.Currency, successfulPayment.Currency);
            Assert.Equal("dhl-express", successfulPayment.ShippingOptionId);
            Assert.NotNull(successfulPayment.OrderInfo);
            Assert.NotNull(successfulPayment.OrderInfo.Email);
            Assert.NotNull(successfulPayment.OrderInfo.Name);
            Assert.NotNull(successfulPayment.OrderInfo.PhoneNumber);
            Assert.NotNull(successfulPayment.OrderInfo.ShippingAddress);
            Assert.NotNull(successfulPayment.OrderInfo.ShippingAddress.City);
            Assert.NotNull(successfulPayment.OrderInfo.ShippingAddress.CountryCode);
            Assert.NotNull(successfulPayment.OrderInfo.ShippingAddress.PostCode);
            Assert.NotNull(successfulPayment.OrderInfo.ShippingAddress.StreetLine1);
            Assert.NotNull(successfulPayment.OrderInfo.ShippingAddress.StreetLine2);
        }
Пример #8
0
        public async Task Should_Answer_PreCheckout_Query_With_Ok_And_Shipment_Option()
        {
            PaymentsBuilder paymentsBuilder = new PaymentsBuilder()
                                              .WithProduct(_ => _
                                                           .WithTitle(title: "Reproduction of \"La nascita di Venere\"")
                                                           .WithDescription(description:
                                                                            "Sandro Botticelli`s the Birth of Venus depicts the goddess Venus arriving at the shore" +
                                                                            " after her birth, when she had emerged from the sea fully-grown ")
                                                           .WithProductPrice(label: "Price of the painting", amount: 500_000)
                                                           .WithProductPrice(label: "Wooden frame", amount: 100_000)
                                                           .WithPhoto(
                                                               url: "https://cdn.pixabay.com/photo/2012/10/26/03/16/painting-63186_1280.jpg",
                                                               width: 1280,
                                                               height: 820
                                                               ))
                                              .WithShipping(_ => _
                                                            .WithTitle(title: "DHL Express")
                                                            .WithId(id: "dhl-express")
                                                            .WithPrice(label: "Packaging", amount: 400_000)
                                                            .WithPrice(label: "Shipping price", amount: 337_600))
                                              .WithCurrency("USD")
                                              .WithPayload("<my-payload>")
                                              .WithFlexible()
                                              .RequireShippingAddress()
                                              .WithPaymentProviderToken(_classFixture.PaymentProviderToken)
                                              .ToChat(_classFixture.PrivateChat.Id);

            double totalCostWithoutShippingCost = paymentsBuilder
                                                  .GetTotalAmountWithoutShippingCost()
                                                  .CurrencyFormat();

            string instruction = FormatInstructionWithCurrency(
                $"Click on *Pay {totalCostWithoutShippingCost:C}* and send your shipping address. Then click *Pay {totalCostWithoutShippingCost:C}* inside payment dialog. Transaction should be completed."
                );
            await _fixture.SendTestInstructionsAsync(instruction, chatId : _classFixture.PrivateChat.Id);

            SendInvoiceRequest requestRequest = paymentsBuilder.BuildInvoiceRequest();

            await BotClient.MakeRequestAsync(requestRequest);

            Update shippingUpdate = await GetShippingQueryUpdate();

            AnswerShippingQueryRequest shippingQueryRequest = paymentsBuilder.BuildShippingQueryRequest(
                shippingQueryId: shippingUpdate.ShippingQuery.Id
                );

            await BotClient.MakeRequestAsync(shippingQueryRequest);

            Update preCheckoutUpdate = await GetPreCheckoutQueryUpdate();

            PreCheckoutQuery query = preCheckoutUpdate.PreCheckoutQuery;

            await _fixture.BotClient.AnswerPreCheckoutQueryAsync(
                preCheckoutQueryId : query.Id
                );

            PreliminaryInvoice preliminaryInvoice = paymentsBuilder.GetPreliminaryInvoice();
            int totalAmount = paymentsBuilder.GetTotalAmount();

            Assert.Equal(UpdateType.PreCheckoutQuery, preCheckoutUpdate.Type);
            Assert.NotNull(query.Id);
            Assert.Equal("<my-payload>", query.InvoicePayload);
            Assert.Equal(totalAmount, query.TotalAmount);
            Assert.Equal(preliminaryInvoice.Currency, query.Currency);
            Assert.Contains(query.From.Username, _fixture.UpdateReceiver.AllowedUsernames);
            Assert.NotNull(query.OrderInfo);
            Assert.Null(query.OrderInfo.PhoneNumber);
            Assert.Null(query.OrderInfo.Name);
            Assert.Null(query.OrderInfo.Email);
            Assert.Equal("dhl-express", query.ShippingOptionId);
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PreCheckoutQueryEventArgs"/> class
 /// </summary>
 /// <param name="preCheckoutQuery">The pre-checkout query</param>
 public PreCheckoutQueryEventArgs(PreCheckoutQuery preCheckoutQuery)
 {
     PreCheckoutQuery = preCheckoutQuery;
 }
Пример #10
0
        public void getUserSettings(Update e)
        {
            Update upd = e;

            msgType = upd.Type;
            switch (msgType)
            {
            case UpdateType.CallbackQuery:
                chatID = upd.CallbackQuery.Message.Chat.Id;
                break;

            case UpdateType.PreCheckoutQuery:
                chatID = upd.PreCheckoutQuery.From.Id;
                break;

            case UpdateType.ShippingQuery:
                chatID = upd.ShippingQuery.From.Id;
                break;

            default:
                chatID = upd.Id;
                break;
            }
            if (Users.ContainsKey(chatID))
            {
                wayNow   = Users[chatID].wayNow;
                callback = upd.CallbackQuery;
                msg      = upd.Message;
                update   = upd;
                preCheck = upd.PreCheckoutQuery;
                if (msgType == UpdateType.CallbackQuery)
                {
                    Users[chatID].CallbackHistory.Add(upd.CallbackQuery);
                }
                else if (msgType == UpdateType.Message)
                {
                    Users[chatID].MessagesHistory.Add(upd.Message);
                    msgText = upd.Message.Text;
                }
            }
            else
            {
                if (msgType == UpdateType.Message)
                {
                    msg     = e.Message;
                    msgText = msg.Text;
                    Users.Add(chatID, new UserController()
                    {
                        MessagesHistory = new List <Message>()
                        {
                            upd.Message
                        },
                        MessagesForEdit   = new List <ChoisenFile>(),
                        MessagesForDelete = new List <ChoisenFile>(),
                        CallbackHistory   = new List <CallbackQuery>(),
                    });
                }
                else if (msgType == UpdateType.CallbackQuery)
                {
                    callback = upd.CallbackQuery;
                    update   = upd;
                    Users.Add(chatID, new UserController()
                    {
                        MessagesHistory = new List <Message>(),
                        CallbackHistory = new List <CallbackQuery>()
                        {
                            upd.CallbackQuery
                        },
                        MessagesForEdit   = new List <ChoisenFile>(),
                        MessagesForDelete = new List <ChoisenFile>(),
                    });
                }
                else if (msgType == UpdateType.PreCheckoutQuery)
                {
                    shipping = upd.ShippingQuery;
                    update   = upd;
                    Users.Add(chatID, new UserController()
                    {
                        MessagesHistory   = new List <Message>(),
                        CallbackHistory   = new List <CallbackQuery>(),
                        MessagesForEdit   = new List <ChoisenFile>(),
                        MessagesForDelete = new List <ChoisenFile>(),
                    });
                }
                else if (msgType == UpdateType.ShippingQuery)
                {
                    preCheck = upd.PreCheckoutQuery;
                    update   = upd;
                    Users.Add(chatID, new UserController()
                    {
                        MessagesHistory   = new List <Message>(),
                        CallbackHistory   = new List <CallbackQuery>(),
                        MessagesForEdit   = new List <ChoisenFile>(),
                        MessagesForDelete = new List <ChoisenFile>(),
                    });
                }
            }
        }