Skip to content

Instantly share code, notes, and snippets.

@Mozu-CS
Last active February 13, 2019 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mozu-CS/a232cdee15b616f7177d to your computer and use it in GitHub Desktop.
Save Mozu-CS/a232cdee15b616f7177d to your computer and use it in GitHub Desktop.
Example demonstrating how to create a single order using the Mozu API
[TestMethod]
public void ImportOrder()
{
//create an instance of the order resource
var orderResource = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext);
//map the order
var order = MapOrder();
//call create order method
var createdOrder = orderResource.CreateOrderAsync(order).Result;
}
[TestMethod]
public void ImportOrder()
{
//create an instance of the order resource
var orderResource = new Mozu.Api.Resources.Commerce.OrderResource(_apiContext);
//map the test order
var order = MapOrder();
//call create order method
var createdOrder = orderResource.CreateOrderAsync(order).Result;
}
private Mozu.Api.Contracts.CommerceRuntime.Orders.Order MapOrder()
{
//create an instance of an order
var order = new Mozu.Api.Contracts.CommerceRuntime.Orders.Order();
//Order Level Detail
order.CustomerAccountId = 1000;
order.IpAddress = "99.11.248.182";
order.SubmittedDate = DateTime.Now;
order.AmountRemainingForPayment = 0;
order.ChannelCode = "US-Online";
order.IsEligibleForReturns = false;
order.Status = "Completed";
order.TotalCollected = 295.37m;
order.Subtotal = 269;
order.DiscountedSubtotal = 269;
order.DiscountTotal = 10;
order.DiscountedTotal = 259;
order.ShippingTotal = 15;
order.ShippingSubTotal = 15;
order.ShippingTaxTotal = 0;
order.HandlingTaxTotal = 0;
order.ItemTaxTotal = 21.37m;
order.TaxTotal = 21.37m;
order.FeeTotal = 0;
order.Total = 295.37m;
order.BillingInfo = MapOrderLevelBillingInfo();
order.FulfillmentInfo = MapOrderLevelShippingInfo();
order.OrderDiscounts = MapOrderLevelDiscounts();
order.AuditInfo = MapOrderLevelAuditInfo();
//Setting this flag allows the import of an order w/out triggering key workflow processing
order.IsImport = true;
//Order Line Level Detail
order.Items = new List<Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem>();
order.Items.Add(MapOrderItemLine1());
order.Items.Add(MapOrderItemLine2());
//Order Fulfillment Detail
order.Packages = new List<Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package>();
order.Packages.Add(MapOrderFulfillmentLevelPackage1());
order.FulfillmentStatus = "Fulfilled";
//Order Payment Detail
order.Payments = new List<Mozu.Api.Contracts.CommerceRuntime.Payments.Payment>();
order.Payments.Add(MapOrderPaymentLevel1(order.BillingInfo));
order.PaymentStatus = "Paid";
return order;
}
private Mozu.Api.Contracts.CommerceRuntime.Orders.Order MapOrder()
{
//create an instance of an order
var order = new Mozu.Api.Contracts.CommerceRuntime.Orders.Order();
//Order Level Detail
order.CustomerAccountId = 1000;
order.IpAddress = "99.11.248.182";
order.SubmittedDate = DateTime.Now;
order.AmountRemainingForPayment = 0;
order.ChannelCode = "US-Online";
order.IsEligibleForReturns = false;
order.Status = "Completed";
order.TotalCollected = 295.37m;
order.Subtotal = 269;
order.DiscountedSubtotal = 269;
order.DiscountTotal = 10;
order.DiscountedTotal = 259;
order.ShippingTotal = 15;
order.ShippingSubTotal = 15;
order.ShippingTaxTotal = 0;
order.HandlingTaxTotal = 0;
order.ItemTaxTotal = 21.37m;
order.TaxTotal = 21.37m;
order.FeeTotal = 0;
order.Total = 295.37m;
order.BillingInfo = MapOrderLevelBillingInfo();
order.FulfillmentInfo = MapOrderLevelShippingInfo();
order.OrderDiscounts = MapOrderLevelDiscounts();
order.AuditInfo = MapOrderLevelAuditInfo();
//Setting this flag allows the import of an order w/out triggering key workflow processing
order.IsImport = true;
//Order Line Level Detail
order.Items = new List<Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem>();
order.Items.Add(MapOrderItemLine1());
order.Items.Add(MapOrderItemLine2());
//Order Fulfillment Detail
order.Packages = new List<Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package>();
order.Packages.Add(MapOrderFulfillmentLevelPackage1());
order.FulfillmentStatus = "Fulfilled";
//Order Payment Detail
order.Payments = new List<Mozu.Api.Contracts.CommerceRuntime.Payments.Payment>();
order.Payments.Add(MapOrderPaymentLevel1(order.BillingInfo));
order.PaymentStatus = "Paid";
return order;
}
private Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package MapOrderFulfillmentLevelPackage1()
{
var package = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package()
{
ShippingMethodName = "Flat Rate",
Code = "Package-1",
Status = "Fulfilled",
FulfillmentDate = DateTime.Now,
FulfillmentLocationCode = "ML-01",
Items = new List<Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem>()
{
new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem()
{
ProductCode = "SUN-GL-1",
Quantity = 1,
FulfillmentItemType = "Physical",
LineId = 1
},
new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem()
{
ProductCode = "GiftCardProduct",
Quantity = 2,
FulfillmentItemType = "Physical",
LineId = 2
},
}
};
return package;
}
private Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package MapOrderFulfillmentLevelPackage1()
{
var package = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.Package()
{
ShippingMethodName = "Flat Rate",
Code = "Package-1",
Status = "Fulfilled",
FulfillmentDate = DateTime.Now,
FulfillmentLocationCode = "ML-01",
Items = new List<Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem>()
{
new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem()
{
ProductCode = "SUN-GL-1",
Quantity = 1,
FulfillmentItemType = "Physical",
LineId = 1
},
new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.PackageItem()
{
ProductCode = "GiftCardProduct",
Quantity = 2,
FulfillmentItemType = "Physical",
LineId = 2
},
}
};
return package;
}
private Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem MapOrderItemLine1()
{
var orderitem = new Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem()
{
FulfillmentLocationCode = "ML-01",
FulfillmentMethod = "Ship",
LineId = 1,
Quantity = 1,
Subtotal = 229,
ExtendedTotal = 229,
TaxableTotal = 220.49m,
DiscountTotal = 0,
DiscountedTotal = 229,
ItemTaxTotal = 18.19m,
ShippingTaxTotal = 0,
FeeTotal = 0,
Total = 247.19m,
UnitPrice = new Mozu.Api.Contracts.CommerceRuntime.Commerce.CommerceUnitPrice()
{
ExtendedAmount = 229,
ListAmount = 249,
SaleAmount = 229
},
Product = new Mozu.Api.Contracts.CommerceRuntime.Products.Product()
{
VariationProductCode = "SUN-GL-1",
Name = "Pilot Sunglasses",
Description = "Avaitor's Top Choice",
Options = new List<Mozu.Api.Contracts.CommerceRuntime.Products.ProductOption>()
{
new Mozu.Api.Contracts.CommerceRuntime.Products.ProductOption()
{
Value = "Butterfly",
ShopperEnteredValue = "Butterfly",
AttributeFQN = "tenant~sunglass-style"
}
},
Price = new Mozu.Api.Contracts.CommerceRuntime.Products.ProductPrice()
{
Price = 249,
SalePrice = 229
},
FulfillmentStatus = "Fulfilled"
},
};
return orderitem;
}
private Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem MapOrderItemLine2()
{
var orderItem = new Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem()
{
FulfillmentLocationCode = "ML-01",
FulfillmentMethod = "Ship",
LineId = 2,
Quantity = 2,
Subtotal = 40,
ExtendedTotal = 40,
TaxableTotal = 35.81m,
DiscountTotal = 0,
DiscountedTotal = 40,
ItemTaxTotal = 3.18m,
ShippingTaxTotal = 0,
FeeTotal = 0,
Total = 43.18m,
UnitPrice = new Mozu.Api.Contracts.CommerceRuntime.Commerce.CommerceUnitPrice()
{
ExtendedAmount = 20,
ListAmount = 20
},
Product = new Mozu.Api.Contracts.CommerceRuntime.Products.Product()
{
ProductCode = "GiftCardProduct",
Name = "GiftCard",
Price = new Mozu.Api.Contracts.CommerceRuntime.Products.ProductPrice()
{
Price = 20,
SalePrice = 20
},
FulfillmentStatus = "Fulfilled"
},
};
return orderItem;
}
private Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem MapOrderItemLine1()
{
var orderitem = new Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem()
{
FulfillmentLocationCode = "ML-01",
FulfillmentMethod = "Ship",
LineId = 1,
Quantity = 1,
Subtotal = 229,
ExtendedTotal = 229,
TaxableTotal = 220.49m,
DiscountTotal = 0,
DiscountedTotal = 229,
ItemTaxTotal = 18.19m,
ShippingTaxTotal = 0,
FeeTotal = 0,
Total = 247.19m,
UnitPrice = new Mozu.Api.Contracts.CommerceRuntime.Commerce.CommerceUnitPrice()
{
ExtendedAmount = 229,
ListAmount = 249,
SaleAmount = 229
},
Product = new Mozu.Api.Contracts.CommerceRuntime.Products.Product()
{
VariationProductCode = "SUN-GL-1",
Name = "Pilot Sunglasses",
Description = "Avaitor's Top Choice",
Options = new List<Mozu.Api.Contracts.CommerceRuntime.Products.ProductOption>()
{
new Mozu.Api.Contracts.CommerceRuntime.Products.ProductOption()
{
Value = "Butterfly",
ShopperEnteredValue = "Butterfly",
AttributeFQN = "tenant~sunglass-style"
}
},
Price = new Mozu.Api.Contracts.CommerceRuntime.Products.ProductPrice()
{
Price = 249,
SalePrice = 229
},
FulfillmentStatus = "Fulfilled"
},
};
return orderitem;
}
private Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem MapOrderItemLine2()
{
var orderItem = new Mozu.Api.Contracts.CommerceRuntime.Orders.OrderItem()
{
FulfillmentLocationCode = "ML-01",
FulfillmentMethod = "Ship",
LineId = 2,
Quantity = 2,
Subtotal = 40,
ExtendedTotal = 40,
TaxableTotal = 35.81m,
DiscountTotal = 0,
DiscountedTotal = 40,
ItemTaxTotal = 3.18m,
ShippingTaxTotal = 0,
FeeTotal = 0,
Total = 43.18m,
UnitPrice = new Mozu.Api.Contracts.CommerceRuntime.Commerce.CommerceUnitPrice()
{
ExtendedAmount = 20,
ListAmount = 20
},
Product = new Mozu.Api.Contracts.CommerceRuntime.Products.Product()
{
ProductCode = "GiftCardProduct",
Name = "GiftCard",
Price = new Mozu.Api.Contracts.CommerceRuntime.Products.ProductPrice()
{
Price = 20,
SalePrice = 20
},
FulfillmentStatus = "Fulfilled"
},
};
return orderItem;
}
private Mozu.Api.Contracts.Core.AuditInfo MapOrderLevelAuditInfo()
{
var auditInfo = new Mozu.Api.Contracts.Core.AuditInfo()
{
UpdateDate = DateTime.Now
};
return auditInfo;
}
private Mozu.Api.Contracts.Core.AuditInfo MapOrderLevelAuditInfo()
{
var auditInfo = new Mozu.Api.Contracts.Core.AuditInfo()
{
UpdateDate = DateTime.Now
};
return auditInfo;
}
private Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo MapOrderLevelBillingInfo()
{
var billingInfo = new Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo()
{
BillingContact = new Mozu.Api.Contracts.Core.Contact()
{
Email = "alice.wick6@mozu.com",
FirstName = "alice",
LastNameOrSurname = "wick",
PhoneNumbers = new Mozu.Api.Contracts.Core.Phone()
{
Mobile = "555-555-0001",
},
Address = new Mozu.Api.Contracts.Core.Address()
{
Address1 = "One Lightning Bug Way",
CityOrTown = "Austin",
StateOrProvince = "TX",
PostalOrZipCode = "78702",
CountryCode = "US"
},
},
Card = new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentCard()
{
NameOnCard = "Bob Wick",
IsCardInfoSaved = false,
PaymentOrCardType = "VISA",
CardNumberPartOrMask = "************1111",
ExpireMonth = 12,
ExpireYear = 2019,
}
};
return billingInfo;
}
private Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo MapOrderLevelBillingInfo()
{
var billingInfo = new Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo()
{
BillingContact = new Mozu.Api.Contracts.Core.Contact()
{
Email = "alice.wick6@mozu.com",
FirstName = "alice",
LastNameOrSurname = "wick",
PhoneNumbers = new Mozu.Api.Contracts.Core.Phone()
{
Mobile = "555-555-0001",
},
Address = new Mozu.Api.Contracts.Core.Address()
{
Address1 = "One Lightning Bug Way",
CityOrTown = "Austin",
StateOrProvince = "TX",
PostalOrZipCode = "78702",
CountryCode = "US"
},
},
Card = new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentCard()
{
NameOnCard = "Bob Wick",
IsCardInfoSaved = false,
PaymentOrCardType = "VISA",
CardNumberPartOrMask = "************1111",
ExpireMonth = 12,
ExpireYear = 2019,
}
};
return billingInfo;
}
private List<Mozu.Api.Contracts.CommerceRuntime.Discounts.AppliedDiscount> MapOrderLevelDiscounts()
{
var orderDiscounts = new List<Mozu.Api.Contracts.CommerceRuntime.Discounts.AppliedDiscount>()
{
new Mozu.Api.Contracts.CommerceRuntime.Discounts.AppliedDiscount()
{
Impact = 10,
Discount = new Mozu.Api.Contracts.CommerceRuntime.Discounts.Discount()
{
Id = 1,
Name = "10 Dollars",
},
Excluded = false
}
};
return orderDiscounts;
}
private List<Mozu.Api.Contracts.CommerceRuntime.Discounts.AppliedDiscount> MapOrderLevelDiscounts()
{
var orderDiscounts = new List<Mozu.Api.Contracts.CommerceRuntime.Discounts.AppliedDiscount>()
{
new Mozu.Api.Contracts.CommerceRuntime.Discounts.AppliedDiscount()
{
Impact = 10,
Discount = new Mozu.Api.Contracts.CommerceRuntime.Discounts.Discount()
{
Id = 1,
Name = "10 Dollars",
},
Excluded = false
}
};
return orderDiscounts;
}
private Mozu.Api.Contracts.CommerceRuntime.Fulfillment.FulfillmentInfo MapOrderLevelShippingInfo()
{
var fulfillmentInfo = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.FulfillmentInfo()
{
FulfillmentContact = new Mozu.Api.Contracts.Core.Contact()
{
Email = "paul.wick6@mozu.com",
FirstName = "paul",
LastNameOrSurname = "wick",
PhoneNumbers = new Mozu.Api.Contracts.Core.Phone()
{
Mobile = "555-555-0002",
},
Address = new Mozu.Api.Contracts.Core.Address()
{
Address1 = "1300 Comanche Trail",
CityOrTown = "San Marcos",
StateOrProvince = "TX",
PostalOrZipCode = "78666",
CountryCode = "US"
}
}
};
return fulfillmentInfo;
}
private Mozu.Api.Contracts.CommerceRuntime.Fulfillment.FulfillmentInfo MapOrderLevelShippingInfo()
{
var fulfillmentInfo = new Mozu.Api.Contracts.CommerceRuntime.Fulfillment.FulfillmentInfo()
{
FulfillmentContact = new Mozu.Api.Contracts.Core.Contact()
{
Email = "paul.wick6@mozu.com",
FirstName = "paul",
LastNameOrSurname = "wick",
PhoneNumbers = new Mozu.Api.Contracts.Core.Phone()
{
Mobile = "555-555-0002",
},
Address = new Mozu.Api.Contracts.Core.Address()
{
Address1 = "1300 Comanche Trail",
CityOrTown = "San Marcos",
StateOrProvince = "TX",
PostalOrZipCode = "78666",
CountryCode = "US"
}
}
};
return fulfillmentInfo;
}
private Mozu.Api.Contracts.CommerceRuntime.Payments.Payment MapOrderPaymentLevel1(Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo billingInfo)
{
var payment = new Mozu.Api.Contracts.CommerceRuntime.Payments.Payment()
{
PaymentType = "CreditCard",
BillingInfo = billingInfo,
Status = "Collected",
IsRecurring = false,
AmountCollected = 295.37m,
AmountCredited = 0,
AmountRequested = 295.37m,
Interactions = new List<Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentInteraction>()
{
new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentInteraction()
{
GatewayInteractionId = 480431,
CurrencyCode = "USD",
InteractionType ="Authorization",
Status = "Authorized",
PaymentEntryStatus = "New",
GatewayTransactionId = "22367057731",
GatewayAuthCode = "XBIBM21",
GatewayAVSCodes = "Y",
GatewayCVV2Codes = "P",
GatewayResponseCode = "1",
GatewayResponseText = "This transaction has been approved.",
Amount = 295.37m,
InteractionDate = DateTime.Now,
},
new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentInteraction()
{
GatewayInteractionId = 480431,
CurrencyCode = "USD",
InteractionType ="Capture",
Status = "Captured",
PaymentEntryStatus = "Authorized",
GatewayTransactionId = "22367057731",
GatewayAuthCode = "XBIBM21",
GatewayAVSCodes = "Y",
GatewayCVV2Codes = "P",
GatewayResponseCode = "1",
GatewayResponseText = "This transaction has been approved.",
Amount = 295.37m,
InteractionDate = DateTime.Now,
},
}
};
return payment;
}
private Mozu.Api.Contracts.CommerceRuntime.Payments.Payment MapOrderPaymentLevel1(Mozu.Api.Contracts.CommerceRuntime.Payments.BillingInfo billingInfo)
{
var payment = new Mozu.Api.Contracts.CommerceRuntime.Payments.Payment()
{
PaymentType = "CreditCard",
BillingInfo = billingInfo,
Status = "Collected",
IsRecurring = false,
AmountCollected = 295.37m,
AmountCredited = 0,
AmountRequested = 295.37m,
Interactions = new List<Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentInteraction>()
{
new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentInteraction()
{
GatewayInteractionId = 480431,
CurrencyCode = "USD",
InteractionType ="Authorization",
Status = "Authorized",
PaymentEntryStatus = "New",
GatewayTransactionId = "22367057731",
GatewayAuthCode = "XBIBM21",
GatewayAVSCodes = "Y",
GatewayCVV2Codes = "P",
GatewayResponseCode = "1",
GatewayResponseText = "This transaction has been approved.",
Amount = 295.37m,
InteractionDate = DateTime.Now,
},
new Mozu.Api.Contracts.CommerceRuntime.Payments.PaymentInteraction()
{
GatewayInteractionId = 480431,
CurrencyCode = "USD",
InteractionType ="Capture",
Status = "Captured",
PaymentEntryStatus = "Authorized",
GatewayTransactionId = "22367057731",
GatewayAuthCode = "XBIBM21",
GatewayAVSCodes = "Y",
GatewayCVV2Codes = "P",
GatewayResponseCode = "1",
GatewayResponseText = "This transaction has been approved.",
Amount = 295.37m,
InteractionDate = DateTime.Now,
},
}
};
return payment;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment