This is a very obvious thing that one would want to do and a rather tricky thing mostly due to the lack of documentation. There are some samples that ship with CS09 and they work in an ASP.NET demo application, but how do you add a new payment method inside the starter site that ships with CS09. This article explains exactly the steps you need to take to introduce a new payment method, for instance, a cheque payment method. This articles assumes you are working with the Mojave starter site code.
1. Create ChequePayment class on the Commerce Server side. In my case we created this class inside an OrderComponents project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.CommerceServer.Runtime.Orders;
using Microsoft.CommerceServer.Orders;
using System.Security.Permissions;
using System.Runtime.Serialization;
namespace XYZ.CommerceServer.Order.Components.BusinessEntities
{
///
///
///
[Serializable]
[ComVisible(false)]
public class ChequePayment : Payment
{
private string chequeNumber = null;
public new PaymentMethodTypes PaymentType
{
get
{
return PaymentMethodTypes.Custom1;
}
}
public ChequePayment()
: base()
{
}
public ChequePayment(string billingAddressId,Guid paymentMethodId)
{
base.BillingAddressId = billingAddressId;
base.PaymentMethodId = paymentMethodId;
}
///
/// Deserialization constructor for ISerializable support.
///
protected ChequePayment(SerializationInfo info, StreamingContext context)
: base(info, context)
{
this.chequeNumber = (string)info.GetValue("ChequeNumber", typeof(string));
}
///
/// Serializes this object to the provided serialization context.
///
[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue("ChequeNumber", this.chequeNumber);
}
///
/// The cheque number.
///
public string ChequeNumber
{
get
{
return this.chequeNumber;
}
set
{
this.SetDirty(value);
this.chequeNumber = value;
}
}
}
}
2. Create ChequePaymentTranslator class.
//-----------------------------------------------------------------------
//
// Copyright © Microsoft Corporation. All rights reserved.
//
// Csr refund sequence component
//-----------------------------------------------------------------------
namespace XYZ.CommerceServer.Order.Components.BusinessEntities
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Commerce.Providers.Translators;
using Microsoft.Commerce.Contracts;
using Microsoft.CommerceServer.Runtime.Orders;
using Microsoft.Commerce.Common;
using CSO = Microsoft.CommerceServer.Runtime.Orders;
public class ChequePaymentAccountTranslator :
IToCommerceEntityTranslator,
IToExternalEntityTranslator
{
private PropertyTranslator chequePropertyTranslator;
private PropertyTranslator ChequePropertyTranslator
{
get
{
return this.chequePropertyTranslator;
}
set
{
this.chequePropertyTranslator = value;
}
}
public ChequePaymentAccountTranslator()
{
// this.ChequePropertyTranslator = new PropertyTranslator
this.ChequePropertyTranslator = new PropertyTranslator(
new FromCommerceServerPropertyTranslator(this.TranslateFromStronglyTypedCommerceServerProperty),
new FromCommerceServerPropertyTranslator(this.TranslateFromWeaklyTypedCommerceServerProperty),
new ToCommerceServerPropertyTranslator(this.TranslateToStronglyTypedCommerceServerProperty),
new ToCommerceServerPropertyTranslator(this.TranslateToWeaklyTypedCommerceServerProperty));
}
public void Translate(CommerceEntity sourceCommerceEntity, object destinationObject)
{
if (sourceCommerceEntity.ModelName.Equals("Cheque"))
{
ChequePayment commerceServerObject = destinationObject as ChequePayment;
if (commerceServerObject == null)
{
ThrowCannotTranslate(sourceCommerceEntity, destinationObject);
}
this.ChequePropertyTranslator.TranslateToCommerceServer(sourceCommerceEntity, commerceServerObject, null);
}
}
public void Translate(object sourceObject, CommerceEntity destination, CommercePropertyCollection propertiesToReturn)
{
ChequePayment commerceServerObject = sourceObject as ChequePayment;
if (commerceServerObject != null)
{
if (!destination.ModelName.Equals("Cheque"))
{
ThrowCannotTranslate(sourceObject, destination);
}
this.ChequePropertyTranslator.TranslateToCommerceEntity(commerceServerObject, destination, propertiesToReturn);
}
}
private static void ThrowCannotTranslate(object source, object destination)
{
string reason = Microsoft.Commerce.Providers.ProviderResources.ExceptionMessages.GetMessage("TranslationFailed", new object[] { source.GetType().FullName, destination.GetType().FullName });
throw new System.ServiceModel.FaultException(new Microsoft.Commerce.Contracts.Faults.GeneralOperationFault(reason), reason);
}
protected bool TranslateToWeaklyTypedCommerceServerProperty(
CSO.Payment commerceServerObject,
string commerceServerPropertyName,
object value)
{
commerceServerObject[commerceServerPropertyName] = value;
return true;
}
protected bool TranslateFromWeaklyTypedCommerceServerProperty(
CSO.Payment commerceServerObject,
string commerceServerPropertyName,
CommerceEntity commerceEntity,
string mojavePropertyName)
{
commerceEntity.Properties[mojavePropertyName] = commerceServerObject[commerceServerPropertyName];
return true;
}
protected virtual bool TranslateToStronglyTypedCommerceServerPropertyBase(
CSO.Payment commerceServerObject,
string commerceServerPropertyName,
object value)
{
switch (commerceServerPropertyName)
{
case "BillingAddressId":
commerceServerObject.BillingAddressId = value as string;
break;
case "CustomerNameOnPayment":
commerceServerObject.CustomerNameOnPayment = value as string;
break;
default:
return false; // the property was NOT translated
}
return true; // the property was translated
}
protected virtual bool TranslateFromStronglyTypedCommerceServerPropertyBase(
CSO.Payment commerceServerObject,
string commerceServerPropertyName,
CommerceEntity commerceEntity,
string mojavePropertyName)
{
switch (commerceServerPropertyName)
{
case "PaymentId":
commerceEntity.Properties[mojavePropertyName] = commerceServerObject.PaymentId.ToString("B");
break;
case "BillingAddressId":
commerceEntity.Properties[mojavePropertyName] = commerceServerObject.BillingAddressId;
break;
case "CustomerNameOnPayment":
commerceEntity.Properties[mojavePropertyName] = commerceServerObject.CustomerNameOnPayment;
break;
default:
return false; // the property was NOT translated
}
return true; // the property was translated
}
protected bool TranslateFromStronglyTypedCommerceServerProperty(
ChequePayment commerceServerObject,
string commerceServerPropertyName,
CommerceEntity commerceEntity,
string mojavePropertyName)
{
if (this.TranslateFromStronglyTypedCommerceServerPropertyBase(commerceServerObject, commerceServerPropertyName, commerceEntity, mojavePropertyName))
{
return true;
}
string str = commerceServerPropertyName;
if (str != null)
{
if (str == "ChequeNumber")
{
commerceEntity.Properties[mojavePropertyName] = commerceServerObject.ChequeNumber;
goto Label_005C;
}
}
return false;
Label_005C:
return true;
}
protected bool TranslateToStronglyTypedCommerceServerProperty(
ChequePayment commerceServerObject,
string commerceServerPropertyName,
object value)
{
if (this.TranslateToStronglyTypedCommerceServerPropertyBase(commerceServerObject, commerceServerPropertyName, value))
{
return true;
}
string str = commerceServerPropertyName;
if (str != null)
{
if (str == "ChequeNumber")
{
commerceServerObject.ChequeNumber = value.ToString();
goto Label_004C;
}
}
return false;
Label_004C:
return true;
}
}
}
3. Create the PaymentResponseBuilder.cs
namespace XYZ.CommerceServer.Order.Components.BusinessEntities
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using CSO = Microsoft.CommerceServer.Runtime.Orders;
using Microsoft.Commerce.Common;
using Microsoft.Commerce.Contracts.CommerceEntities;
using Microsoft.Commerce.Providers.Translators;
using Microsoft.Commerce.Contracts.Messages;
using Microsoft.Commerce.Contracts;
using System.Runtime.InteropServices;
using Microsoft.Commerce.Common.MessageBuilders;
using Microsoft.Commerce.Providers.Utility;
using Microsoft.Commerce.Providers.CSHelpers;
using Microsoft.Commerce.Broker;
using Microsoft.Commerce.Providers.Components;
///
/// This class is responsible for populating the response of the create and update Basket
/// operations with the information relevant to the Payments.
///
[ComVisible(false)]
public class XYZPaymentsResponseBuilder : BasketRelatedItemOperationSequenceComponent
{
#region BasketRelatedItemOperationSequenceComponent Overrides
///
/// Gets the RelationshipName
///
protected override string RelationshipName
{
get { return "Payments"; }
}
///
/// Populates the Basket.Payments collection for the query operation.
///
/// contains the realted item to query
protected override void QueryRelatedItem(CommerceQueryRelatedItem queryRelatedItemOperation)
{
Debug.Assert(queryRelatedItemOperation != null, "queryRelatedItemOperation cannot be null");
Debug.Assert(this.OperationCache != null, "OperationCache must be initialized by the base class.");
CommerceEntity modelPayment = queryRelatedItemOperation.GetModel("Payment");
foreach (CommerceEntity responseBasket in this.GetResponseCommerceEntities("Basket"))
{
CommerceRelationshipList paymentList = responseBasket.Properties["Payments"] as CommerceRelationshipList;
if (paymentList == null)
{
paymentList = new CommerceRelationshipList();
responseBasket.Properties["Payments"] = paymentList;
}
CSO.OrderForm orderForm = this.OperationCache.GetCachedCommerceServerOrderGroup(
responseBasket.Id).GetDefaultOrderForm();
foreach (CSO.Payment commerceServerPayment in orderForm.Payments)
{
CommerceEntity responsePayment = new CommerceEntity("Payment");
paymentList.Add(new CommerceRelationship(responsePayment));
Translator.ToCommerceEntity(commerceServerPayment, responsePayment, modelPayment.Properties);
QueryPaymentAccount(queryRelatedItemOperation, responsePayment, commerceServerPayment);
}
}
}
#endregion
private static void QueryPaymentAccount(
CommerceQueryRelatedItem paymentQuery,
CommerceEntity responsePayment,
CSO.Payment commerceServerPayment)
{
Debug.Assert(paymentQuery != null, "paymentQuery should not be null");
Debug.Assert(responsePayment != null, "responsePayment should not be null");
Debug.Assert(commerceServerPayment != null, "commerceServerPayment should not be null");
CommerceQueryRelatedItem paymentAccountQuery = (paymentQuery.
GetRelatedOperations("PaymentAccount")).FirstOrDefault();
if (paymentAccountQuery == null)
{
return; // PaymentAccount is not requested
}
CommerceEntity paymentAccount = null;
switch (commerceServerPayment.PaymentType)
{
case Microsoft.CommerceServer.Orders.PaymentMethodTypes.CashCard:
paymentAccount = new CommerceEntity("CashCard");
break;
case Microsoft.CommerceServer.Orders.PaymentMethodTypes.CreditCard:
paymentAccount = new CommerceEntity("CreditCard");
break;
case Microsoft.CommerceServer.Orders.PaymentMethodTypes.GiftCertificate:
paymentAccount = new CommerceEntity("GiftCertificate");
break;
case Microsoft.CommerceServer.Orders.PaymentMethodTypes.PurchaseOrder:
paymentAccount = new CommerceEntity("PurchaseOrder");
break;
default:
switch (commerceServerPayment.DerivedClassName)
{
case "ChequePayment":
paymentAccount = new CommerceEntity("Cheque");
break;
case "FreePayment":
paymentAccount = new CommerceEntity("Free");
break;
}
break;
}
if (paymentAccount != null)
{
responsePayment.Properties["PaymentAccount"] = new CommerceRelationship(paymentAccount);
CommerceEntity paymentAccountModel = paymentAccountQuery.Model;
Translator.ToCommerceEntity(commerceServerPayment, paymentAccount, paymentAccountModel.Properties);
QueryPaymentMethod(paymentAccountQuery, paymentAccount, commerceServerPayment);
}
}
private static void QueryPaymentMethod(
CommerceQueryRelatedItem paymentAccountQuery,
CommerceEntity paymentAccount,
CSO.Payment commerceServerPayment)
{
Debug.Assert(paymentAccountQuery != null, "paymentAccountQuery should not be null");
Debug.Assert(paymentAccount != null, "paymentAccount should not be null");
Debug.Assert(commerceServerPayment != null, "commerceServerPayment should not be null");
CommerceQueryRelatedItem paymentMethodQuery = (paymentAccountQuery.
GetRelatedOperations("PaymentMethod")).FirstOrDefault();
if (paymentMethodQuery == null)
{
return; // PaymentMethod is not requested
}
CommerceEntity paymentMethodModel = paymentMethodQuery.GetModel("PaymentMethod");
CommerceEntity paymentMethod = PaymentHelper.GetPaymentMethodByMethodId(
OperationContext.CurrentInstance.SiteName,
OperationContext.CurrentInstance.RequestContext.UserLocale,
commerceServerPayment.PaymentMethodId.ToString(),
paymentMethodModel.Properties);
paymentAccount.Properties["PaymentMethod"] = new CommerceRelationship(paymentMethod);
}
}
}
4. Modify the WSPBuild\CommerceServer\OrderPipelineMappings.xml by adding
5. Modify the WSPBuild\CommerceServer\OrderObjectMappings.xml by adding
...
...
6. Modify the WSPBuild\CommerceServer\MetadataDefinitions.xml by adding
csType="Cactus.CommerceServer.Order.Components.BusinessEntities.ChequePayment"
csAssembly="Cactus.CommerceServer.Order.Components, Version=1.0.0.0, Culture=neutral, PublicKeyToken=911380ffc789d881"
csArea="Orders">
7. Modify the WSPBuild\CommerceServer\ChannelConfiguration.config by adding the following in the ToCommerceEntities tags:
8. Modify the WSPBuild\CommerceServer\ChannelConfiguration.config by adding the following in the ToExternalEntities tags:
9. Modify the SharePointCommon\FeatureActivation\DefaultConfigs\CommerceServer.xml by adding:
name="chequeprocessor"
path="pipelines\Cheque.pcf"
transacted="false"
type="OrderPipeline"
loggingEnabled="false"/>
...
...
...
10. Modify the UI\Orders\WebControls\XsltControls\XsltBasketControl.cs RenderPayments method as follows:
///
/// Renders the payments.
///
/// The XML writer.
protected void RenderPayments(XmlWriter xmlWriter)
{
if (this.currentBasket.Payments != null)
{
foreach (CommerceRelationship relationship in this.currentBasket.Payments)
{
Payment payment = relationship.Target;
xmlWriter.WriteStartElement("Payment");
RenderBusinessItemProperties(payment.ToCommerceEntity(), xmlWriter, null);
if (payment.PaymentAccount != null)
{
CommerceEntity paymentAccount = payment.PaymentAccount.Target;
switch (paymentAccount.ModelName)
{
case "Cheque":
Cheque cheque = payment.PaymentAccount.Target;
if (cheque != null)
{
xmlWriter.WriteStartElement("PaymentMethod");
PaymentMethod paymentMethod = (PaymentMethod)cheque.PaymentMethod.Target;
//// TMP Code, to go get all info from Payment Method
paymentMethod = PaymentMethodHelper.GetPaymentMethods(PaymentType.Custom1)[0];
RenderBusinessItemProperties(paymentMethod.ToCommerceEntity(), xmlWriter, null);
xmlWriter.WriteStartElement("Cheque");
RenderBusinessItemProperties(cheque.ToCommerceEntity(), xmlWriter, null);
xmlWriter.WriteEndElement(); ////Cheque
xmlWriter.WriteEndElement(); ////PayentMethod
}
break;
case "Free":
Free freePayment = payment.PaymentAccount.Target;
if (freePayment != null)
{
xmlWriter.WriteStartElement("PaymentMethod");
PaymentMethod paymentMethod = (PaymentMethod)freePayment.PaymentMethod.Target;
//// TMP Code, to go get all info from Payment Method
paymentMethod = PaymentMethodHelper.GetPaymentMethods(PaymentType.Custom2)[0];
RenderBusinessItemProperties(paymentMethod.ToCommerceEntity(), xmlWriter, null);
xmlWriter.WriteStartElement("Free");
RenderBusinessItemProperties(freePayment.ToCommerceEntity(), xmlWriter, null);
xmlWriter.WriteEndElement(); ////Free
xmlWriter.WriteEndElement(); ////PayentMethod
}
break;
case "CreditCard":
CreditCard cc = payment.PaymentAccount.Target;
if (cc != null)
{
xmlWriter.WriteStartElement("PaymentMethod");
PaymentMethod paymentMethod = (PaymentMethod)cc.PaymentMethod.Target;
//// TMP Code, to go get all info from Payment Method
paymentMethod = PaymentMethodHelper.LoadCreditCardPaymentMethod(paymentMethod.Id);
RenderBusinessItemProperties(paymentMethod.ToCommerceEntity(), xmlWriter, null);
xmlWriter.WriteStartElement("CreditCard");
if (cc.ExpirationMonth.HasValue && cc.ExpirationYear.HasValue)
{
cc.Properties["ShortExpDate"] = cc.ExpirationMonth.Value.ToString(CultureInfo.InvariantCulture).PadLeft(2, '0') + "/" + cc.ExpirationYear.Value.ToString(CultureInfo.InvariantCulture).PadLeft(4, '0');
}
RenderBusinessItemProperties(cc.ToCommerceEntity(), xmlWriter, null);
xmlWriter.WriteStartElement("BillingAddress");
if (cc.BillingAddressId != null && this.currentBasket.Addresses != null)
{
//// Find address
foreach (CommerceRelationship addressRelationship in this.currentBasket.Addresses)
{
Address address = addressRelationship.Target;
if (address.Id == cc.BillingAddressId)
{
this.AdjustAddressEntity(address);
RenderBusinessItemProperties(address.ToCommerceEntity(), xmlWriter, null);
break;
}
}
}
xmlWriter.WriteEndElement(); ////BillingAddress
xmlWriter.WriteEndElement(); ////CreditCard
xmlWriter.WriteEndElement(); ////PaymentMethod
}
else
{
//TODO alternate payment methods
}
break;
}
}
xmlWriter.WriteStartElement("Actions");
RenderActions(ActionLevel.Payment, xmlWriter, payment.ToCommerceEntity());
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement(); ////Payment
}
}
}
11. Modify the web\Common\Controllers\ShoppingController.cs by adding
///
/// Adds the cheque payment create request.
///
/// Name of the basket.
/// The payment method id.
/// The cheque.
/// The amount.
public void AddChequePaymentCreateRequest(string basketName, string paymentMethodId, Cheque cheque, decimal amount)
{
CommerceUpdate> updateBasket = this.GetUpdateBasketBuilder(basketName);
CommerceCreateRelatedItem newPayment = new CommerceCreateRelatedItem(Basket.RelationshipName.Payments);
{
CommerceCreateRelatedItem newPaymentAccount = new CommerceCreateRelatedItem(Payment.RelationshipName.PaymentAccount);
{
newPaymentAccount.Model = cheque;
newPayment.Model.Amount = amount;
newPayment.RelatedOperations.Add(newPaymentAccount);
{
CommerceCreateRelationship existingPaymentMethod = new CommerceCreateRelationship(PaymentAccount.RelationshipName.PaymentMethod);
existingPaymentMethod.SearchCriteria.Model.Id = paymentMethodId;
newPaymentAccount.RelatedOperations.Add(existingPaymentMethod);
}
}
}
updateBasket.RelatedOperations.Add(newPayment);
}
and
///
/// Populates the basket related item.
///
/// The list of related operations to populate.
private void PopulateBasketRelatedItem(List relatedOperations)
{
System.Diagnostics.Debug.Assert(relatedOperations != null, "The value of relatedOperations should never be null.");
if (this.includeLineItems)
{
#region Basket LineItems
// Return Basket LineItems
CommerceQueryRelatedItem lineItemsQuery =
new CommerceQueryRelatedItem(Basket.RelationshipName.LineItems);
lineItemsQuery.Model.Properties = new CommercePropertyCollection();
CommerceQueryRelatedItem lineItemDiscountsQuery =
new CommerceQueryRelatedItem(LineItem.RelationshipName.ItemLevelDiscounts);
lineItemsQuery.Model.Properties = new CommercePropertyCollection();
lineItemsQuery.RelatedOperations.Add(lineItemDiscountsQuery);
CommerceQueryRelatedItem lineItemBasketDiscountsQuery =
new CommerceQueryRelatedItem(LineItem.RelationshipName.BasketLevelDiscounts);
lineItemBasketDiscountsQuery.Model.Properties = new CommercePropertyCollection();
lineItemsQuery.RelatedOperations.Add(lineItemBasketDiscountsQuery);
relatedOperations.Add(lineItemsQuery);
#endregion
}
if (this.includePromoCodes)
{
#region Basket PromoCode
// Return Basket LineItems
CommerceQueryRelatedItem promoCodeQuery =
new CommerceQueryRelatedItem(Basket.RelationshipName.RequestedPromoCodes);
promoCodeQuery.Model.Properties = new CommercePropertyCollection();
relatedOperations.Add(promoCodeQuery);
#endregion
}
if (this.includeAddresses)
{
#region Basket Addresses
// Return Basket Addresses
CommerceQueryRelatedItem addressesQuery =
new CommerceQueryRelatedItem(Basket.RelationshipName.Addresses);
addressesQuery.Model.Properties = new CommercePropertyCollection();
addressesQuery.Model.Properties.Add(Address.PropertyName.Id);
addressesQuery.Model.Properties.Add(Address.PropertyName.AddressName);
addressesQuery.Model.Properties.Add(Address.PropertyName.Line1);
addressesQuery.Model.Properties.Add(Address.PropertyName.Line2);
addressesQuery.Model.Properties.Add(Address.PropertyName.City);
addressesQuery.Model.Properties.Add(Address.PropertyName.CountryRegionCode);
addressesQuery.Model.Properties.Add(Address.PropertyName.CountryRegionName);
addressesQuery.Model.Properties.Add(Address.PropertyName.StateProvinceCode);
addressesQuery.Model.Properties.Add(Address.PropertyName.StateProvinceName);
addressesQuery.Model.Properties.Add(Address.PropertyName.ZipPostalCode);
addressesQuery.Model.Properties.Add(Address.PropertyName.FirstName);
addressesQuery.Model.Properties.Add(Address.PropertyName.LastName);
addressesQuery.Model.Properties.Add(Address.PropertyName.PhoneNumber);
//<
addressesQuery.Model.Properties.Add(Address.PropertyName.ValidationIdentifier);
addressesQuery.Model.Properties.Add("ProfileAddressId");
relatedOperations.Add(addressesQuery);
#endregion
}
if (this.includePayments)
{
#region Basket Payments
// Return Basket Payments
CommerceQueryRelatedItem paymentsQuery =
new CommerceQueryRelatedItem(Basket.RelationshipName.Payments);
paymentsQuery.Model.Properties = new CommercePropertyCollection();
{
CommerceQueryRelatedItem creditcardQuery = new CommerceQueryRelatedItem(Payment.RelationshipName.PaymentAccount);
creditcardQuery.Model.Properties = new CommercePropertyCollection();
{
CommerceQueryRelatedItem paymentMethodQuery = new CommerceQueryRelatedItem(CreditCard.RelationshipName.PaymentMethod);
paymentMethodQuery.Model.Properties = new CommercePropertyCollection();
creditcardQuery.RelatedOperations.Add(paymentMethodQuery);
}
paymentsQuery.RelatedOperations.Add(creditcardQuery);
CommerceQueryRelatedItem chequeQuery = new CommerceQueryRelatedItem(Payment.RelationshipName.PaymentAccount);
chequeQuery.Model.Properties = new CommercePropertyCollection();
{
CommerceQueryRelatedItem paymentMethodQuery = new CommerceQueryRelatedItem("PaymentMethod");
paymentMethodQuery.Model.Properties = new CommercePropertyCollection();
chequeQuery.RelatedOperations.Add(paymentMethodQuery);
}
paymentsQuery.RelatedOperations.Add(chequeQuery);
CommerceQueryRelatedItem freeQuery = new CommerceQueryRelatedItem(Payment.RelationshipName.PaymentAccount);
freeQuery.Model.Properties = new CommercePropertyCollection();
{
CommerceQueryRelatedItem paymentMethodQuery = new CommerceQueryRelatedItem("PaymentMethod");
paymentMethodQuery.Model.Properties = new CommercePropertyCollection();
freeQuery.RelatedOperations.Add(paymentMethodQuery);
}
paymentsQuery.RelatedOperations.Add(freeQuery);
}
relatedOperations.Add(paymentsQuery);
#endregion
}
if (this.includeShipments)
{
#region Basket Shipments
// Return Basket Shipments
CommerceQueryRelatedItem shipmentsQuery =
new CommerceQueryRelatedItem(Basket.RelationshipName.Shipments);
shipmentsQuery.Model.Properties = new CommercePropertyCollection();
CommerceQueryRelatedItem shippingMethodQuery = new CommerceQueryRelatedItem(Shipment.RelationshipName.ShippingMethod);
shippingMethodQuery.Model.Properties = new CommercePropertyCollection();
shipmentsQuery.RelatedOperations.Add(shippingMethodQuery);
CommerceQueryRelatedItem discountQuery = new CommerceQueryRelatedItem(Shipment.RelationshipName.Discounts);
discountQuery.Model.Properties = new CommercePropertyCollection();
shipmentsQuery.RelatedOperations.Add(discountQuery);
relatedOperations.Add(shipmentsQuery);
#endregion
}
}
and
///
/// Adds the basket order submit request.
///
/// Name of the basket.
public void AddBasketOrderubmitRequest(string basketName)
{
CommerceUpdate> update = this.GetUpdateBasketBuilder(basketName);
update.UpdateOptions.ReturnModel.Properties.Add(Basket.PropertyName.OrderNumber);
update.UpdateOptions.ReturnModel.Properties.Add(Basket.PropertyName.BasketType);
update.UpdateOptions.ReturnModel.Properties.Add(Basket.PropertyName.OrderType);
update.UpdateOptions.ReturnModel.Properties.Add(CommerceEntity.PropertyName.Id);
string paymenttype = ((Payment)this.GetBasket(basketName).Payments[0].Target).PaymentAccount.Target.ModelName;
if (paymenttype == Free.ModelNameDefinition || paymenttype == Cheque.ModelNameDefinition)
{
update.Model.Status = BasketStatus.Ordered;
}
else
{
update.Model.Status = BasketStatus.ReadyForCheckout;
}
update.Model.BasketType = BasketType.Order;
update.Model.OrderType = SiteContext.Current.IsCSRLoggedIn ? (int)OrdersType.CSR : (int)OrdersType.Web;
}
12. Add Common\Contracts\CommerceEntities\Cheque.cs as follows:
namespace Microsoft.Commerce.Portal.Common
{
using Microsoft.Commerce.Contracts;
using System;
///
/// Represents the cheque payment.
///
public class Cheque : PaymentAccount
{
///
/// Defines the model name for this commerce entity
///
public new const string ModelNameDefinition = "Cheque";
///
/// Initializes a new instance of the class.
///
public Cheque()
: base(new CommerceEntity(Cheque.ModelNameDefinition))
{
}
///
/// Initializes a new instance of the class.
///
/// The commerce entity.
public Cheque(CommerceEntity commerceEntity)
: base(commerceEntity)
{
}
///
/// Gets or sets the credit card number.
///
/// The credit card number.
public string ChequeNumber
{
get { return this.CommerceEntity.GetPropertyValue(PropertyName.ChequeNumber) as string; }
set { this.CommerceEntity.SetPropertyValue(PropertyName.ChequeNumber, value); }
}
#region Implicit operators
///
/// Performs an implicit conversion from to .
///
/// The commerce entity.
/// The result of the conversion.
public static implicit operator Cheque(CommerceEntity commerceEntity)
{
System.Diagnostics.Debug.Assert(Cheque.ModelNameDefinition.Equals(commerceEntity.ModelName), "Unexpected model name");
return new Cheque(commerceEntity);
}
#endregion
///
/// Names of the properties exposed by this commerce entity.
///
public new class PropertyName : PaymentAccount.PropertyName
{
///
/// The name of the ChequeNumber property for a Cheque.
///
public const string ChequeNumber = "ChequeNumber";
}
}
}