简体   繁体   English

PayPal Rest-API PHP-空白页

[英]PayPal Rest-API PHP - Blank Page

I am having trouble with the PayPal PHP Rest API. 我在使用PayPal PHP Rest API时遇到问题。

For some reason it shows as a blank page and only shows info through puTTY. 由于某种原因,它显示为空白页面,并且仅通过PuTTY显示信息。 I have no idea what's going on. 我不知道发生了什么事。

Here is my script: 这是我的脚本:

<?php
require __DIR__ . '/PayPal-PHP-SDK/autoload.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\Transaction;
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;

$api = new ApiContext(
    new OAuthTokenCredential(
        'yes it is correct',     // ClientID
        'correct '      // ClientSecret
    )
);
$api->setConfig([
'mode' => 'sandbox',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => false,
'log.FileName' => '',
'log.LogLevel' => 'FINE',
'validation.level' => 'log'

]);


$payer = new Payer();
$payer->setPaymentMethod("paypal");



$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')
    ->setCurrency('USD')
    ->setQuantity(1)
    ->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')
    ->setCurrency('USD')
    ->setQuantity(5)
    ->setPrice(2);

$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));



$details = new Details();
$details->setShipping(1.2)
    ->setTax(1.3)
    ->setSubtotal(17.50);

$amount = new Amount();
$amount->setCurrency("USD")
    ->setTotal(20)
    ->setDetails($details);

$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription("Payment description")
    ->setInvoiceNumber(uniqid());




$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("http://uplayeve.ml/PayPal/ExecutePayment.php?success=true")
    ->setCancelUrl("http://uplayeve.ml/PayPal//ExecutePayment.php?success=false");

$payment = new Payment();
$payment->setIntent("sale")
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));

$request = clone $payment;


try {
    $payment->create($api);
} catch (Exception $ex) {
    echo 'Maybe an error or something';
    exit(1);
}

$approvalUrl = $payment->getApprovalLink();

ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);

return $payment;
    ?>

Also here is my current phpinfo() : http://uplayeve.ml/PayPal/phpinfo.php 这也是我当前的phpinfo()http : //uplayeve.ml/PayPal/phpinfo.php

A Blank Page generally in PHP means, something threw an error, but your reporting is not enabled. 通常,PHP中的空白页意味着出现了错误,但是未启用报告。 You could easily enable this by adding these two lines at the top. 您可以通过在顶部添加这两行来轻松启用此功能。

error_reporting(E_ALL);
ini_set('display_errors', '1');

This should potentially print the error now. 现在应该可以打印错误了。 Also, there are few things you should note. 另外,您应该注意一些事情。

  1. ResultPrinter is a sample only code. ResultPrinter是仅示例代码。 Please disregard that, and remove that from your code. 请忽略它,并将其从您的代码中删除。 That could be causing the error. 那可能导致错误。

  2. If for any reason, you wish to catch and read proper exception, add this catch method as shown below. 如果出于任何原因希望捕获并读取适当的异常,请如下所示添加此catch方法。

     try { $payment->create($api); } catch (\\PayPal\\Exception\\PayPalConnectionException $ex) { echo $ex->getData(); } 

Btw, we are adding more and more samples, wiki pages, source docs, etc at http://paypal.github.io/PayPal-PHP-SDK/ to enable developers to integrate with REST API faster. 顺便说一句,我们在http://paypal.github.io/PayPal-PHP-SDK/上添加了越来越多的示例,Wiki页面,源文档等,以使开发人员能够更快地与REST API集成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM