Sending money using the Dwolla API and using PHP to do this?

Hi everyone, I'm back again. In my last post, I tried to use the SOAP api ( Dwolla Integration with PHP with their API ), but I found out that the SOAP API is deprecated, and Dwolla seems to have a more efficient way like REST / oAuth2.0, so I am here today I ask how to use the break API since it was almost 2 weeks old, and I would really like to know that.

First of all, I will say that I managed to get access_token. I have no problem with this. The problem is that when I try to use the sending endpoint ( https://www.dwolla.com/developers/endpoints/accountapi/send ), it basically tries to send money and an invoice. My exact problem is that I can never get a successful answer; only false messages or error messages.

So, on the index page, I have a link "Add money to your account." Users will click on this link and they will go to the Dwolla page to accept them to log in to their Dwolla account and then accept the permissions requested by the website. After the user clicks “Accept”, he will redirect the selected URL that I selected and send back the access_token for use for authorization purposes. Here is my code (This is the page that Dwolla redirects and sends 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 get messages like this

array (1) {["access_token"] => string (50) "redacted"} Warning: file_get_contents ( https://www.dwolla.com/oauth/rest/accountapi/send ): could not open the stream: HTTP- The request failed! HTTP / 1.1 Service 503 Not available in / home / swiftbitcoins / purchase _order.php on line 47 NULL

+8
rest api php dwolla
source share
1 answer

what you are trying to do is request for receipt, while the Dwolla documentation treats this as a message.

Better you can do it in your php library with built-in methods for making calls. it is a standard library for making quiet calls and is much better than recording how you wrote in the code snippet above.

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

0
source share

All Articles