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.

3 comments:

Wes said...

Does this work? I get an Application Exception telling me to Set GoogleMerchantID in web.config when I handle the click and set up the request. It doesn't seem to use the new config section.

Joe Feser said...

Did you set up both parts in the web.config file.

You need to set up the config section itself. If it is not found, it will default to the app keys and not use the section.

The second thing that must be done is you must have the "Google" section, which is the config section itself.

Both parts are required.

Wes said...

Right. I had it configured correctly.

The problem was a config permission exception. I have the site configured for Medium trust.

The solution, in case it comes up again, is to add requirePermission="false" to the section handler configuration:

section name="GoogleCheckout" type="GCheckout.Util.GCheckoutConfigHandler,GCheckout" requirePermission="false"