Sunday, April 1, 2007

Using Config Sections with Google Checkout

**Note, this blog entry is now located here**

Up until now, a common issue with the .NET implementation of Google Checkout was forgetting to change the MerchantID and MerchantKey while changing environments. Many requests were made to allow merchants to have both the Sandbox and Productions configuration data in the config file. Adding additional appSettings keys was one posible solution, along with creating a configuration section.

Today I just finished adding Google Checkout configuration section support to the open source code available at http://code.google.com/p/google-checkout-dotnet-sample-code/source.

The config section was designed to handle all of the current keys, performs the required validation against those keys and enables us to place all the config setting logic into one helper class.

Below is a sample of the config section for the new GCheckoutConfigurationHandler. Every property in the GCheckoutConfigSection class is represented as an attribute on the GoogleCheckout node.




One of the benifits of using a common helper classes for configuration data is the ability to return context sensitive results based on the Environment. When the Environment is set to Sandbox, the SandboxMerchantID is returned with the MerchantID property is called. Once the Environment is set to Production, the ProductionMerchantID is returned for the same MerchantID property. No longer will you need to write conditional code based on the Environment.



Over the next few weeks we will be adding overloaded methods to the project to simplify the calling of constructors and methods requiring the MerchantID, MerchantKey, and Environment.

The new Config section will allow us to simplify the class below by only requiring the OrderID, and MerchantOrderNo.




If you have any questions or ideas on how to improve the project, feel free to post to the group located at http://groups.google.com/group/google-checkout-api-dotnet/topics.