wzul

Payout API Callback

Aug 2nd, 2021 (edited)
501
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function deep_map_pairs($data = array()){
  4.   $a = array();
  5.  
  6.   foreach ($data as $k => $v){
  7.     if ($k == 'x_signature'){
  8.       continue;
  9.     }
  10.     if (is_array($v) && array_keys($v) !== range(0, count($v) - 1)) {
  11.       $b = array();
  12.       $dmp = deep_map_pairs($v);
  13.       $flatted_dmp = new RecursiveIteratorIterator(new RecursiveArrayIterator($dmp));
  14.       foreach ($flatted_dmp as $p){
  15.         $b[] = $k.$p;
  16.       }
  17.       $a[] = $b;
  18.     } else if (is_array($v)){
  19.       $b = array();
  20.       foreach ($v as $c){
  21.          $b[] = deep_map_pairs(array($k => $c));
  22.       }
  23.       $a[] = $b;
  24.     } else {
  25.       $a[] = $k.$v;
  26.     }
  27.   }
  28.  
  29.   return $a;
  30. }
  31.  
  32. $new = deep_map_pairs($_POST);
  33. $flatted_new = new RecursiveIteratorIterator(new RecursiveArrayIterator($new));
  34.  
  35. $array_flatted = [];
  36. foreach ($flatted_new as $p){
  37.   $array_flatted[] = $p;
  38. }
  39.  
  40. $compacted_af = array_filter($array_flatted, function($var){
  41.    return ($var !== NULL && $var !== FALSE && $var !== "");
  42. });
  43.  
  44. sort($compacted_af, SORT_REGULAR | SORT_FLAG_CASE);
  45. $source_string = implode('|', $compacted_af);
  46.  
  47. $xsignature_key = 'S-R5t3Uw6SrwXNWyZV-naVHg'; // Get from your Billplz Account Settings
  48. $xsignature = $_POST['x_signature'];
  49. $equal = hash_equals(hash_hmac('sha256', $source_string, $xsignature_key), $xsignature);
  50.  
  51. if ($equal) {
  52.     error_log('match dah');
  53. } else {
  54.     error_log('x match dah');
  55. }
  56.  
  57.  
RAW Paste Data