Skip to content

Commit

Permalink
CRM-21311 CIVICRM-668 Restore incorrect capitalisation of Mastercard,…
Browse files Browse the repository at this point in the history
… remove JS validation of card types which cannot be defined, remove unused call to CRM.config.creditCardTypes
  • Loading branch information
agileware-justin authored and agilewarealok committed Dec 5, 2017
1 parent d1f2a22 commit fb3e8df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
15 changes: 5 additions & 10 deletions templates/CRM/Core/BillingBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,14 @@
function civicrm_billingblock_set_card_type(ccnumber) {
// Based on http://davidwalsh.name/validate-credit-cards
// See also https://en.wikipedia.org/wiki/Credit_card_numbers
// @todo these patterns should be part of the credit card option group, instead of hard coded
var card_types = {
'mastercard': '(5[1-5][0-9]{2}|2[3-6][0-9]{2}|22[3-9][0-9]|222[1-9]|27[0-1][0-9]|2720)[0-9]{12}',
'visa': '4(?:[0-9]{12}|[0-9]{15})',
'amex': '3[47][0-9]{13}',
'dinersclub': '3(?:0[0-5][0-9]{11}|[68][0-9]{12})',
'carteblanche': '3(?:0[0-5][0-9]{11}|[68][0-9]{12})',
'discover': '6011[0-9]{12}',
'jcb': '(?:3[0-9]{15}|(2131|1800)[0-9]{11})',
'unionpay': '62(?:[0-9]{14}|[0-9]{17})'
'MasterCard': '(5[1-5][0-9]{2}|2[3-6][0-9]{2}|22[3-9][0-9]|222[1-9]|27[0-1][0-9]|2720)[0-9]{12}',
'Visa': '4(?:[0-9]{12}|[0-9]{15})',
'Amex': '3[47][0-9]{13}',
'Discover': '6011[0-9]{12}',
};

var card_values = CRM.config.creditCardTypes;

$.each(card_types, function(card_type_key, pattern) {
card_type_css = card_type_key.toLowerCase();
if (ccnumber.match('^' + pattern + '$')) {
Expand Down
10 changes: 5 additions & 5 deletions tests/phpunit/CRM/Financial/BAO/PaymentProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public function testGetCreditCards() {
'domain_id' => 1,
'accepted_credit_cards' => json_encode(array(
'Visa' => 'Visa',
'Mastercard' => 'Mastercard',
'MasterCard' => 'Mastercard',
'Amex' => 'American Express',
)),
);
$paymentProcessor = CRM_Financial_BAO_PaymentProcessor::create($params);
$expectedCards = array(
'Visa' => 'Visa',
'Mastercard' => 'Mastercard',
'MasterCard' => 'Mastercard',
'Amex' => 'American Express',
);
$cards = CRM_Financial_BAO_PaymentProcessor::getCreditCards($paymentProcessor->id);
Expand All @@ -73,7 +73,7 @@ public function testCreditCardType() {
'domain_id' => 1,
'accepted_credit_cards' => json_encode(array(
'Visa' => 'Visa',
'Mastercard' => 'Mastercard',
'MasterCard' => 'Mastercard',
'Amex' => 'American Express',
)),
);
Expand All @@ -84,7 +84,7 @@ public function testCreditCardType() {
$Cards = CRM_Contribute_PseudoConstant::creditCard($cards);
$expectedCards = array(
'Visa' => 'Visa',
'Mastercard' => 'Mastercard',
'MasterCard' => 'Mastercard',
'Amex' => 'American Express',
);
$this->assertEquals($Cards, $expectedCards, 'Verify correct credit card types are returned');
Expand All @@ -93,7 +93,7 @@ public function testCreditCardType() {
$Cards2 = CRM_Contribute_PseudoConstant::creditCard(array());
$allCards = array(
'Visa' => 'Visa',
'Mastercard' => 'Mastercard',
'MasterCard' => 'Mastercard',
'Amex' => 'American Express',
'Discover' => 'Discover', // Note: Discover is a default credit card type available, not assigned to a processor
);
Expand Down

0 comments on commit fb3e8df

Please sign in to comment.