Skip to content

Conversation

@derekmd
Copy link

@derekmd derekmd commented Feb 16, 2016

Payment gateway APIs require the credit card type in request parameters but why prompt users in the UI to select it when Visa, Amex, etc. can be automatically recognized at the time of performing auth or capture? validCreditCard() with $type as input is useful if the CC details are being stored now without pre-auth until a later date when e.g., a subscription renewal occurs. Otherwise let the payment gateway reject the card number.

Combined with #4 this will add credit card recognition so the correct type can be submitted to payment gateway APIs.

public function getTypeForGateway($type)
{
    CreditCard::TYPE_AMEX:
        return 'Amex constant specific for that payment API';

        break;
    CreditCard::TYPE_DANKORT:
    CreditCard::TYPE_DINERS_CLUB:
    CreditCard::TYPE_DISCOVER:
    CreditCard::TYPE_FORBRUGSFORENINGEN:
    CreditCard::TYPE_JCB:
    CreditCard::TYPE_MAESTRO:
    CreditCard::TYPE_MASTERCARD:
    CreditCard::TYPE_UNION_PAY:
    CreditCard::TYPE_VISA:
    CreditCard::TYPE_VISA_ELECTRON:
        // etc.

        break;
}

public function auth($creditCard)
{
    $payloadForApi = [
        'type' = $this->getTypeForGateway(CreditCard::creditCardType($creditCard->number));

        // ...
    ];

}

For one use case I ended up creating an intermediate wrapper class:

class InachoCreditCard extends \Inacho\CreditCard
{
    public static function getCardType($number)
    {
        $type = strtoupper(static::creditCardType($number));

        // CreditCardType contains constants for Moneris
        if (CreditCardType::isValidValue($type)) {
            return $type;
        }

        return null;
    }
}

@tomsommer
Copy link

+1

1 similar comment
@marius-c
Copy link

+1

@derekmd
Copy link
Author

derekmd commented Sep 27, 2018

@derekmd derekmd closed this Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants