Thinkphp引入paypal支付教程
4493
微信支付、支付宝支付的接口,网络上已经很多。但是接入paypal需要怎么操作呢?这篇教程就帮助大家使用Thinkphp框架引入paypal支付的教程。事实上,任何php程序都可以参考。
1、引入sdk
composer require paypal/paypal-checkout-sdk
2、下单获得付款url:
namespace app\index\controller; use PayPalCheckoutSdk\Orders\OrdersCreateRequest; use PayPalCheckoutSdk\Core\PayPalHttpClient; class Index{ public function index(){ $request = new OrdersCreateRequest(); $request->prefer('return=representation'); $returnUrl = 'https://www.demo.com/pay/callback/paypal?act=success'; $cancelUrl = 'https://www.demo.com/pay/callback/paypal?act=cancel'; $isSandBox = true; $request->body = array( 'intent' => 'CAPTURE', 'application_context' => array( 'return_url' => $returnUrl, 'cancel_url' => $cancelUrl ), 'purchase_units' => array( 0 => array( 'amount' => array( 'currency_code' => 'USD', 'value' => '0.01' ) ) ) ); // 是否是沙盒模式 $envSet = $isSandBox ? 'PayPalCheckoutSdk\Core\SandboxEnvironment' : 'PayPalCheckoutSdk\Core\ProductionEnvironment'; try { $environment = new $envSet('clientid', 'secret'); $client = new PayPalHttpClient($environment); $response = $client->execute($request); $url = $response->result->links[1]->href; return $url; } catch (HttpException $ex) { throw $ex; //echo $ex->statusCode; //print_r($ex->getMessage()); } } }
3、回调并查询订单
根据自己的业务情况编写支付回调逻辑
本文网址:https://www.zztuku.com/index.php/detail-12558.html
站长图库 - Thinkphp引入paypal支付教程
申明:如有侵犯,请 联系我们 删除。
您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!