How to use PayPal standrad with reccuring method.

Use this bellow html form into your code :

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">

<!-- Identify your business so that you can collect the payments. -->

<input type="hidden" name="business" value="example@example.com">

<!-- Specify a Subscribe button. -->

<input type="hidden" name="cmd" value="_xclick-subscriptions">

<!-- Identify the subscription. -->

<input type="hidden" name="item_name" value="Alice's Weekly Digest">
<input type="hidden" name="item_number" value="DIG Weekly">

<!-- Set the terms of the 1st trial period. -->

<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="a1" value="0">
<input type="hidden" name="p1" value="7">
<input type="hidden" name="t1" value="D">

<!-- Set the terms of the 2nd trial period. -->

<input type="hidden" name="a2" value="5.00">
<input type="hidden" name="p2" value="3">
<input type="hidden" name="t2" value="W">

<!-- Set the terms of the regular subscription. -->

<input type="hidden" name="a3" value="49.99">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="src" value="1">

<!-- Display the payment button. -->
<input type="image" name="submit" border="0" src="https://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" alt="PayPal - The safer, easier way to pay online" />

<img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" >

</form>
Name Required or Optional Description Character Length
business Required Your PayPal ID or an email address associated with your PayPal account. Email addresses must be confirmed.
item_name Optional Description of item being sold (maximum 127 characters). If you are collecting aggregate payments, this can include a summary of all items purchased, tracking numbers, or generic terms such as “subscription.” If omitted, customer will see a field in which they have the option of entering an Item Name
currency_code Optional The currency of prices for trial periods and the subscription. The default isUSD. 3
a1 Optional Trial period 1 price. For a free trial period, specify0.
p1 See description. Trial period 1 duration. Required if you specifya1. Specify an integer value in the allowable range for the units of duration that you specify witht1. 2
t1 See description. Trial period 1 units of duration. Required if you specifya1. Allowable values:

  • D– for days; allowable range for p1 is 1 to 90
  • W– for weeks; allowable range for p1 is1 to52
  • M– for months; allowable range for p1 is1 to24
  • Y– for years; allowable range forp1 is1 to 5
1
a2 Optional Trial period 2 price. Can be specified only if you also specify a1.
p2 See description. Trial period 2 duration. Required if you specify a2. Specify an integer value in the allowable range for the units of duration that you specify with t2. 2
t2 See description. Trial period 2 units of duration. Allowable values:

  • D– for days; allowable range for p1 is 1 to 90
  • W– for weeks; allowable range for p1 is1 to52
  • M– for months; allowable range for p1 is1 to24
  • Y– for years; allowable range forp1 is1 to 5
1
a3 Required Regular subscription price.
p3 Required Subscription duration. Specify an integer value in the allowable range for the units of duration that you specify with t3. 2
t3 Required Regular subscription units of duration. Allowable values:

  • D– for days; allowable range for p1 is 1 to 90
  • W– for weeks; allowable range for p1 is1 to52
  • M– for months; allowable range for p1 is1 to24
  • Y– for years; allowable range forp1 is1 to 5
1
src Optional Recurring payments. Subscription payments recur unless subscribers cancel their subscriptions before the end of the current billing cycle or you limit the number of times that payments recur with the value that you specify for srt.Allowable values:

  • 0 – subscription payments do not recur
  • 1 – subscription payments recur

The default is 0.

1
srt Optional Recurring times. Number of times that subscription payments recur. Specify an integer above 1. Valid only if you specify src=”1″. 1
sra Optional Reattempt on failure. If a recurring payment fails, PayPal attempts to collect the payment two more times before canceling the subscription.Allowable values:

  • 0 – do not reattempt failed recurring payments
  • 1 – reattempt failed recurring payments before canceling

The default is 1.

For more information, see

1
no_note Required Do not prompt payers to include a note with their payments. Allowable values for Subscribe buttons:

  • 1 – hide the text box and the prompt For Subscribe buttons, always include no_noteand set it to 1.
1
custom Optional User-defined field which will be passed through the system and returned in your merchant payment notification email. This field will not be shown to your subscribers. 255
invoice Optional User-defined field which must be unique with each subscription. The invoice number will be shown to subscribers with the other details of their transactions 127
modify Optional Modification behavior. Allowable values:

  • 0– allows subscribers to only create new subscriptions
  • 1– allows subscribers to modify their current subscriptions or sign up for new ones
  • 2– allows subscribers to only modify their current subscriptions. The default value is 0.
1
usr_manage Optional Set to1to have PayPal generate usernames and initial passwords for subscribers. 1

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);
}
?>