Block American Express Cards via Stripe API

Published 3 weeks ago by aGandrass

Hi, I am trying to block all American Express Credit Card on my payment form. Is there a way to block them via the Stripe API and show the user that I do no accept American Express Credit Cards? Thank you very much

Best Answer (As Selected By aGandrass)
Cronix
$cc_number = 34567852345235;

$amex = ["34", "37"];

$first2 = substr($cc_number, 0, 2); // get first 2 numbers

if (in_array($first2, $amex)) { // see if first 2 are 34 or 37
    // is amex card, reject
}

or make a helper

function isAmexCard($ccNumber) {
    $amex = ["34", "37"];

    $first2 = substr($ccNumber, 0, 2); // get first 2 numbers

    return (in_array($first2, $amex));
}
if (isAmexCard($cc_number)) {
    // is amex card, reject
}
martinbean

@aGandrass Can you not create a Radar rule?

aGandrass

@martinbean Thank you for your reply. I was looking for a coding solution. I think the commision for Stripe will be higher if you activate Radar.

martinbean

@aGandrass Radar is built into Stripe. It’s not an “extra” product or something additionally charged for.

aGandrass

@martinbean Thank you Martin. I have talked to Stripe and unfortunately they charge me for activating Radar for Teams an additional 2 cents per transaction. But I think that's worth activating it. Thank you

martinbean

@aGandrass I’m not sure what “Radar for Teams” is. I have multiple Stripe accounts for my products, and each one has their own Radar rules.

aGandrass

Maybe it is only for European clients, I don't know. But doesn't matter, I have already activated Radar. Thanks Martin for your help

Cronix
Cronix
3 weeks ago (783,370 XP)

@aGandrass It looks like AmEx cards are unique in several ways, which you could easily check for.

  1. Amex cards all start with "34" or "37". All others start with other numbers. (Visa starts with "4", Mastercard starts with "5", Discover starts with "6", etc

https://www.cybersource.com/developers/getting_started/test_and_manage/best_practices/card_type_id/

http://blog.unibulmerchantservices.com/10-signs-of-a-valid-american-express-card/

Anyway, I just thought I'd throw that out. I know you have a solution in place, but it seems to be costing you a bit of money and the above would be fairly trivial to implement.

aGandrass

@Cronix Thank you for your reply. Actually, that's exactly what I was looking for. :) Do you mind giving me a hint how to code it? Thanks

Cronix
Cronix
3 weeks ago (783,370 XP)
$cc_number = 34567852345235;

$amex = ["34", "37"];

$first2 = substr($cc_number, 0, 2); // get first 2 numbers

if (in_array($first2, $amex)) { // see if first 2 are 34 or 37
    // is amex card, reject
}

or make a helper

function isAmexCard($ccNumber) {
    $amex = ["34", "37"];

    $first2 = substr($ccNumber, 0, 2); // get first 2 numbers

    return (in_array($first2, $amex));
}
if (isAmexCard($cc_number)) {
    // is amex card, reject
}
martinbean

@aGandrass If you’re going to disregard the Radar rule route, then a Token object (whether created with JavaScript or PHP or any other language) has a card.brand property:

$token = Stripe\Token::retrieve($request->paymentToken);

if (strtolower($token->card->brand) == 'mastercard') {
    // Throw exception or something
}

Stripe documentation: https://stripe.com/docs/api/php#token_object

aGandrass

Thank you @Cronix

Please sign in or create an account to participate in this conversation.