HomeGuidesAPI ReferenceChangelogDiscussions
GuidesiMIS ProfessionaliMIS EnterpriseClient SupportLog In
Discussions
These docs are for v20.3.44. Click to read the latest docs for v20.3.192.

Discussions

Ask a Question
Back to All

Getting error while renewing dues subscription

(edited)

Hi,

When I renew a dues product, I am getting a 'ComponentNotRegisteredError'
The error details is
The requested service 'Asi.Soa.Commerce.ServiceContracts.ILegacyBillingService' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

I am using the ASI code sample from the following url https://developer.imis.com/docs/dues

<%@ Page Language="C#" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Linq" %>
<%@ Import Namespace="Asi.Core.Ioc" %>
<%@ Import Namespace="Asi.Soa.ClientServices" %>
<%@ Import Namespace="Asi.Soa.Commerce.DataContracts" %>
<%@ Import Namespace="Asi.Soa.Commerce.ServiceContracts" %>
<%@ Import Namespace="Asi.Soa.Core.DataContracts" %>
<%@ Import Namespace="Asi.Soa.Core.ServiceContracts" %>
<%@ Import Namespace="Asi.Soa.Membership.DataContracts" %>
<%@ Import Namespace="Asi.Soa.Core.Interfaces" %>
<%@ Import Namespace="Autofac" %>

string partyId = "18052"; // Brian Murphy

CartManager joinCartManager = new CartManager(entityManager, partyId);

// Get membership fees item, set item quantities and construct order line using helper method
var findResultsData =
entityManager.Find(
new QueryData(ItemData.EntityTypeName)
.AddCriteria(new CriteriaData("ItemCode",
OperationData.Equal, "REGULAR_MEMBERSHIP_FEES"))).Result;

ItemData item = findResultsData[0] as ItemData;

Dictionary<string, int> quantities = new Dictionary<string, int>
{
{"REGULAR_MEMBERSHIP_FEES/REG", 1},
{"REGULAR_MEMBERSHIP_FEES/PAC", 1},
{"REGULAR_MEMBERSHIP_FEES/NORTH", 1}
};

OrderLineData joinOrderLine = ConstructOrderLine(item, quantities);

// Add line to cart manager, and add payment based off of order total
joinCartManager.AddLine(joinOrderLine);
joinCartManager.Cart.ComboOrder.Payments = new RemittanceDataCollection
{
new RemittanceData
{
Amount = new MonetaryAmountData(
joinCartManager.Cart.ComboOrder.Order.OrderTotal.Value.Amount,
joinCartManager.Cart.ComboOrder.Order.Currency),
PaymentMethod = new PaymentMethodData {PaymentMethodId = "Cash"}
}
};

// Submit the cart
joinCartManager.SubmitCart();

// Need at least a one day offset from the join date to create a renewal billing
DateTime tomorrow = Asi.AppTime.Now.Date.AddDays(1);
DateTime effectiveDate = new DateTime(Asi.AppTime.Now.Year, Asi.AppTime.Now.Month, 1).AddMonths(1).AddYears(1);

// Run membership fees billing cycle
string billingCycle = "Regular Membership Fees";

using (var scope = IocSupport.GetRequestLifetimeScope().BeginLifetimeScope())
{
var billingService = scope.Resolve();

LegacyBillingData runData = new LegacyBillingData
&#123;
  BillingCycleId = billingCycle,
  IsRenewal = true,
  IndividualBillingPartyId = partyId,
  RunDate = tomorrow,
  EffectiveDate = effectiveDate
&#125;;
billingService.Run(runData);
/*
var builder = new ContainerBuilder();
builder.RegisterType<ILegacyBillingService>();
using (var container = builder.Build())
&#123;
	var billingService = container.Resolve<ILegacyBillingService>();
	billingService.Run(runData);
&#125;*/

}

// Instantiate invoice ID, cart manager for renewal invoice, and find invoice by the ID
string invoiceId = string.Format("CASH:{0}:{1:yyyyMMdd}-1", partyId, Asi.AppTime.Now.Date);

CartManager invoiceCartManager = new CartManager(entityManager, partyId);
InvoiceData invoice = entityManager.FindByIdentity(invoiceId);

invoiceCartManager.AddInvoice(invoice);

// Instantiate membership manager and find Party by ID
MembershipManager membershipManager = new MembershipManager(entityManager);
PartyData party = membershipManager.FindPartyByPartyId(partyId);

// Initialize order line from invoice, add it to the cart and create associated payment
var orderLine =
ComboOrderManager.GetOrderLineFromInvoice(invoice, invoiceCartManager.Cart.ComboOrder.Order, party,
entityManager);

invoiceCartManager.AddLine(orderLine);

invoiceCartManager.Cart.ComboOrder.Payments = new RemittanceDataCollection
{
new RemittanceData
{
Amount = new MonetaryAmountData(
invoiceCartManager.Cart.ComboOrder.Order.OrderTotal.Value.Amount,
invoiceCartManager.Cart.ComboOrder.Order.Currency),
PaymentMethod = new PaymentMethodData {PaymentMethodId = "Cash"}
}
};

// Submit the cart
var results = invoiceCartManager.SubmitCart();
Response.Write(results.ValidationResults.Summary);
}

internal static OrderLineData ConstructOrderLine(ItemSummaryData item,
Dictionary<string, int> quantitiesOrdered)
{
OrderLineData orderLine = new OrderLineData
{
Item = item
};

ItemSetItemData itemSet = item as ItemSetItemData;

if (itemSet != null)
{
orderLine.ChildOrderLines = new OrderLineDataCollection();

foreach (ItemSetComponentData component in itemSet.Components)
&#123;
  orderLine.ChildOrderLines.Add(ConstructOrderLine(component.Item, quantitiesOrdered));
&#125;

if (orderLine.ChildOrderLines.Any(
  x => x.QuantityOrdered.HasValue && x.QuantityOrdered.Value.Amount > 0m))
&#123;
  orderLine.QuantityOrdered = new QuantityData(1m);
&#125;

}
else
{
int quantity;

if (quantitiesOrdered.TryGetValue(item.ItemCode, out quantity))
&#123;
  orderLine.QuantityOrdered = new QuantityData(quantity);
&#125;

}

return orderLine;
}

Could any one help to resolve this issue.
I am using iMIS version 20.2.64.8807

Thanks,
Prakasam