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
| //données pour obtenir un token
$postData = http_build_query(
array(
'client_id' => "*********************", //fourni sur le compte de l'association par helloAsso
'client_secret' => "*********************",
'grant_type' => "client_credentials"
)
);
//récupération du token:
$opts = array('http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postData,
)
);
$context = stream_context_create($opts);
//url d'authentification
$url = 'https://api.helloasso.com/oauth2/token';
$result = file_get_contents($url, false, $context);
$tab_rep = json_decode($result, true);
echo"<pre> résultat "; print_r(json_decode($result));echo"<pre>";echo'<br/>';
$token =$tab_rep['access_token'];
echo "token : ".$token ;
//demande de paiement
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.helloasso.com/v5/organizations/nom-association/checkout-intents' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, "{'totalAmount' : 1000, 'initialAmount' : 1000, 'itemName' : 'Adhésion','backUrl' : 'https://domaine.fr/adherent /adhesions_activites_admin.php', 'errorUrl' : 'https://domaine.fr/adherent/HelloAsso/retour_erreur.php', 'returnUrl' :'https://domaine.fr/adherent/HelloAsso /redirectUrl.php',}");
curl_setopt($ch, CURLOPT_HTTPHEADER, array ( 'Accepter' => 'application/json',
'Content-type'=> 'application/x-www-form-urlencoded',
'Authorization' => 'Bearer '. $token ,
'Type de contenu' => 'application/json',
)
);
$reponse = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Erreur :' . curl_error($ch);
}
curl_close($ch);
echo"<pre> résultat "; print_r(json_decode($reponse, true));echo"<pre>";echo'<br/>';
$tab_rep = json_decode($reponse, true);
if(isset($tab_rep['id'])){
$id =$tab_rep['id'];
echo "id : ".$id ;echo'<br/>';
$redirectUrl = $tab_rep['redirectUrl'];
echo "redirectUrl : ".$redirectUrl ;echo'<br/>';
} |
Partager