Pages - Menu

Showing posts with label CyberSource. Show all posts
Showing posts with label CyberSource. Show all posts

Converting a DTD / XSD to strongly typed C# class

We are looking to implement some CyberSource Reporting functions that our system will be able to poll CyberSource for various reports, and call different actions base on the result. After going through the documentations, we know the CyberSource portals are providing us the DTD definitions.

Prerequisite

Implementation

Firstly we will need to download the DTD from the CyberSource portal.


We want to generate the strongly typed model class from the DTD definition, but we will need to convert this into XSD first. This can be done the XML Create Schema function via Visual Studio.



We are now able to generate the C# class by using the XSD.exe. It is available via the Visual Studio Developer Command Prompt.


The generated file will look something like this.


Troubleshooting

[System.InvalidOperationException]: {"<xxx xmlns='some_uri'> was not expected."}

During developments, we got an exception of "There is an error in XML document (0, 0)." and the inner exception is "<Report xmlns='https://ebctest.cybersource.com/ebctest/reports/dtd/cdr.dtd'> was not expected."

This is due to the DTD that we downloaded had a namespace of vendor's live site, therefore our strongly typed class has a name space of the live URI too. However when we are connected to their sandbox, throws an exception as the namespace didn't match.

One approach would be dynamically changing the namespace according to our connections, but I chose an easier way.

Firstly, I removed the namespace from the System.Xml.Serialization Xml Attributes in our generated strongly typed object class.



We will also need to remove the namespace from the incoming xml before we do any deserialization. This can be achieved by creating an extension method to recursively remove all namespaces from all nodes.
private ConversionDetailReport GetConversionDetailReport(string xmlString)
{
    var serializer = new XmlSerializer(typeof(ConversionDetailReport));

    var xDoc = XDocument.Parse(xmlString);

    var xr = xDoc.Root.RemoveAllNamespaces().CreateReader();

    return (ConversionDetailReport)serializer.Deserialize(xr);
}

Testing with CyberSource

I had some random issues about testing in CyberSource in the past. I asked their support a few questions, back and forth. These are already documented by CyberSource, but I found it easier to summerize them in one place.

Test Credit Card

I found this numbers from the DM_developer_guide_SCMP_API.pdf. This can be downloaded from their CyberSource Test Business Center.

American Express  3782 8224 6310 005
MasterCard 5555 5555 5555 4444
Visa 4111 1111 1111 1111

Test Total Amount

If the grand total amount is between $100 and 200, the system may or may not throw error as it is designed for testing different responses. I learnt this in a hard way.

http://www.cybersource.com/developers/getting_started/test_and_manage/simple_order_api/FDI_Australia/soapi_fdiaus_err.html

Test CVV

Similarly, CVV between 901 and 906 yield to different AuthReply response. By the look at the pattern, they might add more test cases later on, so I would avoid using anything > 900.

http://www.cybersource.com/developers/getting_started/test_and_manage/simple_order_api/FDI_Australia/soapi_fdiaus_cvv.html

nopCommerce - Schedule Task Plugin

Scope

Recently having issues with the integration with our payment gateway provider. Occasionally our synchronize call to their server will not get a response back.

We are to write a schedule function to run regularly. It will pull out a list of pending orders and re-run the authorize and capture.

We are:-
  • using nopCommerce 3.3
  • utilizing the nopCommerce Schedule Task
  • using plugin approach

Technical Overview

We are to use the Nop.Services.Tasks.Task and ScheduleTaskService to create a Nop Schedule Task that runs periodically.

Implementation

Task

Firstly create a new plugin. In our plugin, we will create a MyTask class that implements ITask.


The only method in the interface is Execute(). This is the place where we will put our calling codes. In this example, I am calling my own method QueryPendingOrders().

IoC

In my example, I am using a new service class, so I will need to register the service class via IoC in our plugin. A new DependencyRegistrar class will do the trick.


Install Schedule Task

Next, we need to create a schedule task for the task. This can be done by 
the overrides of Nop.Core.Plugins.BasePlugin, In the Install() of my plugin, we will call the following.


Calling Method

For the purpose of demonstration, I am just writing to the log.


Schedule

After installing the plugin, a new schedule task is created as follow. (I have changed the run period to 60 seconds for demo)


Log

Let it run for a few minutes and check the log. It seems quite spot on that it is called every 60 seconds.


Conclusion

There was not much work involved to create a schedule task. All the magic are already done and made available for us from the nopCommerce.

During development, I noticed the TaskManager utilize singleton pattern. It is then responsible to instantiate the instances for the TaskThread. The task threads will run continuously and kick off the Execute() periodically. 

One thing I wanted to do is to compare the performance between Nop Schedule Task vs SQL Server Agent Job. I have a feeling that the sql job may run a little faster as the nop task thread is not a push notification, but simply a continuous running thread.


CyberSource - Login Screen Keep Alive Trick

During development, found a bit frustrated with my CyberSource get timed out too quickly due to their PCI compliance and made me a little unproductive, so I managed to find a little trick to keep my login session alive.

Open the Order Status Notification page with Test Url button. If you know your session timed out, click on the Test Url once before you navigate somewhere else, this little trick actually help generate an "activity" within CyberSource, then you now have an active session again.

Good for developers during development without the hassles of logging in and out where test data are not sensitive information. Not recommended for live environment though.


They maybe fixing this in the future, and I am definitely not reporting this bug to CyberSource for my selfishness. :)

My first nopCommerce website gone Live!!

nopCommerce

After spending 6 months with this open source nopCommerce platform. My first nopCommerce website finally went live. http://www.thenorthface.com.au 

Scope

Our business requirement in a nut shell:-
  • Build a multi tenant e-commerce platform to cater all of our brands.
  • All our brand sites are independent to each others in terms of development requirements or target audience. Only the main workflow is the same.
  • We have multiple integration points that we need to interact with. (Not surprise!!)
  • The first brand is The North Face

Challenges

  • 6 Integration Points
    • CRM (Customer Information)
    • CMS
    • Payment Gateway (CyberSource)
    • Promotions / Product Price (1 way coming in from other integration point)
    • Inventory System
    • Product Reviews
  • 2 Console Apps
    • Bulk Image Upload
    • Inventory System / Price

Thoughts of nopCommerce


Likes

  • Open Source
  • MVC
  • Easy to learn
  • The source code is fairly solid and clean. There were likes and hates, but I am generally happy.
  • Plugins readily available to purchase or easy to build your own
  • Payment workflow is rock solid and easy to integrate with (I am using CyberSource)
  • Multi-tenancy semi-friendly
  • Multi-store ready
  • Admin interface out of the box is nice and professional enough
  • Good support from the official forum

Dislikes

  • There is no Controller Factory in their MVC architecture. I kind of expected that for a "platform"
  • Telerick MVC for admin (but they are now using Kendo UI in v3.3, which is good now)
  • Easy to customize? This is an arguable point. Surely it wasn't hard but could be easier. As a platform, I would like to see the core code set to protected/virtual (to allow custom code override) and more hooks (empty protected class) in the core controllers.

The North Face Australia

A quick comparison of old and new site. Which one do you like more?

Level 1 (Root) Category 

 


L: The level 1 category is a little messy. At the root level, it shows everything from all the child categories.
R: The level 1 category shows featured products of level 2 categories, this is now organized in a systematic way that allow administrator to decide what to show. 

Level 2 (Children) Sub-Category 

 


Color variants of the same product no longer clogging up space. 
We can now show more variety of products on category page.

Category Page - Filter

 


Color filters now more colorful than ever!!

Product Detail Page

 


Customer can choose different color on product detail page.

Shopping Cart

 


Demo

Not too bad? Why not try it out yourself? It may change your decision making should you need to choose an ecommerce platform next time. Definitely recommended.

CyberSource - The Magic Line(s) for Authorize and Capture

Scope


Working on integration with the CyberSource payment gateway that does direct payment (non-hosted option) on our online shop. Using the latest API version 1.93 as of today the article is written, and I followed their instructions and created a SOAP based WCF to connect to their Test Business Center (sandbox).

Problem


I followed copied their sample code, fiddle around to get it compile and submit the transaction with no error.

However, when I login to the test center, I only get authorize but not capture.

auth

(Authorize and Capture is explained in the CyberSource KB.)

Try to search around and finally find this pdf file. On page 176, it clearly explained on how to "request a sale". However, don't get so excited yet, it doesn't work if you just copy and paste the code. That's because they mix the documentations between their old Simple Order API Call and the SOAP API Call.

The 2 magic lines you need to get capture working (and authorize at the same time, essentially we are doing sale) as follow.

magic

Run the code and back to our sandbox, it is now trying to authorize and capture in the same transaction. Notice the green means successful, the red authorization in 2nd row stopped the transaction to proceed for capture, therefore it is neither red nor green color.

sale

Conclusion


It was a no brainer to work out the magic line(s) for the problem if you read the sample code carefully. I only wishful thinking that they would have put these 2 magic lines in the given sample code but I had my fun on a bit of code hunting and reading documentations today. Surely a better understanding of the CyberSource Payment Gateway.