1.申请账号

https://www.paypal.com,申请商家账号
然后进入开发者网址
https://developer.paypal.com

2.使用sanbox测试

2.1 查看账号情况 https://developer.paypal.com/developer/accounts/
sanbox账号详情密码修改,点击对应email ->profile
2.2创建app,获取clientId,clientSecret,https://developer.paypal.com/developer/applications

3.支付代码

copy官网的文档
<?php
namespace app\index\controller;use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;class Index
{public function index(){$clientId = 'xxxx';$clientSecret = 'xxxx';$apiContext = new ApiContext(new OAuthTokenCredential($clientId,$clientSecret));$apiContext->setConfig(array('mode' => 'sandbox','log.LogEnabled' => true,'log.FileName' => '../PayPal.log','log.LogLevel' => 'DEBUG', // PLEASE USE `INFO` LEVEL FOR LOGGING IN LIVE ENVIRONMENTS'cache.enabled' => true,// 'http.CURLOPT_CONNECTTIMEOUT' => 30// 'http.headers.PayPal-Partner-Attribution-Id' => '123123123'//'log.AdapterFactory' => '\PayPal\Log\DefaultLogFactory' // Factory class implementing \PayPal\Log\PayPalLogFactory));// ### Payer// A resource representing a Payer that funds a payment// For paypal account payments, set payment method// to 'paypal'.$payer = new Payer();$payer->setPaymentMethod("paypal");// ### Itemized information// (Optional) Lets you specify item wise// information$item1 = new Item();$item1->setName('商品1')->setCurrency('USD')->setQuantity(1)->setSku("123123") // Similar to `item_number` in Classic API->setPrice(7.5);$item2 = new Item();$item2->setName('商品2')->setCurrency('USD')->setQuantity(5)->setSku("321321") // Similar to `item_number` in Classic API->setPrice(2);$itemList = new ItemList();$itemList->setItems(array($item1, $item2));// ### Additional payment details// Use this optional field to set additional// payment information such as tax, shipping// charges etc.$details = new Details();$details->setShipping(1.2)  ->setTax(1.3) ->setSubtotal(17.50);// ### Amount// Lets you specify a payment amount.// You can also specify additional details// such as shipping, tax.$amount = new Amount();$amount->setCurrency("USD")->setTotal(20)->setDetails($details);// ### Transaction// A transaction defines the contract of a// payment - what is the payment for and who// is fulfilling it. $transaction = new Transaction();$transaction->setAmount($amount)->setItemList($itemList)->setDescription("商品描述")->setInvoiceNumber(uniqid());// ### Redirect urls// Set the urls that the buyer must be redirected to after // payment approval/ cancellation.$baseUrl = 'http://'.$_SERVER["HTTP_HOST"];$redirectUrls = new RedirectUrls();$redirectUrls->setReturnUrl("$baseUrl/public/index.php/index/Index/success")->setCancelUrl("$baseUrl/public/index.php/index/Index/cancel");// ### Payment// A Payment Resource; create one using// the above types and intent set to 'sale'$payment = new Payment();$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));// For Sample Purposes Only.$request = clone $payment;// ### Create Payment// Create a payment by calling the 'create' method// passing it a valid apiContext.// (See bootstrap.php for more on `ApiContext`)// The return object contains the state and the// url to which the buyer must be redirected to// for payment approvaltry {$payment->create($apiContext);} catch (Exception $ex) {// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLYResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);exit(1);}// ### Get redirect url// The API response provides the url that you must redirect// the buyer to. Retrieve the url from the $payment->getApprovalLink()// method$approvalUrl = $payment->getApprovalLink();}public function success(){echo 'success';}public function cancel(){echo 'cancel';}
}

show

4.通知(页面级,异步级)

页面级的上面代码已有,异步 webhook 后面贴上,其实文档写的相当详细

5.相关资料

https://paypal.github.io/PayPal-PHP-SDK/sample 例子都在上面

ps:另外发现php packagist.org也是好东西啊

https://packagist.org/packages/paypal/rest-api-sdk-php

tp5实现paypal支付相关推荐

  1. TP5集成PayPal支付

    项目需要使用到PayPal支付,在网上找了一圈大多写的太过简陋不易看懂,在这里详细记录集成过程方便后期使用. 第一步:下载PayPal-PHP-SDK集成到项目中 最新SDK下载地址: https:/ ...

  2. Android下集成Paypal支付

    近期项目需要研究paypal支付,官网上的指导写的过于复杂,可能是老外的思维和中国人不一样吧.难得是发现下面这篇文章: http://www.androidhive.info/2015/02/andr ...

  3. PAYPAL 支付,sandbox测试的时候遇到异常:请求被中止: 未能创建 SSL/TLS 安全通道,以及解决方法。...

    场景描述: 我公司的网站之前就已经开发好了下单支持paypal支付,当然,这个是其他同事开发的.前段时间,主管让我在另一个场景开发支持使用paypal支付,当时花了些时间看看关于paypal代码,然后 ...

  4. google支付接入PHP语言,PHP语言开发Paypal支付demo的具体实现

    一.paypal支付接口准备工作 首先去申请一个paypal账号,https://www.paypal.com/. 申请完毕并登录,进入https://developer.paypal.com/dev ...

  5. PAYPAL 支付,sandbox测试的时候遇到异常:请求被中止: 未能创建 SSL/TLS 安全通道,以及解决方法。

    PAYPAL 支付,sandbox测试的时候遇到异常:请求被中止: 未能创建 SSL/TLS 安全通道,以及解决方法. 参考文章: (1)PAYPAL 支付,sandbox测试的时候遇到异常:请求被中 ...

  6. PayPal支付集成到自己Web网站

    PayPal如何集成到B2C网站? 因为网上实在找不到集成教程,我习惯性的google了一下相关资料,发现关于paypal接口的中文文档并不多,也不详细,只好自己研究,还好paypal上的资料非常齐全 ...

  7. uni-app:实现PayPal支付功能

    一.相关文档或网址 1.uni-app官方文档地址:开通 | uni-app官网 2.paypal开发者中心:Applications - PayPal Developer 二.开发流程 1.开发前配 ...

  8. vue模块给模块传参_Vue店面的Paypal支付模块

    vue模块给模块传参 Vue店面PayPal付款扩展 (Vue Storefront PayPal Payment Extension) PayPal Payment module for vue-s ...

  9. Java集成PayPal支付

    Java集成PayPal支付 1.申请账号 浏览器中输入:https://www.paypal.com,点击 "注册" 选择 "企业账号" ,信息可以随意填写 ...

最新文章

  1. 一步一步学Linq to sql(六):探究特性
  2. Ganglia 应用实践
  3. 大多数日志文件的后缀名是_编程小短文:find,让你随心所欲查找整块磁盘的任意文件...
  4. 创建MySQL数据库中useUnicode=truecharacterEncoding=UTF-8
  5. .NET与鲲鹏共展翅,昇腾九万里(二)
  6. linuxpython拍照_linux下python抓屏实现方法 -电脑资料
  7. Java的面试汇总,有这些还担心不通过?
  8. eclipse一套全部流程的安装及配置
  9. js中的内置对象(详细篇)
  10. linux怎么建立链接文件,Linux 建立文件夹的链接
  11. 本来都对象棋失去兴趣了, 是特殊的原因让我又开始从侧面搞象棋方面的擦边的游戏...
  12. [Ubuntu 18.04][CPU]MindSpore V1.0源码安装初体验(直播结束)
  13. 解构荣耀销量奇迹背后的化学反应:技术+品质+产品力
  14. CSDN是什么?——我的博客漫漫成长之路
  15. 包含负数的二进制补码的加减运算
  16. Linux Minit Xshell5连接虚拟机Minit
  17. java入门第一周总结
  18. 留在Facebook:首席运营官桑德伯格否认将加入希拉里政府
  19. 系统结构考点之多处理机任务粒度
  20. 网付和收钱吧哪个好?深度对比2个对象之间的差异!

热门文章

  1. taobao.trade.amount.get( 交易帐务查询 )
  2. linux内核模块加载命令
  3. [原创]农村孩子要不要上那些“烂大学”?
  4. Wisdom RESTClient 使用教程
  5. wm_concat标识符无效_ORA-00904:WM_CONCAT:标识符无效
  6. 吉林大学计算机考研资料汇总
  7. 从零开始理解DM368的H264视频编码过程(中)
  8. 微型计算机2015年4月上,2003年4月全国高等教育自学考试电力系统微型计算机继电保护试题...
  9. 从事了多年总承包现场管理,依然没有真正学会项目管理
  10. 如何解析超长的protobuf zhuan