java大神 2018-02-02 20:12:26 532次浏览 0条回复 0 0 0

paypal在线支付源码演示下载:http://t.cn/RlazMp7
首先要去如何获取paypal正式账号
打开https://www.paypal.com,进入个人中心
可以看到sample了,如下图: [img]/Uploads/editor/2018-02-02/5a744bf1c4fc4.png[/img] 图中的PayPal Payments - similar to Express Checkout in Classic APIs即为支付接口,对应的代码路径为~/rest-api-sdk-php/sample/payments/CreatePaymentUsingPayPal.php。 PayPal Payments的逻辑大致如下: 实现如下: ~/rest-api-sdk-php/sample/payments/CreatePaymentUsingPayPal.php有如下代码 至此,PayPal-PHP-SDK支付接口sample支付过程完毕。 在项目根目录创建app文件夹,创建几个必须的文件如下: [img]/Uploads/editor/2018-02-02/5a744c34204a4.png[/img] 完整代码如下: [code] use \PayPal\Api\Payer; use \PayPal\Api\Item; use \PayPal\Api\ItemList; use \PayPal\Api\Details; use \PayPal\Api\Amount; use \PayPal\Api\Transaction; use \PayPal\Api\RedirectUrls; use \PayPal\Api\Payment; use \PayPal\Exception\PayPalConnectionException; require "app/start.php"; if (!isset($_POST['product'], $_POST['price'])) { die("lose some params"); } $product = $_POST['product']; $price = $_POST['price']; $shipping = 2.00; //运费 $total = $price + $shipping; $payer = new Payer(); $payer->setPaymentMethod('paypal'); $item = new Item(); $item->setName($product) ->setCurrency('USD') ->setQuantity(1) ->setPrice($price); $itemList = new ItemList(); $itemList->setItems([$item]); $details = new Details(); $details->setShipping($shipping) ->setSubtotal($price); $amount = new Amount(); $amount->setCurrency('USD') ->setTotal($total) ->setDetails($details); $transaction = new Transaction(); $transaction->setAmount($amount) ->setItemList($itemList) ->setDescription("支付描述内容") ->setInvoiceNumber(uniqid()); $redirectUrls = new RedirectUrls(); $redirectUrls->setReturnUrl(SITE_URL . '/pay.php?success=true') ->setCancelUrl(SITE_URL . '/pay.php?success=false'); $payment = new Payment(); $payment->setIntent('sale') ->setPayer($payer) ->setRedirectUrls($redirectUrls) ->setTransactions([$transaction]); try { $payment->create($paypal); } catch (PayPalConnectionException $e) { echo $e->getData(); die(); } $approvalUrl = $payment->getApprovalLink(); header("Location: {$approvalUrl}") checkout.php通过表单提交上来的参数对支付具体细节和参数进行初始化和设置。这里只列出了常用的部分。paypal提供了很多参数设置。具体更丰富的可以自己参考paypal官方开发者文档。

paypal在线支付源码演示下载:http://t.cn/RlazMp7

    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册