如何在Codeigniter中实现Braintree支付网关?

时间:2016-01-28 16:47:59

标签: codeigniter payment-gateway braintree

我使用Codeigniter开发了一个网站,我想同样使用Braintree。因为我已经关注this但它给出了错误...我甚至试图寻找更好的教程/文档,这将有所帮助我在实施它。任何人都可以告诉我,甚至建议我在Codeigniter中实现Braintree的更好教程。提前谢谢..

1 个答案:

答案 0 :(得分:1)

将此脚本放在header / footer部分后面,这样可以使用:

<?php
require_once 'braintree-php-2.30.0/lib/Braintree.php';

Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('-----------');
Braintree_Configuration::publicKey('-----------');
Braintree_Configuration::privateKey('-----------');
if(isset($_POST['submit'])){
    /* process transaction */
    $result = Braintree_Transaction::sale(array(
     'amount' => '100.00',
     'creditCard' => array(
     'number' => '5454545454545454',
     'expirationDate' => '08/19'
    )
  ));

if ($result->success) {
  print_r("success!: " . $result->transaction->id);
  } else if ($result->transaction) {
    print_r("Error processing transaction:");
    print_r("\n  code: " . $result->transaction->processorResponseCode);
    print_r("\n  text: " . $result->transaction->processorResponseText);
    } else {
      print_r("Validation errors: \n");
      print_r($result->errors->deepAll());
    }
}

$clientToken = Braintree_ClientToken::generate();

?>

<html>
  <head>
  </head>
  <body>
    <div id="checkout" method="post" action="/checkout">
      <div id="dropin"></div>
      <input data-braintree-name="number" value="4111111111111111">
      <input data-braintree-name="expiration_date" value="10/20">
      <input type="submit" id="submit" value="Pay">
      <div id="paypal-button"></div>
    </div>  

  <!-- Scripts -->
  <script src="https://code.jquery.com/jquery-2.1.1.js"></script>
  <script src="https://js.braintreegateway.com/v2/braintree.js"></script>
  <script>
   braintree.setup(clientToken, "dropin", {
        container: "payment-form",
        form: jQuery("#checkout") , 
        paypal: {
                 container: "payment-form",
                 singleUse: false,
               },
        dataCollector: {
                        paypal: true  
                       },
        paymentMethodNonceReceived: function (event, nonce) {
                 // do something
           }
    });
  </script>

  </body>
</html>