paypal / buttonmanager-sdk-php
此包已被弃用且不再维护。未建议替换包。
PHP PayPal 按钮管理器 SDK
v4.0.0
2017-03-28 17:17 UTC
Requires
- php: >=5.3.0
- ext-curl: *
- paypal/sdk-core-php: 3.*
README
从 3.x 迁移到 4.x
我们对 4.x 做了修改,使其与 PayPal Classic SDK 兼容。
- 将引用从
\PayPal\Service\PayPalAPIInterfaceServiceService
更改为\PayPal\Service\ButtonManagerService
。
支持
请联系 PayPal 技术支持 解决任何实时或账户问题。
先决条件
PayPal 的 PHP 按钮管理器 SDK 需要
- PHP 5.3 及以上版本
- curl/openssl PHP 扩展
运行示例
要运行捆绑的示例,首先将 samples 文件夹复制到您的 web 服务器根目录。然后您需要使用 composer(仅限 PHP v5.3+)将 SDK 作为依赖项安装。
在 samples 文件夹中运行 composer update
。
使用 SDK
要使用 SDK,
- 创建一个包含以下内容的 composer.json 文件。
{ "name": "me/shopping-cart-app", "require": { "paypal/buttonmanager-sdk-php": "4.*" } }
- 使用 composer 将 SDK 作为依赖项安装。
- 在您的应用程序中引入
vendor/autoload.php
。 - 选择您想如何配置 SDK - 您可以
- 创建一个包含配置参数的 hashmap 并将其传递给服务对象,或者
- 创建一个
sdk_config.ini
文件并将 PP_CONFIG_PATH 常量设置为指向此文件存在的目录。
- 根据您项目的需求实例化一个服务包装器对象和一个请求对象。
- 在服务对象上调用适当的方法。
例如,
// Sets config file path(if config file is used) and registers the classloader require("PPBootStrap.php"); use PayPal\PayPalAPI\BMButtonSearchReq; use PayPal\PayPalAPI\BMButtonSearchRequestType; use PayPal\Service\ButtonManagerService; // Array containing credentials and confiuration parameters. (not required if config file is used) $config = array( 'mode' => 'sandbox', 'acct1.UserName' => 'jb-us-seller_api1.paypal.com', 'acct1.Password' => 'WX4WTU3S8MY44S7F', "acct1.Signature" => "AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy" ..... ); $buttonSearchReq = new BMButtonSearchReq(); $buttonSearchReq->BMButtonSearchRequest = new BMButtonSearchRequestType(); ...... $buttonManagerService = new ButtonManagerService($config); $buttonSearchResponse = $buttonManagerService->BMButtonSearch($buttonSearchReq); if(strtoupper($buttonSearchResponse->Ack) == 'SUCCESS') { // Success }
身份验证
SDK 提供了多种方法来验证您的 API 调用。
use PayPal\Auth\PPCertificateCredential; use PayPal\Auth\PPTokenAuthorization; $buttonManagerService = new ButtonManagerService($config); // Use the default account (the first account) configured in sdk_config.ini $response = $buttonManagerService->BMButtonSearch($buttonSearchReq); // Use a specific account configured in sdk_config.ini $response = $buttonManagerService->BMButtonSearch($buttonSearchReq, 'jb-us-seller_api1.paypal.com'); // Pass in a dynamically created API credential object $cred = new PPCertificateCredential("username", "password", "path-to-pem-file"); $cred->setThirdPartyAuthorization(new PPTokenAuthorization("accessToken", "tokenSecret")); $response = $buttonManagerService->BMButtonSearch($buttonSearchReq, $cred);
SDK 配置
SDK 允许您配置以下参数
- 集成模式(
sandbox
/live
) - (多个)API 账户凭证
- HTTP 连接参数
- 日志记录
可以通过传递凭据和配置值的 map 来设置动态配置值(如果传递了配置 map,则忽略配置文件)
$config = array( 'mode' => 'sandbox', 'acct1.UserName' => 'jb-us-seller_api1.paypal.com', 'acct1.Password' => 'WX4WTU3S8MY44S7F' ..... ); $service = new ButtonManagerService($config);
或者,您可以通过 sdk_config.ini 文件来配置 SDK。
define('PP_CONFIG_PATH', '/directory/that/contains/sdk_config.ini'); $service = new ButtonManagerService();
您可以在 wiki 页面上找到完整的配置参数列表。
即时支付通知(IPN)
请参阅 'samples/IPN' 目录中的 IPN-README。
POODLE 更新
- 由于 POODLE 漏洞,PayPal 已禁用 SSLv3。
- 为了启用TLS加密,对PPHttpConfig.php进行了修改,该文件位于SDK Core中,使用了针对TLS加密的特定密码列表。
/** * Some default options for curl * These are typically overridden by PPConnectionManager */ public static $DEFAULT_CURL_OPTS = array( CURLOPT_SSLVERSION => 1, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_TIMEOUT => 60, // maximum number of seconds to allow cURL functions to execute CURLOPT_USERAGENT => 'PayPal-PHP-SDK', CURLOPT_HTTPHEADER => array(), CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_CIPHER_LIST => 'TLSv1', );
链接
- API参考 - https://developer.paypal.com/webapps/developer/docs/classic/api/#button-manager
- 如果您需要使用SDK的帮助,或者有问题需要报告,请访问https://github.com/paypal/buttonmanager-sdk-php/issues