php - PayPal SDK error "Credential not found for default user" -


i'm trying integrate paypal sdk site have run problem cannot find solution in documentation or via stackoverflow.

i use standard set-up:

start.php:

    <?php      //require 'vendor/autoload.php';     require __dir__ . '/../vendor/autoload.php';      use paypal\rest\apicontext;     use paypal\auth\oauthtokencredential;      define('base_url', 'http://localhost:80/paypaltut/');      if(!defined("pp_config_path")){             define('pp_config_path', '../vendor/paypal/rest-api-sdk-php/tests/');             }     $clientid = 'are54bhozrcn13nrgldpist46bwop6pybrylp4nulwwtl2iviuklijrup5ldgzfuc0qpbqiugdvfsmek';     $clientsecret = 'ejariez8b_6wez__gzl0us-dmc-ypa1rh1jof1u4_xljje2iinbrcsarhnyzk-djg7kbjs8ceqf5gnvr';      $apicontext = new apicontext(new oauthtokencredential($clientid, $clientsecret));     

index.php:

    <!doctype html>     <html lang="en">     <head>     <meta charset="utf-8">         <meta name="viewport" content="width=device-width, initial-scale=1">         <!--scripts-->         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>         <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>         <script src="../scripts/modernizr.js"> </script> <!-- modernizr -->         <!--stylesheets-->         <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">         <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">         <link rel="stylesheet" href="../css/reset.css"> <!-- css reset -->         <link rel="stylesheet" href="css/"> <!-- resource style -->         <link rel="stylesheet" href="css/ongakustandard.css"> <!-- resource style -->         <link rel="stylesheet" href="../css/signupstyle.css" type="text/css"><!-- sign form , of partials-->         <!--fonts-->         <link href='http://fonts.googleapis.com/css?family=titillium+web:400,600,700' rel='stylesheet' type='text/css'>         <link href='http://fonts.googleapis.com/css?family=josefin+sans:400,600,700' rel='stylesheet' type='text/css'>         <link href='http://fonts.googleapis.com/css?family=fira+sans:400,500,700' rel='stylesheet' type='text/css'>         <link href='http://fonts.googleapis.com/css?family=grand+hotel' rel='stylesheet' type='text/css'>       <title>doc</title> </head> <body>  <div class="container-fluid centerdisp">     <form class="blockdisp" name="productform" method="post" action="checkout.php">         <div class="blockdisp">             <div class="forminputdiv blockdisp">                 <label class="fw-120 label-1">product name</label>                 <input class="medinput" type="text" name="product">             </div>             <div class="forminputdiv blockdisp">                 <label class="label-1 fw-120">quantity</label>                 <input class="medinput" type="number" step="any" min="0" max="15" name="quantity"> <!--                <input class="medinput" type="string" name="quantity">-->             </div>             <div class="forminputdiv blockdisp">                 <label class="label-1 fw-120">price</label>                 <select class="medinput" type="number" name="price">                     <option value="5.00">5.00</option>                     <option value="8.00">8.00</option>                     <option value="12.00">12.00</option>                     <option value="18.00">18.00</option>                     <option value="25.00">25.00</option>                     <option value="60.00">60.00</option>                 </select>             </div>             <br>             <div class="forminputdiv flex-middle">                 <button class="submission fw-200" value="submit">submit</button>             </div>         </div>         <input type="hidden" name="{{ csrf_key }}" value="{{ csrf_token }}" >     </form> </div> <script>      $('input[name="quantity"]').on('change', function(){         var thisval = $(this).val();         $(this).val(thisval + '.00');             });  </script>  </body> </html> 

checkout.php:

<?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; use paypal\rest\apicontext; use paypal\auth\oauthtokencredential;  require 'app/start.php';  if(!isset($_post['product'], $_post['price'], $_post['quantity'])) {     echo "post variables not set!!";     die(); }    $product = $_post['product']; $price = (float) $_post['price']; $quant = (float) $_post['quantity']; $shipping = (float) 2.55; $tax = (float) 1.45; $subtotal = $price * $quant; $total = $subtotal + $shipping + $tax;  //more api variable definition $payer = new payer();     $payer->setpaymentmethod('paypal');  $item = new item();     $item->setname($product);     $item->setcurrency('gbp');     $item->setquantity($quant);     $item->setprice($price);  $itemlist = new itemlist();     $itemlist->setitems([$item]);  $details = new details();     $details->settax($tax);     $details->setshipping($shipping);     $details->setsubtotal($price * $quant);  $amount = new amount();     $amount->setcurrency('gbp');     $amount->settotal($total);     $amount->setdetails($details);  $transaction = new transaction();     $transaction->setitemlist($itemlist);     $transaction->setamount($amount);     $transaction->setdescription('sessions');  $redirecturls = new redirecturls();     $redirecturls->setreturnurl(base_url . 'pay.php?success=true');     $redirecturls->setcancelurl(base_url . 'pay.php?success=false');  $payment = new payment();     $payment->setintent('sale');     $payment->setpayer($payer);     $payment->setredirecturls($redirecturls);     $payment->settransactions([$transaction]);      try{     $payment->create($apicontext);     }  catch (paypal\exception\paypalconnectionexception $ex) {     echo $ex->getcode();      echo $ex->getdata();  } catch (exception $ex) {     die($ex); } $approvalurl = $payment->getapprovallink(); header("location: {$approvalurl}"); exit(1); 

pay.php:

<?php  require 'app/start.php';  use paypal\api\payment; use paypal\api\paymentexecution;      if(!isset($_get['success'], $_get['paymentid'], $_get['payerid'])){         die();     }      if((bool)$_get['success']=== 'false'){          echo 'transaction cancelled!';         die();     }      $paymentid = $_get['paymentid'];     $payerid = $_get['payerid'];      $payment = payment::get($paymentid, $apicontext);      $execute = new paymentexecution();     $execute->setpayerid($payerid);      try{         $result = $payment->execute($execute);     }catch(exception $e){         die($e);     }     echo 'payment made, thanks!'; 

congif.ini:

;account credentials developer portal [account] acct1.clientid = aysq3rdgsmblje-ottkbtm-jbrd1tcqwff9rgfwddnxwz0ufu9ztymylohrs acct1.clientsecret = egnhdxd_qrpdaldzz8icr8n7_mzf-yhptkjs6nkyqvqsbngp4pttvwkpzrbl  acct2.clientid = testclientid acct2.clientsecret = testclientsecret  ;connection information [http] http.connectiontimeout = 60 http.retry = 1 ;http.proxy=http://[username:password]@hostname[:port][/path]  mode=sandbox  ;service configuration [service] service.endpoint="https://api.sandbox.paypal.com" ; uncomment line integrating live endpoint  ; service.endpoint="https://api.paypal.com"   ;logging information [log] log.logenabled=true  ; when using relative path, log file created ; relative .php file entry point ; request. can provide absolute ; path here log.filename=paypal.log  ; logging level can 1 of fine, info, warn or error ; logging verbose in 'fine' level , ; decreases proceed towards error log.loglevel=debug  ;validation configuration [validation] ; if validation set strict, paypalmodel make sure ; there proper accessors (getters , setters) each model ; objects. accepted value ; 'log'     : logs error message logger (default) ; 'strict'  : throws php notice message ; 'disable' : disable validation validation.level=strict 

when attempt process payment using paypal sandbox version of app, error:

 exception 'paypal\exception\paypalinvalidcredentialexception' message 'credential not found default user. please make sure configuration/apicontext has credential information' in d:\webdev\htdocs\paypaltut\vendor\paypal\rest-api-sdk-php\lib\paypal\core\paypalcredentialmanager.php:154 stack trace:  stack trace:  #0 d:\webdev\htdocs\paypaltut\vendor\paypal\rest-api-sdk-php\lib\paypal\rest\apicontext.php(56): paypal\core\paypalcredentialmanager->getcredentialobject()   #1 d:\webdev\htdocs\paypaltut\vendor\paypal\rest-api-sdk-php\lib\paypal\handler\resthandler.php(51): paypal\rest\apicontext->getcredential()   #2 d:\webdev\htdocs\paypaltut\vendor\paypal\rest-api-sdk-php\lib\paypal\transport\paypalrestcall.php(71): paypal\handler\resthandler->handle(object(paypal\core\paypalhttpconfig), '{"payer_id":"6h...', array)   #3 d:\webdev\htdocs\paypaltut\vendor\paypal\rest-api-sdk-php\lib\paypal\common\paypalresourcemodel.php(103): paypal\transport\paypalrestcall->execute(array, '/v1/payments/pa...', 'post', '{"payer_id":"6h...', null)   #4 d:\webdev\htdocs\paypaltut\vendor\paypal\rest-api-sdk-php\lib\paypal\api\payment.php(498): paypal\common\paypalresourcemodel::executecall('/v1/payments/pa...', 'post', '{"payer_id":"6h...', null, null, null)   #5 d:\webdev\htdocs\paypaltut\pay.php(36): paypal\api\payment->execute(object(paypal\api\paymentexecution))  #6 {main} 

i have gone through process of creating app through paypal developer's dashboard, i've tried adding new apicontext teh pay (return url ) file , still same error. know how fix one?

oh i'm using v1.5.0 sdk , php 5.6.1

found root cause.

you forgot pass $apicontext object execute call in pay.php code.

try {     $result = $payment->execute($execute); } catch(exception $e) {     die($e); } 

change this, , should work:

try {     $result = $payment->execute($execute, $apicontext); } catch(exception $e){     die($e); } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -