forked from abhishekwebkul/codesamples-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetBalance.php
More file actions
61 lines (51 loc) · 1.97 KB
/
Copy pathGetBalance.php
File metadata and controls
61 lines (51 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
$path = '../../lib';
set_include_path(get_include_path(). PATH_SEPARATOR . $path);
require_once('PPBootStrap.php');
// # GetBalance API
// The GetBalance API Operation obtains the available balance for a PayPal account.
// This sample code uses Merchant PHP SDK to make API call. You can
// download the SDKs [here](https://github.com/paypal/sdk-packages/tree/gh-pages/merchant-sdk/php)
class GetBalance {
public function getBal() {
$logger = new PPLoggingManager('GetBalance');
// ## GetBalanceReq
$getBalanceReq = new GetBalanceReq();
$getBalanceRequest = new GetBalanceRequestType();
// Indicates whether to return all currencies. It is one of the
// following values:
//
// * 0 – Return only the balance for the primary currency holding.
// * 1 – Return the balance for each currency holding.
$getBalanceRequest->ReturnAllCurrencies = "1";
$getBalanceReq->GetBalanceRequest = $getBalanceRequest;
// ## Creating service wrapper object
// Creating service wrapper object to make API call and loading
// configuration file for your credentials and endpoint
$service = new PayPalAPIInterfaceServiceService();
try {
// ## Making API call
// Invoke the appropriate method corresponding to API in service
// wrapper object
$response = $service->GetBalance($getBalanceReq);
} catch (Exception $ex) {
$logger->error("Error Message : " + $ex->getMessage());
}
// ## Accessing response parameters
// You can access the response parameters using variables in
// response object as shown below
// ### Success values
if ($response->Ack == "Success") {
$balanceHoldingArray = $response->BalanceHoldings;
foreach($balanceHoldingArray as $amount) {
$logger->log("Balance Holdings : " + $amount->value . $amount->currencyID);
}
}
// ### Error Values
// Access error values from error list using getter methods
else {
$logger->error("API Error Message : ". $response->Errors[0]->LongMessage);
}
return $response;
}
}