• France
état des services
démonstrations
assistance
FAQContacter le support
Video tutorials
Rechercher
Catégories
Tags
docs.
France
Espagne
Europe (Anglais)
Inde
Accueil
Cas d'usage
Créer un paiement
Créer un paiement en plusieurs fois
Proposer un paiement complémentaire
Créer un paiement par alias (token)
Créer un lien de paiement
Créer un abonnement
Gérer vos abonnements
Gérer vos transactions (rembourser,...)
Analyser vos journaux
Docs API
Formulaire embarqué
API REST
Formulaire en redirection
SDK Mobile
Échange de fichiers
Mandats SEPA par API REST
Exemples de code
Moyens de paiement
Modules de paiement
Marketplace
Guides
Back Office Marchand
Back Office Expert
Guides fonctionnels

Fichiers d'exemple : ipn.php et paid.php

1. ipn.php

Ce fichier permet d'analyser le résultat du paiement depuis l'IPN.

Il sert à :

  1. vérifier la signature avec le mot de passe (qui commence par testpasswordou prodpassword) pour comparer avec la valeur du kr-hash. (2 ème clé du tableau des clés API REST ).

  2. récupérer des informations de la réponse du kr-answer (le statut, le numéro de la commnande, le numéro unique UUID ...)

https://github.com/lyra/rest-php-examples/blob/master/www/sample/ipn.php
<?php

   include_once 'config.php';

   

   // STEP 1 : check the signature with the password

   if (!checkHash($_POST, PASSWORD)) {

       echo 'Invalid signature. <br />';

       print_r($_POST, true);

       die();

   }

   

   $answer = array();

   $answer['kr-hash'] = $_POST['kr-hash'];

   $answer['kr-hash-algorithm'] = $_POST['kr-hash-algorithm'];

   $answer['kr-answer-type'] = $_POST['kr-answer-type'];

   $answer['kr-answer'] = json_decode($_POST['kr-answer'], true);

           

   function checkHash($data, $key)

   {

       $supported_sign_algos = array('sha256_hmac');

       if (!in_array($data['kr-hash-algorithm'], $supported_sign_algos)) {

           return false;

       }

       $kr_answer = str_replace('\/', '/', $data['kr-answer']);

       $hash = hash_hmac('sha256', $kr_answer, $key);

       return ($hash == $data['kr-hash']);

   }

   

   /* STEP 2 : get some parameters from the answer */

   $orderStatus = $answer['kr-answer'] ['orderStatus'];

   $orderId = $answer['kr-answer']['orderDetails']['orderId'];

   $transactionUuid = $answer['kr-answer']['transactions'][0]['uuid'] ;

   

   /* I update my database if needed */

   /* Add here your custom code */ 

   

   /**

    * Message returned to the IPN caller

    * You can return want you want but

    * HTTP response code should be 200

    */

   print 'OK! OrderStatus is ' . $orderStatus;

   ?>

2. paid.php

Ce fichier permet d'analyser le résultat du paiement lors du retour à la boutique.

Il sert à :

  1. vérifier de la signature avec la Clé HMAC-SHA-256 pour comparer avec la valeur du kr-hash. (4 ème clé du tableau des clés API REST ).

  2. récupérer des informations de la réponse du kr-answer (le statut, le numéro de la commnande, le numéro unique UUID ...)

https://github.com/lyra/rest-php-examples/blob/master/www/sample/paid.php
<?php



include_once 'config.php';



// STEP 1 : check the signature with the SHA_KEY on the file config.php

if (!checkHash($_POST, SHA_KEY)) {

   echo 'Invalid signature. <br />';

   die();

}



$answer = array();

$answer['kr-hash'] = $_POST['kr-hash'];

$answer['kr-hash-algorithm'] = $_POST['kr-hash-algorithm'];

$answer['kr-answer-type'] = $_POST['kr-answer-type'];

$answer['kr-answer'] = json_decode($_POST['kr-answer'], true);



function checkHash($data, $key)

{

   $supported_sign_algos = array('sha256_hmac');



   if (!in_array($data['kr-hash-algorithm'], $supported_sign_algos)) {



      return false;

   }



   $kr_answer = str_replace('\/', '/', $data['kr-answer']);

   $hash = hash_hmac('sha256', $kr_answer, $key);



   return ($hash == $data['kr-hash']);

}

?>



<html>



<head>

   <meta http-equiv="Pragma" content="no-cache">

   <meta http-equiv="Expires" content="-1">

   <title>Successful payment</title>

</head>



<body>

   <div class="container">

      <h2>Data recevied :</h2>

      <!-- STEP 2 : get some parameters from the 'kr-answer'  -->

      <strong>Numéro de la boutique :</strong>

      <?php echo $answer['kr-answer']['shopId']; ?>

      <br />

      <strong>Le statut de la transaction :</strong>

      <?php echo $answer['kr-answer']['orderStatus']; ?>

      <br />

      <strong>Numéro de la transaction :</strong>

      <?php echo $answer['kr-answer']['transactions'][0]['uuid']; ?>

      <br />

      <strong>Numéro de la commande :</strong>

      <?php echo $answer['kr-answer']['orderDetails']['orderId']; ?>

      <br />

   </div>

</body>



</html>
Nous recrutons
Mentions légales
Charte de Protection des Données Personnelles
25.18-1.11