HomeGuidesAPI ReferenceChangelogDiscussions
GuidesiMIS ProfessionaliMIS EnterpriseClient SupportLog In
Guides

Combo Order Manager

Create order and add invoice

Using an existing Party create a ComboOrder with an existing product submit the order with pay later that creates an invoice to add to the ComboOrder

using Asi.Soa.ClientServices;
using Asi.Soa.Commerce.DataContracts;
using Asi.Soa.Core.DataContracts;
using Asi.Soa.Membership.DataContracts;

EntityManager entityManager = new EntityManager();
var membershipManager = new MembershipManager(entityManager);

string partyId = "101";
string itemId = "G15";

// Find existing party record
PartyData personData = membershipManager.FindPartyByPartyId(partyId);
if (personData == null) return;

var comboOrderManager = new ComboOrderManager(entityManager, partyId);

// Create an order line with a product
ItemData itemData = new ItemData { ItemId = itemId };
OrderLineData orderLineData = new OrderLineData { Item = itemData, LineNumber = 1 };
comboOrderManager.AddLine(orderLineData);
// Add a delivery method, which is required for physical products
if (comboOrderManager.ComboOrder.Order.Delivery == null)
    comboOrderManager.ComboOrder.Order.Delivery = new DeliveryDataCollection();

if (comboOrderManager.ComboOrder.Order.Delivery.Count == 0)
    comboOrderManager.ComboOrder.Order.Delivery.Add(new DeliveryData());

comboOrderManager.ComboOrder.Order.Delivery[0].Address = personData.Addresses[0];
comboOrderManager.ComboOrder.Order.Delivery[0].DeliveryMethod =
    new DeliveryMethodData { DeliveryMethodId = "UPS" };
comboOrderManager.UpdatePricing();

var orderTotal = comboOrderManager.ComboOrder.Order.OrderTotal.Value.Amount;

// Apply pay later to ComboOrder so that it generates an invoice
// Below is what the payment remittance looks like when the customer is being billed for the order
if (comboOrderManager.ComboOrder.Order.OrderTotal != null)
{
    comboOrderManager.ComboOrder.Payments = new RemittanceDataCollection
    {
        new RemittanceData
        {
            Amount = new MonetaryAmountData(orderTotal,
                comboOrderManager.ComboOrder.Currency),
            PaymentMethod = new PaymentMethodData { PaymentMethodId = "BillMe" },
            ReferenceNumber = personData.PartyId
        }
    };
}

// Places the order or submits the cart
var results = entityManager.Add(comboOrderManager.ComboOrder);
if (results.IsValid)
{
    var orderData = results.Entity.Order;
    Console.WriteLine("Order Number: {0}", orderData.OrderNumber);
}
else
{
    Console.WriteLine("Cart failed: {0}", results.ValidationResults.Summary);
}
// Sets up a new combo order
comboOrderManager = new ComboOrderManager(entityManager, partyId);

// Find the invoice and add it to the combo order
var invoiceResults = entityManager.FindAll<InvoiceSummaryData>(
        new CriteriaData("BillToPartyId", OperationData.Equal, partyId),
        new CriteriaData("Balance", OperationData.Equal, orderTotal.ToString()));

if (invoiceResults.Count > 0)
{
    var invoice = invoiceResults[invoiceResults.Count - 1];
    Console.WriteLine("Invoice: {0}", invoice);
    comboOrderManager.AddInvoice(invoice);
    comboOrderManager.UpdatePricing();
    Console.WriteLine("Invoice count in cart: {0}", comboOrderManager.ComboOrder.Invoices.Count);
    Console.WriteLine("GrandTotal: {0}", comboOrderManager.TransactionGrandTotal.Amount);
}
// To pay for the invoice you can simply add a payment and submit the cart at this point

Create order and make payment

Using an existing Party and product make a standard order and apply a credit card payment.

using System;
using Asi.Soa.ClientServices;
using Asi.Soa.Commerce.DataContracts;
using Asi.Soa.Core.DataContracts;
using Asi.Soa.Membership.DataContracts;

EntityManager entityManager = new EntityManager();

var partyId = "216";
var itemId = "G15";

var membershipManager = new MembershipManager(entityManager);

// Find existing party record
PartyData personData = membershipManager.FindPartyByPartyId(partyId);
if (personData == null) return;

//Set payment details
var creditCardInformationData = new CreditCardInformationData
{
  CardNumber = "4111111111111111",
  CardType = "VISA",
  Expiration = new YearMonthDateData {Month = 5, Year = DateTime.Now.Year + 1},
  HoldersName = personData.Name,
  SecurityCode = "123"
};

// Create new ComboOrder
var comboOrderManager = new ComboOrderManager(entityManager, personData.PartyId);
comboOrderManager.ComboOrder.Order.Lines = new OrderLineDataCollection();
var orderLineData = new OrderLineData
{
  Item = new ItemData {ItemId = itemId},
  LineNumber = 1,
  QuantityOrdered = new QuantityData(1)
};
comboOrderManager.AddLine(orderLineData);

if (comboOrderManager.ComboOrder.Order.Delivery == null)
  comboOrderManager.ComboOrder.Order.Delivery = new DeliveryDataCollection();

if (comboOrderManager.ComboOrder.Order.Delivery.Count == 0)
  comboOrderManager.ComboOrder.Order.Delivery.Add(new DeliveryData());

comboOrderManager.ComboOrder.Order.Delivery[0].Address = personData.Addresses[0];
comboOrderManager.ComboOrder.Order.Delivery[0].DeliveryMethod =
  new DeliveryMethodData {DeliveryMethodId = "UPS"};
comboOrderManager.UpdatePricing();

// Apply payment to ComboOrder
if (comboOrderManager.ComboOrder.Order.OrderTotal != null)
{
  comboOrderManager.ComboOrder.Payments = new RemittanceDataCollection
  {
    new RemittanceData
    {
      Amount = new MonetaryAmountData(comboOrderManager.ComboOrder.Order.OrderTotal.Value.Amount,
                                      comboOrderManager.ComboOrder.Currency),
      PaymentMethod =
        new PaymentMethodData
      {
        PaymentMethodId = creditCardInformationData.CardType,
        PaymentType = "CreditCard"
      },
      CreditCardInformation = creditCardInformationData,
      ReferenceNumber = personData.PartyId
    }
  };
}

//Submit the cart 
var results = entityManager.Add(comboOrderManager.ComboOrder);
if (results.IsValid)
{
  var orderData = results.Entity.Order;
  Console.WriteLine("Order Number: {0}", orderData.OrderNumber);
}
else
{
  Console.WriteLine(results.ValidationResults.Summary);
}