Last active
January 4, 2016 03:28
-
-
Save hereswhatidid/8561716 to your computer and use it in GitHub Desktop.
Get the last four digits and card type from an Offline Credit Card order in PrestaShop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| protected function getCardType( $ccNum ) { | |
| if (preg_match("/^5[1-5][0-9]{14}$/", $ccNum)) | |
| return "Mastercard"; | |
| if (preg_match("/^4[0-9]{12}([0-9]{3})?$/", $ccNum)) | |
| return "Visa"; | |
| if (preg_match("/^3[47][0-9]{13}$/", $ccNum)) | |
| return "American Express"; | |
| if (preg_match("/^3(0[0-5]|[68][0-9])[0-9]{11}$/", $ccNum)) | |
| return "Diners Club"; | |
| if (preg_match("/^6011[0-9]{12}$/", $ccNum)) | |
| return "Discover"; | |
| if (preg_match("/^(3[0-9]{4}|2131|1800)[0-9]{11}$/", $ccNum)) | |
| return "JCB"; | |
| } | |
| /** | |
| * Retrieve the last four digits and card type for an order | |
| * @author Gabe Shackle <gabe.shackle@gmail.com> | |
| * @param int $order_id Order ID to retrieve data from | |
| * @return mixed Array containing the found data or false if not found | |
| */ | |
| public function getLastFourAndType( $order_id = null ) { | |
| include(dirname(__FILE__).'/serialkey.php'); | |
| include_once(dirname(__FILE__) . '/PrestoChangeoClasses/EncryptDecrypt.php'); | |
| $crypt = new encryption_class(); | |
| $result = Db::getInstance()->ExecuteS(' | |
| SELECT | |
| occ.info1, occ.info2, occ.info3, occ.info4, occ.info5, occ.info6, occ.info7, occ.info8, occ.info9, o.id_address_invoice, o.id_currency, o.total_paid | |
| FROM '._DB_PREFIX_.'offlinecreditcard_info occ | |
| LEFT JOIN '._DB_PREFIX_.'orders o on occ.id_order = o.id_order | |
| WHERE occ.id_order='.$order_id | |
| ); | |
| if (is_array($result) && sizeof($result) > 0) { | |
| $card_number = $crypt->decrypt( $cryptkey, $result[0]['info2'] ); | |
| return array( | |
| 'last_four' => substr( $card_number, -4 ), | |
| 'type' => $this->getCardType( $card_number ) | |
| ); | |
| } else { | |
| return false; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function hookOrderConfirmation($params) | |
| { | |
| $order = $params['objOrder']; | |
| // var_dump( $params ); | |
| $cart = new Cart( (int) $order->id_cart ); | |
| $occObject = new OfflineCreditCard(); | |
| $card_info = $occObject->getLastFourAndType( $order->id ); | |
| $last_four_digits = $card_info['last_four']; | |
| $card_type = $card_info['type']; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment