2011-10-15 1 views
8

안녕하세요 여러분, 다시 돌아 왔습니다. SOAP API (Integrating Dwolla with PHP with their API)를 사용하려고 시도한 마지막 게시물에서 SOAP API가 사용되지 않으며 분명히 Dwolla가 REST/oAuth2.0과 같은보다 효율적인 방법을 가지고 있음을 알았습니다. 내가 오늘 여기 나머지 API를 사용하는 방법을 묻는 이유는 거의 2 주 정도 였으므로 이것을 배우고 싶습니다.Dwolla의 API로 돈을 보내고 PHP로 PHP를 사용 하시겠습니까?

먼저 내가 성공적으로 액세스 할 수있게되었다고 말할 것입니다. 나는이 문제에 아무런 문제가 없습니다. 문제는 내가 Send Endpoint (https://www.dwolla.com/developers/endpoints/accountapi/send)를 사용하여 기본적으로 돈을 보내고 계정을 사용하려고 할 때입니다. 내 정확한 문제는 결코 성공적인 응답을 얻을 수 없다는 것입니다. 허위 또는 오류 메시지 응답 만

그래서 색인 페이지에 "귀하의 계정에 자금 추가"링크가 있습니다. 사용자가 해당 링크를 클릭하면 Dwolla 페이지로 이동하여 Dwolla 페이지에 접속하여 Dwolla 계정에 로그인 한 다음 웹 사이트에서 요구하는 권한을 수락합니다. 사용자가 "Accept (동의)"를 누르면 승인 된 용도로 사용하기 위해 access_token을 선택한 선택한 URL로 리디렉션됩니다. 여기 내 코드는

<?php 
//Define variables 
    $key   = 'redacted'; 
    $secret   = 'redacted'; 
    $dwolla_client_id = urlencode($key); 
    $dwolla_secret_key = urlencode($secret); 
$code = urlencode($_GET["code"]); 
//get token 
    $retireve_token = file_get_contents("https://www.dwolla.com/oauth/v2/token?client_id=".$dwolla_client_id."&client_secret=".$dwolla_secret_key."&grant_type=authorization_code&redirect_uri=http://localhost/purchase_order.php&code=".$code); 


    $decoded_json = json_decode($retireve_token, true); 


     var_dump($decoded_json); 
     if($decoded_json["access_token"]){ 
        $arr = '{ 
          "oauth_token": "'.$decoded_json["access_token"].'", 
          "fundsSource": "balance", 
          "pin": "1111", 
          "notes": "Payment for services rendered", 
          "amount": 1.01, 
          "destinationId": "812-111-1111", 
          "assumeCosts": false, 
          "facilitatorAmount": 0, 
          "destinationType": "dwolla" 
        }'; 
        $opts = array('http'=>array('method'=>"POST",'content'=> $arr, 'header' => 'Content-Type: application/json')); 

        $ctx = stream_context_create($opts); 
      $send_request = file_get_contents('https://www.dwolla.com/oauth/rest/accountapi/send', false, $ctx); 

      var_dump(json_decode($send_request)); 
     } 

?> 

I는 예를 들어 다음과 같이 메시지를 수신 (이에 Dwolla 너무 리디렉션 너무 access_token과를 송신 페이지 임)

어레이 (1) {[ "access_token은"] = > 문자열 (50) "수정 됨"} 경고 : file_get_contents (https://www.dwolla.com/oauth/rest/accountapi/send) : 스트림을 열지 못했습니다 : HTTP 요청이 실패했습니다! HTTP/1.1 503 서비스 라인 47 NULL

+0

감사합니다 : D – Xenland

+1

그것의 모든 좋은 내 자격 증명을 갱신하지했고 이전 내용은 로그를 기반으로 더 이상 – Xenland

+1

유효합니다, 당신이에 Dwolla를 요청한다고 생각합니다. 503 서비스를 사용할 수 없다고했습니다. 이것은 서버에 문제가 있다는 단서를 제공합니다. – ariefbayu

답변

0

에 Dwolla 문서가 게시 요청으로이를 의미하는 반면 당신이 만들려고하는 것은 GET 요청 인에 /home/swiftbitcoins/purchase_order.php에서 사용할 수 없습니다.

당신이 할 수있는 더 나은 방법은 자신의 PHP 라이브러리를 호출하는 내장 된 방법입니다. 이 코드는 위의 코드에서 작성한 방식을 쓰는 것보다 더 편안한 호출을하기위한 표준 라이브러리입니다. 나는 그것에 대해 잊고

https://github.com/Dwolla/dwolla-php

관련 문제