<?php


# Global Definetions :
$TerminalNumber = 1000; # Company terminal 
$UserName = 'test9611';   # API User

                               
###############################################################                              
### Add New Account new  Payment Info new recurring payment.###
###############################################################
$vars =  array();
// Const parameters:
$vars['terminalnumber'] = $TerminalNumber;
$vars['username'] = $UserName;
$vars['codepage'] = '65001'; // unicode
$vars["Operation"] = "update";     # update        do one or all of the following :  Update Account          And\Or Update     account payment info  And\Or Add Update recurring payment


#### Update Recurring Payments  ###
$vars["RecurringPayments.RecurringId"] = "20054"; # the number of the recurring 

## optinal  Send only if you what to update the values ##
$vars["RecurringPayments.IsActive"] = "true"; #   Is the order Active
$vars["RecurringPayments.FlexItem.Price"] = "100"; #   Sum to Bill the account  in every time. (total account bill is TotalNumOfBills*FlexItem.Price)
$vars["RecurringPayments.FlexItem.InvoiceDescription"] = "subsciprion for Recurring0"; # Description for the account invoice 
$vars["RecurringPayments.FlexItem.IsPriceIncludeVat"] = "true"; # the account will be bill 100 include vat - good for BTC , if BTB , send FlexItem.Price no vat and FlexItem.IsPriceIncludeVat=false   

$vars["RecurringPayments.InternalDecription"] = "new order for Recurring0"; # some internal description for the Recurring Payment 
$vars["RecurringPayments.NextDateToBill"] = "31/12/2025"; #  the first time to bill the account .
$vars["RecurringPayments.TotalNumOfBills"] = "1"; #  number of time to bill the account
$vars["RecurringPayments.ReturnValue"] = "Recurring0TEST1000"; #  


// Send Data To Bill Gold Server
$r = PostVars($vars,'https://secure.cardcom.solutions/Interface/RecurringPayment.aspx');



PrintResponse($r);


 

// Print the response for the RecurringPayment.aspx page
function PrintResponse($r){


  parse_str($r,$responseArray);

  # Is Deal OK 
  if ($responseArray['ResponseCode'] == "0") 
  {
      echo "<br/>Description: ".$responseArray['Description']."<br/>"; #  response Description
      echo "Total Recurring: ".$responseArray['TotalRecurring']."<br/>"; # total number of new /update  Recurring Payment
      echo "Is New Account: ".$responseArray['IsNewAccount']."<br/>"; # Is the Account a new One (if not then update)
      
      echo "<br/>Print Recurring Payment result<br/>";
      echo "------------------------------<br/>";
      $total = $responseArray['TotalRecurring'];



      for($i=0 ; $i<$total ; $i++ )
     {

          echo "Recurring Id ".$i.": ".$responseArray['Recurring'.$i.'_RecurringId']."<br/>"; # CardCom  Recurring Id
          echo "Return Value ".$i.": ".$responseArray['Recurring'.$i.'_ReturnValue']."<br/>"; # your custom temp value for the Recurring Payment
          echo "Is New Recurring ".$i.": ".$responseArray['Recurring'.$i.'_IsNewRecurring']."<br/><br/>"; # Is New Recurring Payment ?
    }

      echo "<br/><br/><br/>".$r;
  //     
  }
  # Show Error to developer only
  else
  {
        echo $r;
  }
}

function PostVars($vars,$PostVarsURL)
{
  $urlencoded = http_build_query($vars);
  #init curl connection
  if( function_exists( "curl_init" )) 
  { 
     $CR = curl_init();
    curl_setopt($CR, CURLOPT_URL, $PostVarsURL);
    curl_setopt($CR, CURLOPT_POST, 1);
    curl_setopt($CR, CURLOPT_FAILONERROR, true);
    curl_setopt($CR, CURLOPT_POSTFIELDS, $urlencoded );
    curl_setopt($CR, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($CR, CURLOPT_FAILONERROR,true);
    #actual curl execution perfom
    $r = curl_exec( $CR );
    $error = curl_error ( $CR );
    # some error , send email to developer
    if( !empty( $error )) {

      echo $error;

      die();
    }
   curl_close( $CR );
   return $r;
 }
  else
 {
  echo "No curl_init" ;
  die();
  }
}

?>