Bitcoin Forum

Economy => Services => Topic started by: Xenland on September 25, 2011, 04:20:09 AM



Title: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 25, 2011, 04:20:09 AM
I will give 2 BTC to anyone that can give me some pseudo code or near complete and working code with explination or even simple comments of what everything is doing( i can figure things out pretty quickly if its done in front of my eyes so nothing too specific)

Just go to this link and at the end of your response post your BTC address
http://stackoverflow.com/questions/7543582/integrating-dwolla-with-php-with-their-api


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 25, 2011, 04:57:55 AM
You use the SOAP protocol to communicate with their API.

Here is a link to a discussion on the API:
http://www.dwolla.org/d/showthread.php?3-SOAP-API

Here is a link to the php.net database on SOAP, and how to implement it:
http://www.php.net/manual/en/class.soapclient.php

This is the address that you use to communicate with the API:
https://www.dwolla.com/api/API.svc?wsdl

You authenticate with an API key, generated in your dwolla API settings, I believe. Then you can use the other functions of the API.

Sorry can't be more specific right now, it's pretty late here right now.
But it's pretty easy to do, just read through the documentation on both of those links, and you should figure it out.

I can post more detailed information tomorrow for you.


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 25, 2011, 05:40:49 AM
excellent documentation, I didn't learn about SOAP until like just now although I've heard of it, i think I'm missing something here..... take a look at my format

<?php
Code:
$client = new SoapClient("https://www.dwolla.com/api/API.svc?wsdl");
//Attempt to buy something with dwolla form
$client->RequestPaymentKey("0Aw5gdfgfdgdfgdfgJjfsjdfsdfsdfsdfsfsfsfsdfgfgdj2NA+r0QUFnTeofqvRPl",
"oDzdfgdfgdrgdfvsdfwefvtdbyndgsjfgdgfdghjgklgVwga7qbWoL",
"1.50",
"Testing testing testing",
"812-504-6527");
print_r($client);

var_dump($client->__getFunctions());
?>


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 25, 2011, 05:50:39 AM
Bounty is still up for grabs if someone wants to assist in writing some psuedo-code


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 25, 2011, 05:58:26 AM
excellent documentation, I didn't learn about SOAP until like just now although I've heard of it, i think I'm missing something here..... take a look at my format

<?php
Code:
$client = new SoapClient("https://www.dwolla.com/api/API.svc?wsdl");
//Attempt to buy something with dwolla form
$client->RequestPaymentKey("0Aw5gdfgfdgdfgdfgJjfsjdfsdfsdfsdfsfsfsfsdfgfgdj2NA+r0QUFnTeofqvRPl",
"oDzdfgdfgdrgdfvsdfwefvtdbyndgsjfgdgfdghjgklgVwga7qbWoL",
"1.50",
"Testing testing testing",
"812-504-6527");
print_r($client);

var_dump($client->__getFunctions());
?>

oh yeah error is like this
Quote from: error
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'RequestPaymentKey'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 158. in /home/swiftbitcoins/purchase_order.php:16 Stack trace: #0 /home/swiftbitcoins/purchase_order.php(16): SoapClient->__call('RequestPaymentK...', Array) #1 /home/swiftbitcoins/purchase_order.php(16): SoapClient->RequestPaymentKey('s:50:"0AwevY8CP...', 'oDz1XJ1bjbaTk0i...', '1.50', 'Testing testing...', '812-504-6527') #2 {main} thrown in /home/swiftbitcoins/purchase_order.php on line 16


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 25, 2011, 06:25:42 AM
You can use their test API (https://www.dwolla.com/api/TestAPI.svc?wsdl) to mess around, rather than their official one.

The following code:

Quote
<?php

$client = new SoapClient("https://www.dwolla.com/api/TestAPI.svc?wsdl");
var_dump($client->__getFunctions());

?>

returns the following:

Quote
array(5) { [ 0 ]=> string(50) "SendMoneyResponse SendMoney(SendMoney $parameters)" [1]=> string(83) "SendMoneyAssumeCostsResponse SendMoneyAssumeCosts(SendMoneyAssumeCosts $parameters)" [2]=> string(74) "RequestPaymentKeyResponse RequestPaymentKey(RequestPaymentKey $parameters)" [3]=> string(71) "VerifyPaymentKeyResponse VerifyPaymentKey(VerifyPaymentKey $parameters)" [4]=> string(65) "ConfirmPaymentResponse ConfirmPayment(ConfirmPayment $parameters)" }


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 25, 2011, 06:31:07 AM
You can call the functions by using:

Quote
$client->__soapCall("SomeFunction", array($a, $b, $c));

I think your way will also work i,e, $client->SomeFunction(yada, yada);
It's just a slightly different way of doing it.

Set each variable first, before the call. So you can be sure your strings are strings and amounts are numbers.
I believe your call failed because where in your call you put "1.50" in quotes, the handler is expecting a decimal value, not a string.
Try removing the quotes and see if it works out for you.

The parameters, types and descriptions of the functions and their variables can be found here:
http://www.dwolla.org/d/showthread.php?3-SOAP-API



Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 25, 2011, 06:51:32 AM
Try something along these lines:

Quote
<?php

$apiKey='xyz';
$apiCode='xyz';
$description='test';

//ENTER NUMBER, NOT STRING
$amount=123;

$client = new SoapClient("https://www.dwolla.com/api/TestAPI.svc?wsdl");
$client->__soapCall("RequestPaymentKey", array($apiKey, $apiCode, $amount, $description));

//RequestPaymentKey returns a boolean: true if the request was successfully processed, False or exception otherwise

if($client)
{
     //function executed succesfully
}
else
{
    //it didn't
}

?>

for testing purposes, it says on the dwolla site:

Quote
You are able to test Dwolla’s API by using the following WSDL:
https://www.dwolla.com/api/TestAPI.svc?wsdl

Test API calls will not hit Dwolla’s database & no action save the responses defined are undertaken. For example, the normal generation of an email containing a secure payment key when RequestPaymentKey() is called does not take place. To simulate success or failure of each method, the amount parameter’s value is changed to one of the following values:

Amount    Result
$1.00      Causes the operation to be successful
$3.00      Amount too large (SOAP fault)
$4.00      User is invalid (SOAP fault)
Other      Amount invalid (SOAP fault)

So I think if you change the amount value to those test values, and it will simulate a success ($1), a too large failure ($3), a user invalid failure ($4) or an amount invalid failure (any other value).


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 25, 2011, 07:15:04 AM
Thanks a bunch i will report back with my results you should give me BTC address just for the effort already!


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 25, 2011, 09:48:27 AM
I think it's not picking up the parameters correctly as no matter if I try it my way or your way it just gives me this error about Deserlization or somthing of the sort....

Code:
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'RequestPaymentKey'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 158. in /home/swiftbitcoins/purchase_order.php:21 Stack trace: #0 /home/swiftbitcoins/purchase_order.php(21): SoapClient->__soapCall('RequestPaymentK...', Array) #1 {main} thrown in /home/swiftbitcoins/purchase_order.php on line 21 

Here is the code I use slightly modified you for got the "CustomerId" value

<?php
Code:

$apiKey='0AwevY8CPVHiT2wxoxIl';
$apiCode='oDz1XJ1bjbaTk0i5RMcoEq';
$description='Testing CIB Testing';

$amount=123;

$customerId = "812-504-6527";

$client = new SoapClient("https://www.dwolla.com/api/TestAPI.svc?wsdl");
$client->__soapCall("RequestPaymentKey", array($apiKey, $apiCode, $amount, $description, $customerId));

//RequestPaymentKey returns a boolean: true if the request was successfully processed, False or exception otherwise

if($client)
{
     //function executed succesfully
}
else
{
    //it didn't
}

?>


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: captainteemo on September 25, 2011, 05:05:59 PM
I don't deal with Dwolla, but.


"Fatal error: Uncaught SoapFault exception"

//RequestPaymentKey returns a boolean: true if the request was successfully processed, False or exception otherwise

?


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: nhodges on September 25, 2011, 07:37:46 PM
Is your amount supposed to be a string or int?


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 25, 2011, 11:52:56 PM
Is your amount supposed to be a string or int?

I don't think (int) can accept decimals?


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: nhodges on September 26, 2011, 12:16:36 AM
Is your amount supposed to be a string or int?

I don't think (int) can accept decimals?

$amount=123;

Why do you have int, then? :P


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 26, 2011, 01:07:12 AM
Is your amount supposed to be a string or int?

I don't think (int) can accept decimals?

$amount=123;

Why do you have int, then? :P

Becuase I previously tryed a varchar but doing the value in quotes.
I thought you ment like forceing php to do int like this

$amount = (int) 123;

If i do that I wont accept decimals (as far as i know)


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: nhodges on September 26, 2011, 01:37:28 AM
I think you're not forming your object you are passing to the SOAP interface correctly. Shouldn't you have something, like an associative array, that is defining what parameters you are passing to the API?

Code:
$params = array(
  'ApiKey' => $apiKey,
  'ApiCode' => $apiCode,
  'Amount' => $amount,
  'Description' => $description,
  'CustomerID' => $customerId
);

$client->__soapCall("RequestPaymentKey", $params);

Well-constructed API's don't usually parse bundled data sequentially, since there might be non-required fields that would totally skew that type of processing.


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 26, 2011, 07:43:48 AM
Is your amount supposed to be a string or int?

I don't think (int) can accept decimals?

$amount=123;

Why do you have int, then? :P

Becuase I previously tryed a varchar but doing the value in quotes.
I thought you ment like forceing php to do int like this

$amount = (int) 123;

If i do that I wont accept decimals (as far as i know)


If you have passed your amount to that script as a string, you can get the float value by using: floatval($amount);
You can have it round to 2 decimal places if you use floatval(round($amount,2));

@nhodges: it doesn't matter what you initialize the variable with. If you initialize it with an integer, the variable will be an integer. If you initialize it with a float, it will be a float variable. So it's not necessarily an integer he has defined. For testing purposes yes, but if he wrote $amount=1.23, it would be initialized as a float.


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: nhodges on September 26, 2011, 09:28:23 AM
Is your amount supposed to be a string or int?

I don't think (int) can accept decimals?

$amount=123;

Why do you have int, then? :P

Becuase I previously tryed a varchar but doing the value in quotes.
I thought you ment like forceing php to do int like this

$amount = (int) 123;

If i do that I wont accept decimals (as far as i know)


If you have passed your amount to that script as a string, you can get the float value by using: floatval($amount);
You can have it round to 2 decimal places if you use floatval(round($amount,2));

@nhodges: it doesn't matter what you initialize the variable with. If you initialize it with an integer, the variable will be an integer. If you initialize it with a float, it will be a float variable. So it's not necessarily an integer he has defined. For testing purposes yes, but if he wrote $amount=1.23, it would be initialized as a float.

Sure, I know about PHP's funky type casting (good or bad, however you want to look at it) I was just thinking it might be an issue on the API side. Do you think the issue Xenland is having is more related to the second suggestion I made, though?


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 26, 2011, 09:38:05 AM
Sure, I know about PHP's funky type casting (good or bad, however you want to look at it) I was just thinking it might be an issue on the API side. Do you think the issue Xenland is having is more related to the second suggestion I made, though?

It's quite possible. An associative array might do the trick alright.


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 27, 2011, 12:13:17 AM
I attempted to use the associative array, and made sure all the variables match exactly from any spelling differences. Still getting this error:

Quote
SoapFault exception: [a:DeserializationFailed] The formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'RequestPaymentKey'. End element 'Body' from namespace 'http://schemas.xmlsoap.org/soap/envelope/' expected. Found element 'param1' from namespace ''. Line 2, position 158. in /home/swiftbitcoins/purchase_order.php:31 Stack trace: #0 /home/swiftbitcoins/purchase_order.php(31): SoapClient->__soapCall('RequestPaymentK...', Array) #1 {main}ERROR

using this code
Code:
$client = new SoapClient("https://www.dwolla.com/api/TestAPI.svc?wsdl");
$params = array(
  'ApiKey' => $apiKey,
  'ApiCode' => $apiCode,
  'Amount' => $amount,
  'Description' => $description,
  'CustomerID' => $customerId
);


try{
$client->__soapCall("RequestPaymentKey", $params);
}catch(Exception $e){
echo $e;
echo "ERROR";
}

Just so we are clear ApiCode is really the "Secret" key right?


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 27, 2011, 12:41:37 AM
If i var dump the $client when I first connect i get this

object(SoapClient)#2 (2) { ["_soap_version"]=> int(1) ["sdl"]=> resource(6) of type (Unknown) }


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 27, 2011, 02:09:05 AM
I tried the following code aswell got a diff error

Code:

//$client = new SoapClient("");
$client = new SoapClient(NULL,
        array(
        "location" => "https://www.dwolla.com/api/API.svc?wsdl",
        "uri"      => "urn:xmethods-delayed-quotes",
        "style"    => SOAP_RPC,
        "use"      => SOAP_ENCODED
           ));
var_dump($client);
$params = array( new SoapParam( 'ApiKey',$apiKey),
new SoapParam('ApiCode', $apiCode),
new SoapParam('Amount' , $amount),
new SoapParam('Description', $description),
new SoapParam('DestinationID',$customerId)
);


try{
$client->__soapCall(serialize("RequestPaymentKey"), $params);
}catch(Exception $e){
echo $e;
echo "ERROR";
}

got the example from here: http://devzone.zend.com/article/689#Heading4


my error is this:
Quote
object(SoapClient)#2 (5) { ["uri"]=> string(27) "urn:xmethods-delayed-quotes" ["style"]=> int(1) ["use"]=> int(1) ["location"]=> string(39) "https://www.dwolla.com/api/API.svc?wsdl" ["_soap_version"]=> int(1) } SoapFault exception: [HTTP] Bad Request in /home/swiftbitcoins/purchase_order.php:38 Stack trace: #0 [internal function]: SoapClient->__doRequest('__soapCall('s:17:"RequestPa...', Array) #2 {main}ERROR

Is there somthing I'm not understanding about soap?

I will be willing to throw in 1 BTC to the person who can get a working code going....


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: nhodges on September 27, 2011, 07:49:19 AM
Updated my StackOverflow answer with a working snippet for you. You might want to refresh your API credentials, too, since you publicized them here.

http://stackoverflow.com/questions/7543582/integrating-dwolla-with-php-with-their-api/7553502#7553502


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 27, 2011, 08:05:37 AM
I tried the following code aswell got a diff error

Code:

//$client = new SoapClient("");
$client = new SoapClient(NULL,
        array(
        "location" => "https://www.dwolla.com/api/API.svc?wsdl",
        "uri"      => "urn:xmethods-delayed-quotes",
        "style"    => SOAP_RPC,
        "use"      => SOAP_ENCODED
           ));
var_dump($client);
$params = array( new SoapParam( 'ApiKey',$apiKey),
new SoapParam('ApiCode', $apiCode),
new SoapParam('Amount' , $amount),
new SoapParam('Description', $description),
new SoapParam('DestinationID',$customerId)
);


try{
$client->__soapCall(serialize("RequestPaymentKey"), $params);
}catch(Exception $e){
echo $e;
echo "ERROR";
}

got the example from here: http://devzone.zend.com/article/689#Heading4


my error is this:
Quote
object(SoapClient)#2 (5) { ["uri"]=> string(27) "urn:xmethods-delayed-quotes" ["style"]=> int(1) ["use"]=> int(1) ["location"]=> string(39) "https://www.dwolla.com/api/API.svc?wsdl" ["_soap_version"]=> int(1) } SoapFault exception: [HTTP] Bad Request in /home/swiftbitcoins/purchase_order.php:38 Stack trace: #0 [internal function]: SoapClient->__doRequest('__soapCall('s:17:"RequestPa...', Array) #2 {main}ERROR

Is there somthing I'm not understanding about soap?

I will be willing to throw in 1 BTC to the person who can get a working code going....

To be honest, that code you derived from the example looks really messy and unlikely to work. I think there is something none of us is understanding about soap! LOL. It's probably something to do with formatting the header correctly, which I have no idea how to do. I'm not a coder by trade, just have a lot of experience with PHP.

nhodges code on stackoverflow might work, you could give that a shot.

But if you are still having trouble, take a look at using their REST API instead of their SOAP API. It uses simpler HTTP GET and POST methods, rather than the complicated SOAP protocol. I believe it also encodes responses in JSON format, so that should be familiar to most devs here. I believe it is still sort of in beta though. Their SOAP API is the bigger brother.

Links for more info:
http://www.dwolla.org/d/showthread.php?2-REST-API
http://www.dwolla.org/d/showthread.php?690-Dwolla-GRID-Start-Here-to-Access-the-GRID


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 27, 2011, 08:23:03 AM
BTW, just scanned your avatar with my smartphone and realized your QR code is encoded with the link to your website.
Thats pretty awesome.


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 27, 2011, 03:12:02 PM
Glad you like the QR-Code, I got it from a QR-Code generator on-line somewhere.

Looks like Nuri won the bounty, I'm going to hook up Mjcmurfy with 1 BTC for being really helpful and getting the ball rolling....



Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 27, 2011, 03:25:06 PM
Give me a few hours before bounties are sent guys I'm kind of behind this project. Thanks for your patience


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: nhodges on September 27, 2011, 07:48:26 PM
Give me a few hours before bounties are sent guys I'm kind of behind this project. Thanks for your patience

No problem, I'm glad we got through the issue! :P


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 27, 2011, 07:57:47 PM
Give me a few hours before bounties are sent guys I'm kind of behind this project. Thanks for your patience

No problem, I'm glad we got through the issue! :P

I meant to say nhodges won bounty  ;D
I got your bitcoin address with your forum identity!

It must be a dwolla problem because I have $4 in my dwolla account and It wont let me send money to my self when i use the real API and not the test one.
I get the following error

Quote
object(stdClass)#3 (1) { ["SendMoneyResult"]=> bool(false) }


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 27, 2011, 08:16:07 PM
Dwolla Devs are telling me SOAP API and OAuth API are deprecated so I guess its back to the REST API where i started.... darn it....


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: captainteemo on September 28, 2011, 01:39:06 AM
Dwolla Devs are telling me SOAP API and OAuth API are deprecated so I guess its back to the REST API where i started.... darn it....
rest owns, soap is the worst trainwreck i've ever seen


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 28, 2011, 03:47:22 AM
where were you two days ago.... :P


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: captainteemo on September 28, 2011, 04:15:29 AM
where were you two days ago.... :P
passed out drunk in the london underground


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: mjcmurfy on September 28, 2011, 08:27:08 AM
Glad you like the QR-Code, I got it from a QR-Code generator on-line somewhere.

Looks like Nuri won the bounty, I'm going to hook up Mjcmurfy with 1 BTC for being really helpful and getting the ball rolling....

I wasn't in in for the money mate!
Glad you got it all sorted out.


Title: Re: Looking for a PHP dev that can give me some Pseudo-code for Dwolla API [2BTC]
Post by: Xenland on September 29, 2011, 09:10:52 AM
You da man mjcmurfy!

http://trebekbeatz.ytmnd.com/