Can't integrate Paypal API to PHP: Fatal error: Allowed memory size of 134217728 byte -


i got error:

fatal error: allowed memory size of 134217728 bytes exhausted (tried allocate 262144 bytes) in c:\xampp\htdocs\paypaltest\vendor\paypal\rest-api-sdk-php\lib\paypal\common\paypalmodel.php on line 281

i have start.php file :

<?php  require 'vendor/autoload.php';  define('site_url', 'http://localhost:8080/paypaltest');  $paypal = new paypal\rest\apicontext(new paypal\auth\oauthtokencredential('key', 'secret')); ?> 

and checkout.php file:

<?php  require 'app/start.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($_post['item']) && isset($_post['price'])) {     $item = $_post['item'];     $price = $_post['price'];     $shipping_fee = 2.0;      $total = $price + $shipping_fee;      $payer = new payer();     $payer->setpaymentmethod("paypal");      $item = new item();     $item->setname($item)->setcurrency('php')->setquantity(1)->setprice($price);      $itemlist = new itemlist();     $itemlist->setitems(array($item));      $details = new details();     $details->setshipping($shipping_fee)->setsubtotal($price);      $amount = new amount();     $amount->setcurrency('php')->settotal($total)->setdetails($details);      $transaction = new transaction();     $transaction->setamount($amount)->setitemlist($itemlist)->setdescription('practice')->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(array($transaction));        try {         $payment->create($paypal);         echo "51";     }     catch (exception $e)     {         echo "$e";     }      $approvalurl = $payment->getapprovallink();      echo "$approvalurl"; } else {     echo "error!"; } 

i have composer file used add paypal api project.

composer.json :

{     "require": {         "paypal/rest-api-sdk-php" : "1.12.0"     } } 

i check paypalmodel.php , error around block of code:

/**  * converts params array  *  * @param $param  * @return array  */ private function _converttoarray($param) {     $ret = array();     foreach ($param $k => $v) {         if ($v instanceof paypalmodel) {             $ret[$k] = $v->toarray();         } elseif (sizeof($v) <= 0 && is_array($v)) {             $ret[$k] = array();         } elseif (is_array($v)) {             $ret[$k] = $this->_converttoarray($v);         } else {             $ret[$k] = $v;         }     }     // if array empty, means empty object,     // need convert array stdclass object     // represent json string     if (sizeof($ret) <= 0) {         $ret = new paypalmodel();     }     return $ret; } 

i use xampp, not use framework , testing if code work can apply website.

i change memory_limit in php.ini file higher value (512m, 1024m, 2048m etc.) , -1 still no luck.

i think problem in code causing paypalmodel.php infinite loop (my theory), cannot figure out where. new paypal having difficulties.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -