public function dwolla_sendMoney($tid, $amount, $pin, $desc, $source) { $dest = $this->getSetting('dwolla_id'); $ticket = $this->query("SELECT * from tickets WHERE id='{$tid}'")[0]; $company = $this->query("SELECT * from companies WHERE id='{$ticket['company_id']}'")[0]; $cid = $company['id']; $token = $company['company_dwollatoken']; if (!$token) { return "No Dwolla Authorization."; } $Dwolla = new DwollaRestClient(); $Dwolla->setToken($token); $transactionId = $Dwolla->send($pin, $dest, $amount, 'Dwolla', $desc, 0, false, $source); if (!$transactionId) { return $Dwolla->getError(); } else { $now = time(); $net = $amount - 0.25; $this->query("INSERT into transactions SET transaction_merchant_id='{$transactionId}', transaction_ts='{$now}', transaction_amount='{$amount}', transaction_fee='0.25', transaction_net='{$net}', transaction_source='dwolla', transaction_desc='{$desc}', ticket_id='{$tid}', company_id='{$cid}'"); $this->notifyCompany($cid, "Checking Payment Authorized", "A payment in the amount of {${$amount}} has been authorized.", "/ticket/{$tid}/"); $this->notifyProvider("Dwolla Payment Authorized", "A payment in the amount of {${$amount}} has been authorized from Ticket #{$tid}.", "/ticket/{$tid}/"); return true; } }
require 'lib/dwolla.php'; // Include any required keys require '_keys.php'; // Instantiate a new Dwolla REST Client $Dwolla = new DwollaRestClient($apiKey, $apiSecret); //Testing /* $Dwolla->setDebug(true); echo "<p>User ID=".$_POST["userID"]."</p>";//testing echo "<p>Amount=".$_POST["amount"]."</p>";//testing */ $user = $Dwolla->getUser($_POST["userID"]); $amount = $_POST["amount"]; if ($amount < 0 || $amount > 1) { echo "Error: Invalid dollar amount!"; } elseif (!$user) { echo "Error: {$Dwolla->getError()} \n"; } else { //Hard coded in _keys.php $token="2Dn+YkMrJNG43UR7VMQXyir6ocDAtB6vBasBUtcKM7A3iV/Bga"; $Dwolla->setToken($token); //Make the transaction $transactionId = $Dwolla->send($pin, $user['Id'], $amount); if (!$transactionId) { //Check for errors echo "Error: {$Dwolla->getError()} \n"; } else { // Print Transaction ID echo "Transaction successful (Transaction ID: {$transactionId}) \n"; } } // Valid user and amount