2017-03-24 6 views
1

내 codeigniter website.i에서 Braintree paypal을 통합하고 싶습니다. 내 컨트롤러 생성자에서 서버의 braintree 파일 및 자격 증명을로드하고 다른 코드를 메소드에 넣지 만 항상 오류를 제공합니다. 알 수 없음 또는 만료 된 payment_method_nonce .Below 여기 방법braintree paypal이 codeigniter에서 작동하지 않습니다

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'); 
} 

내가 구글을 시도했지만 사전에없는 luck.please의 도움 덕분입니다.

답변

1

전체 공개 : 나는 브레인 트리에서 작동합니다. 추가 질문이 있으시면 support으로 언제든지 문의하십시오. documentation on Transaction:sale()에서

:

는, 트랜잭션 (transaction)를 만들려면 당신은 금액과 paymentMethodNonce 중 하나 또는 paymentMethodToken를 포함해야합니다.

paymentMethodNonce 매개 변수에 전달할 매개 변수가 payment method nonce이 아닙니다. 대신 client token을 전달하면 오류가 발생합니다. 이 항목들은 유사하게 명명되었지만 매우 다른 목적을 가지고 있습니다.

  • 클라이언트 토큰 : 게이트웨이 계정에 대한 구성 정보가 포함되어 있습니다. client-side SDKs은이를 사용하여 자신의 구성을 올바르게 설정하고 서버와 원활하게 작동하며 트랜잭션 판매 호출에 전달해서는 안됩니다.
  • 지불 방법 넌스 : 신용 카드 번호와 유효 기간 등의 토큰 화 된 결제 수단 정보의 집합에 대한 참조. 일반적으로 사용자가 신용 카드 정보를 입력하면 클라이언트 측 SDK에서 tokenize 호출에 의해 생성됩니다.
  • 지불 방법 토큰 : 당신이 당신의 브레인 계정에 저장 한 지불 방법에 대한 참조.

코드에서 거래를 제대로 만들려면 결제 수단 토큰을 사용하여 저장 한 결제 수단을 참조하거나 새로 결제 한 토큰을 참조해야합니다. 고객이 귀하의 웹 사이트에 제출 한 지불 방법 정보 (지불 방법 nonce를 사용). 당신이 당신의 데이터베이스에 고객의 지불 방법 토큰을 저장했다 예를 들어, 당신이 뭔가를 실행할 수 있습니다

if (!empty($user_details->braintree_customer_id)) { 
     $CustomerId = (string) $user_details->braintree_customer_id; 
     $CustomerSavedPaymentMethod = (string) $user_details->payment_method_token; 
    } else { 
     ... 
    } 

    $result1 = Braintree_Transaction::sale([ 
     'amount' => $amount, 
     'paymentMethodToken' => $CustomerSavedPaymentMethod, 
     'options' => [ 
      'submitForSettlement' => True 
     ] 
    ]); 

당신은 지불 방법 넌스를 생성하고 다시 그것을 전달하는 몇 가지 추가 자원이 필요한 경우 서버의 경우 our full PHP integration example을 참조 할 수 있습니다.