Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

added option to set available card types #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ And then:

Basically the directive sends the credit card details directly to stripe, which then returns a token that you can use to charge the card, subscribe a user or to do other things. This ensures that the card details themselves never hit your backend and thus you have to worry a little bit less.

### Configuration

To configure the available cart types (if your payment gateway doesn't support all) you can do so with the following where `myApp' is your angular module.

The default value is ['amex', 'dinersclub', 'discover', 'jcb', 'maestro', 'mastercard', 'unionpay', 'visa']

myApp.run(['angularPaymentsOptions',
function(angularPaymentsOptions) {
angularPaymentsOptions.enabledCardTypes = ['visa', 'mastercard', 'amex'];
}
]);




## Example

Expand Down
15 changes: 12 additions & 3 deletions lib/angular-payments.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
angular.module('angularPayments', []);angular.module('angularPayments')
angular.module('angularPayments', [])

// Cart types accepted
.value('angularPaymentsOptions', {
enabledCardTypes: ['amex', 'dinersclub', 'discover', 'jcb', 'maestro', 'mastercard', 'unionpay', 'visa']
})
;angular.module('angularPayments')

.factory('Common', [function(){

Expand Down Expand Up @@ -33,12 +39,12 @@ angular.module('angularPayments', []);angular.module('angularPayments')

}]);angular.module('angularPayments')

.factory('Cards', [function(){
.factory('Cards', ['angularPaymentsOptions', '$filter', function(angularPaymentsOptions, $filter){

var defaultFormat = /(\d{1,4})/g;
var defaultInputFormat = /(?:^|\s)(\d{4})$/;

var cards = [
var cardDefinitions = [
{
type: 'maestro',
pattern: /^(5018|5020|5038|6304|6759|676[1-3])/,
Expand Down Expand Up @@ -114,6 +120,9 @@ angular.module('angularPayments', []);angular.module('angularPayments')
}
];

var cards = $filter('filter')(cardDefinitions, function(card) {
return angularPaymentsOptions.enabledCardTypes.indexOf(card.type) > -1;
});

var _fromNumber = function(num){
var card, i, len;
Expand Down
Loading