paypal支付,适用于 andriod 和 IOS & web ,andriod 和 ios 记得webview创建新的js方法接受回调方式
1.composer require "paypal/rest-api-sdk-php:1.7.2" 准备依赖 不清楚的可以留言 小伙伴
2.创建common文件:

<?php
require_once('../newVender/vendor/autoload.php');
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
// 下面为申请app获得的clientId和clientSecret,必填项,否则无法生成token。
$clientId = 'AXF3AVKcQTO7uWQ_FQchEFdK6L318DaFbG3tpaRve5Zi1QTlicBCMMl1ole09w5Aum28kR_OcXArk7Wc';//'ATqjTW5l50aYGPbZU41MFz1wl9vQVycroYmttegHNSV4Br8Mu2JGXLc9ohh_c094iCN6DPp3hUw5b09E';
$clientSecret = 'EMHG6PRn2pmwHQuLz5Yhu5wxUso3DYvTJqMO4HtoGlzdovqLDWbeNvAtMwwK-n6EQS7Tpr3XDr7L2bws';
$apiContext = new ApiContext(
new OAuthTokenCredential(
$clientId,
$clientSecret
)
);
$apiContext->setConfig(
array(
'mode' => 'live',
'log.LogEnabled' => true,
'log.FileName' => '../PayPal.log',
'log.LogLevel' => 'DEBUG',
'cache.enabled' => true
)
);
3.
创建pays.php

<?php
require '../newVender/vendor/autoload.php';
require_once("./common.php");
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\ShippingAddress;
use PayPal\Api\Transaction;
$host = ((int)$_SERVER['SERVER_PORT'] == 80 ? 'http://' : 'https://') . $_SERVER['HTTP_HOST'];
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$check = file_get_contents('http://127.0.0.1');
if(!$check){
exit('请绑定本地127.0.0.1');
}
$ordersn = $_GET['ordersn'];
$type = $_GET['type'];
file_put_contents('paysss.log',$ordersn);
if(!$ordersn){
exit('传入订单号');
}
if($type == 'charge'){ //充值
$data = file_get_contents('http://127.0.0.1/appapi/home/checkOrder?ordersn='.$ordersn);
$data = json_decode($data,1);
$money = $data['data']['money'];
$desc = '充值砖石';
}elseif($type == 'pay'){ //付费
$data = file_get_contents('http://127.0.0.1/appapi/home/checkPayOrder?ordersn='.$ordersn);
$data = json_decode($data,1);
$money = $data['data']['money'];
$desc = '购买付费内容';
}else if($type == 'shop'){
$data = file_get_contents('http://127.0.0.1/appapi/home/checkShopOrder?ordersn='.$ordersn);
$data = json_decode($data,1);
$money = $data['data']['total'];
$desc = '购买商品--'.$data['data']['goods_name'];
}else{
exit('暂未开放');
}
//设置总价,运费等金额。注意:setSubtotal的金额必须与详情里计算出的总金额相等,否则会失败
$details = new Details();
$details->setShipping(0)
->setTax(0)
->setSubtotal($money);
// 同上,金额要相等
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal($money)
->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
->setDescription($desc)
->setInvoiceNumber($ordersn);
/**
* 回调
* 当支付成功或者取消支付的时候调用的地址
* success=true 支付成功
* success=false 取消支付
*/
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl($host."/ok.php?type=".$type.'&ordersn='.$ordersn)
->setCancelUrl($host."/no.html"); //跳转成功 是倒 ok.php页面, 失败是倒 no.html页面
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
//创建支付
$payment->create($apiContext);
//Payment::get(time(),$apiContext);
//生成地址
$approvalUrl = $payment->getApprovalLink();
// var_dump($approvalUrl);
//跳转
header("location:" . $approvalUrl);