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); }
public async Task Should_Receive_Successful_Payment_With_Shipment_Option() { Update successfulPaymentUpdate = await GetSuccessfulPaymentUpdate(); SuccessfulPayment successfulPayment = successfulPaymentUpdate.Message.SuccessfulPayment; int totalAmount = _classFixture.Invoice.TotalAmount + _classFixture.ShippingOption.Prices.Sum(p => p.Amount); Assert.Equal(totalAmount, successfulPayment.TotalAmount); Assert.Equal(_classFixture.Payload, successfulPayment.InvoicePayload); Assert.Equal(_classFixture.Invoice.Currency, successfulPayment.Currency); Assert.Equal(_classFixture.ShippingOption.Id, successfulPayment.ShippingOptionId); }
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); }