public CreateInvoiceResponse CreateInvoice(CreateInvoiceRequest invoiceRequest) { CreateInvoiceResponse rtn = new CreateInvoiceResponse(); _client = new RestClient($"{_settings.Url}{XeroUrl.Invoices}"); _client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("xero-tenant-id", _settings.TenandId); request.AddHeader("Authorization", "Bearer " + _settings.AccessToken); request.AddHeader("Accept", "application/json"); request.AddHeader("Content-Type", "application/json"); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json,application/json", JsonConvert.SerializeObject(invoiceRequest), ParameterType.RequestBody); var response = _client.Execute <XeroCreateInvoiceResponse>(request); rtn.HttpStatusCode = response.StatusCode; if (rtn.HttpStatusCode == System.Net.HttpStatusCode.OK) { rtn.HttpStatusCode = System.Net.HttpStatusCode.Created; } rtn.Status = response.StatusCode == System.Net.HttpStatusCode.Created ? PSC.Common.Enums.ResponseStatus.Success : PSC.Common.Enums.ResponseStatus.Failed; var data = response.Data; rtn.ErrorNumber = data.ErrorNumber; rtn.Type = data?.Type; rtn.Message = data?.Message; rtn.Elements = data?.Elements; rtn.Invoices = data?.Invoices; return(rtn); }
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 CreateInvoiceResponse CreateInvoice(CreateInvoiceRequest createInvoiceRequest, string apiUserName) { string response = Call("CreateInvoice", createInvoiceRequest.ToNVPString(""), apiUserName); NVPUtil util = new NVPUtil(); return(CreateInvoiceResponse.CreateInstance(util.ParseNVPString(response), "", -1)); }
private void CreateInvoice(HttpContext context) { String merchantEmail = context.Request.Params["merchantEmail"]; String currencyCode = context.Request.Params["currencyCode"]; String payerEmail = context.Request.Params["payerEmail"]; String paymentTerms = context.Request.Params["paymentTerms"]; String item_name1 = context.Request.Params["item_name1"]; String item_quantity1 = context.Request.Params["item_quantity1"]; String item_unitPrice1 = context.Request.Params["item_unitPrice1"]; String item_name2 = context.Request.Params["item_name2"]; String item_quantity2 = context.Request.Params["item_quantity2"]; String item_unitPrice2 = context.Request.Params["item_unitPrice2"]; CreateInvoiceRequest cr = new CreateInvoiceRequest(); cr.requestEnvelope = new RequestEnvelope(ERROR_LANGUAGE); cr.invoice = new InvoiceType(); cr.invoice.currencyCode = currencyCode; cr.invoice.merchantEmail = merchantEmail; cr.invoice.payerEmail = payerEmail; cr.invoice.paymentTerms = (PaymentTermsType) Enum.Parse(typeof(PaymentTermsType), paymentTerms); cr.invoice.itemList = new InvoiceItemListType(); cr.invoice.itemList.item = new List <InvoiceItemType>(); cr.invoice.itemList.item.Add( new InvoiceItemType(item_name1, decimal.Parse(item_quantity1), decimal.Parse(item_unitPrice1))); cr.invoice.itemList.item.Add( new InvoiceItemType(item_name2, decimal.Parse(item_quantity2), decimal.Parse(item_unitPrice2))); InvoiceService service = null; CreateInvoiceResponse cir = null; try { service = getService(context); cir = service.CreateInvoice(cr); } 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", cir.responseEnvelope.ack.ToString()); keyResponseParams.Add("correlationId", cir.responseEnvelope.correlationId); keyResponseParams.Add("invoiceId", cir.invoiceID); keyResponseParams.Add("invoiceNumber", cir.invoiceNumber); keyResponseParams.Add("invoiceUrl", cir.invoiceURL); keyResponseParams.Add("totalAmount", cir.totalAmount.ToString()); displayResponse(context, "CreateInvoice", keyResponseParams, service.getLastRequest(), service.getLastResponse(), cir.error, null); }
public void CreateInvoice() { CreateInvoiceSample sample = new CreateInvoiceSample(); CreateInvoiceResponse reponseCreateInvoice = sample.CreateInvoiceAPIOperation(); Assert.IsNotNull(reponseCreateInvoice); Assert.AreEqual(reponseCreateInvoice.responseEnvelope.ack.ToString().Trim().ToUpper(), "SUCCESS"); Assert.IsNotNull(reponseCreateInvoice.invoiceID); }
public void createInvoiceResponseConstruction() { CreateInvoiceResponse cir = CreateInvoiceResponse.CreateInstance(validCreateInvoiceResponse, "", -1); Assert.AreEqual("INV2-PCWG-P78G-7EYV-94QY", cir.invoiceID); Assert.AreEqual("0056", cir.invoiceNumber); Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack); Assert.AreEqual("1917403", cir.responseEnvelope.build); Assert.AreEqual("9b3bb0a44d852", cir.responseEnvelope.correlationId); Assert.AreEqual("2011-05-30T03:31:18.988-07:00", cir.responseEnvelope.timestamp); }
public static CreateInvoiceResponse ToCreateInvoiceResponse(Invoice entity) { int vendorId = 0; var response = new CreateInvoiceResponse() { SuperServiceName = entity.SuperServiceOrder.SuperService.SuperServiceName, DisplayId = entity.SuperServiceOrder.DisplayId }; //TODO: FIX ME BY FIXING THE LINQ QUERY>GetJobsForSearchIndexAsync switch (entity.BillToType.ToUpper()) { case EntityType.ACCOUNT_ENTITY: vendorId = entity.BillToAccountEntityId.GetValueOrDefault(); response.BillToType = EntityType.ACCOUNT_ENTITY; response.BillToId = entity.BillToAccountEntityId; response.BillToName = entity.BillToAccountEntity?.Name; response.VendorAccountingId = entity.BillToAccountEntity?.AccountingId; response.VendorShortAddress = entity.BillToAccountEntity.ShortAddress; break; case EntityType.VENDOR: vendorId = entity.BillToVendorId.GetValueOrDefault(); response.BillToType = EntityType.VENDOR; response.BillToId = entity.BillToVendorId; response.BillToName = entity.BillToVendor?.Name; response.VendorAccountingId = entity.BillToVendor?.Accounting_SI_Code; response.VendorShortAddress = entity.BillToVendor?.ShortAddress; break; case EntityType.TRANSFEREE: vendorId = entity.BillToTransfereeId.GetValueOrDefault(); response.BillToType = EntityType.TRANSFEREE; response.BillToId = entity.BillToTransfereeId; response.BillToName = string.Concat(entity.BillToTransferee?.FirstName, " ", entity.BillToTransferee?.LastName); response.VendorAccountingId = entity.BillToTransferee?.AccountingId.ToString(); response.VendorShortAddress = ToShortAddress(entity.SuperServiceOrder.Job?.OriginAddress); break; } response.ServiceOrderId = entity.SuperServiceOrder.Job.ServiceOrder .FirstOrDefault(s => s.SuperServiceOrderId == entity.SuperServiceOrderId && ( s.ServiceId == ServiceId.AIR_JC || s.ServiceId == ServiceId.OCEAN_JC || s.ServiceId == ServiceId.ROAD_JC || s.ServiceId == ServiceId.STORAGE_JC)).Id; return(response); }
/// <summary> /// /// </summary> ///<param name="createInvoiceRequest"></param> ///<param name="credential">An explicit ICredential object that you want to authenticate this call against</param> public CreateInvoiceResponse CreateInvoice(CreateInvoiceRequest createInvoiceRequest, ICredential credential) { IAPICallPreHandler apiCallPreHandler = new PlatformAPICallPreHandler(this.config, createInvoiceRequest.ToNVPString(string.Empty), ServiceName, "CreateInvoice", credential); ((PlatformAPICallPreHandler)apiCallPreHandler).SDKName = SDKName; ((PlatformAPICallPreHandler)apiCallPreHandler).SDKVersion = SDKVersion; ((PlatformAPICallPreHandler)apiCallPreHandler).PortName = "Invoice"; NVPUtil util = new NVPUtil(); return(CreateInvoiceResponse.CreateInstance(util.ParseNVPString(Call(apiCallPreHandler)), string.Empty, -1)); }
public void CreateInvoiceTest() { CreateInvoiceResponse cir = null; try { InvoiceService service = new InvoiceService(); cir = service.CreateInvoice(this.cr); Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack); Assert.IsNotNull(cir.invoiceID); Assert.IsNotNull(cir.invoiceNumber); } catch (System.Exception e) { Console.Write(e.Message); Assert.Fail(e.Message); } }
//Create Draft Invoice for Customer public CreateInvoiceResponse CreateInvoice(string customerId) { HttpContent content = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("customer", customerId) }); content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); HttpResponseMessage response = (_client.PostAsync("https://api.stripe.com/v1/invoices", content)) .GetAwaiter().GetResult(); var createInvoiceResponse = new CreateInvoiceResponse(); if (response.IsSuccessStatusCode) { createInvoiceResponse = JsonConvert.DeserializeObject <CreateInvoiceResponse>(response.Content.ReadAsStringAsync().Result); } return(createInvoiceResponse); }
public void CreateInvoiceForThirdPartyTest() { CreateInvoiceResponse cir = null; try { InvoiceService service = new InvoiceService(); service.setAccessToken("MflQEeAERGJPxdFYxkH29I53S5Ahcsimnv7fwa14n8x985-ugCgTSA"); service.setAccessTokenSecret("kQE-WPNw2n6soaxftD-1I8Nm0Ss"); this.cr.invoice.merchantEmail = "*****@*****.**"; cir = service.CreateInvoice(this.cr); Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack); Assert.IsNotNull(cir.invoiceID); Assert.IsNotNull(cir.invoiceNumber); } catch (System.Exception e) { Console.Write(e.Message); Assert.Fail(e.Message); } }
// # CreateInvoice API Operation // Use the CreateInvoice API operation to create a new invoice. The call includes merchant, payer, and API caller information, in addition to invoice detail. The response to the call contains an invoice ID and URL. public CreateInvoiceResponse CreateInvoiceAPIOperation() { // Create the CreateInvoiceResponse object CreateInvoiceResponse responseCreateInvoice = new CreateInvoiceResponse(); try { // # CreateInvoiceRequest // Use the CreateInvoiceRequest message to create a new invoice. The // merchant issuing the invoice, and the partner, if any, making the // call, must have a PayPal account in good standing. // The code for the language in which errors are returned, which must be // en_US. RequestEnvelope envelopeRequest = new RequestEnvelope(); envelopeRequest.errorLanguage = "en_US"; List <InvoiceItemType> invoiceItemList = new List <InvoiceItemType>(); // InvoiceItemType which takes mandatory params: // // * `Item Name` - SKU or name of the item. // * `Quantity` - Item count. // * `Amount` - Price of the item, in the currency specified by the // invoice. InvoiceItemType invoiceItem = new InvoiceItemType("Item", Convert.ToDecimal("2"), Convert.ToDecimal("4.00")); invoiceItemList.Add(invoiceItem); // Invoice item. InvoiceItemListType itemList = new InvoiceItemListType(invoiceItemList); // InvoiceType which takes mandatory params: // // * `Merchant Email` - Merchant email address. // * `Personal Email` - Payer email address. // * `InvoiceItemList` - List of items included in this invoice. // * `CurrencyCode` - Currency used for all invoice item amounts and // totals. // * `PaymentTerms` - Terms by which the invoice payment is due. It is // one of the following values: // * DueOnReceipt - Payment is due when the payer receives the invoice. // * DueOnDateSpecified - Payment is due on the date specified in the // invoice. // * Net10 - Payment is due 10 days from the invoice date. // * Net15 - Payment is due 15 days from the invoice date. // * Net30 - Payment is due 30 days from the invoice date. // * Net45 - Payment is due 45 days from the invoice date. InvoiceType invoice = new InvoiceType("*****@*****.**", "*****@*****.**", itemList, "USD", PaymentTermsType.DUEONRECEIPT); // CreateInvoiceRequest which takes mandatory params: // // * `Request Envelope` - Information common to each API operation, such // as the language in which an error message is returned. // * `Invoice` - Merchant, payer, and invoice information. CreateInvoiceRequest createInvoiceRequest = new CreateInvoiceRequest(envelopeRequest, invoice); // Create the service wrapper object to make the API call InvoiceService service = new InvoiceService(); // # API call // Invoke the CreateInvoice method in service wrapper object responseCreateInvoice = service.CreateInvoice(createInvoiceRequest); if (responseCreateInvoice != null) { // Response envelope acknowledgement string acknowledgement = "CreateInvoice API Operation - "; acknowledgement += responseCreateInvoice.responseEnvelope.ack.ToString(); logger.Info(acknowledgement + "\n"); Console.WriteLine(acknowledgement + "\n"); // # Success values if (responseCreateInvoice.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS")) { // ID of the created invoice. logger.Info("Invoice ID : " + responseCreateInvoice.invoiceID + "\n"); Console.WriteLine("Invoice ID : " + responseCreateInvoice.invoiceID + "\n"); } // # Error Values else { List <ErrorData> errorMessages = responseCreateInvoice.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(responseCreateInvoice); }