如何检查信用卡是否对贝宝有效 [英] how to check if the credit card is valid or not for paypal

查看:137
本文介绍了如何检查信用卡是否对贝宝有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须获取用于通过Paypal付款的用户信用卡详细信息. 用户首次输入卡的详细信息时,将通过贝宝(Paypal)专业版进行付款. 如果该卡无效,则不会付款.仅在卡有效时付款.

I have to take the user credit card details for payment through paypal. The first time the user enters the card's details the payment is done through 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.

那么有没有仅检查信用卡详细信息而不处理任何付款的API?

So are there any APIs which only check the credit card details and not process any payment?

我正在运行php和mysql.

I am running php and mysql.

谢谢.

阿维纳什(Avinash)

Avinash

推荐答案

使用Paypal时,您的选择非常有限.如果您使用的是Paypal Pro,则可以通过进行$ 0.00的授权来验证该卡是否存在并合法.如果您使用贝宝(Paypal)提供的其他付款方式,则将无法执行此操作.

With Paypal your options are very limited. If you're using Paypal Pro you can verify the card exists and is legitimate by doing an Authorization Only for $0.00. If you're using the other payment methods offered by Paypal you won't be able to do this.

然后,您的其他选择是验证卡至少包含有效信息.您可以使用 Luhn算法来验证卡号是否合法.所有信用卡号的发行方式都可以使用该算法进行验证.它无法确认该卡是否有效,但会消除输入的虚假信用卡号.您还应该验证有效期限是否未过期,并且Visa,MasterCard和Discover卡的CVV码只有三位数,而美国运通卡的CVV码只有四位数.

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. 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.

如果您需要根据Luhn算法验证卡号的代码,请告诉我,我可以附加答案以包括该代码.

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.

编辑(在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;
}

用法:

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

这篇关于如何检查信用卡是否对贝宝有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆