整合Braintree php时出错

时间:2015-11-23 11:54:15

标签: php codeigniter braintree

我正在使用braintree处理我的codeigniter项目中的信用卡付款, Braintree_Transaction :: sale 会抛出无效参数异常无效密钥帐单地址参数的消息。但我不认为有任何验证错误。我想要做的事情可以简化如下:

$card_info = [
      'cardholderName' =>mysql_real_escape_string($_POST['full_name']),
      'number' =>mysql_real_escape_string($_POST['number']),
      'expirationMonth' =>mysql_real_escape_string($_POST['expiry_month']),
      'expirationYear' =>mysql_real_escape_string($_POST['expiry_year']),
      'cvv' =>mysql_real_escape_string($_POST['card_cvv']),
      'billingAddress' =[
              'firstName' =>mysql_real_escape_string($_POST['first_name']),
              'lastName'=>mysql_real_escape_string($_POST['last_name']),
              'streetAddress'=>mysql_real_escape_string($_POST['user_address']),
              'city'=>mysql_real_escape_string($_POST['user_city']),
              'state'=>mysql_real_escape_string($_POST['user_state']),
              'country' =>mysql_real_escape_string($_POST['user_country']),

                ]
       ]
       $result = Braintree_Transaction::sale(['amount'=>'4.99',
                                              'creditCard'=>$card_info,
                                              'options'=>['submitForSettlement' => true]
                                              ])

但是,当我运行以下代码时,我得到以下错误:

 <br />
 <b>Fatal error</b>:  Uncaught exception 'InvalidArgumentException' with       message 'invalid keys: creditCard[billingAddress][city],   creditCard[billingAddress][country], creditCard[billingAddress][firstName], creditCard[billingAddress][lastName], creditCard[billingAddress][state], creditCard[billingAddress][streetAddress]' in   C:\xampp\htdocs\naya_admin\application\third_party\braintree\lib\Braintree\Util.php:343
 Stack trace:
     #0 C:\xampp\htdocs\naya_admin\application\third_party\braintree\lib\Braintree\TransactionGateway.php(48): Braintree\Util::verifyKeys(Array, Array)
      #1    C:\xampp\htdocs\naya_admin\application\third_party\braintree\lib\Braintree\TransactionGateway.php(251): Braintree\TransactionGateway-&gt;create(Array)
      #2 C:\xampp\htdocs\naya_admin\application\third_party\braintree\lib\Braintree\Transaction.php(480): Braintree\TransactionGateway-&gt;sale(Array)
      #3  C:\xampp\htdocs\naya_admin\application\modules\brain_tree\controllers\brain_tree .php(67): Braintree\Transaction::sale(Array)
      #4 [internal function]: Brain_tree-&gt;transaction()
      #5 in 
 <b>C:\xampp\htdocs\naya_admin\application\third_party\braintree\lib\Braintree\Ut il.php</b> on line 
     <b>343</b>
      <br />

1 个答案:

答案 0 :(得分:3)

完全披露:我在Braintree工作。如果您还有其他问题,请随时contact support

Ilan Hasanov是正确的,您需要将交易参数与交易呼叫中的信用卡详细信息分开传递。此外,您应该替换"city" with "locality""state" with "region""country" with whichever country field you are storing in your database

$billing =[
    'firstName' =>mysql_real_escape_string($_POST['first_name']),
    'lastName'=>mysql_real_escape_string($_POST['last_name']),
    'streetAddress'=>mysql_real_escape_string($_POST['user_address']),
    'locality'=>mysql_real_escape_string($_POST['user_city']),
    'region'=>mysql_real_escape_string($_POST['user_state']),
    'countryName' =>mysql_real_escape_string($_POST['user_country']),
];

此外,为了降低PCI合规性负担,我建议passing a nonce to your server代替信用卡详细信息。