public async Task Should_Send_Invoice() { PaymentsBuilder paymentsBuilder = new PaymentsBuilder() .WithProduct(_ => _ .WithTitle(title: "Lunar crater \"Copernicus\"") .WithDescription(description: "It was named after the astronomer Nicolaus Copernicus. It may have been created by debris" + " from the breakup of the parent body of asteroid 495 Eulalia 800 million years ago.") .WithProductPrice(label: "Price of land inside of the crater", amount: 400_000) .WithProductPrice(label: "One-time fee", amount: 10_000) .WithPhoto( url: "https://upload.wikimedia.org/wikipedia/commons/d/d4/Copernicus_%28LRO%29_2.png", width: 1264, height: 1264 )) .WithCurrency(currency: "USD") .WithStartParameter(startParameter: "crater-copernicus") .WithPayload(payload: "<my-payload>") .WithPaymentProviderToken(paymentsProviderToken: _classFixture.PaymentProviderToken) .ToChat(chatId: _classFixture.PrivateChat.Id); PreliminaryInvoice preliminaryInvoice = paymentsBuilder.GetPreliminaryInvoice(); SendInvoiceRequest requestRequest = paymentsBuilder.BuildInvoiceRequest(); Message message = await BotClient.MakeRequestAsync(requestRequest); Invoice invoice = message.Invoice; Assert.Equal(MessageType.Invoice, message.Type); Assert.Equal(preliminaryInvoice.Title, invoice.Title); Assert.Equal(preliminaryInvoice.Currency, invoice.Currency); Assert.Equal(preliminaryInvoice.TotalAmount, invoice.TotalAmount); Assert.Equal(preliminaryInvoice.Description, invoice.Description); Assert.Equal(preliminaryInvoice.StartParameter, invoice.StartParameter); }
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); }