emirazaiez / paypal
此包最新版本(dev-master)没有提供许可信息。
使用 PHP 的 PayPal API SVN 的简单脚本
dev-master
2015-11-06 13:50 UTC
This package is not auto-updated.
Last update: 2024-09-28 19:09:30 UTC
README
此 PHP 类将简单地消费 PayPal NVP Api 来进行简单支付。
安装
将此行添加到您的 composer.json 中的 require 部分
composer require emirazaiez/paypal
然后将其添加到您的 PHP 文件中(如果您使用框架则无需添加)
require 'vendor/autoload.php'
您可以在该页面上获取有关 PayPal API 和 PayPal 配置的所有信息:PayPal 开发者
一些示例:(您还可以检查 sample.php)
这只是一个示例,最好为每个 "函数" 做一个路由
简单调用 API 获取 PayPal 付款 URL:(路由可以是如:/paypal/checkout)
<?php session_start(); //For use the 'transferData' require 'vendor/autoload.php' use Paypal\CheckoutManager; $paypalConfig = array( 'mode' => 'sandbox', // You can provide 'prod' for use the real paypal service 'user' => '', // You can get it from paypal service 'password' => '', // You can get it from paypal service 'signature' => '', // You can get it from paypal service 'lang' => 'EN' ); $productConfig = array( 'price' => 5, 'currency' => 'USD', 'description' => 'My app subscription for 1 month', //Which will be show on the paypal payment page 'logo' => 'http://creativebits.org/files/500px-Apple_Computer_Logo.svg_.png', //Logo of your company 'returnURL' => 'http://myweb.com/paypal/return', //The return url will be passed to paypal, this url will be call by paypal when the transfere will be done 'cancelURL' => 'http://myweb.com/paypal/cancel', //The return url will be passed to paypal, this url will be call when the user cancel the payment 'transferData' => array('productID' => '1', 'quantity' => '1month') //Those data arn't used by paypal, you can put whatever you want. Those data will be avaible on success of the "return url" called by paypal (You can only use this if you start the session) ); $paypal = new CheckoutManager($paypalConfig['mode'], $paypalConfig['user'], $paypalConfig['password'], $paypalConfig['signature'], $paypalConfig['lang']); $paypal->requestExpressCheckout($productConfig['price'], $productConfig['currency'], $productConfig['description'], $productConfig['logo'], $productConfig['returnURL'], $productConfig['cancelURL']) ->setTransferData($productConfig['transferData']) ->execute( function($paypalCheckoutURL,$success) { //Put your own logic here //You can redirect the user directly to paypal checkout shop : header("Location: " . $paypalCheckoutURL); }, function($errors) { //Put your own logic here });
简单的 PayPal API 返回:(路由可以是如:/paypal/return)
<?php $paypal = new CheckoutManager($paypalConfig['mode'], $paypalConfig['user'], $paypalConfig['password'], $paypalConfig['signature'], $paypalConfig['lang']); $paypal->requestExpressCheckoutPayment($_GET['token'], $_GET['PayerID']) ->execute( function($transferedData, $paypalUser, $success) { //Put your own logic here (Will be some db call for save everything) }, function($errors) { //Put your own logic here });
取消支付:(路由可以是如:/paypal/cancel)
<?php $paypal = new CheckoutManager($paypalConfig['mode'], $paypalConfig['user'], $paypalConfig['password'], $paypalConfig['signature'], $paypalConfig['lang']); $paypal->requestExpressCheckoutDetails($_GET['token']) ->execute( function($transferedData, $paypalUser) { //Put your own logic here }, function($errors) { //Put your own logic here });