Saturday, September 28, 2013

what is ACID use in PHP??

Database ACID (Atomicity, Consistency, Isolation, Durability) Properties

There are a set of properties that guarantee that database transactions are processed reliably, referred to as ACID (Atomicity, Consistency, Isolation, Durability).

Atomicity

Atomicity refers to the ability of the database to guarantee that either all of the tasks of a transaction are performed or none of them are. Database modifications must follow an all or nothing rule. Each transaction is said to be atomic if when one part of the transaction fails, the entire transaction fails.

Consistency

The consistency property ensures that the database remains in a consistent state before the start of the transaction and after the transaction is over (whether successful or not). For example, in a storefront there is an inconsistent view of what is truly available for purchase if inventory is allowed to fall below 0, making it impossible to provide more than an intent to complete a transaction at checkout time. An example in a double-entry accounting system illustrates the concept of a true transaction. Every debit requires an associated credit. Both of these happen or neither happen.
A distributed data system is either strongly consistent or has some form of weak consistency. Once again, using the storefront example, a database needs to provide consistency and isolation, so that when one customer is reducing an item in stock and in parallel is increasing the basket by one, this is isolated from another customer who will have to wait while the data store catches up. At the other end of the spectrum is BASE (Basically Available Soft-state Eventual consistency).
Weak consistency is sometimes referred to as eventual consistency, the database eventually reaches a consistent state. Weak consistency systems are usually ones where data is replicated; the latest version is sitting somewhere in the cluster, older versions are still out there. Eventually all nodes will see the latest version.

Isolation

Isolation refers to the requirement that other operations cannot access or see the data in an intermediate state during a transaction. This constraint is required to maintain the performance as well as the consistency between transactions in a database. Thus, each transaction is unaware of another transactions executing concurrently in the system.

Durability

Durability refers to the guarantee that once the user has been notified of success, the transaction will persist, and not be undone. This means it will survive system failure, and that the database system has checked the integrity constraints and won't need to abort the transaction. Many databases implement durability by writing all transactions into a transaction log that can be played back to recreate the system state right before a failure. A transaction can only be deemed committed after it is safely in the log.
Durability does not imply a permanent state of the database. Another transaction may overwrite any changes made by the current transaction without hindering durability.

Thursday, September 26, 2013

Easy way to integration of ccavenue payment gateway using php

CCavenue is most popular Payment gateway for online Shopping. It provide payment through using International credit card as well using your Bank (who have bond with CCavenue) online Account or using it's debit card(ATM card). It is one of the most secure place for given your money to online shop.

For Integrate it with your website you should have ccavenue account and they give you a merchant id and a unique key for your site that is most important for money transaction.


Creat a validCCAvenueparam.php  for server side generate valid checksum param
----------------------------------------------------------------------------------------
<?php


function getchecksum($MerchantId,$Amount,$OrderId ,$URL,$WorkingKey)
  {
  $str ="$MerchantId|$OrderId|$Amount|$URL|$WorkingKey";
  $adler = 1;
  $adler = adler32($adler,$str);
  return $adler;
  }


function verifychecksum($MerchantId,$OrderId,$Amount,$AuthDesc,$CheckSum,$WorkingKey)
  {
  $str = "$MerchantId|$OrderId|$Amount|$AuthDesc|$WorkingKey";
  $adler = 1;
  $adler = adler32($adler,$str);

  if($adler == $CheckSum)
  return "true" ;
  else
  return "false" ;
  }


function adler32($adler , $str)
  {
  $BASE =  65521 ;


$s1 = $adler & 0xffff ;
  $s2 = ($adler >> 16) & 0xffff;
  for($i = 0 ; $i < strlen($str) ; $i++)
  {
  $s1 = ($s1 + Ord($str[$i])) % $BASE ;
  $s2 = ($s2 + $s1) % $BASE ;
  //echo "s1 : $s1 <BR> s2 : $s2 <BR>";


}
  return leftshift($s2 , 16) + $s1;
  }


function leftshift($str , $num)
  {


$str = DecBin($str);


for( $i = 0 ; $i < (64 - strlen($str)) ; $i++)
  $str = "0".$str ;


for($i = 0 ; $i < $num ; $i++) 
  {
  $str = $str."0";
  $str = substr($str , 1 ) ;
  //echo "str : $str <BR>";
  }
  return cdec($str) ;
  }


function cdec($num)
  {


for ($n = 0 ; $n < strlen($num) ; $n++)
  {
  $temp = $num[$n] ;
  $dec =  $dec + $temp*pow(2 , strlen($num) - $n - 1);
  }


return $dec;
  }
  ?>
-------------------------------------------------------------------------------------------------------------------------------

Step -2
create cat page form cart.php


 <?php
    $Merchant_Id = "M_apa18528_18528";//This id(also User Id)  available at "Generate Working Key" of "Settings & Options" 
    $Amount = 900;;//your script should substitute the amount in the quotes provided here
    $Order_Id = 689663;//your script should substitute the order description in the quotes provided here
    $WorkingKey = "";//Note : if you empty the working value then CCavenue "return 
Error Code: 108
Error Description: Checksum+mismatch
because CCavenue security key providing to merchant . 

    $Redirect_Url ="http://www.englishleap.com/users/payment/";
    $Checksum = getCheckSum($Merchant_Id,$Amount,$Order_Id ,$Redirect_Url,$WorkingKey); // Validate All value 
    ?>


<form action="https://www.ccavenue.com/shopzone/cc_details.jsp" method="post">
<!--<br/>Merchant_Id:
--><input type="hidden" value="<?php echo $Merchant_Id; ?>" name="Merchant_Id">
<!--<br/>Amount:
--><input type="hidden" value="<?php echo $Amount; ?>" name="Amount">
<!--<br/>Order_Id:
--><input type="hidden" value="<?php echo $Order_Id; ?>" name="Order_Id">
<!--<br/>Redirect_Url:
--><input type="hidden" value="<?php echo $Redirect_Url; ?>" name="Redirect_Url">
<!--<br/>Checksum:
--><input type="hidden" value="<?php echo $Checksum; ?>" name="Checksum">
<!--<br/>billing_cust_name:
--><input type="hidden" value="bp.nayak20000" name="billing_cust_name"> 
<!--<br/>billing_cust_address:
--><input type="hidden" value="" name="billing_cust_address"> 
<!--<br/>billing_cust_country:
--><input type="hidden" value="" name="billing_cust_country"> 
<!--<br/>billing_cust_state:
--><input type="hidden" value="" name="billing_cust_state"> 
<!--<br/>billing_zip:
--><input type="hidden" value="" name="billing_zip"> 
<!--<br/>billing_cust_tel:
--><input type="hidden" value="" name="billing_cust_tel"> 
<!--<br/>billing_cust_email:
--><input type="hidden" value="bp.nayak20000@gmail.com" name="billing_cust_email"> 
<!--<br/>delivery_cust_name:
--><input type="hidden" value="bp.nayak20000" name="delivery_cust_name"> 
<!--<br/>delivery_cust_address:
--><input type="hidden" value="" name="delivery_cust_address"> 
<!--<br/>delivery_cust_country:
--><input type="hidden" value="" name="delivery_cust_country"> 
<!--<br/>delivery_cust_state:
--><input type="hidden" value="" name="delivery_cust_state"> 
<!--<br/>delivery_cust_tel:
--><input type="hidden" value="" name="delivery_cust_tel"> 
<!--<br/>delivery_cust_notes:
--><input type="hidden" value="" name="delivery_cust_notes"> 
<!--<br/>Merchant_Param:
--><input type="hidden" value="" name="Merchant_Param"> 
<!--<br/>billing_cust_city:
--><input type="hidden" value="" name="billing_cust_city"> 
<!--<br/>billing_zip_code:
--><input type="hidden" value="" name="billing_zip_code"> 
<!--<br/>delivery_cust_city:
--><input type="hidden" value="" name="delivery_cust_city"> 
<!--<br/>delivery_zip_code:
--><input type="hidden" value="" name="delivery_zip_code"> 
<input type="submit" class="button-placeorder" value="Pay by CCavenue ">
</form>