Beispiel #1
0
        public async Task Should_Answer_Shipping_Query_With_Ok()
        {
            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(currency: "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.");
            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);

            Assert.Equal(UpdateType.ShippingQuery, shippingUpdate.Type);
            Assert.Equal("<my-payload>", shippingUpdate.ShippingQuery.InvoicePayload);
            Assert.NotNull(shippingUpdate.ShippingQuery.ShippingAddress.CountryCode);
            Assert.NotNull(shippingUpdate.ShippingQuery.ShippingAddress.City);
            Assert.NotNull(shippingUpdate.ShippingQuery.ShippingAddress.State);
            Assert.NotNull(shippingUpdate.ShippingQuery.ShippingAddress.StreetLine1);
            Assert.NotNull(shippingUpdate.ShippingQuery.ShippingAddress.PostCode);
        }
Beispiel #2
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);
        }
Beispiel #3
0
        public async Task Should_Throw_When_Answer_Shipping_Query_With_Duplicate_Shipping_Id()
        {
            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))
                                              .WithShipping(_ => _
                                                            .WithTitle(title: "DHL Express (Duplicate)")
                                                            .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}*, send your shipping address. You should receive an error."
                );
            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
                );

            ApiRequestException exception = await Assert.ThrowsAnyAsync <ApiRequestException>(
                async() => await BotClient.MakeRequestAsync(shippingQueryRequest)
                );

            Assert.Equal(400, exception.ErrorCode);
            Assert.Equal("Bad Request: SHIPPING_ID_DUPLICATE", exception.Message);

            await _fixture.BotClient.AnswerShippingQueryAsync(
                shippingQueryId : shippingUpdate.ShippingQuery.Id,
                errorMessage : "✅ Test Passed"
                );
        }
Beispiel #4
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);
        }