Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## incoming data
- {
- "id": "123abc"
- "Recipient": {
- "FirstName": "xxx",
- "LastName": "xxx",
- "Address": "12435",
- "City": "tucson",
- "State": "az",
- },
- "LineItems": [
- {
- "ItemName": "test item",
- "Quantity" : 1
- }
- ]
- }
- ## models
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace RainWorx.FrameWorx.MVC.Models.Shipping_Easy
- {
- public class EasyShipOrder
- {
- public string id { get; set; }
- public EasyShipRecipient Recipient { get; set; }
- public List<EasyShipLineItem> LineItems { get; set; }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace RainWorx.FrameWorx.MVC.Models.Shipping_Easy
- {
- [Serializable]
- public class EasyShipRecipient
- {
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Address { get; set; }
- public string City { get; set; }
- public string State { get; set; }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace RainWorx.FrameWorx.MVC.Models.Shipping_Easy
- {
- public class EasyShipLineItem
- {
- public string ItemName { get; set; }
- public int Quantity { get; set; }
- }
- }
- ## controller fun
- [AcceptVerbs(HttpVerbs.Post)]
- public ActionResult ShippingEasy(string Data)
- {
- String baseUrl = "https://app.shippingeasy.com";
- String EasyShipMode = Resources.EasyShip.Mode;
- // from Settings > API Credentials
- String apiKey = "";
- String apiSecret = "";
- // from Settings > Stores
- String storeApiKey = "";
- JavaScriptSerializer serializer = new JavaScriptSerializer();
- Request.InputStream.Position = 0;
- var input = new StreamReader(Request.InputStream).ReadToEnd();
- var order = serializer.Deserialize<Models.Shipping_Easy.EasyShipOrder>(input);
- var recipient = order.Recipient;
- var lineitems = order.LineItems;
- if (EasyShipMode == "test")
- {
- apiKey = Resources.EasyShip.DemoClientApiKey;
- apiSecret = Resources.EasyShip.DemoClientSecret;
- storeApiKey = Resources.EasyShip.DemoClientStoreApiKey;
- }
- else
- {
- apiKey = Resources.EasyShip.ProductionClientApiKey;
- apiSecret = Resources.EasyShip.ProductionClientSecret;
- storeApiKey = Resources.EasyShip.ProductionClientStoreApiKey;
- }
- var client = new Client(apiKey, apiSecret, baseUrl);
- var result = client.CreateOrder(storeApiKey, new Order
- {
- ExternalOrderIdentifier = order.id,
- OrderedAt = DateTime.Now,
- Recipients =
- {
- new Recipient
- {
- FirstName = recipient.FirstName,
- LastName = recipient.LastName,
- Address = recipient.Address,
- City = recipient.City,
- State = recipient.State,
- LineItems = lineitems.Select(x => new ShippingEasy.LineItem{ ItemName = x.ItemName, Quantity = x.Quantity}).ToList()
- }
- },
- });
- ShippingEasy.HttpResponse response = result.HttpResponse;
- return View();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement