BrainTree是一个国外集成信用卡支付的卡包。

沙盒登陆地址:

https://sandbox.braintreegateway.com/login

登陆沙盒得到商户ID、公钥、私钥。

1.配置web.config

  1. <BraintreeSection>
  2.  
  3. <BraintreeAuthentication
  4.  
  5. Environment="SANDBOX" //生产环境为PRODUCT
  6.  
  7. MerchantId="bnnvkfgf3crhvbcs"
  8.  
  9. PublicKey="rp28gffvwtj7gygz"
  10.  
  11. PrivateKey="906d2077d76e81f90b51c3b409682815">
  12.  
  13. </BraintreeAuthentication>
  14.  
  15. </BraintreeSection>

2.引入Braintree.dll

3.引入Braintree.js

4.配置Braintree证书

  1. var gateway = new BraintreeGateway
  2.  
  3. {
  4.  
  5. Environment = Braintree.Environment.SANDBOX; //沙盒
  6.  
  7. MerchantId = config.MerchantId,
  8.  
  9. PublicKey = config.PublicKey,
  10.  
  11. PrivateKey = config.PrivateKey
  12.  
  13. };

5.  作为客户将客户Id及信息保存在Braintree中。

  1. private string getCustomerId()
  2.  
  3. {
  4.  
  5. string customerId = "customer_" + CurrentUserId;
  6.  
  7. try
  8.  
  9. {
  10.  
  11. var customer = getGateway().Customer.Find(customerId); //查找该客户的所有信息
  12.  
  13. if (customer != null)
  14.  
  15. {
  16.  
  17. return customer.Id;
  18.  
  19. }
  20.  
  21. }
  22.  
  23. catch
  24.  
  25. {
  26.  
  27. //没找到则添加
  28.  
  29. var model = UserDataService.GetUserInfo(CurrentUserId);
  30.  
  31. var request = new CustomerRequest
  32.  
  33. {
  34.  
  35. Id = "customer_" + CurrentUserId,
  36.  
  37. FirstName = model.FirstName,
  38.  
  39. LastName = model.LastName,
  40.  
  41. Email = model.Email,
  42.  
  43. Phone = model.CellPhone,
  44.  
  45. Company = model.BusinessName
  46.  
  47. };
  48.  
  49. Result<Customer> result = getGateway().Customer.Create(request); //创建客户
  50.  
  51. if (result.IsSuccess())
  52.  
  53. {
  54.  
  55. return result.Target.Id;
  56.  
  57. }
  58.  
  59. }
  60.  
  61. return null;
  62.  
  63. }

6.  获得该客户的所有信用卡信息。

  1. var customer = getGateway().Customer.Find(customerId);
  2.  
  3. if (customer.CreditCards != null)//信用卡部分
  4.  
  5. {
  6.  
  7. return Json(new { result = true, data = customer.CreditCards.Select(c => new { Token = c.Token, MaskedNumber = c.MaskedNumber, CardType = c.CardType.ToString(), IsDefault = c.IsDefault, ImageUrl = c.ImageUrl }) }); //token支付用的凭证,MaskedNumber卡号,CardType 卡类型,IsDefault 默认卡,ImageUrl 图片路径
  8.  
  9. }

1.2信用卡验证

1.Braintree介入方式(1。Dropin 2。custom) 前者使用现成的框架,后者自定义框架(意味着卡的验证也要自己)

2.Dropin显示方法:

  1. <form id="CreditCards-form" method="post" action="/Braintree/AddPaymentMenthod">
  2.  
  3. <div id="payment-form"></div>
  4.  
  5. <div id="show" style="display:none">
  6.  
  7. <input type="checkbox" id="default" name="default" checked="checked" value="true" /> Set As Default
  8.  
  9. <div style="text-align:center">
  10.  
  11. <input type='submit' id="btnAddCreditCard" value='Add Credit Cards'/>
  12.  
  13. </div>
  14.  
  15. </div>
  16.  
  17. </form>

默认只有卡号,年月日输入框,自动根据卡号验证卡的类型,CVV AVS 需要在控制面板开启,设为默认是自己后加的。

PayPal按钮需要线上关闭,沙盒无法关闭。

设置方法:

一些其他支付方式的支持,卡类型的支持均在此处设置。

调用braintree封装好的方法显示该UI。首先需要取得客户端Token:

  1. var clientToken = getGateway().ClientToken.generate();

得到客户端令牌后就可以调用js方法展示该UI了

  1. braintree.setup(data, "dropin", {
  2.  
  3. container: "payment-form",
  4.  
  5. form: "CreditCards-form",
  6.  
  7. onReady: function () {
  8.  
  9. $("#ts").hide();
  10.  
  11. $("#show").show();
  12.  
  13. }
  14.  
  15. });

1.3:添加一张信用卡:

创建的ui自动会生成一个付款方式随机数,该随机数包含信用卡的卡号、卡类型、有效期以及我们设置的CVV。

payment_method_nonce

为客户添加信用卡

  1. var request = new PaymentMethodRequest
  2.  
  3. {
  4.  
  5. CustomerId = customerId,
  6.  
  7. PaymentMethodNonce = payment_method_nonce,
  8.  
  9. Options = new PaymentMethodOptionsRequest
  10.  
  11. {
  12.  
  13. VerifyCard = true, //卡验证
  14.  
  15. FailOnDuplicatePaymentMethod = true //拒绝重复添加
  16.  
  17. }
  18.  
  19. };
  20.  
  21. Result<PaymentMethod> result = getGateway().PaymentMethod.Create(request);
  22.  
  23. if (result.IsSuccess())
  24.  
  25. {
  26.  
  27. }

IsSuccess为成功状态。添加信用卡时可以设置对卡片进行有效性验证,以及不可以重复添加等。

1.4:删除一张信用卡:

  1. var result = getGateway().PaymentMethod.Delete(token); //token为信用卡支付以及删除的唯一标识。

删除信用卡后,自动将下一张设为默认卡。

1.5:设为默认:

  1. var updateRequest = new PaymentMethodRequest
  2.  
  3. {
  4.  
  5. Options = new PaymentMethodOptionsRequest
  6.  
  7. {
  8.  
  9. MakeDefault = true, //默认
  10.  
  11. }
  12.  
  13. };
  14.  
  15. Result<PaymentMethod> result = getGateway().PaymentMethod.Update(token, updateRequest);
  16.  
  17. if (result.IsSuccess())
  18.  
  19. {
  20.  
  21. return Json(new { result = true });
  22.  
  23. }

只需要设置MakeDefault为true即可。

2.1:支付方式新增信用卡支付:

调用Braintree的消费方法

  1. var request = new TransactionRequest
  2.  
  3. {
  4.  
  5. Amount = amount,
  6.  
  7. PaymentMethodToken = token,
  8.  
  9. Options = new TransactionOptionsRequest
  10.  
  11. {
  12.  
  13. SubmitForSettlement = true
  14.  
  15. }
  16.  
  17. };
  18.  
  19. Result<Transaction> result = getGateway().Transaction.Sale(request); //支付
  20.  
  21. var payResult = PayStatus.WaitingForPayment;
  22.  
  23. var message = "";
  24.  
  25. if (result.Target != null)
  26.  
  27. {
  28.  
  29. message = result.Target.ProcessorResponseText;//错误 Message
  30.  
  31. }
  32.  
  33. else if (result.Message != null)
  34.  
  35. {
  36.  
  37. message = result.Message;
  38.  
  39. }
  40.  
  41. if (result.IsSuccess())
  42.  
  43. {
  44.  
  45. UpdatePaymentMenthod(token);
  46.  
  47. payResult = PayStatus.PaymentSuccess;
  48.  
  49. }
  50.  
  51. else
  52.  
  53. {
  54.  
  55. payResult = PayStatus.PaymentFailed;
  56.  
  57. }

如果支付成功,则修改当前方式为默认付款方式。

如果PayEnd异常则立即取消这笔信用卡消费,调用transaction的void方法。 稍后说明void方法与refund方法区别

Void方法调用时也需要Begin  中间void  结束 End 证明一笔交易。

Result<Transaction> result = getGateway().Transaction.Void(transactionId);

关于退款:

部分退款时调用refund方法,但是需要检测信用卡状态,如果信用卡状态为:SUBMITTED_FOR_SETTLEMENT或AUTHORIZED只可以使用void方法取消整笔订单,如果是SETTLED或SETTLING 则使用refund方法进行部分退款。

getGateway().Transaction.Refund(transactionId, amount); 如果不传钱 则全部退款

一、BrainTree后台操作说明

3.1:控制面板管理Dashboard:

介绍了两种集成方式,以及近期收入的统计。

3.2:交易信息管理Transactions:

按检索条件检索数据

Sale为消费,Submitted For Settlement 为刚提交的交易,Voided为已取消的交易。Credit为已退款的交易,Settled 为已完结的交易。

点击交易号ID 可以对交易进行操作:Submitted For Settlement的则可以Void 取消交易操作,Settled则可以refund部分退款操作。

3.3:信用卡验证管理Verifications:

添加信用卡的时候对信用卡的有效进行验证,花1美金,看支付状态。点击可以查看该验证的详细信息。

3.4:保险库管理Vault:

所有保存在Braintree中的客户信息,以及该客户的所有信用卡,所有的交易等。

3.5:订阅服务管理Subscription:

订阅服务

3.6:创建交易New Transaction:

创建一笔新的交易,可以指定某个客户或 输入卡进行付款。

3.7:交易统计  Transaction Summary:

对卡的类型进行消费退款等统计。

3.7: 支出汇总 Disbursement summary:

按月份对每种卡进行支出汇总

3.8: 争议 Disputes:

已完结汇总

3.9: 创建新的客户 New Customer:

创建新的客户

3.10: 即将到期的卡 Expiring Cards:

即将过期的信用卡。

3.11: 导出客户信息 Export Customers:

导出客户资料,以及信用卡信息等。

3.12: 计划 Plans:

定期每月使用某卡付款的功能,我们没开发这个功能。

3.13: 附加/折扣 add-ons / discounts:

附加费或打折设置,每次交易时的附加费,或者享受的折扣。

3.14: 邮件通知 Email Notifications:

定期邮件通知

四: 设置 Settings:

4.1: 处理选项 Processing:

这些设置可能无法立即生效,可能需要几分钟。

Duplicate Transaction Checking 重复交易检查

Accept Paypal 使用PayPal

Accept Venmo 使用Venmo

Accept Apple Pay 使用Apple Pay

Accept Android Pay 使用Android Pay

Venmo Touch 让你的账户支持其他商家中的信用卡

AVS 开启AVS验证

cvv 开启CVV验证

Risk ThreSholds 风险控制

Advanced Credit Fraud Tools  信用卡诈骗工具

Card Verification 信用卡验证 开启后会对信用卡进行有效性验证,支付0~1之间的美金,如果通过则会存储在保险库中,否则不会保存。

Card Verification – Retry All Failed $0  重试所有验证失败的

Display Additional Processor Response 当处理器拒绝时显示拒绝原因, 无论是否设置总是显示拒绝原因。

Dispute Notifications 争议通知 产生争议时会发送邮件到一个邮箱,一批通知每天一次

Transaction lssue Notifications 交易问题的通知邮箱

Custom Fields 自定义字段

Email Receipts  Email收据

Recurring Billing 周期性结算

4.2: 安全选项 Security Options:

限制ip访问

4.3: 用户权限 User and Roles:

可以添加邮箱 权限

BrainTree信用卡包的更多相关文章

  1. Paypal、Stripe、Braintree,跨境电商金流第三方支付该用哪家?

    在台湾做跨境电子商务生意,电商网站的金流肯定是一个最大的麻烦,Paypal或是Stripe和Braintree则是国际上大家最常用的金流整合第三方支付服务商.这些金流服务大幅简化网站付费过程,都让消费 ...

  2. iOS 资源大全

    这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...

  3. Webhooks PHP

    Webhooks/Parse When webhooks are triggered in the gateway, a notification is sent as a POST request ...

  4. IOS中文版资源库

    Swift 语言写成的项目会被标记为  ★ ,AppleWatch 的项目则会被标记为 ▲. [转自]https://github.com/jobbole/awesome-ios-cn#librari ...

  5. 采访ServiceStack的项目领导Demis Bellot——第2部分(转)

    ServiceStack是一个开源的.支持.NET与Mono平台的REST Web Services框架.InfoQ有幸与Demis Bellot深入地讨论了这个项目.在这篇两部分报道的第2部分中,我 ...

  6. 人们对Python在企业级开发中的10大误解

    From : 人们对Python在企业级开发中的10大误解 在PayPal的编程文化中存在着大量的语言多元化.除了长期流行的C++和Java,越来越多的团队选择JavaScript和Scala,Bra ...

  7. webapp构建工具库

    Meteor:JavaScript App Platform braintree:在线支付 jquery datetimepicker:日期控件 Hotjar Tracking Code:网站追踪 Z ...

  8. 墙裂推荐 iOS 资源大全

    这是个精心编排的列表,它包含了优秀的 iOS 框架.库.教程.XCode 插件.组件等等. 这个列表分为以下几个部分:框架( Frameworks ).组件( Components ).测试( Tes ...

  9. Magento 编译 php5.6.21 命令

    ./configure  '--prefix=/alidata/server/php' '--enable-opcache' '--with-config-file-path=/alidata/ser ...

随机推荐

  1. JMS的作用

    JMS就是生产者与消费者模式.消费者负责消费生产者产生的消息.通过JMS可以做后台的异步操作,应用到具体工作中的话,有用它来发内部消息的.发邮件的.发短信的,做大操作时在后台做异步操作的. Java ...

  2. Automatic Code Generation-->Implement Interface

    https://msdn.microsoft.com/en-us/library/hk90416s(v=vs.110).aspx VS中自带的只能提示,一个类继承自某一个接口. 由VS为类生成接口所要 ...

  3. FindBugs

    FindBugs是一个能静态分析源代码中可能会出现Bug的Eclipse插件工具. 可以从http://sourceforge.net/project/showfiles.php?group_id=9 ...

  4. 【转】关于Certificate、Provisioning Profile、App ID的介绍及其之间的关系

    原文网址:http://www.cnblogs.com/cywin888/p/3263027.html 刚接触iOS开发的人难免会对苹果的各种证书.配置文件等不甚了解,可能你按照网上的教程一步一步的成 ...

  5. Android 应用页面延缓载入

    1.新建一个线程,使用handle的延缓运行线程 new Handler().postDelayed(new Runnable() { // 为了减少代码使用匿名Handler创建一个延时的调用 pu ...

  6. POJ ---2531

    Network Saboteur Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8751   Accepted: 4070 ...

  7. devi into python 笔记(六)正则表达式 原始字符串

    字符串函数replace: #string.replace: #字符串的replace方法:替换子串,不改变原来的字符串 s = "broad road" #打印出来会发现不单单是 ...

  8. Bzoj 1976: [BeiJing2010组队]能量魔方 Cube 最小割,最大流

    1976: [BeiJing2010组队]能量魔方 Cube Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 879  Solved: 304[Submi ...

  9. Bzoj 3171: [Tjoi2013]循环格 费用流

    3171: [Tjoi2013]循环格 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 741  Solved: 463[Submit][Status][ ...

  10. codeforces 358D

    题目链接:http://codeforces.com/contest/358/problem/D #include<cstdio> #include<iostream> #in ...