Advertisement
Guest User

Untitled

a guest
Aug 7th, 2014
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.58 KB | None | 0 0
  1. // incl/dwollaKeys.php
  2. <?php
  3.  
  4. // Dwolla Secret Stuff
  5. $dwollaKey = 'eSEV37L/3VTMZpK4rmbC7y/HNUg+V9fUgwKoJrADYF41dDmvDj';
  6. $dwollaSecret = 'sObX/aXpL4LAAeb1MjpEzwX1R3y6nNSNrIZfU1bpwcYfbAPRIJ';
  7.  
  8. //form.php
  9. //accid = orderId
  10.     require "incl/dwollaKeys.php";
  11.    
  12.     $unixtime = time();
  13.     $accid = '2512';
  14.  
  15.     echo '<div class="dwolla">
  16.         <form accept-charset="UTF-8" action="https://uat.dwolla.com/payment/pay" method="post">
  17.                 <input id="key" name="key" type="hidden" value="'.$dwollaKey.'" />
  18.                 <input id="signature" name="signature" type="hidden" value="'.hash_hmac('sha1', "{$dwollaKey}&{$unixtime}&{$accid}", $dwollaSecret).'" />
  19.                 <input id="callback" name="callback" type="hidden" value="'.basename($_SERVER['PHP_SELF']).'/notificationsDwolla.php" />
  20.                 <input id="redirect" name="redirect" type="hidden" value="'.$_SERVER['PHP_SELF'].'?thanks" />
  21.                 <!--<input id="test" name="test" type="hidden" value="true" />-->
  22.                 <input id="description" name="description" type="hidden" value="Amount will be credited to your account" />
  23.                 <input id="destinationid" name="destinationid" type="hidden" value="812-166-7117" />
  24.                 <div class="ui-corner-all ui-button">
  25.                     USD: $<input id="amount" name="amount" type="number" placeholder="Amount in USD" maxlength="10" min="1.00" step="1.00" />
  26.                 </div>
  27.                 <input id="allowFundingSources" name="allowFundingSources" type="hidden" value="true" />
  28.                 <input id="orderid" name="orderid" type="hidden" value="'.$accid.'" />
  29.                 <input id="timestamp" name="timestamp" type="hidden" value="'.$unixtime.'" />
  30.                 <button type="submit" name="submit" alt="Checkout with Dwolla.">Checkout with Dwolla</button>
  31.         </form>
  32.     </div>';
  33.  
  34. //notificationsDwolla.php
  35.     require "incl/dwollaKeys.php";
  36.  
  37.     function verifyGatewaySignature($proposedSignature, $checkoutId, $amount) {
  38.         $amount = number_format($amount, 2);
  39.         $signature = hash_hmac('sha1', "{$checkoutId}&{$amount}", $dwollaSecret);
  40.         return $signature == $proposedSignature;
  41.     }
  42.  
  43.     $data = json_decode(file_get_contents('php://input'));
  44.  
  45.     $sigantureValid = verifyGatewaySignature($data->Signature, $data->CheckoutId, $data->Amount);
  46.  
  47.     $debugFile = "debugDwolla.log";
  48.     $fh = fopen($debugFile, 'a') or die("can't open file");
  49.     $stringData = json_encode($data)."\n";
  50.     fwrite($fh, $stringData);
  51.     $stringData = $sigantureValid ? 'true' : 'false' .", ".$data->Signature.", ".$data->CheckoutId.", ".$data->Amount."\n";
  52.     fwrite($fh, $stringData);
  53.     fclose($fh);
  54.  
  55.     if( $sigantureValid ){
  56.         //do thing when it's validated
  57.     } else {
  58.         echo 'Signature not valid';
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement