Reading Time: 5 minutes

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 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 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:

latest report
Learn why we are the Leaders in API management and iPaaS

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:

This inbound AJAX endpoint allows for us to listen to all publish requests sent to the “/payments” channel. This also includes RPC requests made by the client which we will be using in this example. Now lets switch gears and take a look at how we send data to this inbound endpoint from the client-side JavaScript:

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.