Paypal SDK运行环境
1.下载
(1)下载 composer.json, 使用php composer.phar安装
(a)用命令行到项目根目录,eg: /project,
(b)解压复制上面的下载文件到根目录/project 或 /Vendor 或 其它自定义目录
安装后的目录如下图
(2)或者直接下载 https://github.com/paypal/PayPal-PHP-SDK/releases
解压到项目根目录,方法同(1)
2、在根目录创建测试文件 paypalDemo.php
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
// After Step 1
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', // ClientID
'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL' // ClientSecret
)
);
// After Step 2
$creditCard = new \PayPal\Api\CreditCard();
$creditCard->setType("visa")
->setNumber("4417119669820331")
->setExpireMonth("11")
->setExpireYear("2019")
->setCvv2("012")
->setFirstName("Joe")
->setLastName("Shopper");
// After Step 3
try {
$creditCard->create($apiContext);
echo $creditCard;
}
catch (\PayPal\Exception\PayPalConnectionException $ex) {
// This will print the detailed information on the exception.
//REALLY HELPFUL FOR DEBUGGING
echo $ex->getData();
}
//运行php -f paypalDemo.php, 或在apache打开运行