cpierce / cakephp-paypalwpp
CakePHP 插件,用于处理 PayPal 网络支付专业版
dev-main
2016-10-20 01:10 UTC
Requires
This package is auto-updated.
Last update: 2024-08-29 03:58:04 UTC
README
CakePHP 2.x 组件,用于与 PayPal WPP 交互
用法
在您的 APP 中加载插件,并通过以下 bootstrap.php 配置文件启用它
CakePlugin::load('PaypalWPP');
通过以下方式打开 Config/paypal.php 文件来配置您的账户
$config = [
'paypal' => [
'username' => 'username_api1.domain.com',
'password' => 'THGSWS658IKUN79S',
'signature' => 'AFYn4irhcVyzOOiJkc.H2zPIuztlArzO7mr5uXMO6DLICAE85JF.H5PPp',
'endpoint' => 'https://api-3t.paypal.com/nvp',
'version' => '53.0',
],
];
将组件加载到您选择的控制器中。
public $components = [
'PaypalWPP.PaypalWPP',
];
接下来对您的数据进行 urlencode,并通过方法和 nvp 将其发送到组件。对于使用 DoDirectPayment(https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)进行支付,以下示例将有效
/**
* Add Method.
*/
public function add()
{
if ($this->request->is('post') || $this->request->is('put')) {
$firstName = urlencode($this->request->data['Sale']['first_name']);
$lastName = urlencode($this->request->data['Sale']['last_name']);
$creditCardType = $this->request->data['Sale']['card_type'];
$creditCardNumber = $this->request->data['Sale']['card_number'];
$expDateMonth = $this->request->data['Sale']['exp']['month'];
$padDateMonth = str_pad($expDateMonth, 2, '0', STR_PAD_LEFT);
$expDateYear = $this->request->data['Sale']['exp']['year'];
$cvv2Number = $this->request->data['Sale']['cvv2'];
$amount = $this->request->data['Sale']['amount'];
$nvp = '&PAYMENTACTION=Sale';
$nvp .= '&AMT=' . $amount;
$nvp .= '&CREDITCARDTYPE=' . $creditCardType;
$nvp .= '&ACCT=' . $creditCardNumber;
$nvp .= '&CVV2=' . $cvv2Number;
$nvp .= '&EXPDATE=' . $padDateMonth.$expDateYear;
$nvp .= '&FIRSTNAME=' . $firstName;
$nvp .= '&LASTNAME=' . $lastName;
$nvp .= '&COUNTRYCODE=US&CURRENCYCODE=USD';
$response = $this->PaypalWPP->wpp_hash('DoDirectPayment', $nvp);
if ($response['ACK'] == 'Success') {
$this->Session->setFlash('Payment Successful');
} else {
$this->Session->setFlash('Payment Failed');
}
debug($response);
}
}
其他方法可以在以下链接找到 https://devtools-paypal.com/apiexplorer/PayPalAPIs