Braintree Dropin UI,如何检测卡类型?

时间:2015-07-24 08:38:23

标签: .net paypal braintree

我正在使用Braintree Dropin UI,我需要找出像AMEX,VISA等卡片类型。

我正在使用JS + .NET。这是我的付款请求代码:

var request = new TransactionRequest
                {
                    Amount = Math.Round(amount, 2),
                    PaymentMethodNonce = nonce,
                    MerchantAccountId = merchantAccount,
                    Options = new TransactionOptionsRequest
                    {
                        SubmitForSettlement = true
                    }
                };

实际上,在进行交易之前,我需要针对某些特定的卡片类型使用特定的merchantAcount

有没有办法让PaymentMethod使用来自客户端的requestnonceclientToken

我可以在Braintree保险库中看到PaymentMethod令牌。

任何帮助都将不胜感激。

提前致谢。

2 个答案:

答案 0 :(得分:0)

创建事务后,您可以从事务响应对象中获取CardType。 CardType will be in the CreditCard attribute

如果您正在使用Braintree的Drop-In UI,它会在用户输入卡号时自动显示卡片类型。

如果您想自己制作take a look at this JavaScript library for checking card type

实施例

var getCardTypes = require('credit-card-type');

var visaCards = getCardTypes('4111');
console.log(visaCards[0].type);  // 'visa'

var ambiguousCards = getCardTypes('6');
console.log(ambiguousCards.length);       // 3
console.log(ambiguousCards[0].niceType);  // 'Discover'
console.log(ambiguousCards[1].niceType);  // 'UnionPay'
console.log(ambiguousCards[2].niceType);  // 'Maestro'

答案 1 :(得分:0)

我是Braintree的开发人员。有global configurations可以与Drop-in集合一起使用以获取卡类型。 onPaymentMethodReceived回调允许您检查有关用户付款方式的一些基本信息。

此回调拦截表单提交事件,因此您可以将卡片类型添加到表单并将其传递给服务器端代码。 More details about the callback are listed here。这是一个如何看起来的例子:

 <form id="checkout" method="post" action="/checkout"> 
   <div id="payment-form"></div> 
   <input type="hidden" id="nonce" name="payment_method_nonce" value=""> 
   <input type="hidden" id="card_type" name="card_type" value="">
   <input type="submit" value="Submit"> 
 </form> 

然后在客户端Braintree设置中配置回调:

braintree.setup(clientTokenFromServer, "dropin", {
    container: "payment-form",
    onPaymentMethodReceived: function (obj) {
        var form = document.getElementById("checkout");
        var nonce = document.getElementById("nonce");
        var card_type = document.getElementById("card_type");
        nonce.value = obj.nonce;
        card_type.value = obj.details.cardType;
        form.submit();
    }
}); 

您会注意到,由于提交事件被截获,我将付款方式nonce添加到表单并在表单上调用submit()以完成提交。希望有所帮助!

相关问题