Integrating with 6.2 TPC Ecommerce 

 

Extending or Building Custom Providers

The TPC Checkout widget has been designed to allow most components to be overwritten/extended. The main extensible components are listed below:

ITpcPaymentProvider – This interface represents the  class responsible for interacting with a specific payment provider, processing a payment transaction, validating it, and generating the view specific to a payment provider. This interface requires a custom configuration type to be provided as a generic argument.

ITpcPaymentLogicProvider – This interface represents the class responsible for the way a payment interacts with Dynamics CRM. It is used to decouple the business logic from any specific payment processor. It is used to dispatch events, update entities in CRM, and dispatch workflows. This interface does not require a configuration type.

ITpcTaxProvider – This interface represents the class responsible for applying taxes to an order.  This interface requires a custom configuration type to be provided as a generic argument.

ITpcShippingProvider – This interface represents the class responsible for how shipping quotes are generated and how shipping is processed after the payment is complete. This interface requires a configuration type to be provided as a generic argument.

 

Registering a Custom Provider

 

To create your own provider to extend the TPC Checkout widget, you will need to register the provider /configuration. The first step in registering the custom provider/configuration is to create a NinjectModule that will bind the dependencies. You can call the file  InterfaceMappings.cs. Below is a sample of what this will look like.

 

/// < summary>

/// This class is used to describe the bindings which will be used by the Ninject container when resolving ecommerce classes

/// </ summary>

public  class InterfaceMappings  : NinjectModule

{

/// < summary>

/// Loads the module into the kernel.

/// </ summary>

public  override void  Load( )

{

//Get System Configuration

ConfigManager  manager =  ConfigManager.GetManager ();

SystemConfig  systemConfig = manager .GetSection< SystemConfig>();

 

//Bind Payment Provider/Configuration Example

Bind< ITpcPaymentProviderConfiguration>().To <SylogistPayPaymentProviderConfiguration>(). InTransientScope().WithConstructorArgument ("parent " systemConfig);

Bind< ITpcPaymentProvider>().To <SylogistPayPaymentProvider>(). InTransientScope();

 

//Bind Payment Logic Provider Example

Bind< ITpcPaymentLogicProvider>().To <DefaultPaymentLogicProvider>(). InTransientScope();

 

//Bind Shipping Provider/Configuration Example

Bind< ITpcShippingProviderConfiguration>().To <PickupShippingProviderConfiguration>(). InTransientScope().WithConstructorArgument ("parent " systemConfig);

Bind< ITpcShippingProvider>().To <PickupShippingProvider>(). InTransientScope();

//Bind Tax Provider/Configuration Example

Bind< ITpcTaxProviderConfiguration>().To <FlatTaxProviderConfiguration>(). InTransientScope().WithConstructorArgument ("parent " systemConfig);

Bind< ITpcTaxProvider>().To <FlatTaxProvider>(). InTransientScope();

 

// you haven't created the DemoEcommerceAdminAppInitializer yet, but more on this later

Bind<ITpcAdminAppSitefinityInitializer>().To<DemoEcommerceAdminAppInitializer>().InSingletonScope();

}

}

 

 

If you are registering an extension to an element that requires a configuration such as the ITpcPaymentProvider, ITpcTaxProvider, or ITpcShippingProvider, there are 2 additional steps to finish registering the classes. Both steps can be completed by inheriting from the TpcAdminAppSitefinityInitializer class. You will also need to register your custom initializer using dependency injection like we did in the previous step. Below is an example of DemoEcommerceAdminAppInitializer.cs. The ImplementationTypeMappings method is required to be overridden as it will allow Sitefinity to work with the dynamic configurations you create for your custom providers. The method InitializeConfigurations can also be used if you want to register a default empty configuration for your dynamic configuration types.

 


public  DemoEcommerceAdminAppInitializer(: TpcAdminAppSitefinityInitializer

{

ModuleName  = PortalConnectorMvcEcommerceModule. ModuleName;

Order =  3;

}

 

/// < summary>

/// This method is used to add the implementation type mappings for  Ecomm Configuration Elements

/// </ summary>

/// < returns>Type Mappings </returns>

public  override Tuple <Type Type>[ImplementationTypeMappings ()

{

return  new Tuple <Type Type>[]

{

//Payment Example

Tuple .Create typeof(SylogistPayPaymentProviderConfiguration ), typeof( ITpcPaymentProviderConfiguration)),

//Shipping Example

Tuple .Create ( typeof(PickupShippingProviderConfiguration ), typeof( ITpcShippingProviderConfiguration)),

//Taxes Example

Tuple .Create ( typeof(FlatTaxProviderConfiguration ), typeof( ITpcTaxProviderConfiguration))

};

}

 

/// < summary>

/// This method is used to initialize configuration logic for  Ecomm Configuration Elements.

/// </ summary>

public  override void  InitializeConfigurations( )

{

try

{

bool  saveChanges = false ;

 

//Get Configurations Manager

ConfigManager  configManager =  ConfigManager.GetManager ();

PortalConnectorMvcEcommerceConfig  config =  configManager.GetSection <PortalConnectorMvcEcommerceConfig>( );

 

//Add Default Tax Configuration(s)

AddDefaultToConfigElementDictionary <TpcTaxProviderConfiguration FlatTaxProviderConfigurationFlatTaxProvider >(config. TaxProvidersref  saveChanges);

 

//Add Default Shipping Configurations(s)

AddDefaultToConfigElementDictionary <TpcShippingProviderConfiguration PickupShippingProviderConfigurationPickupShippingProvider >(config. ShippingProvidersref  saveChanges);

 

//Add Default Payment Configurations(s)

AddDefaultToConfigElementDictionary <TpcPaymentProviderConfiguration SylogistPayPaymentProviderConfigurationSylogistPayPaymentProvider >(config. PaymentProvidersref  saveChanges);

 

//Save Changes

if ( saveChangesconfigManager .SaveSection( config);

}

catch ( Exception ex )

{

ExceptionManager .HandleError( "Initialize Ecommerce Configurations "ex );

}

}

}

 

The last step is to add the binding to the Ninject Module we created earlier. Once this has been completed, your custom provider and configurations should be registered correctly with The Portal Connector, and the TPC Checkout widget should show your new providers as options within the configuration backend. You can navigate to  Sitefinity > Administration > Configurations > Advanced > PortalConnectorMvcEcommerce if you would like to add or modify existing provider configurations.

ITpcPaymentProvider

When creating your own ITpcPaymentLogicProvider  you have 2 options. You can create one from scratch by creating a class that implements ITpcPaymentLogicProvider , or you can extend the class DefaultPaymentLogicProvider  if you only need to overwrite select functionality.  ITpcPaymentLogicProvider implements the following methods:

 

ITpcLogicInterface  PrePaymentInput get ; }

 

ITpcLogicInterface  PostPaymentInput get ; }

 

TpcPaymentEntity GetProducts (ITpcPaymentTransaction   transaction);

 

TpcPaymentEntity CreatePrePaymentEntities (ITpcPaymentTransaction   transaction);

 

void DispatchPrePaymentEvent (ITpcPaymentTransaction   transaction);

 

TpcPaymentEntity C reatePostPaymentEntities (I TpcPaymentTransaction  transaction );

 

void DispatchPostPaymentEvent (ITpcPaymentTransaction   transaction);

 

void SavePrePaymentEntities (ITpcPaymentTransaction   transaction);

 

void SavePostPaymentEntities (ITpcPaymentTransaction   transaction);

 

Whenever extending Payment Provider, please make sure to assign PaymentViewPath and TransactionType. Payment Provider will have its own View which will have a Pay Button to send the request to payment provider. Create a View for the payment provider you want to integrate with and assign the property “PaymentViewPath” with the View path you create.

 

For e.g.

Currently we are supporting 4 Payment Processing requests:

  1. ExecutePostPayment - This function is used to execute post payment for javascript API payment providers.

  2. PaymentPost - This function is used to return from a payment provider that sends a POST request after the transaction is complete.

  3. PaymentGet - This function is used to return from a payment provider that sends a GET request after the transaction is complete.

  4. ExecutePayment - This function is used to execute payment for server-side processing payment providers. This requires PCI compliance.

 

 

When the Transaction is complete, it needs to make an ajax request to any of the above methods to process the transaction from your view.

 

 

ITpcTaxProvider

 

When creating your own ITpcTaxProvider  you have 2 options. You can create one from scratch by creating a class that implements ITpcTaxProvider , or you can extend an existing provider if you only need to overwrite select functionality. The  ITpcTaxProvider  implements the following methods:

 

IList< ITpcTaxInformation GetTaxes (ITpcPaymentTransaction   transaction);

 

The custom tax provider configuration needs to extend the  TpcTaxProviderConfiguration  class. It can be extended to include any additional properties you would like to set as part of your custom tax provider configuration.

 

 

ITpcShippingProvider

 

When creating your own ITpcShippingProvider  you have 2 options. You can create one from scratch by creating a class that implements ITpcShippingProvider , or you can extend an existing provider if you only need to overwrite select functionality. The  ITpcShippingProvider  implements the following methods:

 

ITpcShippingInformation  ProcessShippingRequest(ITpcPaymentTransaction  transaction );

 

ITpcShippingQuoteInformation[ GenerateShippingQuotes( ITpcContactDetails contactDetails ITpcShippingDetails   shippingDetailsITpcCartDetails  cartDetails );

 

 

The custom shipping provider configuration needs to extend the TpcShippingProviderConfiguration  class. It can be extended to include any additional properties you would like to set as part of your custom shipping provider configuration.