Zend - The PHP Company




Commerce

Add Code


Jens J. Parree  

Type: code fragment
Added by: Cyberskater
Entered: 31/05/2003
Last modified: 07/12/2006
Rating: - (fewer than 3 votes)
Views: 3795
When working with realtime credit card billing systems, e.g. Wire Card C3 you need to convert prices to cent values. Example: "9.99" $ must be "999" or "123.10" must be "12310" So here ist the method for doing a simple conversion:


<?php
#####################################
function _convertToWireCardPrice($price) {
    
//checking the syntax and format
    
$price strval($price);
    if(
eregi('^[0-9]{1,}[.]{1}[0-9]{2}$'$price)) {
        
/* format is valid */
        
$price eregi_replace("."""$price); // removing the .dot
        
return $price;
    } else {
        echo 
"Incorrect number format for transactions via the Wire Card C3 ("$price").<br />";
        exit;
    }
}
#####################################
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories