Skip to content

Commit 6f33613

Browse files
committed
Merge pull request AuthorizeNet#19 from rahulrnitc/master
Added get-customer-shipping-address and get-transaction-list. Thanks Rahul
2 parents e319102 + e1d90ed commit 6f33613

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
require 'vendor/autoload.php';
3+
use net\authorize\api\contract\v1 as AnetAPI;
4+
use net\authorize\api\controller as AnetController;
5+
define("AUTHORIZENET_LOG_FILE", "phplog");
6+
// Common setup for API credentials
7+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
8+
$merchantAuthentication->setName("5KP3u95bQpv");
9+
$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S");
10+
11+
// An existing customer profile id and shipping address id for this merchant name and transaction key
12+
$customerProfileId = "36731856";
13+
$customerAddressId = "35850995";
14+
15+
$request = new AnetAPI\GetCustomerShippingAddressRequest();
16+
$request->setMerchantAuthentication($merchantAuthentication);
17+
$request->setCustomerProfileId($customerProfileId);
18+
$request->setCustomerAddressId($customerAddressId);
19+
20+
$controller = new AnetController\GetCustomerShippingAddressController($request);
21+
22+
//Retrieving existing customer shipping address
23+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
24+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
25+
{
26+
echo "Get Customer Shipping Address SUCCESS" . "\n";
27+
echo " FirstName : " . $response->getAddress()->getFirstName() . "\n";
28+
echo " LastName : " . $response->getAddress()->getLastName() . "\n";
29+
echo " Company : " . $response->getAddress()->getCompany() . "\n";
30+
echo " Address : " . $response->getAddress()->getAddress() . "\n";
31+
echo " City : " . $response->getAddress()->getCity() . "\n";
32+
echo " State : " . $response->getAddress()->getState() . "\n";
33+
echo " Zip : " . $response->getAddress()->getZip() . "\n";
34+
echo " Country : " . $response->getAddress()->getCountry() . "\n";
35+
echo " Phone Number : " . $response->getAddress()->getPhoneNumber() . "\n";
36+
echo " FAX Number : " . $response->getAddress()->getFaxNumber() . "\n";
37+
echo "Customer AddressId : " . $response->getAddress()->getCustomerAddressId() . "\n";
38+
}
39+
else
40+
{
41+
echo "Get Customer Shipping Address ERROR : Invalid response\n";
42+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
43+
}
44+
?>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
require 'vendor/autoload.php';
3+
use net\authorize\api\contract\v1 as AnetAPI;
4+
use net\authorize\api\controller as AnetController;
5+
define("AUTHORIZENET_LOG_FILE", "phplog");
6+
7+
// Common Set Up for API Credentials
8+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
9+
$merchantAuthentication->setName( "5KP3u95bQpv");
10+
$merchantAuthentication->setTransactionKey("4Ktq966gC55GAX7S");
11+
12+
$refId = 'ref' . time();
13+
14+
//Setting a valid batch Id for the Merchant
15+
$batchId = "4606008";
16+
$request = new AnetAPI\GetTransactionListRequest();
17+
$request->setMerchantAuthentication($merchantAuthentication);
18+
$request->setBatchId($batchId);
19+
20+
$controller = new AnetController\GetTransactionListController($request);
21+
22+
//Retrieving transaction list for the given Batch Id
23+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
24+
25+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
26+
{
27+
echo "SUCCESS: Get Transaction List for BatchID : " . $batchId . "\n\n";
28+
if ($response->getTransactions() == null) {
29+
echo "No Transaction to dispaly in this Batch.";
30+
return ;
31+
}
32+
//Displaying the details of each transaction in the list
33+
foreach ($response->getTransactions() as $transaction) {
34+
echo " ->Transaction Id : " . $transaction->getTransId() . "\n";
35+
echo " Submitted on (Local) : " . date_format($transaction->getSubmitTimeLocal(), 'Y-m-d H:i:s') . "\n";
36+
echo " Status : " . $transaction->getTransactionStatus() . "\n";
37+
echo " Settle amount : " . number_format($transaction->getSettleAmount(), 2, '.', '') . "\n";
38+
}
39+
}
40+
else
41+
{
42+
echo "ERROR : Invalid response\n";
43+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
44+
45+
}
46+
?>

0 commit comments

Comments
 (0)