defr

<?php
/*——————— FORMULAIRE DE PAIEMENT SHERLOCK’S ———————//
Auteur : Azzedine Khetiri
Date de création : 03 04 2024
Date de mise à jour : 26 04 2024
version : 0.1
/* Votre boutique de test */
$urlForPaymentInitialisation    = « https://payment-webinit.test.sips-services.com/rs-services/v2/paymentInit/ »;
$merchantId                     = « 216040024960001 »;
$secretKey                      = « RkYM6RJjwo4eVzVv0kJqCPHjFCZLfsSL8RKVHYrVfjI »;
$keyVersion                     = « 7 »;
/* Votre boutique de test */
$urldusite                      = get_url_du_site();  //url de votre site récupéré automatiquement.
$sealAlgorithm                  = « HMAC-SHA-256 »;
$interfaceVersion               = « IR_WS_3.4 »;
$Encode= » »;
$EncodeAlgorithm= » »;
$automaticResponseUrl           = $urldusite. ‘automaticResponseUrl.php’; //cette page sera appelée de serveur à serveur, elle correspond au retour IPN. c’est ici qui faut traiter le retour du paiement.
$normalReturnUrl                = $urldusite. ‘automaticResponseUrl.php’; //Cette page sera affiché au client après le paiement, c’est ici que vous indiqué au client le statut de son paiement
$paymentMeanBrandList           = «  »; // »VISA, CB, MASTERCARD, VPAY, AMEX »;
$paymentPattern                 = « ONE_SHOT »;
$orderid                        = rand(1,9999);                 //réference de la commande
$transactionReference           = « trans ».rand(10000000, 99999999);
$transactionId                  = rand(111111,999999);          //A transmettre obligatoirement pour les contrats historique V1 migré
$transactionOrigin              = « AVEM »;
$orderChannel                   = « INTERNET »;
$captureMode                    = « AUTHOR_CAPTURE »;
$captureDay                     = « 0 »;
$total_amount                   = « 2500 »;               // montant total de l’achat x100  // 100 = 1 euro
$first_amount                   = « 1000 »;               //montant de la première échéance
$second_amount                  = « 1000 »;               //montant de la deuxieme échéance
$third_amount                   = « 500 »;                //montant de la troisieme et derniere échéance
$first_amount_date              = « 20240628 »;           //date de la premiere échéance
$second_amount_date             = « 20240701 »;           //date de la deuxieme échéance
$third_amount_date              = « 20240705 »;           //date de la troisieme et derniere échéance
$currencyCode                   = « 978 »;                        // Devise du paiement
$customerEmail                  = « ecommerce_lcl@avem-groupe.com »; // adresse email du porteur (client)
$challengeMode3DS               = « CHALLENGE_MANDATE »;
$billingAddress_city                = »ville du porteur »;
$billingAddress_country             = »FRA »;
$billingAddress_addressAdditional1  = »addresse 1 du porteur »;
$billingAddress_zipCode             = »11000″;
$billingAddress_state               = »departement du porteur »;
$holderContact_email                = »adresse_du_porteur@email.fr »;
$holderContact_firstName            = »prenom du porteur »;
$holderContact_lastName             = »nom du porteur »;
/*Fonction qui permet de récupérer votre url */
function get_url_du_site()
{
  if(isset($_SERVER[‘HTTPS’]) && $_SERVER[‘HTTPS’] === ‘on’)
    $url = « https »;
  else
    $url = « http »;
  // Ajoutez // à l’URL.
  $url .= « :// »;
  // Ajoutez l’hôte (nom de domaine, ip) à l’URL.
  $url .= $_SERVER[‘HTTP_HOST’];
  // Ajouter l’emplacement de la ressource demandée à l’URL
  $url .= $_SERVER[‘REQUEST_URI’];
  $pos = strrpos( $url, ‘/’ ); // recherche le dernier /
  $url = substr( $url, 0, $pos+1 ); // supprime le nom du fichier en cours de l’url
  return $url;
}
function compute_payment_init_seal($sealAlgorithm, $data, $secretKey)
{
   $dataStr = flatten($data);
   return compute_seal_from_string($sealAlgorithm, $dataStr, $secretKey, true);
}
function compute_payment_response_seal($sealAlgorithm, $data, $secretKey)
{
   return compute_seal_from_string($sealAlgorithm, $data, $secretKey, false);
}
function compute_seal_from_string($sealAlgorithm, $data, $secretKey, $hmac256IsDefault)
{
   if (strcmp($sealAlgorithm, « HMAC-SHA-256 ») == 0){
      $hmac256 = true;
   }elseif(empty($sealAlgorithm)){
      $hmac256 = $hmac256IsDefault;
   }else{
      $hmac256 = false;
   }
   return compute_seal($hmac256, $data, $secretKey);
}
function compute_seal($hmac256, $data, $secretKey)
{
   $serverEncoding = mb_internal_encoding();
   if(strcmp($serverEncoding, « UTF-8 ») == 0){
      $dataUtf8 = $data;
      $secretKeyUtf8 = $secretKey;
   }else{
      $dataUtf8 = iconv($serverEncoding, « UTF-8 », $data);
      $secretKeyUtf8 = iconv($serverEncoding, « UTF-8 », $secretKey);
   }
   if($hmac256){
      $seal = hash_hmac(‘sha256’, $data, $secretKey);
   }else{
      $seal = hash(‘sha256’,  $data.$secretKey);
   }
   return $seal;
}
//This function flattens the sorted payment data table into singleDimArray
function flatten($multiDimArray)
{
   global $singleDimArray;
   $sortedMultiDimArray = recursive_table_sort($multiDimArray);
   array_walk_recursive($sortedMultiDimArray, ‘valueResearch’);
   $string = implode(«  », $singleDimArray);
   $singleDimArray = array();
   return $string;
}
//Alphabetical order of field names in the table
function recursive_table_sort($table)
{
   ksort($table);
   foreach($table as $key => $value)
   {
      if(is_array($value)){
         $value = recursive_table_sort($value);
         $table[$key] = $value;
      }
   }
   return $table;
}
function valueResearch($value, $key)
{
   global $singleDimArray;
   $singleDimArray[] = $value;
   return $singleDimArray;
}
//This function generates a payment request
function generate_the_payment_request($requestData, $sealAlgorithm, $secretKey, $keyVersion)
{
   $requestTable = $requestData;
   $requestTable[‘seal’] = compute_payment_init_seal($sealAlgorithm, $requestData, $secretKey);
   $requestTable[‘keyVersion’] = $keyVersion;
   $requestTable[‘sealAlgorithm’] = $sealAlgorithm;
   return $requestTable;
}
//This function initializes the payment and redirects the client to Sips server
function send_payment_request($requestTable, $urlForPaymentInitialisation,$sealAlgorithm,$secretKey )
{
   $requestJson = json_encode($requestTable, JSON_UNESCAPED_UNICODE, ‘512’);
   //SENDING OF THE PAYMENT REQUEST
   $option = array(
      ‘http’ => array(
         ‘method’ => ‘POST’,
         ‘header’ => « content-type: application/json »,
         ‘content’ => $requestJson
      ),
   );
   $context = stream_context_create($option);
   $responseJson = file_get_contents($urlForPaymentInitialisation, false, $context);
   $responseTable = json_decode($responseJson, true);
   //RECALCULATION OF SEAL
   foreach($responseTable as $key => $value)
   {
      if(strcasecmp($key, « seal ») != 0){
         $responseData[$key] = $value;
      }
      //store responseTable in session to access responseData from other pages
      $_SESSION[$key] = $value;
   }
   $computedResponseSeal = compute_payment_init_seal($sealAlgorithm, $responseData, $secretKey);
   //REDIRECTION TO SIPS PAYPAGE JSON
   if(strcmp($computedResponseSeal, $responseTable[‘seal’]) == 0){
      if($responseTable[‘redirectionStatusCode’] == 00){
         //header(‘Location: Common/redirectionForm.php’);
         //exit();
        ?>
        <html lang = « en »>
        <head>
           <meta charset = « UTF-8 »>
           <meta name = « viewport » content = « width=device-width, initial-scale=1.0 »>
           <meta http-equiv = « X-UA-Compatible » content = « ie=edge »>
           <title>Redirection Form</title>
        </head>
        <body>
           <form id = « form » method = « POST » action = « <?php echo $responseData[‘redirectionUrl’]; ?> »>
              <input type = « hidden » name = « redirectionVersion » value = « <?php echo  $responseData[‘redirectionVersion’]; ?> »/>
              <input type = « hidden » name = « redirectionData » value = « <?php echo  $responseData[‘redirectionData’]; ?> »/>
              <input type = « submit » />
           </form>
           <script type = « text/javascript »>
              <!–document.getElementById(« form »).submit();–>
           </script>
        </body>
        </html>
    <?php
      }else{
            echo
            ‘<style>
               table, th, td{
                  border: 1px solid black;
                  border-collapse: collapse;
               }
               th, td{
                  padding: 5px;
                  text-align: left;
               }
            </style>
            <table >
               <tr>
                  <th>Field Name</th>
                  <th>Value</th>
               </tr>
               <tr>
                  <td>redirectionStatusCode</td>
                  <td>’.$_SESSION[‘redirectionStatusCode’].'</td>
               </tr>
               <tr>
                  <td>redirectionStatusMessage</td>
                  <td>’.$_SESSION[‘redirectionStatusMessage’].'</td>
               </tr>
               <tr>
                  <td>redirectionVersion</td>
                  <td>’.$_SESSION[‘redirectionVersion’].'</td>
               </tr>
               <tr>
                  <td>seal</td>
                  <td>’.$_SESSION[‘seal’].'</td>
               </tr>
            </table>’;
      }
   }else{
      var_dump($responseTable);
      echo « Your payment could not be processed »;
      echo « <br> ». »Please contact Worldline Technical Support »;
   }
}
$requestData = array(
    « normalReturnUrl »           => $normalReturnUrl,
    « automaticResponseUrl »      => $automaticResponseUrl,
    « merchantId »                => $merchantId,
    « transactionOrigin »         => « SCOUTINERIE »,
    // »transactionReference »        => $transactionReference,
    // »s10TransactionReference » => array (« s10TransactionId » => $transactionId),
    « amount »                    => $total_amount ,
    « fraudData »                 => array(« challengeMode3DS » =>  $challengeMode3DS ),
    « orderChannel »              => $orderChannel,
    « currencyCode »              => $currencyCode,
    « interfaceVersion »          => $interfaceVersion,
    « paymentMeanBrandList »      => array($paymentMeanBrandList),
    « paymentPattern »            => $paymentPattern,
    « captureMode »               => $captureMode,
    « captureDay »                => $captureDay,
    « customerContact »           => array(« email » => $customerEmail ),
    « orderId »                   => rand(1,999),
    « billingAddress »            => array(   « addressAdditional1 »    => $billingAddress_addressAdditional1,
                                            « city »                  => $billingAddress_city,
                                            « zipCode »               => $billingAddress_zipCode,
                                            « country »               => $billingAddress_country,
                                        ),
    « holderContact »             => array(   « email »                 => $holderContact_email,
                                            « firstname »             => $holderContact_firstName,
                                            « lastname »              => $holderContact_lastName
                                        ),
);
$requestTable = generate_the_payment_request($requestData, $sealAlgorithm, $secretKey, $keyVersion);
send_payment_request($requestTable, $urlForPaymentInitialisation,$sealAlgorithm,$secretKey );
?>

Post a Comment

Get all products for only $59!

With our extensive collection of elements, creating and customizing layouts becomes
second nature. Forget about coding and enjoy our themes.