How to integrate DIBS payment gateway api in php ?

Integrating DIBS payment Gateway(Redirect method and API method)

 

HTML Form
Redirect method

  • Integrating DIBS payment Gateway is Simple ,You need to create a test account in dibs and with those details we can integrate dibs in your application
  • Integrating via redirect method or server post method
  • After the saving the buy details just save those in your Database and after that redirect to the below form page with filled details and need to submit
  • Below is the example of sample dibs form
<form action="https://pay.dibspayment.com/" method="post" name="dibs">
    <input type="hidden" name="merchant" value="merchant_id" />
    <input type="hidden" name="account" value="account-name" />
    <input type="hidden" name="amount" value="TotalPrice*100" />
    <input type="hidden" name="currency" value="208" />
    <input type="hidden" name="orderid" value="unique_id" />
    <input type="hidden" name="acceptReturnUrl" value="http://www.yoururl.com/success.php" />
    <input type="hidden" name="paytype" value="cardtype" />
    <input type="hidden" name="uniqueid" value="uniqueid" />
    <input type="hidden" name="callbackurl" value="http://www.yoururl.com/callbackurl.php"/>
    <input type="hidden" name="cancelreturnurl" value="http://www.yoururl.com/error.php" />
    <input type="hidden" name="language" value="da_DK" />
    <input type="hidden" name="test" value="1" />
</form>

After the Successfull Payment user will be redirected to our website(accepturl)

<?php
$Merchant = "123456";
$MD5 = "qJuH6vjXHLSDB*%€&/hbnkjlBHGhjJKJ";
$test ="yes";
if($_GET['status']=='ACCEPTED'){
$paid = DIBSCapt($Merchant,$_GET['amount'], $_GET['transaction'],$_GET['orderid'],$MD5,$test);
if ($paid==true){ /* Payment Captured */ }else{ /* Payment Failed */ }
}
?> 

API Method

  • For API or webservice Way of Payment Integration
  • Just need to call two functions for capturing the Payment
  • First need to authorise the Payment by calling
 <?php
$trancaction = DIBSAuth($Merchant,$Amount,$Currency,$CardNo, $ExpMon,$ExpYear,$CVC,$OrderID,$postype="ssl", $MD5="",$test="no");
$paid = DIBSCapt($Merchant,$amount,$trancaction['transaction'], $trancaction['orderid'],$MD5,$test);
if ($paid==true){ /* Payment Captured */ }else{ /* Payment Failed */ }
?>

CODE Include this functions

 <?php //!A function for asking DIBS for authorisation of a creditcard payment
function DIBSAuth($Merchant,$Amount,$Currency,$CardNo,$ExpMon, $ExpYear,$CVC,$OrderID,$postype="ssl",$MD5="",$test="no") {

//Set up post-variable string
$postvars = "merchant=".parmchk($Merchant);
$postvars .= "&orderid=".parmchk($OrderID);
$postvars .= "&currency=".parmchk($Currency);
$postvars .= "&amount=".parmchk($Amount);

//Check if MD5key check is used and add if it is

if ( count($MD5) == 2 ) {
$md5Key = md5($MD5['K2'].md5($MD5['K1'].$postvars));
$postvars .= "&md5key=".$md5Key;
}

$postvars .= "&cardno=".parmchk($CardNo);
$postvars .= "&expmon=".parmchk($ExpMon);
$postvars .= "&expyear=".parmchk($ExpYear);
$postvars .= "&cvc=".parmchk($CVC);
$postvars .= "&textreply=yes";
$postvars .= "&postype=".parmchk($postype);


//Add testvar if "yes"

if ( $test == "yes" ) {
$postvars .= "&test=yes";
}

//Send post request
$response = http_post(‘payment.architrade.com’,'/cgi-ssl/auth.cgi’, $postvars );

//Deal with reponse
$response = explode("&",$response);
$N = count($response);
if ( $N < 2 ) { 
//Response is an error
$AuthInfo = false;
} 
else { 
//Response is good (does not mean that authorisation was granted)
$AuthInfo = array(); //Define output array
while ( $N– > 0 ) {
$A = explode("=",$response[$N]);
$AuthInfo[$A[0]] = $A[1];
}
}

//Check that the returned MD5 key is correct
if ( $AuthInfo['authkey'] != "" ) {
$vars = "transact=".$AuthInfo['transact']."&amount=".$Amount."&currency=".$Currency;
$Control = md5($MD5['K2'].md5($MD5['K1'].$vars));
if ( $Control != $AuthInfo['authkey'] ) {
$AuthInfo = array();
$AuthInfo['result'] = "MD5key authorisation failed";
}
}

return $AuthInfo;
}

//!A function for asking DIBS for capturing an already authorised creditcard payment
function DIBSCapt($Merchant,$Amount,$Transact,$OrderID,$MD5,$test="no") {

//Set up post-variable string
$postvars = "merchant=".parmchk($Merchant);
$postvars .= "&orderid=".parmchk($OrderID);
$postvars .= "&transact=".parmchk($Transact);
$postvars .= "&amount=".parmchk($Amount);

//Check if MD5key check is used and add if it is
if ( count($MD5) == 2 ) {
$md5Key = md5($MD5['K2'].md5($MD5['K1'].$postvars));
$postvars .= "&md5key=".$md5Key;
}

$postvars .= "&textreply=yes";
$postvars .= "&force=true";

//Add testvar if "yes"
if ( $test == "yes" ) {
$postvars .= "&test=yes";
}

//Send post request
$response = http_post(‘payment.architrade.com’,'/cgi-bin/capture.cgi’, $postvars );

//Deal with reponse
$response = explode("&",$response);
$N = count($response);
if ( $N == 1 ) {
$CaptInfo['result'] = $response[0];
} else {
if ( $N < 2 ) { 
//Response is an error
$CaptInfo = false;
} 
else { 
//Response is good (does not mean that the capture was successfull)
$CaptInfo = array(); //Define output array
while ( $N– > 0 ) {
$A = explode("=",$response[$N]);
$CaptInfo[$A[0]] = $A[1];
}
}
}

return $CaptInfo;
}

//!Function for sending a ‘within-php’ post-request and receive the response-body as a string
function http_post($host, $path, $data, $auth="") {

$sock = fsockopen("ssl://".$host, 443, $errno, $errstr, 30);
if (!$sock) die("$errstr ($errno)\n");

fwrite($sock, "POST ".$path." HTTP/1.0\r\n");
fwrite($sock, "Host: ".$host."\r\n");
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: " . strlen($data) . "\r\n");
fwrite($sock, "User-Agent: PHP-DIBS (Kaka Consult) v1.0 \r\n");

//If basic authentication is required (e.g. payinfo.cgi, changestatus.cgi and refund.cgi)
if ( is_array($auth) ) {
fwrite($sock, "Authorization: Basic ".base64_encode($auth['username'].":".$auth['password'])."\r\n");
}

fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, $data."\r\n");
fwrite($sock, "\r\n");

//Take out the header first
$headers = "";
while ( $str = trim(fgets($sock, 4096)) ) {
$headers .= "$str\n";
}

//Then collect the body and prepare for returning
$body = "";
while ( !feof($sock) ) {
$body .= fgets($sock, 4096);
}

fclose($sock);

return $body;
}

//!Function for checking that the parameters do not contain any &, which may corrupt message to DIBS
function parmchk($in) {
return str_replace("&","",$in);
}
?> 

How to get thumbnail of YouTube video link using YouTube API?

Each YouTube video has 4 generated images. They are predictably formatted as follows:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

For the high quality version of the thumbnail use a url similar to this:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

There is also a medium quality version of the thumbnail, using a url similar to the HQ:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/mqdefault.jpg

For the maximum resolution version of the thumbnail use a url similar to this:

http://img.youtube.com/vi/<insert-youtube-video-id-here>/maxresdefault.jpg

All of the above urls are available over https too. Just change http to https in any of the above urls.

Alternatively, you can use the YouTube API to get thumbnail images.