forked from AuthorizeNet/sample-code-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-customer-profile.php
More file actions
105 lines (95 loc) · 4.65 KB
/
update-customer-profile.php
File metadata and controls
105 lines (95 loc) · 4.65 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
require 'vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
define("AUTHORIZENET_LOG_FILE", "phplog");
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName("556KThWQ6vf2");
$merchantAuthentication->setTransactionKey("9ac2932kQ7kN2Wzq");
$refId = 'ref' . time();
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber( "4111111111111111" );
$creditCard->setExpirationDate( "2038-12");
$paymentCreditCard = new AnetAPI\PaymentType();
$paymentCreditCard->setCreditCard($creditCard);
// Create the Bill To info
$billto = new AnetAPI\CustomerAddressType();
$billto->setFirstName("Ellen");
$billto->setLastName("Johnson");
$billto->setCompany("Souveniropolis");
$billto->setAddress("14 Main Street");
$billto->setCity("Pecan Springs");
$billto->setState("TX");
$billto->setZip("44628");
$billto->setCountry("USA");
// Create a Customer Profile Request
// 1. create a Payment Profile
// 2. create a Customer Profile
// 3. Submit a CreateCustomerProfile Request
// 4. Validate Profiiel ID returned
$paymentprofile = new AnetAPI\CustomerPaymentProfileType();
$paymentprofile->setCustomerType('individual');
$paymentprofile->setBillTo($billto);
$paymentprofile->setPayment($paymentCreditCard);
$paymentprofiles[] = $paymentprofile;
$customerprofile = new AnetAPI\CustomerProfileType();
$customerprofile->setDescription("Update Customer Profile Request Test for PHP");
$merchantCustomerId = time().rand(1,150);
$customerprofile->setMerchantCustomerId($merchantCustomerId);
$customerprofile->setEmail("customerprofile@domain.com");
$customerprofile->setPaymentProfiles($paymentprofiles);
$request = new AnetAPI\CreateCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setRefId( $refId);
$request->setProfile($customerprofile);
$controller = new AnetController\CreateCustomerProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo "SUCCESS: CreateCustomerProfile PROFILE ID : " . $response->getCustomerProfileId() . "\n";
$profileidcreated = $response->getCustomerProfileId();
}
else
{
echo "ERROR : CreateCustomerProfile: Invalid response\n";
}
// Update an existing customer profile
$updatecustomerprofile = new AnetAPI\CustomerProfileExType();
$updatecustomerprofile->setCustomerProfileId($profileidcreated);
$updatecustomerprofile->setDescription("Updated existing Profile Request");
$updatecustomerprofile->setEmail("updatecustomerprofile@domain.com");
$request = new AnetAPI\UpdateCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setProfile($updatecustomerprofile);
$controller = new AnetController\UpdateCustomerProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo "UpdateCustomerProfile SUCCESS : " . "\n";
// Validate the description and e-mail that was updated
$request = new AnetAPI\GetCustomerProfileRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setCustomerProfileId($profileidcreated );
$controller = new AnetController\GetCustomerProfileController($request);
$response = $controller->executeWithApiResponse( \net\authorize\api\constants\ANetEnvironment::SANDBOX);
if (($response != null) && ($response->getMessages()->getResultCode() == "Ok") )
{
echo "Get updated CustomerProfile SUCCESS : " . "\n";
$profileselected = $response->getProfile();
echo "Updated Customer Profile Customer description : " . $profileselected->getDescription() . "\n";
echo "Updated Customer Profile EMail description : " . $profileselected->getEmail() . "\n";
}
else
{
echo "ERROR : GetCustomerProfile: Invalid response\n";
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
}
}
else
{
echo "ERROR : UpdateCustomerProfile: Invalid response\n";
echo "Response : " . $response->getMessages()->getMessage()[0]->getCode() . " " .$response->getMessages()->getMessage()[0]->getText() . "\n";
}
?>