Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //incl/dwollaKeys.php
- $dwollaKey = 'g...';
- $dwollaSecret = 'P...';
- //client page
- require 'incl/dwollaKeys.php';
- $orderId = 1234;
- $unixtime = time();
- echo '<form accept-charset="UTF-8" action="https://www.dwolla.com/payment/pay" method="post">
- <input id="key" name="key" type="hidden" value="'.$dwollaKey.'" />
- <input id="signature" name="signature" type="hidden" value="'.hash_hmac('sha1', "{$dwollaKey}&{$unixtime}&{$orderId}", $dwollaSecret).'" />
- <input id="callback" name="callback" type="hidden" value="http://www.example.org/notificationsDwolla.php" />
- <input id="redirect" name="redirect" type="hidden" value="http://www.example.org/contribute.php?thanks" />
- <input id="test" name="test" type="hidden" value="true" />
- <input id="name" name="name" type="hidden" value="Test name" />
- <input id="description" name="description" type="hidden" value="Test desc" />
- <input id="destinationid" name="destinationid" type="hidden" value="812-495-7813" />
- <div class="ui-corner-all ui-button">
- USD: $<input id="amount" name="amount" type="number" placeholder="Amount in USD" maxlength="10" min="1.00" step="1.00" />
- </div>
- <input id="allowFundingSources" name="allowFundingSources" type="hidden" value="true" />
- <input id="orderid" name="orderid" type="hidden" value="'.$orderId.'" />
- <input id="timestamp" name="timestamp" type="hidden" value="'.$unixtime.'" />
- <input id="test" name="test" type="hidden" value="true" />
- <button type="submit" name="submit" alt="Checkout with Dwolla.">Checkout with Dwolla</button>
- </form>';
- //server callback
- require 'incl/dwollaKeys.php';
- function verifyGatewaySignature($proposedSignature, $checkoutId, $amount) {
- $signature = hash_hmac('sha1', "{".$checkoutId.'}&{'.number_format($amount, 2)."}", $dwollaSecret);
- return $signature == $proposedSignature;
- }
- $data = json_decode(file_get_contents('php://input'));
- $sigantureValid = verifyGatewaySignature($data->Signature, $data->CheckoutId, $data->Amount);
- if( $sigantureValid ){
- echo 'passed';
- } else {
- echo 'failed';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement