PHP关于Braintree支付

现国内关于Braintree支付的资料少之又少,所以我来分享下关于Braintree支付的相关代码,希望能对需要的人有所帮助。

一 :获取key以及MerchantID。

1.1:首先在https://sandbox.braintreegateway.com/login登录。

1.2: 进入后:Account->My User->View Authorizations->Private Key(如果没有,点击Generate New Tokenization Key创建)->进入后界面如图所示:![注意:要先选择PHP](https://img-blog.csdn.net/20170512185915404?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvczIzbG9zZXI=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)

获取key以及MerchantID就完成了。

 二 : 下载SDK。
  2.1 : SDK下载路径:https://GitHub.com/braintree/braintree_php

 三:项目部署。

  3.1 :创建Braintree.php 引入SDK。

        public function _initialize(){
        vendor('Braintree.lib.Braintree');
        \Braintree_Configuration :: environment('');
        \Braintree_Configuration :: merchantId('');
        \Braintree_Configuration :: publicKey('');
        \Braintree_Configuration :: privateKey('');
        }

3.2:创建index.html文件。
3.2.1:引入js文件

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>  
  <script src="https://js.braintreegateway.com/js/braintree-2.31.0.min.js"></script>

3.2.2: style样式。


<style>
        label.heading {
            font-weight: 600;
        }
        .payment-form{
            width: 300px;
            margin-left: auto;
            margin-right: auto;
            padding: 10px;
            border: 1px #333 solid;
        }
    </style>

3.2.3: body内容。

<body style="background: #fff;">
<form id="checkout-form" action="(回调路径)" method="post" class="payment-form">

    <label for="firstName" class="heading">First Name</label>
    <br>
    <input type="text" name="firstName" id="firstName"></br><br>

    <label for="LastName" class="heading">Last Name</label>
    <br>
    <input type="text" name="LastName" id="LastName"></br><br>

    <label for="amount" class="heading">Amount(USD)</label>
    <br>
    <input type="text" name="amount" id="amount"></br><br>

    <div id="dropin-container"></div>
    <br>
    <button type="submit">pay with BrainTree</button>

</form>
</body>

3.3: 获取token。
3.3.1:在Braintree.php 文件内加上:

public function tokens(){
        $clientToken = \Braintree_ClientToken::generate();
        $this->ajaxReturn($clientToken);
    }

3.3.2:在index.html页面添加ajax。(注意别忘了先引入jQuery文件)

<script>
        $.ajax({
            url:'braintreee/tokens',
            type:'get',
            dataType:'json',
            success: function(data){
                braintree.setup(data,'dropin',{container:'dropin-container'});
            }

        })
    </script>

如上:braintree支付就此完成,希望对你有所帮助。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值