title: Master card migs md5 to SHA-256 HMAC php
body: <p>I have a gateway from migs but they are changed md5 to SHA-256 HMAC how can i change it on my code i tried too many times but i geting error 400 i think there are some issue on my code</p>
  
  <p>existing code </p>
  
  <pre><code>&lt;?php
  $db1 = new ps_DB();
  $q = "SELECT country_2_code FROM #__vm_country WHERE     country_3_code='".$user-&gt;country."' ORDER BY country_2_code ASC";
  $db1-&gt;query($q);
  
  
  $url = "https://migs.mastercard.com.au/vpcpay";
  
  $SECURE_SECRET = MIGS_SS;
  $vpcURL = $url . "?";
  $md5HashData = $SECURE_SECRET;
  
  $tax_total = $db-&gt;f("order_tax") + $db-&gt;f("order_shipping_tax");
  $discount_total = $db-&gt;f("coupon_discount") + $db-&gt;f("order_discount");
  
   if( MIGS_TEST == 1)
    $amt123 = MIGS_TESTMODEAMT*100;
   else
    $amt123 =   round(($db-&gt;f("order_total")+$tax_total-$discount_total)*100,2);
  
      $post_variables = Array(
     "vpc_Version" =&gt; "1",
      "vpc_Command" =&gt; "pay",
      "vpc_AccessCode" =&gt; MIGS_ACCESSCODE,
      "vpc_MerchTxnRef" =&gt; $db-&gt;f("order_id").'_'.$db-&gt;f("order_number"),
      "vpc_Merchant" =&gt; MIGS_MID,
      "vpc_OrderInfo" =&gt;  $VM_LANG-&gt;_('PHPSHOP_ORDER_PRINT_PO_NUMBER')."_".   $db-&gt;f("order_id"),
     "vpc_Amount" =&gt; $amt123, 
     "vpc_Locale" =&gt; 'en',
     "vpc_ReturnURL" =&gt; SECUREURL ."index.php?option=com_virtuemart&amp;  page=checkout.migs&amp;order_id=".$db-&gt;f("order_id")
  
      );
      ksort ($post_variables);
  
      if( $page == "checkout.thankyou" ) {
      $query_string = "?";
      foreach( $post_variables as $name =&gt; $value ) {
      $query_string .= urlencode($name). "=" . urlencode($value) ."&amp;";
      //$vpcURL .= urlencode($name). "=" . urlencode($value) ."&amp;";
      $md5HashData .= $value;
       }
  
      if (strlen($SECURE_SECRET) &gt; 0) {
      $query_string .=  "vpc_SecureHash=" . strtoupper(md5($md5HashData));
      //$vpcURL .= "vpc_SecureHash=" . strtoupper(md5($md5HashData));
      }
  
      //die(  $url.' pppppppp '.$query_string);
  
     vmRedirect( $url . $query_string );
     } else {
     echo '&lt;form action="'.$url.'" method="post" target="_blank"&gt;';
    echo '&lt;input type="image" name="submit" src="https://www.paypal.com/en_US  /i/btn/x-click-but6.gif" alt="Click to pay with PayPal - it is fast, free and secure!" /&gt;';
  
      foreach( $post_variables as $name =&gt; $value ) {
     echo '&lt;input type="hidden" name="'.$name.'"    value="'.htmlspecialchars($value).'" /&gt;';
      }
     echo '&lt;/form&gt;';
  
      }
    ?&gt;
  </code></pre>
  
  <p>the new code i got from migs</p>
  
  <pre><code>    foreach($_POST as $key =&gt; $value) {
       // create the hash input and URL leaving out any fields that have no  value
      if (strlen($value) &gt; 0) {
      ?&gt;
           &lt;input type="hidden" name="&lt;?php echo($key); ?&gt;"  value="&lt;?php    echo($value); ?&gt;"/&gt;&lt;br&gt;
    &lt;?php             
   if ((strlen($value) &gt; 0) &amp;&amp; ((substr($key, 0,4)=="vpc_") ||       (substr($key,0,5) =="user_"))) {
       $hashinput .= $key . "=" . $value . "&amp;";
      }
      }
  
     }
     $hashinput = rtrim($hashinput, "&amp;");
      ?&gt;      
           &lt;!-- attach SecureHash --&gt;
                          &lt;input type="hidden" name="vpc_SecureHash"  value="&lt;?php echo(strtoupper(hash_hmac('SHA256',
    $hashinput, pack('H*',$securesecret)))); ?&gt;"/&gt;
      &lt;input type="hidden" name="vpc_SecureHashType" value="SHA256"&gt;
  </code></pre>
  
  <p>how can i use it in my code?    the md5 based code working well but when i convert it to sha the 400 error is geting after reaching gateway i have removed migs secret codes due to security issues</p>