php - PayPal Incoming JSON request does not map to API -


i'm trying create payment paypal , errors.

errors:

400{"name":"malformed_request","message":"incoming json request not map api request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#malformed_request","debug_id":"f79dc9a739991"}exception 'paypal\exception\paypalconnectionexception' message 'got http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment.' in /home/nork/domains/nork.lt/public_html/cms/xxx/system/payments/paypal-php-sdk/paypal/rest-api-sdk-php/lib/paypal/core/paypalhttpconnection.php:202 stack trace: #0 /home/nork/domains/nork.lt/public_html/cms/xxx/system/payments/paypal-php-sdk/paypal/rest-api-sdk-php/lib/paypal/transport/paypalrestcall.php(73): paypal\core\paypalhttpconnection->execute('{"intent":"sale...') #1 /home/nork/domains/nork.lt/public_html/cms/xxx/system/payments/paypal-php-sdk/paypal/rest-api-sdk-php/lib/paypal/common/paypalresourcemodel.php(104): paypal\transport\paypalrestcall->execute(array, '/v1/payments/pa...', 'post', '{"intent":"sale...', null) #2 /home/nork/domains/nork.lt/public_html/cms/xxx/system/payments/paypal-php-sdk/paypal/rest-api-sdk-php/lib/paypal/api/payment.php(577): paypal\common\paypalresourcemodel::executecall('/v1/payments/pa...', 'post', '{"intent":"sale...', null, object(paypal\rest\apicontext), null) #3 /home/nork/domains/nork.lt/public_html/cms/xxx/checkout.php(73): paypal\api\payment->create(object(paypal\rest\apicontext)) #4 {main}

code:

 <?php  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;  if(isset($_get['type']) && isset($_get['amount']) && isset($_get['gold'])) {     if($_get['type'] == 'paypal') // if payment paypal     {         require 'system/payments/paypal.php';          $gold           = $_get['gold'];         $amount         = $_get['amount'];         $pricepervnt    = 0.00;         $productname    = '';         $shipping = 0.00;          switch($gold)         {             case 'first':             {                 $productname = 'first name';                 $pricepervnt = 1.19;                 break;             }             case 'second':             {                 $productname = 'second name';                 $pricepervnt = 0.21;                 break;             }         }         if(!$pricepervnt) die();          $totalamount = $amount * $pricepervnt;          $payer = new payer();         $payer->setpaymentmethod('paypal');          $item = new item();         $item->setname($productname)->setcurrency('usd')->setquantity('1')->setprice($pricepervnt);          $itemlist = new itemlist();         $itemlist->setitems($item);          $amount = new amount();         $amount->setcurrency('usd')->settotal($totalamount);          $transaction = new transaction();         $transaction->setamount($pricepervnt)->setdescription($productname)->setinvoicenumber(uniqid());          $redirecturls = new redirecturls();         $redirecturls->setreturnurl('http://google.lt')->setcancelurl('http://cancel.lt');          $payment = new payment();         $payment->setintent('sale')->setpayer($payer)->setredirecturls($redirecturls)->settransactions($transaction);          try {             $payment->create($paypal);         } catch (paypal\exception\paypalconnectionexception $ex) {             echo $ex->getcode(); // prints error code             echo $ex->getdata(); // prints detailed error message              die($ex);         } catch (exception $ex) {             die($ex);         }         //print_r($payment);          //echo $approvalurl = $payment->getapprovallink();         //header('location: {$approvalurl}');     } }  ?> 

the answer appears not sending sufficient request values:

{"intent":"sale...', null)

note null. in order see error dump in more details, can tweak var_dump complexity:

ini_set('xdebug.var_display_max_depth', 10); ini_set('xdebug.var_display_max_children', 256); ini_set('xdebug.var_display_max_data', 1024); 

then see full json , can figure out missing or malformed.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -