简体   繁体   English

如何检查信用卡是否对PayPal有效

[英]how to check if the credit card is valid or not for paypal

I have to take the user credit card details for payment through paypal. 我必须通过paypal获取用户信用卡详细信息。 The first time the user enters the card's details the payment is done through paypal pro. 用户第一次输入卡的详细信息时,付款是通过paypal pro完成的。 If the card is not valid, the payment will not be done. 如果该卡无效,则不会付款。 The payment will be done only if the card is valid. 只有在卡有效时才会付款。

The first time the user enters a valid card details and the payment is done, if such user modifies the credit card details at that time i need to check again if the card is valid for paypal or not. 用户第一次输入有效的卡详细信息并完成付款时,如果此时用户修改了信用卡详细信息,我需要再次检查该卡是否对PayPal有效。

So are there any APIs which only check the credit card details and not process any payment? 那么有没有API只检查信用卡详细信息而不处理任何付款?

I am running php and mysql. 我正在运行php和mysql。

Thanks. 谢谢。

Avinash 阿维纳什

With Paypal your options are very limited. 使用Paypal,您的选择非常有限。 If you're using Paypal Pro you can verify the card exists and is legitimate by doing an Authorization Only for $0.00. 如果您使用的是Paypal Pro,则只需0.00美元即可通过授权验证该卡是否存在且合法。 If you're using the other payment methods offered by Paypal you won't be able to do this. 如果您使用的是Paypal提供的其他付款方式,您将无法执行此操作。

Your other options then would be to verify the card at least contains valid information. 您的其他选择是验证卡至少包含有效信息。 You can verify the card number is legitimate by using the Luhn algorithm . 您可以使用Luhn算法验证卡号是否合法。 All credit card numbers are issued in a pattern that can be verified using that algorithm. 所有信用卡号都以可以使用该算法验证的模式发布。 It can't confirm that the card is valid but it will eliminate fake credit card numbers from being entered. 它无法确认该卡是否有效,但它将消除输入的伪造信用卡号。 You should also verify that expiration date is not expired and that the CVV code is only three digits long for Visa, MasterCard, and Discover Card and four digits long for American Express. 您还应验证到期日期是否已过期,以及Visa,MasterCard和Discover Card的CVV代码长度仅为三位数,American Express为四位数。

If you need code for validating the card number against the Luhn algorithm let me know and I can append my answer to include it. 如果您需要使用代码验证Luhn算法的卡号,请告诉我,我可以附上我的答案以包含它。

EDIT (added Luhn algorithm code in PHP): 编辑(在PHP中添加了Luhn算法代码):

function passes_luhn_check($cc_number) {
    $checksum  = 0;
    $j = 1;
    for ($i = strlen($cc_number) - 1; $i >= 0; $i--) {
        $calc = substr($cc_number, $i, 1) * $j;
        if ($calc > 9) {
            $checksum = $checksum + 1;
            $calc = $calc - 10;
        }
        $checksum += $calc;
        $j = ($j == 1) ? 2 : 1;
    }
    if ($checksum % 10 != 0) {
        return false;
    }
    return true;
}

Usage: 用法:

$valid_cc = passes_luhn_check('4427802641004797'); // returns true
$valid_cc = passes_luhn_check('4427802641004798'); // returns false

Without knowing much about Paypal I would imagine that they have some kind of authorization API where you can do a $0.00 authorization to see if the card is valid. 在不了解Paypal的情况下,我会想象他们有某种授权API,您可以在这里获得$ 0.00授权,看看该卡是否有效。

Remember the PCI requirements when storing credit card details. 存储信用卡详细信息时请记住PCI要求。

What details of the creditcard can be changed by the customer that have impact on the data that you have stored. 客户可以更改哪些信用卡详细信息会对您存储的数据产生影响。 If the customer changes something substantial like his embossing name, then the issuer gives the customer a new card. 如果客户改变了像他的浮雕名称那样重要的东西,那么发行人会给客户一张新卡。 From your point of view, this should be a new card (even if the cardnumber did not change). 从您的角度来看,这应该是一张新卡(即使卡号没有改变)。

If you save some other details, then you're saving too much. 如果你保存一些其他细节,那么你节省了太多。

From my point of view (I'm working at an issuer), don't go the way of authorizations of $0.00. 从我的观点来看(我在发行人工作),不要采用0.00美元的授权方式。 If you want to charge the customer, then do your authorization. 如果您想向客户收费,请进行授权。 Not Paypall, but the issuer will handle the autorization. 不是Paypall,但发行人将处理自动化。 And in the end, only the issuer knows if the card is valid or not. 最后,只有发卡机构知道该卡是否有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM