Advertisement
Guest User

Untitled

a guest
Nov 19th, 2011
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2.  
  3.     $clientid  = 'a';
  4.     $secretkey = 'b';
  5.     $redirect  = 'http://return.to/apage.php';
  6.  
  7.     if(isset($_GET['code'])) {
  8.         $code = urlencode($_GET["code"]);
  9.     } else {
  10.         header("Location: https://www.dwolla.com/oauth/v2/authenticate?client_id=".urlencode($clientid)."&response_type=code&redirect_uri=".urlencode($redirect)."&scope=send%7Ctransactions"); exit;
  11.     }
  12.  
  13.     # fetch auth token
  14.  
  15.     $url  = "https://www.dwolla.com/oauth/v2/token?client_id=".urlencode($clientid)."&client_secret=".urlencode($secretkey)."&grant_type=authorization_code&code=".$code."&redirect_uri=".urlencode($redirect);
  16.     $tok  = file_get_contents($url);
  17.     $json = json_decode($tok, true);
  18.  
  19.     # do a send
  20.  
  21.     $target = 'https://www.dwolla.com/oauth/rest/accountapi/send';
  22.     $array  = array(
  23.         'oauth_token' => $json['access_token'],
  24.         'pin' => '1234',
  25.         'destinationId' => '812-111-1111',
  26.         'amount' => 1,
  27.         'facilitatorAmount' => 0,
  28.         'notes' => 'Test'
  29.     );
  30.  
  31.     $curl = curl_init($target);
  32.     curl_setopt($curl, CURLOPT_HEADER, false);
  33.     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  34.     curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
  35.     curl_setopt($curl, CURLOPT_POST, true);
  36.     curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($array));
  37.  
  38.     $response = curl_exec($curl); print_r($response); exit;
  39.  
  40.     $json = json_decode(curl_exec($curl), true);
  41.  
  42.     curl_close($curl);
  43.  
  44.     print_r($json); exit;
  45.  
  46. ?>
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement