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+ 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 " );
11+
12+ $ refId = 'ref ' . time ();
13+
14+ // Subscription Type Info
15+ $ subscription = new AnetAPI \ARBSubscriptionType ();
16+ $ subscription ->setName ("Sample Subscription " );
17+
18+ $ interval = new AnetAPI \PaymentScheduleType \IntervalAType ();
19+ $ interval ->setLength ("1 " );
20+ $ interval ->setUnit ("months " );
21+
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 " );
27+
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 " );
35+
36+ $ payment = new AnetAPI \PaymentType ();
37+ $ payment ->setCreditCard ($ creditCard );
38+
39+ $ subscription ->setPayment ($ payment );
40+
41+ $ billTo = new AnetAPI \NameAndAddressType ();
42+ $ billTo ->setFirstName ("John " );
43+ $ billTo ->setLastName ("Smith " );
44+
45+ $ subscription ->setBillTo ($ billTo );
46+
47+ $ request = new AnetAPI \ARBCreateSubscriptionRequest ();
48+ $ request ->setmerchantAuthentication ($ merchantAuthentication );
49+ $ request ->setRefId ($ refId );
50+ $ request ->setSubscription ($ subscription );
51+ $ controller = new AnetController \ARBCreateSubscriptionController ($ request );
52+
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" ;
63+ }
64+ ?>
0 commit comments