Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //incl/dwollaKeys.php
  2. $dwollaKey = 'g...';
  3. $dwollaSecret = 'P...';
  4.  
  5. //client page
  6.     require 'incl/dwollaKeys.php';
  7.     $orderId = 1234;
  8.     $unixtime = time();
  9.  
  10.     echo '<form accept-charset="UTF-8" action="https://www.dwolla.com/payment/pay" method="post">
  11.         <input id="key" name="key" type="hidden" value="'.$dwollaKey.'" />
  12.         <input id="signature" name="signature" type="hidden" value="'.hash_hmac('sha1', "{$dwollaKey}&{$unixtime}&{$orderId}", $dwollaSecret).'" />
  13.         <input id="callback" name="callback" type="hidden" value="http://www.example.org/notificationsDwolla.php" />
  14.         <input id="redirect" name="redirect" type="hidden" value="http://www.example.org/contribute.php?thanks" />
  15.         <input id="test" name="test" type="hidden" value="true" />
  16.         <input id="name" name="name" type="hidden" value="Test name" />
  17.         <input id="description" name="description" type="hidden" value="Test desc" />
  18.         <input id="destinationid" name="destinationid" type="hidden" value="812-495-7813" />
  19.         <div class="ui-corner-all ui-button">
  20.             USD: $<input id="amount" name="amount" type="number" placeholder="Amount in USD" maxlength="10" min="1.00" step="1.00" />
  21.         </div>
  22.         <input id="allowFundingSources" name="allowFundingSources" type="hidden" value="true" />
  23.         <input id="orderid" name="orderid" type="hidden" value="'.$orderId.'" />
  24.         <input id="timestamp" name="timestamp" type="hidden" value="'.$unixtime.'" />
  25.         <input id="test" name="test" type="hidden" value="true" />
  26.         <button type="submit" name="submit" alt="Checkout with Dwolla.">Checkout with Dwolla</button>
  27.     </form>';
  28.  
  29.  
  30. //server callback
  31.     require 'incl/dwollaKeys.php';
  32.  
  33.     function verifyGatewaySignature($proposedSignature, $checkoutId, $amount) {
  34.         $signature = hash_hmac('sha1', "{".$checkoutId.'}&{'.number_format($amount, 2)."}", $dwollaSecret);
  35.         return $signature == $proposedSignature;
  36.     }
  37.  
  38.     $data = json_decode(file_get_contents('php://input'));
  39.  
  40.     $sigantureValid = verifyGatewaySignature($data->Signature, $data->CheckoutId, $data->Amount);
  41.  
  42.     if( $sigantureValid ){
  43.         echo 'passed';
  44.     } else {
  45.         echo 'failed';
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement