Paypal API calls on behalf of a third party

980 Views Asked by At

I can't find how to make API call with PayPal SDK on behalf of a third party . I found this https://developer.paypal.com/docs/classic/permissions-service/integration-guide/PermissionsAbout/ and this PayPal Permissions API, but I did'n see any methods in Paypal permissions-sdk-php or rest-api-sdk-php to do that. Does anybody know how make API call with user access token?

1

There are 1 best solutions below

4
On

I was actually asking the same question. But I finally found the answer by looking at sample code on the JAVA SDK here.

Since I am using PHP on my code I need to simply convert it like below:

use PayPal\Auth\IPPThirdPartyAuthorization;
use PayPal\Auth\PPSignatureCredential;
use PayPal\Auth\PPTokenAuthorization;

require 'vendor/autoload.php';

$requestEnvelope = new RequestEnvelope("en_US");
$attributeList = new PersonalAttributeList();
$attributeList->attribute = array(
    'http://axschema.org/namePerson/first',
    'http://axschema.org/namePerson/last',
    'http://axschema.org/contact/email',
    'http://axschema.org/contact/fullname',
    'http://openid.net/schema/company/name',
    'http://axschema.org/contact/country/home',
    'https://www.paypal.com/webapps/auth/schema/payerID'
);

$request = new GetBasicPersonalDataRequest( $attributeList );
$request->requestEnvelope = $requestEnvelope;

$apiCredential = null;
if ( ! empty( $data['token'] ) && ! empty( $data['tokenSecret'] ) ) {
    $thirdPartyAuth = new PPTokenAuthorization( $data['token'], $data['tokenSecret'] );
    $apiCredential = new PPSignatureCredential( 'jb-us-seller_api1.paypal.com', 
        'WX4WTU3S8MY44S7F', 'AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu' );

    $apiCredential->setApplicationId( 'APP-80W284485P519543T' );
    $apiCredential->setThirdPartyAuthorization( $thirdPartyAuth );
}

$service = new PermissionsService( $config );
try {

    /*
     *  ## Making API call
    Invoke the appropriate method corresponding to API in service
    wrapper object
    */
    if ( $apiCredential != null )
        $response = $service->GetBasicPersonalData( $request, $apiCredential );
    else 
        $response = $service->GetBasicPersonalData( $request );

    return $response;
} catch (Exception $ex) {}

I hope this helps everyone having the same issue.

EDIT 1:

Thanks @Alex for pointing this out. For the classes under namespace PayPal\Auth please include PayPal SDK Core that you can get here. If you use composer to use the PayPal Adaptive SDK then those classes should be included automatically.