Namespace
PayPal Connector
Community
Release Notes: PayPal Anypoint Connector Release Notes
The PayPal Connector facilitates connections between Mule integration and PayPal. The PayPal Connector v3.0 supports the PayPal operations described in https://developer.paypal.com/docs/classic/api/. The connector currently supports Signature API credential type of authentication.
PayPal is a service that enables you to pay, send money, and accept payments without revealing your financial information. Simply click the PayPal checkout button, log in to your PayPal account, and select your preferred payment method. Mule completes the payment process—without sharing your info with merchants and sellers.
Before You Begin
This document assumes you are familiar with Mule, Anypoint Connectors and Anypoint Studio Essentials. Review Elements in a Mule Flow and Global Elements if you are unfamiliar with these topics.
This document describes implementation examples within the context of Anypoint Studio, Mule’s graphical user interface, and includes configuration details for configuring using the XML Editor.
Installing and Configuring
You can install a connector in Anypoint Studio from Anypoint Exchange.
Updating From an Older Version
Each time an updated version of a connector is released, Anypoint studio displays a popup in the bottom right corner of you screen with the following message: Updates Available.
To upgrade to the newest version of the PayPal connector:
-
Click the popup and check for the available updates.
-
Select the PayPal Connector 3.0 check-box and click Next.
-
Follow the instructions provided by the user interface.
-
Restart Studio when prompted. After restarting, if you have several versions of the connector installed, Mule asks you for the version of the connector you like to use.
Creating a New Project
To use the PayPal connector in a Mule application project:
-
In Studio, select File > New > Mule Project.
-
Enter a name for your new project and leave the remaining options with their default values.
-
If you plan to use Git, select Create a .gitignore file for the project with default ignores for Studio Projects, and then click Next.
-
Click Finish to create the project.
Configuring the PayPal Connector Global Element
To use the PayPal Connector in your Mule application, you must configure a global PayPal element that can be used by all the PayPal connectors in the application (read more about global elements).
PayPal SOAP API relies on the authentication information being passed using SOAP headers as part of SOAP messages. The configuration supports Signature API credentials style SOAP headers. For more details on different types of authentication mechanism in PayPal please refer to PayPal Credentials.
To create a global PayPal configuration:
-
Click the Global Elements tab at the base of the canvas.
-
On the Global Mule Configuration Elements screen, click Create.
-
In the Choose Global Type wizard, expand Connector Configuration, and select PayPal Connector: configuration (Signature).
-
Click OK.
-
Enter the global element properties:
-
For PayPal Connector: Configuration:
Field Description Name
Alphanumeric text string that uniquely identifies the user who owns the account
Username
Key that plays the role of a username
Password
Key that plays the role of a password
Service Address
PayPal endpoint reference. Refer to this for PayPal endpoints.
Signature
API Signature given by PayPal for this username
App Id
PayPal Application ID.
The placeholder values refer to a configuration file placed in the src folder of your project. Learn how to configure properties. You can either enter your credentials into the global configuration properties, or reference a configuration file that contains these values. For simpler maintenance and better re-usability of your project, Mule recommends that you use a configuration file. Keeping these values in a separate file is useful if you need to deploy to different environments, such as production, development, and QA, where your access credentials differ. See Deploying to Multiple Environments for instructions on how to manage this.
-
-
Click Validate Config to confirm that the parameters of your global configuration are accurate, and that Mule is able to successfully connect to PayPal.
-
Click OK to save the global connector configurations.
Using the Connector
The PayPal Connector v3.0 is an operation-based connector, which means that when you add the connector to your flow, you need to configure a specific operation (Invoke operation) for the connector to perform. The XML element for the Invoke operation is:
<paypal:invoke>
After you call the Invoke operation, you can use the Service and Operation fields to select a method to execute. The PayPal connector v3.0 allows you to use all the SOAP API’s exposed by PayPal WSDL file.
Use Cases
The following are a few common use case for the PayPal Connector v5.0:
-
Read balance for the PayPal Account
-
Accept payments from merchants
-
Accept bulk payments
Refer to PayPal API reference for the possible use cases.
Adding the PayPal Connector to a Flow
-
Create a new Mule project in Anypoint Studio.
-
Drag the PayPal connector onto the canvas, then select it to open the properties editor.
-
Configure the connector’s parameters:
Field Description Display Name
Enter a unique label for the connector
Connector Configuration
Select a global PayPal connector element from the drop-down.
Operation
Invoke.
Service
Select a Service from the drop-down.
Operation
Select the operation to perform on the table your select.
-
Click the blank space on the canvas to save your connector configurations.
Example Use Case
Create a Mule flow to get the balance from a PayPal account.
-
Create a Mule Project in your Anypoint Studio.
-
Drag an HTTP connector onto the canvas.
-
Click the green plus symbol for Connector Configuration.
-
Set the Host to localhost and the Port to 8081 and leave the default values for all other fields
-
Reference the HTTP Listener Configuration global element and set the path to */getbalance:
-
Drag the PayPal Connector v3.0 into the flow.
-
Click the plus sign next to the Connector Configuration field.
-
Click Validate Config to confirm that Mule can connect with PayPal. If the connection is successful, click OK to save the configurations of the global element. If unsuccessful, revise or correct any incorrect parameters, then test again.
-
Back in the properties editor of the PayPal Connector v3.0, configure the remaining parameters:
-
Drag a DataWeave Transform Message component between the HTTP connector and the PayPal Connector v3.0.
%dw 1.0 %output application/xml %namespace ns0 urn:ebay:api:PayPalAPI %namespace ns1 urn:ebay:apis:eBLBaseComponents --- { ns0#GetBalanceReq: { ns0#GetBalanceRequest: { ns1#Version: inboundProperties.'http.query.params'.version } } }
-
Add a Logger component between the DataWeave and PayPal Connector component to log the payload.
-
Add another Logger component after the PayPal connector component to log the response.
-
Add a XML to JSON transformer.
-
Save and run the project as a Mule Application.
-
From a browser, navigate to http://localhost:8081/paypal/getbalance?version=51.
-
Mule performs the query to get the current balance in the PayPal account associated with the user defined in the global element.
Example Code
For this code to work in Anypoint Studio, you must provide the credentials for the PayPal account. You can either replace the variables with their values in the code, or you can add a file named mule.properties in the src/main/resources folder to provide the values for each variable.
<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:paypal="http://www.mulesoft.org/schema/mule/paypal" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/paypal http://www.mulesoft.org/schema/mule/paypal/current/mule-paypal.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="paypal" doc:name="HTTP Listener Configuration"/>
<paypal:config name="PayPal_Connector__configuration__Signature_" username="${config.username}" password="${config.password}" serviceAddress="${config.serviceAddress}" signature="${config.signature}" appId="${config.appId}" doc:name="PayPal Connector: configuration (Signature)"/>
<flow name="paypal-operations-form-flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<parse-template location="paypal-operations-demo.html" doc:name="Parse Template"/>
<set-property propertyName="Content-Type" value="text/html" doc:name="Property"/>
</flow>
<flow name="getbalance-flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/getbalance" doc:name="/getbalance"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 urn:ebay:api:PayPalAPI
%namespace ns1 urn:ebay:apis:eBLBaseComponents
---
{
ns0#GetBalanceReq: {
ns0#GetBalanceRequest: {
ns1#Version: inboundProperties.'http.query.params'.version
}
}
}]]></dw:set-payload>
</dw:transform-message>
<logger message="Before -- #[payload]" level="INFO" doc:name="Logger"/>
<paypal:invoke config-ref="PayPal_Connector__configuration__Signature_" type="PayPalAPI||GetBalance" doc:name="PayPal Connector Get Balance"/>
<logger message="After -- #[payload]" level="INFO" doc:name="Logger"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
</flow>
<flow name="getpaldetails-flow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/getpaldetails" doc:name="/getpaldetails"/>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 urn:ebay:api:PayPalAPI
%namespace ns1 urn:ebay:apis:eBLBaseComponents
---
{
ns0#GetPalDetailsReq: {
ns0#GetPalDetailsRequest: {
ns1#Version: inboundProperties.'http.query.params'.version
}
}
}]]></dw:set-payload>
</dw:transform-message>
<paypal:invoke config-ref="PayPal_Connector__configuration__Signature_" type="PayPalAPI||GetPalDetails" doc:name="PayPal Connector Get Pal Details"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
</flow>
</mule>