-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathCreateCustomerProfile.cs
More file actions
123 lines (103 loc) · 5.25 KB
/
CreateCustomerProfile.cs
File metadata and controls
123 lines (103 loc) · 5.25 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
using System;
using System.Collections.Generic;
using AuthorizeNet.Api.Controllers;
using AuthorizeNet.Api.Contracts.V1;
using AuthorizeNet.Api.Controllers.Bases;
namespace net.authorize.sample
{
public class CreateCustomerProfile
{
public static ANetApiResponse Run(string ApiLoginID, string ApiTransactionKey, string emailId)
{
Console.WriteLine("Create Customer Profile Sample");
// set whether to use the sandbox environment, or production enviornment
ApiOperationBase<ANetApiRequest, ANetApiResponse>.RunEnvironment = AuthorizeNet.Environment.SANDBOX;
// define the merchant information (authentication / transaction id)
ApiOperationBase<ANetApiRequest, ANetApiResponse>.MerchantAuthentication = new merchantAuthenticationType()
{
name = ApiLoginID,
ItemElementName = ItemChoiceType.transactionKey,
Item = ApiTransactionKey,
};
var creditCard = new creditCardType
{
cardNumber = "4111111111111111",
expirationDate = "1028"
};
var bankAccount = new bankAccountType
{
accountNumber = "231323342",
routingNumber = "000000224",
accountType = bankAccountTypeEnum.checking,
echeckType = echeckTypeEnum.WEB,
nameOnAccount = "test",
bankName = "Bank Of America"
};
// standard api call to retrieve response
paymentType cc = new paymentType { Item = creditCard };
paymentType echeck = new paymentType {Item = bankAccount};
List<customerPaymentProfileType> paymentProfileList = new List<customerPaymentProfileType>();
customerPaymentProfileType ccPaymentProfile = new customerPaymentProfileType();
ccPaymentProfile.payment = cc;
customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();
echeckPaymentProfile.payment = echeck;
paymentProfileList.Add(ccPaymentProfile);
paymentProfileList.Add(echeckPaymentProfile);
List<customerAddressType> addressInfoList = new List<customerAddressType>();
customerAddressType homeAddress = new customerAddressType();
homeAddress.address = "10900 NE 8th St";
homeAddress.city = "Seattle";
homeAddress.zip = "98006";
customerAddressType officeAddress = new customerAddressType();
officeAddress.address = "1200 148th AVE NE";
officeAddress.city = "NorthBend";
officeAddress.zip = "92101";
addressInfoList.Add(homeAddress);
addressInfoList.Add(officeAddress);
customerProfileType customerProfile = new customerProfileType();
customerProfile.merchantCustomerId = "Test CustomerID";
customerProfile.email = emailId;
customerProfile.paymentProfiles = paymentProfileList.ToArray();
customerProfile.shipToList = addressInfoList.ToArray();
var request = new createCustomerProfileRequest{ profile = customerProfile, validationMode = validationModeEnum.none};
// instantiate the controller that will call the service
var controller = new createCustomerProfileController(request);
controller.Execute();
// get the response from the service (errors contained if any)
createCustomerProfileResponse response = controller.GetApiResponse();
// validate response
if (response != null)
{
if (response.messages.resultCode == messageTypeEnum.Ok)
{
if(response.messages.message != null)
{
Console.WriteLine("Success!");
Console.WriteLine("Customer Profile ID: " + response.customerProfileId);
Console.WriteLine("Payment Profile ID: " + response.customerPaymentProfileIdList[0]);
Console.WriteLine("Shipping Profile ID: " + response.customerShippingAddressIdList[0]); }
}
else
{
Console.WriteLine("Customer Profile Creation Failed.");
Console.WriteLine("Error Code: " + response.messages.message[0].code);
Console.WriteLine("Error message: " + response.messages.message[0].text);
}
}
else
{
if (controller.GetErrorResponse()?.messages?.message != null && controller.GetErrorResponse().messages.message.Length > 0)
{
Console.WriteLine("Customer Profile Creation Failed.");
Console.WriteLine("Error Code: " + controller.GetErrorResponse().messages.message[0].code);
Console.WriteLine("Error message: " + controller.GetErrorResponse().messages.message[0].text);
}
else
{
Console.WriteLine("Null Response.");
}
}
return response;
}
}
}