1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| <?php
class Paypal{
private $user = '***';
private $pwd = '***';
private $signature = '*** ';
public $endpoint = 'https://api-3T.sandbox.paypal.com/nvp';
public $errors = array();
public function __construct($user = false, $pwd = false, $signature = false, $prod = false){
if($user){
$this->user=$user;
}
if($pwd){
$this->pwd=$pwd;
}
if($signature){
$this->signature=$signature;
}
if($prod){
$this->endpoint = str_replace('sandbox.', '',$this->endpoint);
}
}
public function request($method,$params){
$params = array_merge($params, array(
'METHOD' => $method,
'VERSION' => '201',
'USER' => $this->user,
'PWD' => $this->pwd,
'SIGNATURE' => $this->signature
));
$params = http_build_query($params);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $this->endpoint,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_VERBOSE => 1
));
$response = curl_exec($curl);
parse_str($response, $responseArray);
if(curl_errno($curl)){
$this->errors = curl_error($curl);
curl_close($curl);
return false;
}else{
if($responseArray['ACK'] == 'Success'){
curl_close($curl);
return $responseArray;
}else{
var_dump($responseArray);
$this->errors = curl_error($curl);
curl_close($curl);
return false;
}
}
}
}
?> |
Partager