Skip to content

Commit c0f7e0f

Browse files
author
akankari
committed
Move the ARB and Transaction details sample codes to function
1 parent e80fb39 commit c0f7e0f

11 files changed

Lines changed: 469 additions & 378 deletions

RecurringBilling/cancel-subscription.php

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,40 @@
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
66

7-
// Common Set Up for API Credentials
8-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
9-
$merchantAuthentication->setName( "556KThWQ6vf2");
10-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
11-
12-
$refId = 'ref' . time();
13-
14-
$request = new AnetAPI\ARBCancelSubscriptionRequest();
15-
$request->setMerchantAuthentication($merchantAuthentication);
16-
$request->setRefId($refId);
17-
$request->setSubscriptionId("100748");
18-
19-
$controller = new AnetController\ARBCancelSubscriptionController($request);
20-
21-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
22-
23-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
24-
{
25-
echo "SUCCESS" . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
26-
}
27-
else
28-
{
29-
echo "ERROR : Invalid response\n";
30-
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
31-
7+
function cancelSubscription($subscriptionId) {
8+
9+
// Common Set Up for API Credentials
10+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11+
$merchantAuthentication->setName( "556KThWQ6vf2");
12+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
13+
14+
$refId = 'ref' . time();
15+
16+
$request = new AnetAPI\ARBCancelSubscriptionRequest();
17+
$request->setMerchantAuthentication($merchantAuthentication);
18+
$request->setRefId($refId);
19+
$request->setSubscriptionId($subscriptionId);
20+
21+
$controller = new AnetController\ARBCancelSubscriptionController($request);
22+
23+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
24+
25+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
26+
{
27+
echo "SUCCESS" . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
28+
}
29+
else
30+
{
31+
echo "ERROR : Invalid response\n";
32+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
33+
34+
}
35+
36+
return $response;
37+
3238
}
33-
?>
39+
40+
if(!defined(DONT_RUN_SAMPLES))
41+
cancelSubscription("100748");
42+
43+
?>

RecurringBilling/create-subscription.php

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,71 @@
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
66
date_default_timezone_set('America/Los_Angeles');
7-
// Common Set Up for API Credentials
8-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
9-
$merchantAuthentication->setName( "556KThWQ6vf2");
10-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
7+
8+
function createSubscription($intervalLength) {
119

12-
$refId = 'ref' . time();
10+
// Common Set Up for API Credentials
11+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
12+
$merchantAuthentication->setName( "556KThWQ6vf2");
13+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
1314

14-
// Subscription Type Info
15-
$subscription = new AnetAPI\ARBSubscriptionType();
16-
$subscription->setName("Sample Subscription");
15+
$refId = 'ref' . time();
1716

18-
$interval = new AnetAPI\PaymentScheduleType\IntervalAType();
19-
$interval->setLength("1");
20-
$interval->setUnit("months");
17+
// Subscription Type Info
18+
$subscription = new AnetAPI\ARBSubscriptionType();
19+
$subscription->setName("Sample Subscription");
2120

22-
$paymentSchedule = new AnetAPI\PaymentScheduleType();
23-
$paymentSchedule->setInterval($interval);
24-
$paymentSchedule->setStartDate(new DateTime('2020-08-30'));
25-
$paymentSchedule->setTotalOccurrences("12");
26-
$paymentSchedule->setTrialOccurrences("1");
21+
$interval = new AnetAPI\PaymentScheduleType\IntervalAType();
22+
$interval->setLength($intervalLength);
23+
$interval->setUnit("days");
2724

28-
$subscription->setPaymentSchedule($paymentSchedule);
29-
$subscription->setAmount("10.29");
30-
$subscription->setTrialAmount("0.00");
31-
32-
$creditCard = new AnetAPI\CreditCardType();
33-
$creditCard->setCardNumber("4111111111111111");
34-
$creditCard->setExpirationDate("2020-12");
25+
$paymentSchedule = new AnetAPI\PaymentScheduleType();
26+
$paymentSchedule->setInterval($interval);
27+
$paymentSchedule->setStartDate(new DateTime('2020-08-30'));
28+
$paymentSchedule->setTotalOccurrences("12");
29+
$paymentSchedule->setTrialOccurrences("1");
3530

36-
$payment = new AnetAPI\PaymentType();
37-
$payment->setCreditCard($creditCard);
31+
$subscription->setPaymentSchedule($paymentSchedule);
32+
$subscription->setAmount("10.29");
33+
$subscription->setTrialAmount("0.00");
34+
35+
$creditCard = new AnetAPI\CreditCardType();
36+
$creditCard->setCardNumber("4111111111111111");
37+
$creditCard->setExpirationDate("2020-12");
3838

39-
$subscription->setPayment($payment);
39+
$payment = new AnetAPI\PaymentType();
40+
$payment->setCreditCard($creditCard);
4041

41-
$billTo = new AnetAPI\NameAndAddressType();
42-
$billTo->setFirstName("John");
43-
$billTo->setLastName("Smith");
42+
$subscription->setPayment($payment);
4443

45-
$subscription->setBillTo($billTo);
44+
$billTo = new AnetAPI\NameAndAddressType();
45+
$billTo->setFirstName("John");
46+
$billTo->setLastName("Smith");
4647

47-
$request = new AnetAPI\ARBCreateSubscriptionRequest();
48-
$request->setmerchantAuthentication($merchantAuthentication);
49-
$request->setRefId($refId);
50-
$request->setSubscription($subscription);
51-
$controller = new AnetController\ARBCreateSubscriptionController($request);
48+
$subscription->setBillTo($billTo);
5249

53-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
54-
55-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
56-
{
57-
echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n";
58-
}
59-
else
60-
{
61-
echo "ERROR : Invalid response\n";
62-
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
50+
$request = new AnetAPI\ARBCreateSubscriptionRequest();
51+
$request->setmerchantAuthentication($merchantAuthentication);
52+
$request->setRefId($refId);
53+
$request->setSubscription($subscription);
54+
$controller = new AnetController\ARBCreateSubscriptionController($request);
55+
56+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
57+
58+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
59+
{
60+
echo "SUCCESS: Subscription ID : " . $response->getSubscriptionId() . "\n";
61+
}
62+
else
63+
{
64+
echo "ERROR : Invalid response\n";
65+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
66+
}
67+
68+
return $response;
6369
}
70+
71+
if(!defined(DONT_RUN_SAMPLES))
72+
createSubscription(23);
73+
6474
?>

RecurringBilling/get-list-of-subscriptions.php

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,50 @@
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
66

7-
// Common Set Up for API Credentials
8-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
9-
$merchantAuthentication->setName( "556KThWQ6vf2");
10-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
11-
12-
$refId = 'ref' . time();
13-
14-
$sorting = new AnetAPI\ARBGetSubscriptionListSortingType();
15-
$sorting->setOrderBy("id");
16-
$sorting->setOrderDescending("false");
17-
18-
$paging = new AnetAPI\PagingType();
19-
$paging->setLimit("1000");
20-
$paging->setOffset("1");
21-
22-
$request = new AnetAPI\ARBGetSubscriptionListRequest();
23-
$request->setMerchantAuthentication($merchantAuthentication);
24-
$request->setRefId($refId);
25-
$request->setSearchType("subscriptionInactive");
26-
$request->setSorting($sorting);
27-
$request->setPaging($paging);
28-
29-
30-
$controller = new AnetController\ARBGetSubscriptionListController($request);
31-
32-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
33-
34-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
35-
{
36-
echo "SUCCESS: Subscription Details:" . $response->getSubscriptionDetails() . "\n";
37-
echo "Total Number In Results:" . $response->getTotalNumInResultSet() . "\n";
38-
}
39-
else
40-
{
41-
echo "ERROR : Invalid response\n";
42-
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
43-
7+
function getListOfSubscriptions() {
8+
9+
// Common Set Up for API Credentials
10+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11+
$merchantAuthentication->setName( "556KThWQ6vf2");
12+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
13+
14+
$refId = 'ref' . time();
15+
16+
$sorting = new AnetAPI\ARBGetSubscriptionListSortingType();
17+
$sorting->setOrderBy("id");
18+
$sorting->setOrderDescending("false");
19+
20+
$paging = new AnetAPI\PagingType();
21+
$paging->setLimit("1000");
22+
$paging->setOffset("1");
23+
24+
$request = new AnetAPI\ARBGetSubscriptionListRequest();
25+
$request->setMerchantAuthentication($merchantAuthentication);
26+
$request->setRefId($refId);
27+
$request->setSearchType("subscriptionInactive");
28+
$request->setSorting($sorting);
29+
$request->setPaging($paging);
30+
31+
32+
$controller = new AnetController\ARBGetSubscriptionListController($request);
33+
34+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
35+
36+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
37+
{
38+
echo "SUCCESS: Subscription Details:" . $response->getSubscriptionDetails() . "\n";
39+
echo "Total Number In Results:" . $response->getTotalNumInResultSet() . "\n";
40+
}
41+
else
42+
{
43+
echo "ERROR : Invalid response\n";
44+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
45+
46+
}
47+
48+
return $response;
4449
}
45-
?>
50+
51+
if(!defined(DONT_RUN_SAMPLES))
52+
getListOfSubscriptions();
53+
?>

RecurringBilling/get-subscription-status.php

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,39 @@
44
use net\authorize\api\controller as AnetController;
55
define("AUTHORIZENET_LOG_FILE", "phplog");
66

7-
// Common Set Up for API Credentials
8-
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
9-
$merchantAuthentication->setName( "556KThWQ6vf2");
10-
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
11-
12-
$refId = 'ref' . time();
13-
14-
$request = new AnetAPI\ARBGetSubscriptionStatusRequest();
15-
$request->setMerchantAuthentication($merchantAuthentication);
16-
$request->setRefId($refId);
17-
$request->setSubscriptionId("100748");
18-
19-
$controller = new AnetController\ARBGetSubscriptionStatusController($request);
20-
21-
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
22-
23-
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
24-
{
25-
echo "SUCCESS: Subscription Status : " . $response->getStatus() . "\n";
26-
}
27-
else
28-
{
29-
echo "ERROR : Invalid response\n";
30-
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
31-
7+
function getSubscriptionStatus($subscriptionId) {
8+
9+
// Common Set Up for API Credentials
10+
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
11+
$merchantAuthentication->setName( "556KThWQ6vf2");
12+
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
13+
14+
$refId = 'ref' . time();
15+
16+
$request = new AnetAPI\ARBGetSubscriptionStatusRequest();
17+
$request->setMerchantAuthentication($merchantAuthentication);
18+
$request->setRefId($refId);
19+
$request->setSubscriptionId($subscriptionId);
20+
21+
$controller = new AnetController\ARBGetSubscriptionStatusController($request);
22+
23+
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
24+
25+
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok"))
26+
{
27+
echo "SUCCESS: Subscription Status : " . $response->getStatus() . "\n";
28+
}
29+
else
30+
{
31+
echo "ERROR : Invalid response\n";
32+
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
33+
34+
}
35+
36+
return $response;
3237
}
33-
?>
38+
39+
if(!defined(DONT_RUN_SAMPLES))
40+
getSubscriptionStatus("100748");
41+
42+
?>

0 commit comments

Comments
 (0)