90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
<?php
|
|
|
|
class Cardpay_model extends CI_Model {
|
|
|
|
function __construct() {
|
|
|
|
}
|
|
|
|
public function verifyCardData($data){
|
|
$error_status = false;
|
|
$errorArray = array ();
|
|
/*
|
|
$cd['cardnumber'] = $this->input->post('cardnumber');
|
|
$cd['exp_month'] = $this->input->post('exp_month');
|
|
$cd['exp_year'] = $this->input->post('exp_year');
|
|
$cd['cvc'] = $this->input->post('cvc');
|
|
$cd['description']= $this->input->post('description');
|
|
*/
|
|
|
|
if ( strlen( $data['cvc'] ) == 0 ){
|
|
$error_status = true;
|
|
$errorArray[]="Enter valid card CVV";
|
|
}
|
|
|
|
if ( strlen( $data['cardnumber'] ) == 0 || $this->luhn_check( $data['cardnumber'] ) == false){
|
|
$error_status = true;
|
|
$errorArray[]="Enter valid card number";
|
|
}
|
|
|
|
if ( strlen( $data['exp_year'] ) == 0 || $data['exp_year'] < date('Y') ){
|
|
$error_status = true;
|
|
$errorArray[]="Enter valid card expiration date";
|
|
}
|
|
else{
|
|
|
|
// let us test the month now
|
|
}
|
|
|
|
if ( strlen( $data['description'] ) == 0 ){
|
|
$error_status = true;
|
|
$errorArray[]="Enter name on card";
|
|
}
|
|
|
|
return [
|
|
"error_status" => $error_status,
|
|
"error_message" => $errorArray
|
|
];
|
|
}
|
|
|
|
public function verifyCCNumber($cardNumber) {
|
|
|
|
return $this->luhn_check($cardNumber);
|
|
}
|
|
|
|
/* Luhn algorithm number checker - (c) 2005-2008 shaman - www.planzero.org *
|
|
* This code has been released into the public domain, however please *
|
|
* give credit to the original author where possible. */
|
|
|
|
private function luhn_check($number) {
|
|
|
|
// Strip any non-digits (useful for credit card numbers with spaces and hyphens)
|
|
$number=preg_replace('/\D/', '', $number);
|
|
|
|
// Set the string length and parity
|
|
$number_length=strlen($number);
|
|
$parity=$number_length % 2;
|
|
|
|
// Loop through each digit and do the maths
|
|
$total=0;
|
|
for ($i=0; $i<$number_length; $i++) {
|
|
$digit=$number[$i];
|
|
// Multiply alternate digits by two
|
|
if ($i % 2 == $parity) {
|
|
$digit*=2;
|
|
// If the sum is two digits, add them together (in effect)
|
|
if ($digit > 9) {
|
|
$digit-=9;
|
|
}
|
|
}
|
|
// Total up the digits
|
|
$total+=$digit;
|
|
}
|
|
|
|
// If the total mod 10 equals 0, the number is valid
|
|
return ($total % 10 == 0) ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
}
|