robmcvey/cakephp-paypal

此软件包最新版本(1.0.3)没有可用的许可信息。

PayPal 插件

安装: 42

依赖项: 0

建议者: 0

安全: 0

星标: 60

关注者: 12

分支: 44

开放问题: 11

类型:cakephp-plugin

1.0.3 2015-05-07 10:09 UTC

This package is not auto-updated.

Last update: 2024-10-02 10:40:13 UTC


README

Build Status

一个 CakePHP 插件,用于与 PayPal 的“经典”和新 REST API 进行交互。

要求

  • CakePHP 2.x
  • 一个 PayPal 网站支付专业账户

安装

[手册]

[GIT 子模块]

在您的应用程序目录中输入

git submodule add -b master git://github.com/robmcvey/cakephp-paypal.git Plugin/Paypal
git submodule init
git submodule update

[GIT 克隆]

在您的 Plugin 目录中输入

git clone -b master git://github.com/robmcvey/cakephp-paypal.git Paypal

用法

确保插件在 app/Config/bootstrap.php 中被加载。

CakePlugin::load('Paypal');

PayPal 经典方法

使用您的 PayPal 凭据创建该类的实例。出于测试目的,请确保 sandboxMode 设置为 true

App::uses('Paypal', 'Paypal.Lib');

$this->Paypal = new Paypal(array(
	'sandboxMode' => true,
	'nvpUsername' => '{username}',
	'nvpPassword' => '{password}',
	'nvpSignature' => '{signature}'
));

SetExpressCheckout

按照以下格式创建订单(s)。 setExpressCheckout 将返回一个字符串 URL,用于将客户重定向到。

$order = array(
	'description' => 'Your purchase with Acme clothes store',
	'currency' => 'GBP',
	'return' => 'https://www.my-amazing-clothes-store.com/review-paypal.php',
	'cancel' => 'https://www.my-amazing-clothes-store.com/checkout.php',
	'custom' => 'bingbong',
	'shipping' => '4.50',
	'items' => array(
		0 => array(
			'name' => 'Blue shoes',
			'description' => 'A pair of really great blue shoes',
			'tax' => 2.00,
			'subtotal' => 8.00,
			'qty' => 1,
		),
		1 => array(
			'name' => 'Red trousers',
			'description' => 'Tight pair of red pants, look good with a hat.',
			'tax' => 1.50,
			'subtotal' => 6.00,
			'qty' => 3,
		),
	)
);
 try {
	$this->Paypal->setExpressCheckout($order);
} catch (Exception $e) {
	// $e->getMessage();
}	

GetExpressCheckoutDetails

一旦客户返回您的网站(请参阅上面的 return URL),您可以使用来自 setExpressCheckout 方法的令牌来请求他们的详细信息。

try {
	$this->Paypal->getExpressCheckoutDetails($token);
} catch (Exception $e) {
	// $e->getMessage();
}		

DoExpressCheckoutPayment

使用相同的订单详细信息完成交易。 $token$payerId 将来自 setExpressCheckout 方法。

如果用户的资金方式(与他们的 PayPal 账户关联的信用卡或银行账户)需要更新,此方法可能会抛出 PaypalRedirectException。异常消息将包含一个 URL,用户将被重定向到,他们将在此处被提示更新他们的资金方式。

$order = array(
	'description' => 'Your purchase with Acme clothes store',
	'currency' => 'GBP',
	'return' => 'https://www.my-amazing-clothes-store.com/review-paypal.php',
	'cancel' => 'https://www.my-amazing-clothes-store.com/checkout.php',
	'custom' => 'bingbong',
	'shipping' => '4.50',
	'items' => array(
		0 => array(
			'name' => 'Blue shoes',
			'description' => 'A pair of really great blue shoes',
			'tax' => 2.00,
			'subtotal' => 8.00,
			'qty' => 1,
		),
		1 => array(
			'name' => 'Red trousers',
			'description' => 'Tight pair of red pants, look good with a hat.',
			'tax' => 1.50,
			'subtotal' => 6.00,
			'qty' => 3,
		),
	)
);

try {
	$this->Paypal->doExpressCheckoutPayment($order, $token, $payerId);	
} catch (PaypalRedirectException $e) {
	$this->redirect($e->getMessage());
} catch (Exception $e) {
	// $e->getMessage();
}	

DoDirectPayment

对信用卡进行收费。确保您正在使用 SSL 并遵循 PCI 合规性指南。

$payment = array(
	'amount' => 30.00,
	'card' => '4008 0687 0641 8697', // This is a sandbox CC
	'expiry' => array(
		'M' => '2',
		'Y' => '2016',
	),
	'cvv' => '321',
	'currency' => 'USD' // Defaults to GBP if not provided
);

try {
	$this->Paypal->doDirectPayment($payment);
} catch (Exception $e) {
	// $e->getMessage();
}	

RefundTransaction

退款交易。交易只能在完成日期后的 60 天内退款。

$refund = array(
	'transactionId' => '96L684679W100181R' 	// Original PayPal Transcation ID
	'type' => 'Partial', 					// Full, Partial, ExternalDispute, Other
	'amount' => 30.00, 						// Amount to refund, only required if Refund Type is Partial
	'note' => 'Refund because we are nice',	// Optional note to customer
	'reference' => 'abc123',  				// Optional internal reference
	'currency' => 'USD'  					// Defaults to GBP if not provided
);

try {
	$this->Paypal->refundTransaction($refund);
} catch (Exception $e) {
	// $e->getMessage();
}	

PayPal REST 方法

使用您的 PayPal 凭据创建该类的实例,包括您的客户端 ID 和密钥。出于测试目的,请确保 sandboxMode 设置为 true

App::uses('Paypal', 'Paypal.Lib');

$this->Paypal = new Paypal(array(
	'sandboxMode' => true,
	'nvpUsername' => '{username}',
	'nvpPassword' => '{password}',
	'nvpSignature' => '{signature}',
	'oAuthClientId' => '{client ID}',
	'oAuthSecret' => '{secret key}',
));

在保险库中存储卡片

您可以将客户的卡片存储在保险库中,作为交换,您将获得一个令牌,可以用于未来的交易。

$creditCard = array(
	'payer_id' => 186,
	'type' => 'visa',
	'card' => 'xxxxxxxxxxxx8697',
	'cvv2' => 232,
	'expiry' => array(
	    'M' => '2',
        'Y' => '2018',
    ),
	'first_name' => 'Joe',
	'last_name' => 'Shopper'
);

try {
	$this->Paypal->storeCreditCard($creditCard);
} catch (Exception $e) {
	// $e->getMessage();
}	

对存储的卡片进行收费

一旦卡片存储在保险库中,您可以使用首次存储时发行的令牌在该卡上执行收费(s)。

$cardPayment = array(
	'intent' => 'sale',
	'payer' => array(
		'payment_method' => 'credit_card',
		'funding_instruments' => array(
			0 => array(
				'credit_card_token' => array(
					'credit_card_id' => 'CARD-39N7854321M2DDC2',
					'payer_id' => '186'
				)
			)
		)
	),
	'transactions' => array(
		0 => array(
			'amount' => array(
				'total' => '0.60',
				'currency' => 'GBP',
				"details" => array(
					"subtotal" => "0.50",
					"tax" => "0.10",
					"shipping" => "0.00"
		        )
			),
			'description' => 'This is test payment'
		)
	)
);

try {
	$this->Paypal->chargeStoredCard($cardPayment);
} catch (Exception $e) {
	// $e->getMessage();
}	

PayPal Adaptive Payments

使用您的 PayPal 凭据创建该类的实例,包括您的自适应应用程序 ID 和自适应用户名。出于测试目的,请确保 sandboxMode 设置为 true

App::uses('Paypal', 'Paypal.Lib');

$this->Paypal = new Paypal(array(
	'sandboxMode' => true,
	'nvpUsername' => '{username}',
	'nvpPassword' => '{password}',
	'nvpSignature' => '{signature}',
	'adaptiveAppID' => '{adaptive app id}',
	'adaptiveUserID' => '{adaptive user id}'
));

GetVerifiedStatus

GetVerifiedStatus API 操作允许您确定指定的 PayPal 账户的状态是否经过验证或未经验证。

try {
	$this->Paypal->getVerifiedStatus('hello@gmail.com')
} catch (Exception $e) {
	// $e->getMessage();
}