douan2907 2015-09-01 10:37
浏览 51

Json数据如何获取PHP的内容

I am trying to use the paypal developer SDK for PHP for the first time. I have followed a tutorial on youtube all going well until I tried to execute it and the response I recieved was malformed_request JSON request doesn not map to API request. How do I get the struscture and contents of the JSON object so I can investigate further? please see code below error happens on the try. I am developing in netbeans 7.4

<?PHP
//this is copied from this tutorial here on youtube https://www.youtube.com/watch?v=BD1dOWIABe0
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;
require '/../app/start.php';
$pTotal = 20.00;
$shipping = 1.00;
$Total = $pTotal + $shipping ;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$item = new Item();
$item->setName("tieThisToSomething")
->setCurrency('GBP')
->setQuantity(1)
->setPrice($pTotal);
$itemList = new ItemList();
$itemList->setItems($item); //I have removed square brackets from here []
$details = new Details();
$details->setShipping($shipping)
    ->setSubtotal($pTotal);
$amount = new Amount();
$amount->setCurrency('GBP')
    ->setTotal($Total)
    ->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription('Pay for all your santa fun')
    ->setInvoiceNumber(uniqid());//perhaps tie this to order number?

$redirectUrls = new RedirectUrls();
$redirectUrls->setCancelUrl(SITE_URL . '/pay.php?success=false')
         ->setReturnUrl(SITE_URL . '/pay.php?success=true'); 

$payment = new Payment();
$payment->setPayer($payer)
    ->setTransactions($transaction)
    ->setIntent('sale')
    ->setRedirectUrls($redirectUrls)   ; //should [] be needed here?

//try {
//    $payment->create($paypal);
//} catch (Exception $e) {
//    die($e);
//}

try {
   $payment->create($paypal);  //Error happens here!
} catch (PayPal\Exception\PayPalConnectionException $ex) {
  echo $ex->getCode(); // Prints the Error Code
  echo $ex->getData(); // Prints the detailed error message 
 die($ex);
} catch (Exception $ex) {
 die($ex);
}

$approvalUrl = $payment->getApprovalLink();
header("Location: {$approvalUrl}");
  • 写回答

1条回答 默认 最新

  • dtnrsmi824877 2015-10-11 20:01
    关注

    Adding logging would definitely help you investigate the raw details of the message. Here is the link to add configurations to enable logging:

    https://github.com/paypal/PayPal-PHP-SDK/wiki/Adding-Configurations

    Also, there are a lot of sample codes that could help you setup your code. Here is the one that shows creating "Payment with PayPal". You could infact run those locally by following instructions here.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题