我找不到如何代表第三方使用PayPal SDK进行API调用。我发现了这个https://developer.paypal.com/docs/classic/permissions-service/integration-guide/PermissionsAbout/和这个PayPal Permissions API,但我没看到Paypal权限-sdk-php或rest-api-sdk-php中的任何方法来做到这一点。有人知道API如何使用用户访问令牌调用吗?
答案 0 :(得分:0)
我其实是在问同样的问题。但我终于通过查看JAVA SDK here上的示例代码找到了答案。
由于我在代码上使用PHP,我需要简单地将其转换为如下所示:
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) {}
我希望这可以帮助每个人遇到同样的问题。
编辑1:
感谢@Alex指出这一点。对于命名空间PayPal\Auth
下的类,请包含PayPal SDK Core,您可以获得here。如果您使用composer来使用PayPal Adaptive SDK,则应自动包含这些类。