forked from AuthorizeNet/sample-code-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-batch-statistics.php
More file actions
65 lines (54 loc) · 2.6 KB
/
get-batch-statistics.php
File metadata and controls
65 lines (54 loc) · 2.6 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
61
62
63
64
65
<?php
require 'vendor/autoload.php';
require_once 'Constants.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
function getBatchStatistics() {
// Common Set Up for API Credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(Constants::MERCHANT_LOGIN_ID);
$merchantAuthentication->setTransactionKey(Constants::MERCHANT_TRANSACTION_KEY);
$refId = 'ref' . time();
//Setting a valid batch Id for the Merchant
$batchId = "4532808";
// Creating a request
$request = new AnetAPI\GetBatchStatisticsRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setBatchId($batchId);
//Creating the controller
$controller = new AnetController\GetBatchStatisticsController($request);
//Retrieving response
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
{
echo "SUCCESS: Successfully got the list of subscriptions : \n\n";
echo "Batch ID : " . $response->getBatch()->getBatchId() . "\n";
echo "Settlement Time : " . date_format($response->getBatch()->getSettlementTimeUTC(),"Y/m/d H:i:s") . "\n";
echo "Settlement state : " . $response->getBatch()->getSettlementState() . "\n";
echo "Payment Method : " . $response->getBatch()->getPaymentMethod() . "\n";
echo "Statistic Details:";
//Displaying the details of each transaction in the list
foreach ($response->getBatch()->getStatistics() as $statistics)
{
echo " Account Type : " . $statistics->getAccountType() . "\n";
echo " Charge Amount : " . $statistics->getChargeAmount() . "\n";
echo " Charge Count : " . $statistics->getChargeCount() . "\n";
echo " Refund Amount : " . $statistics->getRefundAmount() . "\n";
echo " Refund Count : " . $statistics->getRefundCount() . "\n";
echo " Void Count : " . $statistics->getRefundCount() . "\n";
echo " Decline Count : " . $statistics->getRefundCount() . "\n";
echo " Error Count : " . $statistics->getRefundCount() . "\n";
}
}
else
{
echo "ERROR : Failed to get the batch statistics\n";
$errorMessages = $response->getMessages()->getMessage();
echo "Response : " . $errorMessages[0]->getCode() . " " .$errorMessages[0]->getText() . "\n";
}
return $response;
}
if(!defined('DONT_RUN_SAMPLES'))
getBatchStatistics();
?>