Cake PHP 2.x 的 PayPal Web Payments Pro 插件
使用 PayPal 的 WPP API 的 NVP 方法的基本插件。组件将方法和 NVP 组合推送到 paypal url curl。php 中需要 php5-curl 配置。
CakePHP 2.x 的 PayPal WebPaymentsPro (WPP) 插件
用于与 PayPal WPP 交互的 CakePHP 2.x 插件
插件可在 https://bitbucket.org/chrispierce/paypalwpp-plugin-for-cakephp-2.x/overview 找到
用法
在您的 APP 中加载插件,并使用以下 bootstrap.php 配置启用它
`
CakePlugin::load('PaypalWPP');
`
通过打开 Config/paypal.php 文件,配置您的帐户,如下所示
`
$config=array(
'paypal'=>array(
'username'=>'username_api1.domain.com',
'password'=>'THGSWS658IKUN79S',
'signature'=>'AFYn4irhcVyzOOiJkc.H2zPIuztlArzO7mr5uXMO6DLICAE85JF.H5PPp',
'endpoint'=>'https://api-3t.paypal.com/nvp',
'version'=>'53.0',
),
);
`
将组件加载到您选择的控制器中。
`
public$components=array(
'PaypalWPP.PaypalWPP',
);
`
接下来,对您的数据进行 urlencode,并使用方法和 nvp 将其发送到组件。要使用 DoDirectPayment 进行付款 (https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/),以下示例将起作用
`
publicfunctionadd(){
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=urlencode($this->request->data['Sale']['card_type']);
$creditCardNumber=urlencode($this->request->data['Sale']['card_number']);
$expDateMonth=$this->request->data['Sale']['exp']['month'];
$padDateMonth=urlencode(str_pad($expDateMonth,2,'0',STR_PAD_LEFT));
$expDateYear=urlencode($this->request->data['Sale']['exp']['year']);
$cvv2Number=urlencode($this->request->data['Sale']['cvv2']);
$amount=urlencode($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('PaymentSuccessful');
}else{
$this->Session->setFlash('PaymentFailed');
}
debug($response);
}
}
`
其他方法可在 https://devtools-paypal.com/apiexplorer/PayPalAPIs 找到