cpierce/paypal-wpp
Composer 安装命令:
composer require cpierce/paypal-wpp
包简介
Client library for Paypal Web Payments Pro.
README 文档
README
This package was written to interact with any PHP application, but I'll demo using CakePHP 3.x to show how to connect to it.
Composer Settings
First we'll want to add the library in via the composer.json file.
"cpierce/paypal-wpp": "3.*" will need to be added into your require as follows:
File: composer.json
{
"name": "cakephp/app",
"description": "CakePHP skeleton app",
"homepage": "http://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"php": ">=5.5.9",
"cakephp/cakephp": "~3.3",
"mobiledetect/mobiledetectlib": "2.*",
"cakephp/migrations": "~1.0",
"cakephp/plugin-installer": "*",
"cpierce/paypal-wpp": "3.*"
},
"require-dev": {
"psy/psysh": "@stable",
"cakephp/debug_kit": "~3.2",
"cakephp/bake": "~1.1"
},
"suggest": {
"phpunit/phpunit": "Allows automated tests to be run without system-wide install.",
"cakephp/cakephp-codesniffer": "Allows to check the code against the coding standards used in CakePHP."
},
"autoload": {
"psr-4": {
"App\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"App\\Test\\": "tests",
"Cake\\Test\\": "./vendor/cakephp/cakephp/tests"
}
},
"scripts": {
"post-install-cmd": "App\\Console\\Installer::postInstall",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump"
},
"minimum-stability": "stable",
"prefer-stable": true
}
Once you have this change saved run composer update and let the package download
into the vendor app.
General Configuration
To begin you'll need to configure your service username, password and signature. The configuration will need to look something like this:
File: config/bootstrap.php
/**
* Paypal WPP Payload
*/
Configure::write('PaypalWPP.username', 'username_api1.domain.com');
Configure::write('PaypalWPP.password', '5SWM6YY8YSUY888');
Configure::write('PaypalWPP.signature', 'tlArzO7mr5uXMO6.H2zPIuzAFYn4irhcVyzOPeiUcocJF.H3mGr');
Making a transaction to PayPal WPP
After the configuration is setup you'll want to connect to PayPal WPP using the library.
File: src/Form/SalesForm.php
<?php
namespace App\Form;
use Cake\Form\Form;
use Cake\Form\Schema;
use Cake\Validation\Validator;
use PaypalWPP\PaypalWPP;
use Cake\Core\Configure;
/**
* Sales Form class.
*
* @extends Cake\Form\Form
*/
class SalesForm extends Form
{
/**
* Parse Data Array.
*
* @var array
*/
protected $parseData = [];
/**
* Build Schema Method.
*
* @param Schema $schema
*
* @return Schema $schema
*/
protected function _buildSchema(Schema $schema)
{
return $schema->addField('first_name', 'string')
->addField('last_email', 'string')
->addField('card_number', 'string')
->addField('amount', 'string');
}
/**
* Build Validator Method.
*
* @param Validator $validator
*
* @return Validator $validator
*/
protected function _buildValidator(Validator $validator)
{
return $validator
->notBlank('first_name', __('Your first name is required.'))
->notBlank('last_name', __('Your last name is required.'))
->creditCard('card_number', [
'amex',
'visa',
'disc',
'mc',
], __('Please enter a valid credit card number.'))
->notBlank('amount', __('Please enter an amount.'));
}
/**
* Execute Method.
*
* @param array $data
*
* @return bool
*/
protected function _execute(array $data)
{
$paypal = new PaypalWPP(Configure::read('PaypalWPP'));
$payment = $paypal->doDirectPayment($data);
if ($payment['ACK'] == 'Success') {
$this->parseData = [
'transaction_id' => $payment['TRANSACTIONID'],
];
return true;
} else {
$this->parseData = [
'failure_message' => $payment['L_LONGMESSAGE0'],
'failure_short' => $payment['L_SHORTMESSAGE0'],
];
}
return false;
}
/**
* Get Parse Data Method.
*
* @return string
*/
public function getParseData()
{
return $this->parseData;
}
}
File: src/Controller/SalesController.php
<?php
namespace App\Controller;
use App\Form\SalesForm;
/**
* Sales Controller.
*/
class SalesController extends AppController
{
/**
* Add Method.
*/
public function add()
{
$sales = new SalesForm();
if ($this->request->is(['post', 'put'])) {
$transaction_execute = $sales->execute($this->request->data);
$transaction = $sales->getParseData();
if ($transaction_execute) {
$this->Flash->success(
__('Payment Completed Successfully: '.$transaction['transaction_id'])
);
$this->render('success');
} else {
$this->Flash->error(
__('Payment Failed: '.$transaction['failure_message'].'['.$transaction['failure_short'].']')
);
}
}
$this->set(compact('sales'));
}
}
cpierce/paypal-wpp 适用场景与选型建议
cpierce/paypal-wpp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 373 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cpierce/paypal-wpp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cpierce/paypal-wpp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 373
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-27