2013-09-06 3 views
0

저는 Wordpress 테마로 PayPal 지불을 구현하려고합니다. 나는 토큰을 받고, 지불을 만들고, 사용자를 승인 링크로 리디렉션하고, 사용자로부터 aproval을 얻지 만 어떤 이유로 지불을 실행할 수 없다 "라고 말합니다.페이팔 휴식 API 실행 오류

여기에 코드가 있습니다.) URL 및 토큰을 실행하고 그들은 올바른

if (isset($_GET['token']) && isset($_GET['PayerID'])){ 
    $received_token  = sanitize_text_field ($_GET['token']); 
    $received_payerId = sanitize_text_field ($_GET['PayerID']); 
    $execute_urls  = get_option('paypal_processing'); 
    $payment_execute_url= $execute_urls[$current_user->ID]; 
    $execute_urls[$current_user->ID] = ''; 
    update_option('paypal_processing',$execute_urls); 

    $payment_execute = array(
    'payer_id' => $received_payerId 
     ); 
    $json = json_encode($payment_execute); 

    $json_resp = make_post_call($payment_execute_url, $json,$received_token); 
    print_r($json_resp); 
    echo "Payment Execute processed " . $json_resp['id'] ." with state '". $json_resp['state']."'"; 
    } 





function make_post_call($url, $postdata,$token) { 
    $curl = curl_init($url); 
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($curl, CURLOPT_HEADER, false); 
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
      'Authorization: Bearer '.$token, 
      'Accept: application/json', 
      'Content-Type: application/json' 
      )); 

    curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata); 
    #curl_setopt($curl, CURLOPT_VERBOSE, TRUE); 
    $response = curl_exec($curl); 
    if (empty($response)) { 
     // some kind of an error happened 
      print 'curl error'; 
     curl_close($curl); // close cURL handler 
    } else { 
    $info = curl_getinfo($curl); 
     // echo "Time took: " . $info['total_time']*1000 . "ms\n"; 
    curl_close($curl); // close cURL handler 
    if($info['http_code'] != 200 && $info['http_code'] != 201) { 
     //echo "Received error: " . $info['http_code']. "\n"; 
     //echo "Raw response:".$response."\n"; 
     exit('paypal error'); 
    } 
    } 

    // Convert the result from JSON format to a PHP array 
    $jsonResponse = json_decode($response, TRUE); 
    return $jsonResponse; 
    } 
+0

이 응답을 확인하십시오. http : // st ackoverflow.com/questions/15651716/paypal-rest-api-for-payments-returns-null-in-the-sandbox u가 물어 본 질문과 비슷합니다. – lib4

+0

말풍선 스위치가주는 정보는 무엇입니까? 모든 응답 헤더? 실행 URL을 게시 할 수 있습니까? – aydiv

+0

@lib 4 - 헤더가 누락 된 상황 - 내가 설정 한 상황. Thx 응답에 대한 – Crerem

답변

2

당신이 승인 URL, 손실 된 토큰의 이전에 저장된 정보와 실행 URL에서 돌아갑니다. 비어가된다. 당신은 그것을 저장하거나 필요 쿠키 또는 데이터베이스 테이블을 검색하고 실행하기 위해 사이트로 돌아 왔을 때 검색하십시오.