-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.php
More file actions
153 lines (120 loc) · 3.94 KB
/
example.php
File metadata and controls
153 lines (120 loc) · 3.94 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* Example for PHP 5 class to assist with
* Authorize.net Customer Information Manager (CIM)
*
* Requires cURL and SimpleXML extensions in PHP 5
*
* Version 0.4 on 29 Dec 2010
* By Chris Blay (chris@meosphere.com, chris.b.blay@gmail.com)
* Copyright (c) 2010 Meosphere (http://meosphere.com, http://meolabs.com)
*
* License: http://www.gnu.org/licenses/lgpl-3.0.txt
* Website: http://github.com/chris-blay/PHP-5-AuthDotNetCIM-Class
*
* Please keep this header information here
*
*/
require_once('AuthDotNetCIM.class.php');
try {
// instantiate the class in test mode
// XXX you'll need to change 'api_auth_id' and 'transaction_key'
$cim = new AuthDotNetCIM('api_auth_id', 'transaction_key', array(
'test_mode' => true, # optional, default: false
'debug_mode' => false, # optional, default: false
'direct_response_separator' => '|', # optional, default: '|'
));
// just call the method you want and pass in an array
// with your parameters
// see http://www.authorize.net/support/CIM_XML_guide.pdf
// for information about what methods are available and
// what parameters are required/accepted
// a SimpleXMLElement object is returned that has shortcuts
// for the result code and directResponse values along
// with everything else sent back. it can be inspected
// via debug mode
// if an error occured then a standard exception is thrown
// as seen below
// you can change debug_mode and direct_response_separator
// via their respective public properties
// test creating customer profile
echo "Attempting to create a customer profile...\n";
$result = $cim->createCustomerProfile(array(
'profile' => array(
'merchantCustomerId' => rand(1000000, 100000000),
'paymentProfiles' => array(
'billTo' => array(
'firstName' => 'John',
'lastName' => 'Doe',
'address' => '1234 Street',
'city' => 'Seattle',
'state' => 'WA',
'zip' => '98101',
),
'payment' => array(
'creditCard' => array(
'cardNumber' => '4111111111111111',
'expirationDate' => '2025-01',
),
),
),
),
));
if ($result->ok) {
echo "Created customer profile {$result->customerProfileId}\n\n";
} else {
echo "Error creating customer profile :(\n";
var_dump($result);
die("\n");
}
$customerProfileId = (string) $result->customerProfileId;
// test getting customer profile id
echo "Attempting to get customer profile...\n";
$result = $cim->getCustomerProfile(array(
'customerProfileId' => $customerProfileId,
));
if ($result->ok) {
echo "Got customer profile $customerProfileId\n\n";
} else {
echo "Error getting customer profile $customerProfileId\n";
var_dump($result);
die("\n");
}
$customerPaymentProfileId =
(string) $result->profile->paymentProfiles->customerPaymentProfileId;
// test customer profile transaction
// notice that the class automatically parses the directResponse property
// into a more manageable 'response' property
echo "Attempting to create transaction...\n";
$result = $cim->createCustomerProfileTransaction(array(
'transaction' => array(
'profileTransAuthOnly' => array(
'amount' => '0.01',
'customerProfileId' => $customerProfileId,
'customerPaymentProfileId' => $customerPaymentProfileId,
),
),
));
if ($result->ok) {
echo "Created customer profile transaction ".
"{$result->response->transactionId}\n\n";
} else {
echo "Error creating customer profile transaction\n";
var_dump($result);
die("\n");
}
// test deleting customer profile
echo "Attempting to delete customer profile...\n";
$result = $cim->deleteCustomerProfile(array(
'customerProfileId' => $customerProfileId,
));
if ($result->ok) {
echo "Deleted customer profile $customerProfileId\n\n";
} else {
echo "Error deleting customer profile $customerProfileId\n";
var_dump($result);
die("\n");
}
} catch (Exception $ex) {
echo 'Caught an exception: ' . $ex->getMessage() . "\n\n";
}