当前位置: 首页>>代码示例>>PHP>>正文


PHP valid::credit_card方法代码示例

本文整理汇总了PHP中valid::credit_card方法的典型用法代码示例。如果您正苦于以下问题:PHP valid::credit_card方法的具体用法?PHP valid::credit_card怎么用?PHP valid::credit_card使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在valid的用法示例。


在下文中一共展示了valid::credit_card方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: credit_card

 /**
  * Validates a credit card number using the Luhn (mod10) formula.
  * @see http://en.wikipedia.org/wiki/Luhn_algorithm
  *
  * @param   integer       credit card number
  * @param   string|array  card type, or an array of card types
  * @return  boolean
  */
 public static function credit_card($number, $type = NULL)
 {
     // Remove all non-digit characters from the number
     if (($number = preg_replace('/\\D+/', '', $number)) === '') {
         return FALSE;
     }
     if ($type == NULL) {
         // Use the default type
         $type = 'default';
     } elseif (is_array($type)) {
         foreach ($type as $t) {
             // Test each type for validity
             if (valid::credit_card($number, $t)) {
                 return TRUE;
             }
         }
         return FALSE;
     }
     $cards = Kohana::config('credit_cards');
     // Check card type
     $type = strtolower($type);
     if (!isset($cards[$type])) {
         return FALSE;
     }
     // Check card number length
     $length = strlen($number);
     // Validate the card length by the card type
     if (!in_array($length, preg_split('/\\D+/', $cards[$type]['length']))) {
         return FALSE;
     }
     // Check card number prefix
     if (!preg_match('/^' . $cards[$type]['prefix'] . '/', $number)) {
         return FALSE;
     }
     // No Luhn check required
     if ($cards[$type]['luhn'] == FALSE) {
         return TRUE;
     }
     // Checksum of the card number
     $checksum = 0;
     for ($i = $length - 1; $i >= 0; $i -= 2) {
         // Add up every 2nd digit, starting from the right
         $checksum += substr($number, $i, 1);
     }
     for ($i = $length - 2; $i >= 0; $i -= 2) {
         // Add up every 2nd digit doubled, starting from the right
         $double = substr($number, $i, 1) * 2;
         // Subtract 9 from the double where value is greater than 10
         $checksum += $double >= 10 ? $double - 9 : $double;
     }
     // If the checksum is a multiple of 10, the number is valid
     return $checksum % 10 === 0;
 }
开发者ID:Juuro,项目名称:Dreamapp-Website,代码行数:61,代码来源:valid.php

示例2: pay

 public function pay($method)
 {
     $payment = new Payment($method);
     if ($method == 'Paypal') {
         Session::instance()->delete('paypal_token');
         $order = new Order_Model($this->order->id);
         //$inv = uniqid('payPal_');
         $inv = $this->getTransID();
         $order->trans_id = $inv;
         $order->save();
         $attributes = array('AMT' => $this->total(), 'INVNUM' => $inv, 'SHIPTONAME' => $this->order->shipping->first_name . ' ' . $this->order->shipping->last_name, 'SHIPTOSTREET' => $this->order->shipping->address1, 'SHIPTOCITY' => $this->order->shipping->city, 'SHIPTOCOUNTRYCODE' => $this->order->shipping->country, 'SHIPTOSTATE' => $this->order->shipping->state, 'SHIPTOZIP' => $this->order->shipping->zip);
         //$this->payment->GETDETAILS = FALSE;
     } else {
         if (!valid::credit_card($this->order->payment->card->card_num)) {
             throw new Exception('Invalid credit card data');
         }
         $attributes = array('card_num' => $this->order->payment->card->card_num, 'exp_date' => $this->order->payment->card->exp_date, 'amount' => $this->total(), 'ship_to_first_name' => $this->order->shipping->first_name, 'ship_to_last_name' => $this->order->shipping->last_name, 'ship_to_address' => $this->order->shipping->address1, 'ship_to_city' => $this->order->shipping->city, 'ship_to_state' => $this->order->shipping->state, 'ship_to_zip' => $this->order->shipping->zip, 'ship_to_country' => $this->order->shipping->country, 'first_name' => $this->order->billing->first_name, 'last_name' => $this->order->billing->last_name, 'address' => $this->order->billing->address1, 'city' => $this->order->billing->city, 'state' => $this->order->billing->state, 'zip' => $this->order->billing->zip, 'country' => $this->order->billing->country);
     }
     $payment->set_fields($attributes);
     $this->order->finance_state = 'CHARGING';
     if ($payment->process()) {
         $this->order->finance_state = 'CHARGED';
         $this->order->status = 2;
         //$this->order->save();
         return true;
     } else {
         $this->order->finance_state = 'DENIED';
         $this->order->status = 3;
         //$this->order->save();
         throw new Exception('Payment operation failed (' . $payment->getLastError() . ')');
     }
 }
开发者ID:VinceOmega,项目名称:mcb-nov-build,代码行数:32,代码来源:Order.php

示例3: valid_credit_card_test

 public function valid_credit_card_test()
 {
     $this->assert_true_strict(valid::credit_card('4222222222222'))->assert_true_strict(valid::credit_card('4012888888881881'))->assert_true_strict(valid::credit_card('5105105105105100'))->assert_true_strict(valid::credit_card('6011111111111117'))->assert_false_strict(valid::credit_card('6011111111111117', 'visa'));
     // invalid visa test nr
 }
开发者ID:enormego,项目名称:EightPHP,代码行数:5,代码来源:validhelper.php

示例4: credit_card

 /**
  * Validates a credit card number using the Luhn (mod10) formula.
  * @see http://en.wikipedia.org/wiki/Luhn_algorithm
  *
  * @param   integer       credit card number
  * @param   string|array  card type, or an array of card types
  * @return  boolean
  */
 public static function credit_card($number, $type = NULL)
 {
     // Remove all non-digit characters from the number
     if (($number = preg_replace('/\\D+/', '', $number)) === '') {
         return FALSE;
     }
     if ($type == NULL) {
         // Use the default type
         $type = 'default';
     } elseif (is_array($type)) {
         foreach ($type as $t) {
             // Test each type for validity
             if (valid::credit_card($number, $t)) {
                 return TRUE;
             }
         }
         return FALSE;
     }
     $cards = array('default' => array('length' => '13,14,15,16,17,18,19', 'prefix' => '', 'luhn' => TRUE), 'american express' => array('length' => '15', 'prefix' => '3[47]', 'luhn' => TRUE), 'diners club' => array('length' => '14,16', 'prefix' => '36|55|30[0-5]', 'luhn' => TRUE), 'discover' => array('length' => '16', 'prefix' => '6(?:5|011)', 'luhn' => TRUE), 'jcb' => array('length' => '15,16', 'prefix' => '3|1800|2131', 'luhn' => TRUE), 'maestro' => array('length' => '16,18', 'prefix' => '50(?:20|38)|6(?:304|759)', 'luhn' => TRUE), 'mastercard' => array('length' => '16', 'prefix' => '5[1-5]', 'luhn' => TRUE), 'visa' => array('length' => '13,16', 'prefix' => '4', 'luhn' => TRUE));
     // Check card type
     $type = strtolower($type);
     if (!isset($cards[$type])) {
         return FALSE;
     }
     // Check card number length
     $length = strlen($number);
     // Validate the card length by the card type
     if (!in_array($length, preg_split('/\\D+/', $cards[$type]['length']))) {
         return FALSE;
     }
     // Check card number prefix
     if (!preg_match('/^' . $cards[$type]['prefix'] . '/', $number)) {
         return FALSE;
     }
     // No Luhn check required
     if ($cards[$type]['luhn'] == FALSE) {
         return TRUE;
     }
     // Checksum of the card number
     $checksum = 0;
     for ($i = $length - 1; $i >= 0; $i -= 2) {
         // Add up every 2nd digit, starting from the right
         $checksum += $number[$i];
     }
     for ($i = $length - 2; $i >= 0; $i -= 2) {
         // Add up every 2nd digit doubled, starting from the right
         $double = $number[$i] * 2;
         // Subtract 9 from the double where value is greater than 10
         $checksum += $double >= 10 ? $double - 9 : $double;
     }
     // If the checksum is a multiple of 10, the number is valid
     return $checksum % 10 === 0;
 }
开发者ID:jonthornton,项目名称:JMVC,代码行数:61,代码来源:valid.php

示例5: credit_card

 /**
  * Tests the valid::credit_card() function.
  * @dataProvider credit_card_provider
  * @group core.helpers.valid.credit_card
  * @test
  */
 public function credit_card($input_number, $card_type, $expected_result)
 {
     $result = valid::credit_card($input_number, $card_type);
     $this->assertEquals($expected_result, $result);
 }
开发者ID:swk,项目名称:bluebox,代码行数:11,代码来源:Helper_Valid_Test.php


注:本文中的valid::credit_card方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。