Skip to content

Commit

Permalink
Example of getting a charge with Payments API.
Browse files Browse the repository at this point in the history
  • Loading branch information
consolibyte committed Nov 9, 2015
1 parent bbf63aa commit de4724a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
54 changes: 52 additions & 2 deletions QuickBooks/Payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,40 @@ public function tokenize($Context, $Object)
return false;
}

public function getCharge($Context, $id)
{
$resp = $this->_http($Context, QuickBooks_Payments::URL_CHARGE . '/' . $id, null);

$data = json_decode($resp, true);

if ($this->_handleError($data))
{
return false;
}

return new QuickBooks_Payments_Transaction($data);
}

public function getDebit($id)
{

}

public function refund()
{

}

public function getChargeRefund()
{

}

public function getDebitRefund()
{

}

protected function _handleError($data)
{
if (isset($data['errors']))
Expand Down Expand Up @@ -339,7 +373,12 @@ public function log($message)

protected function _http($Context, $url_path, $raw_body)
{
$method = 'POST';
$method = 'GET';
if ($raw_body)
{
$method = 'POST';
}

$url = $this->_getBaseURL() . $url_path;

$authcreds = $Context->authcreds();
Expand Down Expand Up @@ -368,7 +407,18 @@ protected function _http($Context, $url_path, $raw_body)
$HTTP->verifyHost(false);
$HTTP->verifyPeer(false);

$return = $HTTP->POST();
if ($method == 'POST')
{
$return = $HTTP->POST();
}
else if ($method == 'GET')
{
$return = $HTTP->GET();
}
else
{
$return = null; // ERROR
}

$this->_last_request = $HTTP->lastRequest();
$this->_last_response = $HTTP->lastResponse();
Expand Down
41 changes: 41 additions & 0 deletions docs/payments/example_charge_get.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

require_once dirname(__FILE__) . '/config.php';

require_once dirname(__FILE__) . '/views/header.tpl.php';

?>

<pre>

<?php

$id = 'EY32QCYC6RTX';

$Payments = new QuickBooks_Payments($oauth_consumer_key, $oauth_consumer_secret, $sandbox);

if ($Transaction = $Payments->getCharge($Context, $id))
{
print('Id: ' . $Transaction->getId() . '<br>');
print('Auth Code: ' . $Transaction->getAuthCode() . '<br>');
print('Status: ' . $Transaction->getStatus() . '<br>');
}
else
{
print('Error while getting charge: ' . $Payments->lastResponse());
}

print('<br><br><br><br>');
print("\n\n\n\n\n\n\n\n");
print('Request [' . $Payments->lastRequest() . ']');
print("\n\n\n\n");
print('Response [' . $Payments->lastResponse() . ']');
print("\n\n\n\n\n\n\n\n\n");

?>

</pre>

<?php

require_once dirname(__FILE__) . '/views/footer.tpl.php';
2 changes: 1 addition & 1 deletion docs/payments/example_creditcard_tokenize.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$city = 'Mt Pleasant';
$region = 'MI';

$Payments = new QuickBooks_Payments($sandbox);
$Payments = new QuickBooks_Payments($oauth_consumer_key, $oauth_consumer_secret, $sandbox);

$CreditCard = new QuickBooks_Payments_CreditCard($name, $number, $expyear, $expmonth, $street, $city, $region);

Expand Down
3 changes: 3 additions & 0 deletions docs/payments/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
$tmp = explode('_', $file);
switch (end($tmp))
{
case 'get.php':
$examples[$file] = 'Get a ' . implode(' ', array_slice($tmp, 1, -1));
break;
case 'fail.php':
$examples[$file] = 'Try (and fail) to charge a ' . implode(' ', array_slice($tmp, 1, -1));
break;
Expand Down

0 comments on commit de4724a

Please sign in to comment.