Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #359 from common-group/fix/credt_card_holder_name_…
Browse files Browse the repository at this point in the history
…normalization

Fix credit card holder name normalization
  • Loading branch information
devton authored May 7, 2020
2 parents c05c0bf + e8c83f6 commit 18acf57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
20 changes: 19 additions & 1 deletion legacy/src/h.js
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,24 @@ const _dataCache = {},
} catch (e) {
Sentry.captureException(e);
}
};
},
titleCase = (str) => {
// remove leading and trailing spaces
let newString = str ? str.trim() : '';
// remove multiple spaces
newString = newString.replace(/\s{2,}/g, ' ');
// lowercase
newString = newString.toLowerCase();

return newString.split(' ').map(function(word) {
if (['de', 'da', 'do', 'das', 'dos'].includes(word)) {
return word.toLowerCase()
} else {
return word ? word.replace(word[0], word[0].toUpperCase()) : '';
}
}).join(' ');
}


/**
* @param {string} phoneNumberStr
Expand Down Expand Up @@ -1362,4 +1379,5 @@ export default {
isDevEnv,
trust,
attachEventsToHistory,
titleCase,
};
12 changes: 1 addition & 11 deletions legacy/src/vms/common-payment-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,14 @@ const updateUser = user => m.request({

const setNewCreditCard = (creditCardFields) => {
const creditCard = new window.PagarMe.creditCard();
creditCard.cardHolderName = titleCase(creditCardFields.name());
creditCard.cardHolderName = h.titleCase(creditCardFields.name());
creditCard.cardExpirationMonth = creditCardFields.expMonth();
creditCard.cardExpirationYear = creditCardFields.expYear();
creditCard.cardNumber = creditCardFields.number();
creditCard.cardCVV = creditCardFields.cvv();
return creditCard;
};

const titleCase = (str) => {
return str.toLowerCase().split(' ').map(function(word) {
if (['de', 'da', 'do', 'das', 'dos'].includes(word)) {
return word.toLowerCase()
} else {
return word.replace(word[0], word[0].toUpperCase());
}
}).join(' ');
}

const userPayload = (customer, address) => ({
id: h.getUser().id,
cpf: customer.ownerDocument(),
Expand Down
12 changes: 1 addition & 11 deletions legacy/src/vms/payment-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,14 @@ const paymentVM = () => {

const setNewCreditCard = () => {
const creditCard = new window.PagarMe.creditCard();
creditCard.cardHolderName = titleCase(creditCardFields.name());
creditCard.cardHolderName = h.titleCase(creditCardFields.name());
creditCard.cardExpirationMonth = creditCardFields.expMonth();
creditCard.cardExpirationYear = creditCardFields.expYear();
creditCard.cardNumber = creditCardFields.number();
creditCard.cardCVV = creditCardFields.cvv();
return creditCard;
};

const titleCase = (str) => {
return str.toLowerCase().split(' ').map(function(word) {
if (['de', 'da', 'do', 'das', 'dos'].includes(word)) {
return word.toLowerCase()
} else {
return word.replace(word[0], word[0].toUpperCase());
}
}).join(' ');
}

const payWithNewCard = (contribution_id, installment) => {
const p = new Promise((resolve, reject) => {
m.request({
Expand Down

0 comments on commit 18acf57

Please sign in to comment.