Reputation: 4123
I am implementing payment gateway using Stripe and I am not able to find a way how to restrict certain types of credit cards to be accepted. Please is there any simple way how to achieve that? I am using React Elements.
Upvotes: 2
Views: 2842
Reputation: 7198
You can check the brand field from the change
event of the Stripe Element. For example this : https://jsfiddle.net/nwyf587t/ blocks American Express cards in vanilla JS.
https://stripe.com/docs/js/element/events/on_change?type=cardElement https://stripe.com/docs/js/element/events/on_change?type=cardElement#element_on_change-handler-brand
card.on('change', function(event) {
if (event.brand === 'amex') {
errorElement.textContent = 'American Express cards are not supported.';
errorElement.classList.add('visible');
payButtonElement.disabled = true;
}
});
Note that this is only ever going to be a client-side check and theoretically it coud be circumvented if the user really wanted to using their browser devtools. You could use Radar rules in Stripe to block payments entirely https://stripe.com/docs/radar/rules/reference
Upvotes: 2