Millions of online transactions occur every day in the purchasing of goods and services. With each transaction a number of systems are involved. First some form of payment must be processed. Next the customer information is captured which must end up in a CRM system. Then the order for goods must be fulfilled by notifying the fulfillment system or by alerting a specific department to the order. Each step in the process is normally handled by a separate system with its own set of APIs and data model. This type of integration is something that Mule eats up!
The example I’m going to use is the Mule Store which can be found in MuleSoft’s public github repository. In the Mule Store example the customer is prompted to pick a Mule, fill out their information along with payment information which is sent to Mule using the AJAX endpoint. The example uses Mule Payment Services and if the payment information is valid then the customer information is entered into SalesForce using the SalesForce Cloud Connector along with an email that is created to notify the order department of the order. So lets start by looking at the configuration needed to setup all the connections:
The first item to be configured is the AJAX transport. Here we are specifying that we are using AJAX over HTTPS so we need to have a keystore configured for SSL encryption. A new keystore is easy to create using the keytool utility provided by Java. Next we configure our connection to Authorize.NET, SalesForce and lastly to GMail for sending of messages.
Now we are ready to start on the flow. Lets take a look at how we will define the inbound endpoint and how it will be called:
Here making the request to Mule is as simple as making a call to mule.rpc(channel, payload, callback). At this point our Mule flow will be executed and once completed will call the callback function specified. In this callback function we can easily access the message or the data associated with the message at message.data. Note that the ‘mule.rpc’ call sets up a private, once-only reply channel from the server to the client, once a message is received on the reply channel, the callback is invoked and the reply channel is removed.
Now that we are ready for the real work to begin we’ll take a break and pick this back up in the next iteration where we will cover the rest of the flow and how to handle any exceptions that might occur while processing the order.