Appels à CURL pour Paypal
Posté : 18 août 2014, 14:02
Bonjour à tous, voilà je dois créer une librairie de fonctionnalités qui revoient des requêtes à Paypal pour une appli de mobile.
J'ai crée une classe InitPaypal qui ressemble à ça pour le moment :
<?php
Ce malin me dit : object(stdClass)#3 (5) { ["message"]=> string(13) "Invalid Token" ["errorCode"]=> int(600032) ["developerMessage"]=> string(202) "The provided access token is no longer valid. It may have simply expired; if so, you should use your refresh token to request a new access token. If this fails, your access to this API has been revoked." ["errorType"]=> string(26) "oauth/invalid_access_token" ["correlationId"]=> string(13) "6578ebe21e8a2" }
SVP aidez-moi, car j'ai l'impression de pas m'y prendre de la bonne façon :s
J'ai crée une classe InitPaypal qui ressemble à ça pour le moment :
<?php
class InitPaypal {
private $clientId = "blibli";
private $secret = "blabla";
protected $ch;
protected $result;
public $accessToken;
public function __construct(){
$this->ch = curl_init();
}
public function connect(){
curl_setopt($this->ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($this->ch, CURLOPT_HEADER, false);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_POST, true);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_USERPWD, $this->clientId.":".$this->secret);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
}
public function test(){
curl_setopt($this->ch, CURLOPT_URL, "https://api.sandbox.paypal.com/retail/merchant/v1/locations");
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_POST, true);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_USERPWD, $this->clientId.":".$this->secret);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, 'access_token= '.$this->accessToken);
}
public function exec() {
$this->result = curl_exec($this->ch);
return(json_decode($this->result));
}
public function close(){
curl_close($this->ch);
}
}
J'appelle ma classe de cette façon :<?php
include_once 'classes/InitPaypal.php';
$ch = new InitPaypal();
$ch->connect();
$connect = $ch->exec();
$ch->accessToken = $connect->access_token;
$ch->test();
$result = $ch->exec();
var_dump($result);
$ch->close();
?>
Au var_dump, ben ma fonction veut pas s'exécuter !!!!Ce malin me dit : object(stdClass)#3 (5) { ["message"]=> string(13) "Invalid Token" ["errorCode"]=> int(600032) ["developerMessage"]=> string(202) "The provided access token is no longer valid. It may have simply expired; if so, you should use your refresh token to request a new access token. If this fails, your access to this API has been revoked." ["errorType"]=> string(26) "oauth/invalid_access_token" ["correlationId"]=> string(13) "6578ebe21e8a2" }
SVP aidez-moi, car j'ai l'impression de pas m'y prendre de la bonne façon :s