Skip to content

Commit de4724a

Browse files
committed
Example of getting a charge with Payments API.
1 parent bbf63aa commit de4724a

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

QuickBooks/Payments.php

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,40 @@ public function tokenize($Context, $Object)
246246
return false;
247247
}
248248

249+
public function getCharge($Context, $id)
250+
{
251+
$resp = $this->_http($Context, QuickBooks_Payments::URL_CHARGE . '/' . $id, null);
252+
253+
$data = json_decode($resp, true);
254+
255+
if ($this->_handleError($data))
256+
{
257+
return false;
258+
}
259+
260+
return new QuickBooks_Payments_Transaction($data);
261+
}
262+
263+
public function getDebit($id)
264+
{
265+
266+
}
267+
268+
public function refund()
269+
{
270+
271+
}
272+
273+
public function getChargeRefund()
274+
{
275+
276+
}
277+
278+
public function getDebitRefund()
279+
{
280+
281+
}
282+
249283
protected function _handleError($data)
250284
{
251285
if (isset($data['errors']))
@@ -339,7 +373,12 @@ public function log($message)
339373

340374
protected function _http($Context, $url_path, $raw_body)
341375
{
342-
$method = 'POST';
376+
$method = 'GET';
377+
if ($raw_body)
378+
{
379+
$method = 'POST';
380+
}
381+
343382
$url = $this->_getBaseURL() . $url_path;
344383

345384
$authcreds = $Context->authcreds();
@@ -368,7 +407,18 @@ protected function _http($Context, $url_path, $raw_body)
368407
$HTTP->verifyHost(false);
369408
$HTTP->verifyPeer(false);
370409

371-
$return = $HTTP->POST();
410+
if ($method == 'POST')
411+
{
412+
$return = $HTTP->POST();
413+
}
414+
else if ($method == 'GET')
415+
{
416+
$return = $HTTP->GET();
417+
}
418+
else
419+
{
420+
$return = null; // ERROR
421+
}
372422

373423
$this->_last_request = $HTTP->lastRequest();
374424
$this->_last_response = $HTTP->lastResponse();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
require_once dirname(__FILE__) . '/config.php';
4+
5+
require_once dirname(__FILE__) . '/views/header.tpl.php';
6+
7+
?>
8+
9+
<pre>
10+
11+
<?php
12+
13+
$id = 'EY32QCYC6RTX';
14+
15+
$Payments = new QuickBooks_Payments($oauth_consumer_key, $oauth_consumer_secret, $sandbox);
16+
17+
if ($Transaction = $Payments->getCharge($Context, $id))
18+
{
19+
print('Id: ' . $Transaction->getId() . '<br>');
20+
print('Auth Code: ' . $Transaction->getAuthCode() . '<br>');
21+
print('Status: ' . $Transaction->getStatus() . '<br>');
22+
}
23+
else
24+
{
25+
print('Error while getting charge: ' . $Payments->lastResponse());
26+
}
27+
28+
print('<br><br><br><br>');
29+
print("\n\n\n\n\n\n\n\n");
30+
print('Request [' . $Payments->lastRequest() . ']');
31+
print("\n\n\n\n");
32+
print('Response [' . $Payments->lastResponse() . ']');
33+
print("\n\n\n\n\n\n\n\n\n");
34+
35+
?>
36+
37+
</pre>
38+
39+
<?php
40+
41+
require_once dirname(__FILE__) . '/views/footer.tpl.php';

docs/payments/example_creditcard_tokenize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$city = 'Mt Pleasant';
1919
$region = 'MI';
2020

21-
$Payments = new QuickBooks_Payments($sandbox);
21+
$Payments = new QuickBooks_Payments($oauth_consumer_key, $oauth_consumer_secret, $sandbox);
2222

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

docs/payments/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
$tmp = explode('_', $file);
1818
switch (end($tmp))
1919
{
20+
case 'get.php':
21+
$examples[$file] = 'Get a ' . implode(' ', array_slice($tmp, 1, -1));
22+
break;
2023
case 'fail.php':
2124
$examples[$file] = 'Try (and fail) to charge a ' . implode(' ', array_slice($tmp, 1, -1));
2225
break;

0 commit comments

Comments
 (0)