我想将 Braintree paypal 集成到我的 codeigniter 网站中。我在我的控制器构造函数中从服务器加载 Braintree 文件和凭据,并将其他代码放入一个方法中,但它总是给出错误 Unknown or expired payment_method_nonce。下面是方法
public function braintree(){
if($this->session->userdata('user_id') != '' && $this->session->userdata('user_id') != 'user'){
$user_id = $this->input->post('user_id');
$amount = $this->input->post('amount');
$inscription_id = $this->input->post('inscription_id');
$user_details = $this->db->get_where('spm_users',array('id'=>$user_id))->row_array();
if(!empty($user_details->braintree_customer_id)){
$CustomerId = (string)$user_details->braintree_customer_id;
}else{
$result = Braintree_Customer::create([
'firstName' => $user_details->name,
'lastName' => $user_details->surname,
'email' => $user_details->email,
'phone' => $user_details->telephone,
]);
$CustomerId = (string)$result->customer->id;
$this->db->where("id",$user_id);
$this->db->update("spm_users", array('braintree_customer_id'=>$CustomerId));
}
$clientToken = Braintree_ClientToken::generate([
"customerId" => $CustomerId
]);
$card_id ='';
$clientToken_new = Braintree_ClientToken::generate();
$result1 = Braintree_Transaction::sale([
'amount' => $amount,
'paymentMethodNonce' => $clientToken_new,
'options' => [
'submitForSettlement' => True
]
]);
if($result1->success == true){
$updateArr = array(
'amount'=>$result1->transaction->amount,
'balance_transaction'=>$result1->transaction->id,
'inscription_status'=>2,
'status'=>1,
'data'=>json_encode($result1),
'payment_method' => 'Braintree',
'payment_date'=>date('Y-m-d H:i:s')
);
$this->db->where("id",$inscription_id);
$this->_db->update("spm_inscription", $updateArr);
$this->session->set_flashdata('msg','Inscription Payment Success');
redirect('frontend/paypalpayment/'.$inscription_id);
}else{
$this->session->set_flashdata('msg','Payment failed');
redirect('frontend/paypalpayment/'.$inscription_id);
}
}else{
redirect('frontend');
}
}
这是我的构造函数
public function __construct() {
parent::__construct();
require_once '/home/public_html/mysite/braintree/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('zxxxxxxxxxxxxxxd');
Braintree_Configuration::publicKey('7xxxxxxxxxxxxxxx7');
Braintree_Configuration::privateKey('1xxxxxxxxxxxxxxxxxxxxxx8');
}
我试过谷歌但没有运气。请提前帮助和感谢。