Bonjour,
Voila je rencontre un petit problème avec mon code.
https://i.imgur.com/kLeqpFy.png
Décrivez ici votre code ou ce que vous cherchez à faire
private function auth()
{
$postvals = "grant_type=client_credentials";
$uri = $this->uri . "v1/oauth2/token";
$auth_response = $this->curl($uri, "POST", $postvals, true);
if (
is_object($auth_response) and
property_exists($auth_response, "access_token") and
property_exists($auth_response, "token_type")
) {
$this->accessToken = $auth_response->access_token;
$this->tokenType = $auth_response->token_type;
}
}
private function curl(string $url, string $method = "GET", $postvals = null, $auth = false): ?stdClass
{
$ch = curl_init($url);
if ($ch === false) {
throw new Exception('failed to initialize');
}
//if we are sending request to obtain bearer token
if ($auth) {
$clientId = "";
$secret = "";
if (property_exists($this, "id") and property_exists($this, "secret")) {
$clientId = $this->id;
$secret = $this->secret;
}
$headers = ["Accept: application/json", "Accept-Language: en_US"];
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $secret);
} else {
// if we are sending request with the bearer token for protected resources
$headers = ["Content-Type:application/json", "Authorization:{$this->tokenType} {$this->accessToken}"];
}
$options = [
// CURLOPT_HEADER => true,
CURLOPT_HEADER => false,
CURLINFO_HEADER_OUT => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_VERBOSE => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSLVERSION => CURL_SSLVERSION_MAX_DEFAULT,
];
if ($method === "POST") {
$options[CURLOPT_POSTFIELDS] = $postvals;
$options[CURLOPT_CUSTOMREQUEST] = $method;
}
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
if ($response === false) {
throw new Exception(curl_error($ch), curl_errno($ch));
}
// $header = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
// $body = json_decode(substr($response, curl_getinfo($ch, CURLINFO_HEADER_SIZE)));
curl_close($ch);
// return ['header' => $header, 'body' => $body];
return json_decode($response);
}
public function order()
{
$uri = $this->uri . "v2/checkout/orders";
$postvals = [
"intent" => "CAPTURE",
"purchase_units" => [
[
"reference_id" => "test_ref_id1",
"amount" => [
"currency_code" => "USD",
"value" => "100.00"
]
]
],
"application_context" => [
"cancel_url" => "https://paypal.exemple.fr/cancel.php",
"return_url" => "https://paypal.exemple.fr/return.php"
]
];
return $this->curl($uri, "POST", json_encode($postvals));
}
$paypal = new Paypal();
$response = $paypal->order();
if (
is_object($response) and
property_exists($response, "id")
) {
header("Location: https://www.sandbox.paypal.com/checkoutnow?token=" . $response->id);
exit;
}
public function completed(string $token): ?stdClass
{
$uri = $this->uri . "v2/checkout/orders/{$token}/capture";
return $this->curl($uri, "POST", "");
}
Obtenir le statut terminer sur paypal.
J'obtien le statut Non récupéré.
Je ne vois quel étape il me reste a faire.
J'utilise les liens checkout V2.
Et j'ai tenté d'utilisé l'api fourni par paypal mais je me retrouve au même résultat.
Je suis obligé de confirmer le paiement manuellement sur l'interface paypal.