Import using yarn add cru-payments
or npm install cru-payments --save
Note: If you only need to accept one type of payment, use one of the specific builds:
- Use
dist/cru-payments.js
for credit cards and bank accounts - Use
dist/cru-payments-ba.js
for bank accounts only - Use
dist/cru-payments-cc.js
for credit cards only
- Add
node_modules/cru-payments/dist/cru-payments.js
to a script tag in your app. You may have to move the file somewhere else for it to be publicly accessible. - Use the global variable
cruPayments
import cruPayments from 'cru-payments/dist/cru-payments';
Credit card payments do not work in IE 9 or below Bank account payments do not work in IE 8 or below
yarn
ornpm install
yarn run build
ornpm run build
- Use
dist/cru-payments.js
in your app
import cruPayments from 'cru-payments/dist/cru-payments';
cruPayments.creditCard.init('production', '00000000000000', '00000000000000000000');
cruPayments.creditCard.encrypt('4111111111111111', '123', '03', '2020')
.subscribe(tokenObj => {
console.log({
tokenizedCardNumber: tokenObj.tsepToken,
lastFourDigits: tokenObj.maskedCardNumber,
expirationDate: tokenObj.expirationDate,
cvv: tokenObj.cvv2,
cardType: tokenObj.cardType,
transactionId: tokenObj.transactionID,
});
}, error => {
console.log('Error tokenizing credit card', error);
});
import cruPayments from 'cru-payments/dist/cru-payments';
cruPayments.creditCard.init('production', '00000000000000', '00000000000000000000');
cruPayments.creditCard.encrypt('4111111111111111', '123', '03', '2020')
.toPromise() // Relies on browser's native promise implementation by default. Will throw error on older browsers.
.then(tokenObj => {
console.log({
tokenizedCardNumber: tokenObj.tsepToken,
lastFourDigits: tokenObj.maskedCardNumber,
expirationDate: tokenObj.expirationDate,
cvv: tokenObj.cvv2,
cardType: tokenObj.cardType,
transactionId: tokenObj.transactionID,
});
}, error => {
console.log('Error tokenizing credit card', error);
});
You can pass a valid ES2015 compatible promise to .toPromise(PromiseConstructor)
to prevent it from failing on browsers without promise implementations. Passing Angular's $q
works. Providing a polyfill would also work. See: http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-toPromise
Note: Use cruPayments
instead of cruPayments.creditCard
if using cru-payments-cc.js
Must be called at least once before calling cruPayments.creditCard.encrypt
. If environment is 'production'
, it will grab the code from TSYS's production servers, otherwise it will use TSYS's staging servers.
Returns true if card number, cvv, and expiry date are all valid
Returns an Observable of that emits the results of the tokenization. If a Promise
is desired, call .toPromise()
on this Observable. cruPayments.creditCard.init
must have been called first.
Returns true if card number has a valid min length
Returns true if card number has a valid max length
Returns true if card type is known by the system
Returns true if card type is known by the system and the length is valid for that type
Returns true if the card number's checksum is valid
Returns true if all of the above card validators return true
Returns an array of error message strings. For each invalid validator above (excluding all
), a string containing an error message for that validator will be added in the above order.
Returns 'Visa'
, 'MasterCard'
, 'American Express'
, 'Discover'
, 'Diners Club'
, or ''
(if the type is unknown)
Returns an array containing the lengths allowed for the detected type. Could be useful in creating error messages.
Returns true if card cvv has a valid min length
Returns true if card cvv has a valid max length
Returns true if card cvv length matches the allowed lengths for the given card type
Returns true if all of the above cvv validators return true
Returns an array of error message strings. For each invalid validator above (excluding all
), a string containing an error message for that validator will be added in the above order.
Returns true if the expiration date is the current month or in the future
Returns true if the year is not in the past
Alias for cruPayments.creditCard.expiryDate.validate.month
Returns an array of error message strings. For each invalid validator above, a string containing an error message for that validator will be added in the above order.
Note: Use cruPayments
instead of cruPayments.bankAccount
if using cru-payments-ba.js
Must be called at least once before calling cruPayments.bankAccount.encrypt
. If environment is 'production'
, it will grab the encryption key from CCP's production servers, otherwise it will use CCP's staging servers. If the backupKey
is provided, it will be used when fetching a key from CCP's servers fails.
Returns true if routing number and account number are valid
Returns an Observable of that emits the results of the account number encryption. If a Promise
is desired, call .toPromise()
on this Observable. cruPayments.bankAccount.init
must have been called first.
Returns true if routing number has a valid length
Returns true if routing number has a valid checksum
Returns true if all of the above routing number validators return true
Returns an array of error message strings. For each invalid validator above (excluding all
), a string containing an error message for that validator will be added in the above order.
Returns true if account number has a valid min length
Returns true if account number has a valid max length
Returns true if all of the above account number validators return true
Returns an array of error message strings. For each invalid validator above (excluding all
), a string containing an error message for that validator will be added in the above order.
yarn
or npm install
yarn run start
or npm run start
yarn run build
or npm run build
yarn run lint
or npm run lint
yarn run test
or npm run test