Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [TestMethod()]
- public void TestMultiInit()
- {
- var Client2 = new cpEasyPost("123");
- var Client = new cpEasyPost("123456qq785412");
- var Shipment = Client.CreateShipment(
- new EasyPost.Address
- {
- street1 = "417 MONTGOMERY ST",
- street2 = "FLOOR 5",
- city = "SAN FRANCISCO",
- state = "CA",
- zip = "94104",
- country = "US",
- company = "EasyPost"
- },
- new EasyPost.Address
- {
- street1 = "417 MONTGOMERY ST",
- street2 = "FLOOR 5",
- city = "SAN FRANCISCO",
- state = "CA",
- zip = "94104",
- country = "US",
- company = "EasyPost"
- },
- new EasyPost.Parcel
- {
- length = 20.2,
- width = 10.9,
- height = 5,
- weight = 65.9
- });
- var Shipment2 = Client2.CreateShipment(
- new EasyPost.Address
- {
- street1 = "417 MONTGOMERY ST",
- street2 = "FLOOR 5",
- city = "SAN FRANCISCO",
- state = "CA",
- zip = "94104",
- country = "US",
- company = "EasyPost"
- },
- new EasyPost.Address
- {
- street1 = "417 MONTGOMERY ST",
- street2 = "FLOOR 5",
- city = "SAN FRANCISCO",
- state = "CA",
- zip = "94104",
- country = "US",
- company = "EasyPost"
- },
- new EasyPost.Parcel
- {
- length = 20.2,
- width = 10.9,
- height = 5,
- weight = 65.9
- });
- }
- public cpEasyPost(string secretKey)
- {
- SecretKey = secretKey;
- //Original way of init Client
- //ClientManager.SetCurrent(SecretKey);
- //Create ClientManager
- ClientManager.SetCurrent(() => new Client(new ClientConfiguration(SecretKey)));
- }
- public Shipment CreateShipment(Address AddressFrom, Address AddressTo, Parcel Parcel, CustomsInfo customs = null, string CustomReference = "", double? InsauranceAmount = null)
- {
- //Validate Adress
- var isValidFrom = ValidateAddress(AddressFrom);
- var isValidTo = ValidateAddress(AddressFrom);
- if (!isValidFrom.isSuccess)
- throw new Exception("Address From is not Valid");
- if (!isValidTo.isSuccess)
- throw new Exception("Address To is not Valid");
- //Validate Pacrcel
- var isValidParcel = ValidateParcel(Parcel);
- if (!isValidFrom.isSuccess)
- throw new Exception("Parcel is not Valid");
- //Create Shipment
- Shipment shipment = new Shipment()
- {
- reference = CustomReference,
- to_address = AddressTo,
- from_address = AddressFrom,
- parcel = Parcel,
- customs_info = customs
- };
- //ClientManager.SetCurrent(SecretKey); **
- shipment.Create();
- //Add Insurance
- if (InsauranceAmount != null)
- shipment.Insure(InsauranceAmount.Value);
- return shipment;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement