Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

PayPal Anypoint Connector

Community

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.

Prerequisites

This document assumes you are familiar with Mule, Anypoint Connectors and Anypoint Studio Essentials. To increase your familiarity with Studio, consider completing the Anypoint Connector quickstart. See also Elements in a Mule Flow and Global Elements.

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.

Compatibility Matrix

Application/Service Version

Mule Runtime

3.7.0 and later

PayPal

Classic SOAP API ver 2.0

Namespace and Schema

Item Description

Namespace

Schema Location

Schema Version

1.0

Installing and Configuring

You can install a connector in Anypoint Studio using the instructions in Installing a Connector 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:

  1. Click the popup and check for the available updates.

  2. Select the PayPal Connector 3.0 check-box and click Next.

  3. Follow the instructions provided by the user interface.

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

  1. In Studio, select File > NewMule Project:

    ppc_filenew

  2. Enter a name for your new project and leave the remaining options with their default values.

    ppc_project_settings

  3. If you plan to use Git, select Create a .gitignore file for the project with default ignores for Studio Projects, and then click Next.

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

  1. Click the Global Elements tab at the base of the canvas.

  2. On the Global Mule Configuration Elements screen, click Create.

  3. In the Choose Global Type wizard, expand Connector Configuration, and select PayPal Connector: configuration (Signature).

    ppc_choose_global_type

  4. Click OK.

  5. Enter the global element properties:

    ppc_global_element_properties 

    1. 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.

  6. Click Validate Config to confirm that the parameters of your global configuration are accurate, and that Mule is able to successfully connect to PayPal. Read more about Testing Connections.

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


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

  1. Create a new Mule project in Anypoint Studio.

  2. Drag the PayPal connector onto the canvas, then select it to open the properties editor.

  3. Configure the connector’s parameters:

    ppc_GetBalanceExample

    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.

  4. 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.

  1. Create a Mule Project in your Anypoint Studio.

  2. Drag an HTTP connector onto the canvas.

  3. Click the green plus symbol for Connector Configuration.

  4. Set the Host to localhost and the Port to 8081 and leave the default values for all other fields

    ppchttp

  5. Reference the HTTP Listener Configuration global element and set the path to */getbalance:

    ppc_setpath

  6. Drag the PayPal Connector v3.0 into the flow.

    ppcflow

  7. Click the plus sign next to the Connector Configuration field.

  8. 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.

  9. Back in the properties editor of the PayPal Connector v3.0, configure the remaining parameters:

    ppc_GetBalanceExample

  10. Drag a DataWeave Transform Message component between the HTTP connector and the PayPal Connector v3.0.

    DataWeaveExample

    %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
            }
        }
    }
  11. Add a Logger component between the DataWeave and PayPal Connector component to log the payload.

  12. Add another Logger component after the PayPal connector component to log the response.

  13. Add a XML to JSON transformer.

    ppcflow2

  14. Save and run the project as a Mule Application.

  15. From a browser, navigate to http://localhost:8081/paypal/getbalance?version=51.

  16. 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.


          
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<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" version="EE-3.7.0"
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>

See Also