forked from infusionsoft/API-Sample-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataService-Sample.php
More file actions
62 lines (53 loc) · 2.1 KB
/
DataService-Sample.php
File metadata and controls
62 lines (53 loc) · 2.1 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
<?php
###########################################################################################################
### Sample Created by Justin Morris on 7/9/08 ###
### In this Sample we will use the dataservice to create a credit card in Infusionsoft for a contact ###
###########################################################################################################
###Include our XMLRPC Library###
include("xmlrpc-2.0/lib/xmlrpc.inc");
###Set our Infusionsoft application as the client###
$client = new xmlrpc_client("https://mach2.infusionsoft.com/api/xmlrpc");
###Return Raw PHP Types###
$client->return_type = "phpvals";
###Dont bother with certificate verification###
$client->setSSLVerifyPeer(FALSE);
###Our API Key###
$key = "13643d3c8910057ce07623ed01bb22b2";
##############################################
### Our Function to add a credit card ###
##############################################
function addCard($CC) {
global $client, $key;
###Set up the call to add the card###
$call = new xmlrpcmsg("DataService.add", array(
php_xmlrpc_encode($key), #The encrypted API key
php_xmlrpc_encode("CreditCard"), #The table to add the record to.
php_xmlrpc_encode($CC), #The Credit Card Data
));
###Send the call###
$result = $client->send($call);
if(!$result->faultCode()) {
$cardID = $result->value();
print "Credit Card added - ID: " . $cardID;
print "<BR>";
} else {
print $result->faultCode() . "<BR>";
print $result->faultString() . "<BR>";
}
return $cardID;
}
###############################
### Build the card data ###
###############################
$card = array(
"ContactId" => 1300,
"NameOnCard" => "FirstName LastName",
"CardType" => "Visa", #Options are 'American Express','Discover', 'MasterCard', 'Visa'
"CardNumber" => "4111111111111111",
"ExpirationMonth" => "01", #must be MM
"ExpirationYear" => "2011", #must be YYYY
"CVV2" => "123",
);
### Create the card and store its returned ID ###
$CCID = addCard($card);
?>