83403

Exception Using PayPal-PHP-SDK [Http response code 400]

Question:

I'm following a tutorial about how to use PayPal-PHP-SDK and i got stuck in somewhere with this error in the console:

[Sun Mar 08 16:11:21.729977 2015] [:error] [pid 4484:tid 1760] [client ::1:4308] PHP Fatal error: Uncaught exception 'PayPal\\Exception\\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Core\\PayPalHttpConnection.php:176\nStack trace:\n#0 C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Transport\\PayPalRestCall.php(74): PayPal\\Core\\PayPalHttpConnection->execute('{"intent":"sale...')\n#1 C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Common\\PayPalResourceModel.php(103): PayPal\\Transport\\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL)\n#2 C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Api\\Payment.php(424): PayPal\\Common\\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPal\\Rest\\ApiContext), NULL)\n#3 C:\\UniServerZ\\www\\PayPal\\member\\payment.php(48): PayPal\\Api\\Payment->create(Object(PayPal\\Rest\\ApiContext))\n#4 {mai in C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Core\\PayPalHttpConnection.php on line 176, referer: http://localhost:1313/PayPal/

UPDATE

The new message from the log after try updating the name of the function is:

[Mon Mar 09 23:28:26.612147 2015] [:error] [pid 4344:tid 1772] [client ::1:2189] PHP Fatal error: Uncaught exception 'PayPal\\Exception\\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Core\\PayPalHttpConnection.php:176\nStack trace:\n#0 C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Transport\\PayPalRestCall.php(74): PayPal\\Core\\PayPalHttpConnection->execute('{"intent":"sale...')\n#1 C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Common\\PayPalResourceModel.php(103): PayPal\\Transport\\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL)\n#2 C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Api\\Payment.php(424): PayPal\\Common\\PayPalResourceModel::executeCall('/v1/payments/pa...', 'POST', '{"intent":"sale...', NULL, Object(PayPal\\Rest\\ApiContext), NULL)\n#3 C:\\UniServerZ\\www\\PayPal\\member\\payment.php(48): PayPal\\Api\\Payment->create(Object(PayPal\\Rest\\ApiContext))\n#4 {mai in C:\\UniServerZ\\www\\PayPal\\vendor\\paypal\\rest-api-sdk-php\\lib\\PayPal\\Core\\PayPalHttpConnection.php on line 176, referer: http://localhost:1313/PayPal/

This is the code:

<?php use PayPal\Api\Payer; use PayPal\Api\Details; use PayPal\Api\Amount; use PayPal\Api\Transaction; use PayPal\Api\Payment; use PayPal\Api\RedirectUrls; require '../scr/start.php'; $payer = new Payer(); $details = new Details(); $amount = new Amount(); $transaction = new Transaction(); $payment = new Payment(); $redirectUrls = new RedirectUrls(); // Payer $payer->setPaymentMethod('paypal'); // Details $details->setShipping('2.00') ->setTax('0.00') ->setSubtotal('20.00'); //feed for membership // Amount $amount->setCurrency('CLP') ->setTotal('22.00') // Shipping + Tax + Subtotal + Everything else you need to charge ->setDetails($details); // Transaction $transaction->setAmount($amount) ->setDescription('Membership'); $payment->setIntent('sale') ->setPayer($payer) ->setTransactions([$transaction]); // Redirect URLs $redirectUrls->setReturnUrl('http://localhost:1313/PayPal/PayPall/Pay.php?approved=true') ->setCancelUrl('http://localhost:1313/PayPal/PayPall/Pay.php?approved=false'); $payment->setRedirectUrls($redirectUrls); try { $payment->create($api); // Generate and store hash // Prepare and execute transaction storage } catch (PPConnectionException $e) { // Perhaps log an error header('Location: ../PayPall/error.php'); } var_dump($payment->getLinks()); ?>

Any orientation, question for improve this same question, comment, advice or request of clarification/more info about it, etc[...] than help to reach the solution of the problem would be much appreciated.

Answer1:

Make this code change. PPConnectionException was renamed to PayPalConnectionException. You could also do $e->getData() to retrieve detailed exception message.

} catch (PayPalConnectionException $e) { echo $e->getData(); // Perhaps log an error header('Location: ../PayPall/error.php'); }

Recommend

  • Image error in DOMPDF for ZF2
  • How do you submit a rails 3 form without refreshing the page?
  • Using nativescript converters
  • Infer constraints for both if and else of type equality
  • How to replace a contour (rectangle) in an image with a new image using Python?
  • Creating an array of products in JSON-LD
  • Why do I have to use LD_PRELOAD for libcl.2 to use XML::LibXML::Common on HP/UX?
  • Why must we Forward Declare a class and include the corresponding header file in a header file
  • fetch all links under/in a specific class-selenium webdriver (java)
  • Why Is jQuery Not Submitting This Form? (Or What Have I Done Wrong? :-p)
  • Send money from Braintree
  • Eloquent Relationship on Partial Match
  • Less Conflicting Session Manager for Zope 2
  • Redirect to Post Method/Action
  • RxJava debounce by arbitrary value
  • pyodbc doesn't report sql server error
  • Does Mobilefirst provide a provision to access web services directly?
  • NSScanner Loop Question
  • Display java JPanel in a JFrame
  • How to attach a node.js readable stream to a Sendgrid email?
  • how to adjust image in a panel in Java swing?
  • Installing Hadoop, Java Exception about illegal characters at index 7?
  • Encrypt data by using a public key in c# and decrypt data by using a private key in php
  • Different response to non-authenticated users and AJAX calls
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Hazelcast - OperationTimeoutException
  • Rearranging Cells in UITableView Bug & Saving Changes
  • RestKit - RKRequestDelegate does not exist
  • Linker errors when using intrinsic function via function pointer
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Revoking OAuth Access Token Results in 404 Not Found
  • Benchmarking RAM performance - UWP and C#
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • Memory offsets in inline assembly
  • Turn off referential integrity in Derby? is it possible?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • LevelDB C iterator
  • How can i traverse a binary tree from right to left in java?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize