tanatoss / merchant-sdk-php
PHP PayPal 商户 SDK
v3.6.106
2013-08-22 18:32 UTC
Requires
- php: >=5.3.0
- ext-curl: *
- paypal/sdk-core-php: 2.4.*
This package is not auto-updated.
Last update: 2024-09-24 07:42:29 UTC
README
商户 SDK 可用于集成 Express Checkout、Mass Pay、Web Payments Pro API。
此 SDK 已弃用。强烈建议新实现使用 PHP Rest SDK
先决条件
PayPal 的 PHP 商户 SDK 需要
- PHP 5.2 及以上版本
- curl/openssl PHP 扩展
运行示例
要运行捆绑的示例,首先将 samples 文件夹复制到您的 web 服务器根目录。然后,您需要使用 composer(仅限 PHP V5.3+)或通过运行 SDK 提供的定制安装脚本来将 SDK 作为依赖项安装。
如果使用 composer,请在 samples 文件夹中运行 composer update
。否则,从 merchant-sdk-php/samples 目录运行 install.php。
cd samples curl https://raw.github.com/paypal/merchant-sdk-php/stable/samples/install.php | php OR php install.php
使用 SDK
要使用 SDK,
- 创建一个包含以下内容的 composer.json 文件。
{ "name": "me/shopping-cart-app", "require": { "paypal/merchant-sdk-php":"v2.*" } }
- 使用 composer 或 install.php 脚本将 SDK 作为依赖项安装。
- 根据您是否使用了 composer 或自定义安装程序,在您的应用程序中需要
vendor/autoload.php
或PPBootStrap.php
。 - 选择您想要如何配置 SDK - 您可以
- 创建一个包含配置参数的 hashmap 并将其传递给服务对象 OR
- 创建一个
sdk_config.ini
文件并将 PP_CONFIG_PATH 常量设置为指向该文件存在的目录。
- 根据您项目的需求实例化服务包装器对象和请求对象。
- 在服务对象上调用适当的方法。
例如,
// Sets config file path(if config file is used) and registers the classloader require("PPBootStrap.php"); // 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' ..... ); // Create request details $itemAmount = new BasicAmountType($currencyId, $amount); $setECReqType = new SetExpressCheckoutRequestType(); $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails; // Create request $setECReq = new SetExpressCheckoutReq(); $setECReq->SetExpressCheckoutRequest = $setECReqType; ...... // Perform request $paypalService = new PayPalAPIInterfaceServiceService($config); $setECResponse = $paypalService->SetExpressCheckout($setECReq); // Check results if(strtoupper($setECResponse->Ack) == 'SUCCESS') { // Success }
身份验证
SDK 提供了多种方式来验证您的 API 调用。
$paypalService = new PayPalAPIInterfaceServiceService($config); // Use the default account (the first account) configured in sdk_config.ini $response = $paypalService->SetExpressCheckout($setECReq); // Use a specific account configured in sdk_config.ini $response = $paypalService->SetExpressCheckout($setECReq, '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 = $paypalService->SetExpressCheckout($setECReq, $cred);
SDK 配置
SDK 允许您配置以下参数-
- 集成模式(沙盒/实时)
- (多个)API 账户凭证。
- HTTP 连接参数
- 日志记录
可以通过传递凭证和配置值的映射来设置动态配置值(如果传递了配置映射,则忽略配置文件)
$config = array( 'mode' => 'sandbox', 'acct1.UserName' => 'jb-us-seller_api1.paypal.com', 'acct1.Password' => 'WX4WTU3S8MY44S7F' ..... ); $service = new PayPalAPIInterfaceServiceService($config);
或者,可以从文件中加载凭证和配置。
define('PP_CONFIG_PATH', '/directory/that/contains/sdk_config.ini'); $service = new PayPalAPIInterfaceServiceService();
您可以在 wiki 页面上查看配置参数的完整列表。
有关更多信息,请参阅此捆绑包中提供的示例配置文件。
即时支付通知 (IPN)
请参阅 'samples/IPN' 目录中的 IPN-README。
故障排除
链接
- API 参考 - https://developer.paypal.com/webapps/developer/docs/classic/api/#merchant
- 如果您需要使用 SDK 的帮助,需要的新功能或要报告的问题,请访问 https://github.com/paypal/merchant-sdk-php/issues