66
77 define ("AUTHORIZENET_LOG_FILE " , "phplog " );
88
9- function updateCustomerPaymentProfile ($ customerProfileId = "36731856 " ,
10- $ customerPaymentProfileId = "33211899 "
11- ) {
9+ function updateCustomerPaymentProfile ($ customerProfileId = "1916322670 " ,
10+ $ customerPaymentProfileId = "1829639667 " )
11+ {
1212 /* Create a merchantAuthenticationType object with authentication details
1313 retrieved from the constants file */
1414 $ merchantAuthentication = new AnetAPI \MerchantAuthenticationType ();
@@ -18,87 +18,77 @@ function updateCustomerPaymentProfile($customerProfileId = "36731856",
1818 // Set the transaction's refId
1919 $ refId = 'ref ' . time ();
2020
21- //Set profile ids of profile to be updated
22- $ request = new AnetAPI \UpdateCustomerPaymentProfileRequest ();
23- $ request ->setMerchantAuthentication ($ merchantAuthentication );
24- $ request ->setCustomerProfileId ($ customerProfileId );
25- $ controller = new AnetController \GetCustomerProfileController ($ request );
26-
27-
28- // We're updating the billing address but everything has to be passed in an update
29- // For card information you can pass exactly what comes back from an GetCustomerPaymentProfile
30- // if you don't need to update that info
31- $ creditCard = new AnetAPI \CreditCardType ();
32- $ creditCard ->setCardNumber ( "4111111111111111 " );
33- $ creditCard ->setExpirationDate ("2038-12 " );
34- $ paymentCreditCard = new AnetAPI \PaymentType ();
35- $ paymentCreditCard ->setCreditCard ($ creditCard );
36-
37- // Create the Bill To info for new payment type
38- $ billto = new AnetAPI \CustomerAddressType ();
39- $ billto ->setFirstName ("Mrs Mary " );
40- $ billto ->setLastName ("Doe " );
41- $ billto ->setAddress ("1 New St. " );
42- $ billto ->setCity ("Brand New City " );
43- $ billto ->setState ("WA " );
44- $ billto ->setZip ("98004 " );
45- $ billto ->setPhoneNumber ("000-000-0000 " );
46- $ billto ->setfaxNumber ("999-999-9999 " );
47- $ billto ->setCountry ("USA " );
21+ $ request = new AnetAPI \GetCustomerPaymentProfileRequest ();
22+ $ request ->setMerchantAuthentication ($ merchantAuthentication );
23+ $ request ->setRefId ( $ refId );
24+ $ request ->setCustomerProfileId ($ customerProfileId );
25+ $ request ->setCustomerPaymentProfileId ($ customerPaymentProfileId );
4826
27+ $ controller = new AnetController \GetCustomerPaymentProfileController ($ request );
28+ $ response = $ controller ->executeWithApiResponse ( \net \authorize \api \constants \ANetEnvironment::SANDBOX );
29+ if (($ response != null ) && ($ response ->getMessages ()->getResultCode () == "Ok " ))
30+ {
31+ $ billto = new AnetAPI \CustomerAddressType ();
32+ $ billto = $ response ->getPaymentProfile ()->getbillTo ();
33+
34+ $ creditCard = new AnetAPI \CreditCardType ();
35+ $ creditCard ->setCardNumber ( "4111111111111111 " );
36+ $ creditCard ->setExpirationDate ("2038-12 " );
37+
38+ $ paymentCreditCard = new AnetAPI \PaymentType ();
39+ $ paymentCreditCard ->setCreditCard ($ creditCard );
40+ $ paymentprofile = new AnetAPI \CustomerPaymentProfileExType ();
41+ $ paymentprofile ->setBillTo ($ billto );
42+ $ paymentprofile ->setCustomerPaymentProfileId ($ customerPaymentProfileId );
43+ $ paymentprofile ->setPayment ($ paymentCreditCard );
4944
50- // Create the Customer Payment Profile object
51- $ paymentprofile = new AnetAPI \CustomerPaymentProfileExType ();
52- $ paymentprofile ->setCustomerPaymentProfileId ($ customerPaymentProfileId );
53- $ paymentprofile ->setBillTo ($ billto );
54- $ paymentprofile ->setPayment ($ paymentCreditCard );
45+ // We're updating the billing address but everything has to be passed in an update
46+ // For card information you can pass exactly what comes back from an GetCustomerPaymentProfile
47+ // if you don't need to update that info
48+
49+ // Update the Bill To info for new payment type
50+ $ billto ->setFirstName ("Mrs Mary " );
51+ $ billto ->setLastName ("Doe " );
52+ $ billto ->setAddress ("9 New St. " );
53+ $ billto ->setCity ("Brand New City " );
54+ $ billto ->setState ("WA " );
55+ $ billto ->setZip ("98004 " );
56+ $ billto ->setPhoneNumber ("000-000-0000 " );
57+ $ billto ->setfaxNumber ("999-999-9999 " );
58+ $ billto ->setCountry ("USA " );
59+
60+ // Update the Customer Payment Profile object
61+ $ paymentprofile ->setBillTo ($ billto );
5562
56- // Submit a UpdatePaymentProfileRequest
57- $ request ->setPaymentProfile ( $ paymentprofile );
63+ // Submit a UpdatePaymentProfileRequest
64+ $ request = new AnetAPI \UpdateCustomerPaymentProfileRequest ();
65+ $ request ->setMerchantAuthentication ($ merchantAuthentication );
66+ $ request ->setCustomerProfileId ($ customerProfileId );
67+ $ request ->setPaymentProfile ( $ paymentprofile );
5868
59- $ controller = new AnetController \UpdateCustomerPaymentProfileController ($ request );
60- $ response = $ controller ->executeWithApiResponse ( \net \authorize \api \constants \ANetEnvironment::SANDBOX );
61- if (($ response != null ) && ($ response ->getMessages ()->getResultCode () == "Ok " ) )
62- {
63- echo "Update Customer Payment Profile SUCCESS: " . "\n" ;
64-
65- // Update only returns success or fail, if success
66- // confirm the update by doing a GetCustomerPaymentProfile
67- $ getRequest = new AnetAPI \GetCustomerPaymentProfileRequest ();
68- $ getRequest ->setMerchantAuthentication ($ merchantAuthentication );
69- $ getRequest ->setRefId ( $ refId );
70- $ getRequest ->setCustomerProfileId ($ customerProfileId );
71- $ getRequest ->setCustomerPaymentProfileId ($ customerPaymentProfileId );
69+ $ controller = new AnetController \UpdateCustomerPaymentProfileController ($ request );
70+ $ response = $ controller ->executeWithApiResponse ( \net \authorize \api \constants \ANetEnvironment::SANDBOX );
71+ if (($ response != null ) && ($ response ->getMessages ()->getResultCode () == "Ok " ) )
72+ {
73+ $ Message = $ response ->getMessages ()->getMessage ();
74+ print_r ($ response );
75+ echo "Update Customer Payment Profile SUCCESS: " . $ Message [0 ]->getCode () . " " .$ Message [0 ]->getText () . "\n" ;
76+ }
77+ else
78+ {
79+ echo "Failed to Update Customer Payment Profile : " . $ errorMessages [0 ]->getCode () . " " .$ errorMessages [0 ]->getText () . "\n" ;
80+ }
81+
82+ return $ response ;
83+ }
84+ else
85+ {
86+ echo "Failed to Get Customer Payment Profile : " . $ errorMessages [0 ]->getCode () . " " .$ errorMessages [0 ]->getText () . "\n" ;
87+ }
7288
73- $ controller = new AnetController \GetCustomerPaymentProfileController ($ getRequest );
74- $ response = $ controller ->executeWithApiResponse ( \net \authorize \api \constants \ANetEnvironment::SANDBOX );
75- if (($ response != null )){
76- if ($ response ->getMessages ()->getResultCode () == "Ok " )
77- {
78- echo "GetCustomerPaymentProfile SUCCESS: " . "\n" ;
79- echo "Customer Payment Profile Id: " . $ response ->getPaymentProfile ()->getCustomerPaymentProfileId () . "\n" ;
80- echo "Customer Payment Profile Billing Address: " . $ response ->getPaymentProfile ()->getbillTo ()->getAddress (). "\n" ;
81- }
82- else
83- {
84- echo "GetCustomerPaymentProfile ERROR : Invalid response \n" ;
85- $ errorMessages = $ response ->getMessages ()->getMessage ();
86- echo "Response : " . $ errorMessages [0 ]->getCode () . " " .$ errorMessages [0 ]->getText () . "\n" ;
87- }
88- }
89- else {
90- echo "NULL Response Error " ;
91- }
89+ return $ response ;
90+ }
9291
93- }
94- else
95- {
96- echo "Update Customer Payment Profile: ERROR Invalid response \n" ;
97- $ errorMessages = $ response ->getMessages ()->getMessage ();
98- echo "Response : " . $ errorMessages [0 ]->getCode () . " " .$ errorMessages [0 ]->getText () . "\n" ;
99- }
100- return $ response ;
101- }
102- if (!defined ('DONT_RUN_SAMPLES ' ))
103- updateCustomerPaymentProfile ();
92+ if (!defined ('DONT_RUN_SAMPLES ' ))
93+ updateCustomerPaymentProfile ();
10494?>
0 commit comments