public function main($content) { $permissions = ["Send", "Transactions", "Balance", "AccountInfoFull", "Funding"]; if (isset($content['myid'])) { $myid = $content['myid']; } else { $myid = $this->company->id; } if (!$this->isProvidingCompany()) { $myid = $this->company->id; } $Dwolla = new DwollaRestClient($this->getSetting('dwolla_app_key'), $this->getSetting('dwolla_app_secret'), $this->getSetting('atikit_url') . "/dwauth/{$myid}/", $permissions); if (!isset($content['code'])) { $durl = $Dwolla->getAuthUrl(); header("Location: {$durl}"); } if (isset($content['error'])) { $this->notifyCompany($myid, "Dwolla Error", $content['error_description'], null); $this->reloadTarget(); } else { if (isset($content['code'])) { $code = $content['code']; $token = $Dwolla->requestToken($code); if (!$token) { print $Dwolla->getError(); // Check for errors die("Unable to Obtain token"); } else { $this->query("UPDATE companies SET company_dwollatoken='{$token}' WHERE id='{$myid}'"); $this->notifyCompany($myid, "Dwolla Authorized!", "You can now begin using Dwolla with aTikit.", null); if (!$this->isProvidingCompany()) { $this->reloadTarget('billing/checking/'); } else { $this->reloadTarget(); } } // Print the access token } } }
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
public function addBankAccount($content) { if (!$content['routing'] || !$content['account'] || !$content['type'] || !$content['nickname']) { $this->failJson("Unable to Add", "Some fields are blank, Please try again."); } $myid = $this->company->id; $Dwolla = new DwollaRestClient($this->getSetting('dwolla_app_key'), $this->getSetting('dwolla_app_secret'), $this->getSetting('atikit_url') . "dwauth/{$myid}/"); $Dwolla->setToken($this->company->company_dwollatoken); $newFundingSource = $Dwolla->addFundingSource($content['account'], $content['routing'], $content['type'], $content['nickname']); if (!$newFundingSource) { $this->failJson("Unable to Add", $Dwolla->getError()); } $json = []; $json['action'] = 'reload'; $json['url'] = "/billing/checking/"; $this->jsone('success', $json); }