Get your PayPal account balance with the PayPal SOAP API using the Web interface

  09 October 2013       This post has 0 comment       By Mikaël DELSOL

This first blog post about how to use the web interface and what is to be used is certainly the most exciting among a future series of blog posts on this feature. What we want to show you is that it is very simple and intuitive. As we promised, you don't have to know anything about programming and writing code.

A simple case: get your PayPal account balance

To get your account balance, you need to call the GetBalance operation. This operation is located in the Get service class named PayPalServiceGet. When calling this operation, you'll get the amount available on your account. If you have multiple currencies, you will be able to get your account balance either in only one currency or in each currency.

You can also read the the official PayPal GetBalance SOAP operation.

First step: load the GetBalance definition

To set the GetBalance call, open the PayPalServiceGet folder. This folder represents the PayPalServiceGet class which contains multiple methods. Each method corresponds to a PayPal SOAP API operation.

PayPal SOAP API Get operations - WSDL to php

If you don't already know, all these operations are gathered within this class because their name starts with the string Get.

Now click on the GetBalance name identified with the icon An operation, a service - WSDL to php and wait for the operation to be fully loaded. During the loading, the previous icon is replaced by the icon Loading - WSDL to php wich then comes back to the original when all is loaded.

You should then see this interface:

PayPal SOAP API Intuitive Interface - WSDL to php

Second step: set the Web service location

As the operation is not critical for your account integrity - because it only gets your account balance - we are going to set the Web service location to the production environment. Indeed, PayPal provides multiple Web service locations depending on your development process and the protocol you use to call the Web service (SOAP or REST). In our case, the location is then the production environment: https://api-3t.paypal.com/2.0/.

In the interface, edit the Web service location field in the SOAP options part as:

PayPal SOAP Options: Web Service location - WSDL to php

If you wish, you can find Acces to all PayPal API endpoints.

Third step: set the credentials

When you call a PayPal SOAP API operation, you have to send a header in order to be identified. When a header is required, a doc block is defined for the generated method. In our case, the GetBalance operation requires a header named RequesterCredentials in the namespace urn:ebay:api:PayPalAPI. The value of the header must be a PayPalStructCustomSecurityHeaderType object. We use the signature authentication method. To get your signature credentials (username, password, signature), you have to go to your PayPal account and get your API access.

The Web interface detects this required header and load autmatically the header definition part in order to help you define it. If there are several headers it will load each required header. Moreover, you'll see that known informations are automatically used to fill the fields such as the Namespace, the Name and the Data fields (it uses the generated doc block associated to the method in order to detect this type of informations). In this case, you only have to edit the header value which means you have to load the PayPalStructUserIdPasswordType definition by clicking the button and wait until Loading - WSDL to php disapears (indicates that the element definiton is being loaded). You should then see this interface:

PayPal SOAP API Credentials - WSDL to php

Then fill the fields:

  • Username: with your PayPal API access username
  • Password: with your PayPal API access password
  • Signature: with your PayPal API access signature

And that's it for the credentials!

If you want to fully understand this method, please refer to the native SoapClient::__setSoapheaders() method and the native SoapHeader class.

Last step: call the GetBalance operation

In order to set the operation parameters, load the PayPalStructGetBalanceRequestType definition by clicking its associated button and fill the Version field with the value 98.0 (the latest available version of the PayPal API, indicated in the ns:version attribute of the WSDL definitions root tag, may be modified since this article has been written). Do as below:

PayPal SOAP API Parameters - WSDL to php

At this step, you can click the Send request button to get your PayPal account balance in all your avaible account currencies. If you wish to have your PayPal account balance in your main currency only, fill the ReturnAllCurrencies field with the value 0 and send the request again.

As soon as the request ends, you'll get many informations:

  • the sent request details:
    • the HTTP header: returned by calling the PayPalWsdlClass::getSoapClient()->__getLastRequestHeaders() method
    • the SOAP header: the data that has been sent has header in the SOAP request
    • the XML content: the SOAP XML request returned by calling the PayPayWsdlClass->getLastRequest() method
    • the generated PHP used: an export of the generated PHP object used to send the request
  • the response details:
    • the HTTP header: returned by calling the PayPalWsdlClass::getSoapClient()->__getLastResponseHeaders() method
    • the XML content: the SOAP XML response returned by calling the PayPayWsdlClass->getLastResponse() method
    • the PHP content: an export of the generated PHP objects thanks to the classmap definition

See below what you should get displayed:

PayPal SOAP API Requests and Responses - WSDL to php

Conclusion

As you can see, getting your account balance is pretty trivial and quick. We saw that each value is OOP and that responses are entirely returned as objetcs so we can easily manipulate them. The generated classes aim to ease the communication with SOAP Web services at each step. If you have any question, feel free to send me comments on this topic. Now, you can easily call any other PayPal API operation by following this methodology.

If you wish to do it programmatically, read the dedicated article to get your PayPal account balance with the generated package.