7

Hello everyone I'm back again, In my last post I was attempting to use the SOAP api (Integrating Dwolla with PHP with their API) but I found out the SOAP API is deprecated and apparently Dwolla has more efficient way such as the REST/oAuth2.0 which is why I'm here today asking how to use the rest API as its been almost 2 weeks and I'd really like to learn this.

First off I'll say that I've successfully been able to get an access_token I have no problem doing that. The issue is that when I try to use an a Send Endpoint(https://www.dwolla.com/developers/endpoints/accountapi/send) basically trying to send money to and account. My exact issue is that I can never get a successful response; only false or error message responses.

So on the index page I have "Add funds to your account" link. Users will click that link and it will take them to the Dwolla Page that will accept them to Sign in to their Dwolla account an then accept the permissions the website is asking for. After the user presses "Accept" it will redirect to the selected URL that I chose and send back an access_token to use for authorization purposes. Here is my code (This is the page that Dwolla redirects too and sends the access_token too)

<?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 receive messages like this for example

array(1) { ["access_token"]=> string(50) "redacted" } Warning: file_get_contents(https://www.dwolla.com/oauth/rest/accountapi/send): failed to open stream: HTTP request failed! HTTP/1.1 503 Service Unavailable in /home/swiftbitcoins/purchase_order.php on line 47 NULL

Community
  • 1
  • 1
Xenland
  • 510
  • 1
  • 6
  • 19
  • Thanks I forgot about that :D – Xenland Oct 15 '11 at 02:15
  • 1
    Its all good I've renewed my credentials and the old ones are no longer valid – Xenland Oct 15 '11 at 08:46
  • 1
    based on your log, I think you should ask dwolla. It said 503 Service Unavailable. This give clue that there's problem with the server. – ariefbayu Oct 15 '11 at 18:17
  • Dwollas API documentation says that any errors will result in a disconnection. I've been able to successfully do a GET request with this same method its only when I'm required to send data to the server it does not work which is a POST request. – Xenland Oct 15 '11 at 20:29
  • Well this is "one" of the posts I've been having with Dwolla http://getsatisfaction.com/dwolla/topics/post_request_doesnt_work_bet_get_requests_do_php5_code – Xenland Oct 18 '11 at 08:27
  • I would not encourage the use of file_get_contents on an API like this. I personally would be using Curl which will give you a bit more control – Catharsis Jun 17 '15 at 12:27

1 Answers1

0

what you are trying to make is a get request whereas Dwolla documentation refers to this as post request.

better you can do is user their php Library with built in methods to make calls. this is a standard library for making restful calls and much better than writing the way you have written in the code snippet above.

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

akmsharma
  • 151
  • 1
  • 1
  • 7