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); }
private void SendInvoice(HttpContext context) { String invoiceId = context.Request.Params["invoiceId"]; SendInvoiceRequest sr = new SendInvoiceRequest(); sr.invoiceID = invoiceId; sr.requestEnvelope = new RequestEnvelope(ERROR_LANGUAGE); InvoiceService service; SendInvoiceResponse sir = null; try { service = getService(context); sir = service.SendInvoice(sr); } catch (System.Exception e) { context.Response.Write(e.Message); return; } // Display response values. Dictionary <string, string> keyResponseParams = new Dictionary <string, string>(); keyResponseParams.Add("API status", sir.responseEnvelope.ack.ToString()); keyResponseParams.Add("correlationId", sir.responseEnvelope.correlationId); keyResponseParams.Add("invoiceId", sir.invoiceID); keyResponseParams.Add("invoiceUrl", sir.invoiceURL); displayResponse(context, "SendInvoice", keyResponseParams, service.getLastRequest(), service.getLastResponse(), sir.error, null); }
public async Task Should_Throw_When_Send_Invoice_Invalid_Provider_Data() { 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>") .WithProviderData("INVALID-JSON") .WithPaymentProviderToken(_classFixture.PaymentProviderToken) .ToChat(_classFixture.PrivateChat.Id); SendInvoiceRequest requestRequest = paymentsBuilder.BuildInvoiceRequest(); ApiRequestException exception = await Assert.ThrowsAnyAsync <ApiRequestException>( async() => await BotClient.MakeRequestAsync(requestRequest) ); Assert.Equal(400, exception.ErrorCode); Assert.Equal("Bad Request: DATA_JSON_INVALID", exception.Message); }
public int sendInvoice(string receiverAlias, bool isWithZip) { using (new OperationContextScope(eInvoiceOIBPortClient.InnerChannel)) { var req = new SendInvoiceRequest(); req.REQUEST_HEADER = RequestHeader.getRequestHeaderOib; if (isWithZip) { req.REQUEST_HEADER.COMPRESSED = EI.ActiveOrPasive.Y.ToString(); } else { req.REQUEST_HEADER.COMPRESSED = EI.ActiveOrPasive.N.ToString(); } req.SENDER = new SendInvoiceRequestSENDER(); req.RECEIVER = new SendInvoiceRequestRECEIVER(); req.RECEIVER.alias = receiverAlias; req.INVOICE = invoiceList.ToArray(); invoiceList.Clear(); var res = eInvoiceOIBPortClient.SendInvoice(req); if (res.REQUEST_RETURN != null) { return(res.REQUEST_RETURN.RETURN_CODE); } return(-1); } }
public void SendInvoiceTest() { SendInvoiceRequest sr = new SendInvoiceRequest(); sr.requestEnvelope = new RequestEnvelope(); sr.requestEnvelope.errorLanguage = "en_US"; sr.requestEnvelope.detailLevel = DetailLevelCode.RETURNALL; SendInvoiceResponse sir = null; CreateInvoiceResponse cir = null; try { InvoiceService service = new InvoiceService(); cir = service.CreateInvoice(this.cr); Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack); sr.invoiceID = cir.invoiceID; sir = service.SendInvoice(sr); } catch (System.Exception e) { Console.Write(e.Message); Assert.Fail(e.Message); } Assert.AreEqual(AckCode.SUCCESS, sir.responseEnvelope.ack); Assert.AreEqual(cir.invoiceID, sir.invoiceID); }
/** * AUTO_GENERATED */ public SendInvoiceResponse SendInvoice(SendInvoiceRequest sendInvoiceRequest, string apiUserName) { string response = Call("SendInvoice", sendInvoiceRequest.ToNVPString(""), apiUserName); NVPUtil util = new NVPUtil(); return(SendInvoiceResponse.CreateInstance(util.ParseNVPString(response), "", -1)); }
/** * */ public SendInvoiceResponse SendInvoice(SendInvoiceRequest SendInvoiceRequest, string apiUsername) { string resp = call("SendInvoice", SendInvoiceRequest.toNVPString(""), apiUsername); NVPUtil util = new NVPUtil(); return(new SendInvoiceResponse(util.parseNVPString(resp), "")); }
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); }
/// <summary> /// /// </summary> ///<param name="sendInvoiceRequest"></param> ///<param name="apiUserName">API Username that you want to authenticate this call against. This username and the corresponding 3-token/certificate credentials must be available in Web.Config/App.Config</param> public SendInvoiceResponse SendInvoice(SendInvoiceRequest sendInvoiceRequest, string apiUserName) { IAPICallPreHandler apiCallPreHandler = new PlatformAPICallPreHandler(this.config, sendInvoiceRequest.ToNVPString(string.Empty), ServiceName, "SendInvoice", apiUserName, getAccessToken(), getAccessTokenSecret()); ((PlatformAPICallPreHandler)apiCallPreHandler).SDKName = SDKName; ((PlatformAPICallPreHandler)apiCallPreHandler).SDKVersion = SDKVersion; ((PlatformAPICallPreHandler)apiCallPreHandler).PortName = "Invoice"; NVPUtil util = new NVPUtil(); return(SendInvoiceResponse.CreateInstance(util.ParseNVPString(Call(apiCallPreHandler)), string.Empty, -1)); }
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 void sendInvoiceRequestSerialization() { SendInvoiceRequest sir = new SendInvoiceRequest(); sir.invoiceID = "INV-123456"; sir.requestEnvelope = new RequestEnvelope("en_US"); string expectedNVPString = "requestEnvelope.errorLanguage=en_US&invoiceID=INV-123456&"; Assert.AreEqual(expectedNVPString, sir.ToNVPString("")); sir = new SendInvoiceRequest(new RequestEnvelope("en_US"), "INV-123456"); Assert.AreEqual(expectedNVPString, sir.ToNVPString("")); }
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." ); }
public async Task SendInvoice(SendInvoiceRequest request) { // Get data stored in this service var invoice = await _queryProcessor.ProcessAsync(new GetInvoiceQuery(request.InvoiceId), CancellationToken.None); var invoiceEmployee = await _queryProcessor.ProcessAsync(new GetInvoiceEmployeeQuery(invoice.EmployeeId), CancellationToken.None); var invoiceCustomer = await _queryProcessor.ProcessAsync(new GetInvoiceCustomerQuery(invoice.CustomerId), CancellationToken.None); var amount = invoice.InvoiceItems.Sum(item => item.Price * invoice.Vat); if (invoice.HasTaxReduction) { var reductionAmount = amount * 0.30m; amount = amount * 0.70m; await _skatteverketService.ApplyForReduction(invoiceCustomer.Name, reductionAmount); } _invoicePrinter.PrintInvoice(invoiceEmployee.Name, invoiceCustomer.Address, amount); await _commandBus.PublishAsync(new InvoiceSendCommand(InvoiceId.With(request.InvoiceId)), CancellationToken.None); }
public async Task Should_Send_Invoice_With_Reply_Markup() { InlineKeyboardMarkup replyMarkup = new(new[] { new[] { InlineKeyboardButton.WithPayment("Pay this invoice"), InlineKeyboardButton.WithUrl("Repository", "https://github.com/TelegramBots/Telegram.Bot") }, new[] { InlineKeyboardButton.WithCallbackData("Some other button") } }); 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>") .WithReplyMarkup(replyMarkup) .WithPaymentProviderToken(_classFixture.PaymentProviderToken) .ToChat(_classFixture.PrivateChat.Id); SendInvoiceRequest requestRequest = paymentsBuilder.BuildInvoiceRequest(); await BotClient.MakeRequestAsync(requestRequest); }
// # SendInvoice API Operation // Use the SendInvoice API operation to send an invoice to a payer, and notify the payer of the pending invoice. public SendInvoiceResponse SendInvoiceAPIOperation() { // Create the SendInvoiceResponse object SendInvoiceResponse responseSendInvoice = new SendInvoiceResponse(); try { // # SendInvoiceRequest // Use the SendInvoiceRequest message to send an invoice to a payer, and // notify the payer of the pending invoice. // The code for the language in which errors are returned, which must be // en_US. RequestEnvelope envelopeRequest = new RequestEnvelope(); envelopeRequest.errorLanguage = "en_US"; // SendInvoiceRequest which takes mandatory params: // // * `Request Envelope` - Information common to each API operation, such // as the language in which an error message is returned. // * `Invoice ID` - ID of the invoice to send. SendInvoiceRequest requestSendInvoice = new SendInvoiceRequest(envelopeRequest, "INV2-ZC9R-X6MS-RK8H-4VKJ"); // Create the service wrapper object to make the API call InvoiceService service = new InvoiceService(); // # API call // Invoke the SendInvoice method in service responseSendInvoice = service.SendInvoice(requestSendInvoice); if (responseSendInvoice != null) { // Response envelope acknowledgement string acknowledgement = "SendInvoice API Operation - "; acknowledgement += responseSendInvoice.responseEnvelope.ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responseSendInvoice.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { // ID of the created invoice. logger.Info("Invoice ID : " + responseSendInvoice.invoiceID + "\n"); Console.WriteLine("Invoice ID : " + responseSendInvoice.invoiceID + "\n"); } // # Error Values else { List <ErrorData> errorMessages = responseSendInvoice.error; foreach (ErrorData error in errorMessages) { logger.Debug("API Error Message : " + error.message); Console.WriteLine("API Error Message : " + error.message + "\n"); } } } } // # Exception log catch (System.Exception ex) { // Log the exception message logger.Debug("Error Message : " + ex.Message); Console.WriteLine("Error Message : " + ex.Message); } return(responseSendInvoice); }
public async Task SendInvoice(SendInvoiceRequest request) { await _commandBus.PublishAsync(new InvoiceSendCommand(InvoiceId.With(request.InvoiceId)), CancellationToken.None); }
public SendInvoiceResponse SendInvoice(SendInvoiceRequest SendInvoiceRequest) { return(SendInvoice(SendInvoiceRequest, null)); }
/// <summary> /// /// </summary> ///<param name="sendInvoiceRequest"></param> public SendInvoiceResponse SendInvoice(SendInvoiceRequest sendInvoiceRequest) { return(SendInvoice(sendInvoiceRequest, (string)null)); }
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" ); }
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); }
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); }