/// <summary> /// Convert the item to an auto gen item. /// </summary> /// <param name="item">The item to convert</param> /// <param name="currency">The currency</param> /// <returns></returns> public static AutoGen.Item CreateAutoGenItem(IShoppingCartItem item, string currency) { GCheckout.AutoGen.Item currentItem = new AutoGen.Item(); currentItem.itemname = EncodeHelper.EscapeXmlChars(item.Name); currentItem.itemdescription = EncodeHelper.EscapeXmlChars(item.Description); currentItem.quantity = item.Quantity; //if there is a subscription, you may not have a unit price if (item.Subscription != null && item.Price > 0) { throw new ApplicationException( "The unit price must be 0 if you are using a subscription item."); } currentItem.unitprice = new AutoGen.Money(); currentItem.unitprice.currency = currency; currentItem.unitprice.Value = item.Price; //TODO determine if we should try to catch if a UK customer tries to //use this value. if (item.Weight > 0) { currentItem.itemweight = new AutoGen.ItemWeight(); currentItem.itemweight.unit = "LB"; //this is the only option. currentItem.itemweight.value = item.Weight; } if (item.MerchantItemID != null && item.MerchantItemID.Length > 0) { currentItem.merchantitemid = item.MerchantItemID; } if (item.MerchantPrivateItemDataNodes != null && item.MerchantPrivateItemDataNodes.Length > 0) { AutoGen.anyMultiple any = new AutoGen.anyMultiple(); any.Any = item.MerchantPrivateItemDataNodes; currentItem.merchantprivateitemdata = any; } if (item.TaxTable != null && item.TaxTable != AlternateTaxTable.Empty) { currentItem.taxtableselector = item.TaxTable.Name; } //if we have a digital item then we need to append the information if (item.DigitalContent != null) { currentItem.digitalcontent = new GCheckout.AutoGen.DigitalContent(); //we have one of two types, email or key/url if (item.DigitalContent.EmailDelivery) { currentItem.digitalcontent.emaildelivery = true; currentItem.digitalcontent.emaildeliverySpecified = true; } else { if (item.DigitalContent.Description.Length > 0) { currentItem.digitalcontent.description = item.DigitalContent.Description; } if (item.DigitalContent.Key.Length > 0) { currentItem.digitalcontent.key = item.DigitalContent.Key; } if (item.DigitalContent.Url.Length > 0) { currentItem.digitalcontent.url = item.DigitalContent.Url; } currentItem.digitalcontent.displaydisposition = item.DigitalContent.GetSerializedDisposition(); } } //see if we have subscription information if (item.Subscription != null) { if (item.Subscription.RecurrentItem == null) { throw new ApplicationException( "You must set a RecurrentItem for a subscription."); } Subscription sub = item.Subscription; //we have to assume the item was validated currentItem.subscription = new GCheckout.AutoGen.Subscription(); GCheckout.AutoGen.Subscription autoSub = currentItem.subscription; if (sub.NoChargeAfter.HasValue) { autoSub.nochargeafter = sub.NoChargeAfter.Value; autoSub.nochargeafterSpecified = true; } autoSub.payments = new GCheckout.AutoGen.SubscriptionPayment[sub.Payments.Count]; for (int sp = 0; sp < sub.Payments.Count; sp++) { SubscriptionPayment payment = sub.Payments[sp]; autoSub.payments[sp] = new GCheckout.AutoGen.SubscriptionPayment(); autoSub.payments[sp].maximumcharge = EncodeHelper.Money(currency, payment.MaximumCharge); if (payment.Times > 0) { autoSub.payments[sp].times = payment.Times; autoSub.payments[sp].timesSpecified = true; } autoSub.period = sub.Period; if (sub.RecurrentItem != null && sub.RecurrentItem.Subscription != null) { throw new ApplicationException( "A RecurrentItem may not contain a subscription."); } //call this method to create the recurrent item. autoSub.recurrentitem = ShoppingCartItem.CreateAutoGenItem(sub.RecurrentItem, currency); if (sub.StartDate.HasValue) { autoSub.startdate = sub.StartDate.Value; autoSub.startdateSpecified = true; } autoSub.type = sub.Type.ToString(); } } return(currentItem); }
/// <summary> /// Convert the item to an autogen item /// </summary> /// <param name="currency">The currency</param> /// <returns></returns> public AutoGen.Item CreateAutoGenItem(string currency) { return(ShoppingCartItem.CreateAutoGenItem(this, currency)); }