title: Saferpay Implementation
body: <p>Sorry for my bad english.</p>
  
  <p>I have to implement saferpay in my project. I have two php file for now </p>
  
  <ol>
  <li>checkout.php</li>
  <li>success.php</li>
  </ol>
  
  <p>When I execute the checkout.php file it redirects to success.php and then it shows an error. </p>
  
  <p>I have tried to remove this error but I'm unable to remove it. Please tell me any solutions by which I can remove the error.</p>
  
  <p>Here is the code for checkout.php</p>
  
  <pre><code>&lt;?
  /* get the web server’s self URL */
  $SERVER_NAME = 'localhost/';
  $SCRIPT_NAME = 'saferpay/test.php';
  $self_url = "http://" . $SERVER_NAME . $SCRIPT_NAME;
  //print_r($self_url);
  $self_url = substr($self_url, 0, strrpos($self_url, '/')) . "/";
  //print_r($self_url);
  /* the hosting gateway URL to create pay init URL */
  $gateway = "https://www.saferpay.com/hosting/CreatePayInit.asp";
  /* set the payment attributes */
  $accountid = "99867-94913159"; /* saferpay account id */
  $orderid = "4711"; /* use your own order or basket identifier */
  $amount = "1295"; /* 12.95 */
  $currency = "EUR";
  $description = urlencode("\"Test Purchase - saferpay PHP sample\"");
  $successlink = $self_url."success.php"; /* return URL if payment successful */
  //print_r($successlink);
  $faillink = $self_url."failed.php";     /* return URL if payment failed */
  $backlink = $self_url."checkout.php";   /* return URL if user cancelled */
  /* put all attributes together and create hosting URL */
  $attributes = "ACCOUNTID=$accountid&amp;AMOUNT=$amount&amp;CURRENCY=$currency&amp;DESCRIPTION=$descripti
  on&amp;SUCCESSLINK=$successlink&amp;FAILLINK=$faillink&amp;BACKLINK=$backlink";
  $url = "$gateway?$attributes";
  /* get the PayInit URL from the hosting server */
  $payinit_url = join("", file($url));
  //print_r($payinit_url);
  ?&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;Saferpay Checkout Sample for PHP (Hosting)&lt;/title&gt;
  &lt;script src="http://www.saferpay.com/OpenSaferpayScript.js"&gt;&lt;/script&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;saferpay Checkout Sample Page for PHP (Hosting)&lt;/h1&gt;
  &lt;h2&gt;Order ID: &lt;? print $orderid; ?&gt;&lt;br&gt;&lt;/h2&gt;
  &lt;h2&gt;Click &lt;a href="&lt;? print $payinit_url; ?&gt;"
  onclick="OpenSaferpayTerminal('&lt;? print $payinit_url; ?&gt;', this, 'LINK');"&gt;
  here&lt;/a&gt;
  to purchase for &lt;? printf("%s %d.%02d", $currency, $amount / 100, $amount %
  100); ?&gt;!
  &lt;/h2&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and Success.php</p>
  
  <pre><code>&lt;?php
  /* parse the query string and get DATA and SIGNATURE */
  //print_r()
  $a = ($_SERVER['QUERY_STRING']);
  $array=array();
  parse_str($a,$array);
  $DATA = $array['DATA'];
  $SIGNATURE = $array['SIGNATURE'];
  /*
  foreach($array as &amp;$value){
      print_r($value);
  }
  */
  urldecode($DATA);
  urldecode($SIGNATURE);
  
  /* the hosting gateway URL to verify pay confirm */
  $gateway = "https://www.saferpay.com/hosting/VerifyPayConfirm.asp";
  $accountid = "99867-94913159"; /* saferpay account id */
  /* put it all together */
  $url = "$gateway?DATA=".urlencode($DATA)."&amp;SIGNATURE=".urlencode($SIGNATURE);
  /* verify pay confirm message at hosting server */
  $result = join("", file($url));
  /* check if result is OK... */
  if (substr($result, 0, 3) == "OK:")
  {
        print("Your Order has been successfully processed.");
        parse_str(substr($result, 3));
         echo '&lt;br/&gt;';
        print_r($result);
  
        /* $ID    = saferpay transaction identifier, store in DBMS */
        /* $TOKEN = token of transaction, store in DBMS */
        /***** Optional: Finalize payment by capture of transaction *****/
        /* the hosting gateway URL to complete payment */
        $gateway = "https://www.saferpay.com/hosting/PayComplete.asp";
        /* put it all together */
        $url = "$gateway?ACCOUNTID=$accountid&amp;ID=".urlencode($ID).
               "&amp;TOKEN=".urlencode($TOKEN);
        /* complete payment by hosting server */
         echo '&lt;br/&gt;';
          print_r($url);
          echo '&lt;br/&gt;';
        $result = join("", file($url));
        print_r($result);
        if (substr($result, 0, 2) == "OK")
              print("Capture has been done successfully");
        else
              print("Error: retry capture later...");
  }
  else /* ...or if an error happened */
  {
        print $result;
  }
  
  ?&gt;
  </code></pre>