• França
lyra.com
Procurando
Categoria
Tags
pagina inicial
Suporte técnico

Arquivos de exemplo : ipn.php et paid.php

1. ipn.php

Este arquivo permite analisar o resultado do pagamento a partir da IPN.

Serve para:

  1. verifique a assinatura com a senha (que começa com testpassword ou prodpassword ) para comparar com o valor do kr-hash . ( 2ª chave da tabela de chaves da API REST ).

  2. recuperar dados da resposta do kr-answer (o status, o número de pedido, o número único 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

Este arquivo permite que você analise o resultado do pagamento ao retornar à loja .

Serve para:

  1. verifique a assinatura com a chave HMAC-SHA-256 para comparar com o valor kr-hash . ( 4ª chave na tabela de chaves da API REST ).

  2. recuperar dados da resposta do kr-answer (o status, o número de pedido, o número único 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>
Jobs
Legal
GDPR
25.28-1.11