Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aGandrass's avatar

Block American Express Cards via Stripe API

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

0 likes
11 replies
aGandrass's avatar

@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's avatar

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

aGandrass's avatar

@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's avatar

@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's avatar

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's avatar

@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's avatar

@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's avatar
Cronix
Best Answer
Level 67
$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's avatar

@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

Please or to participate in this conversation.