-
Notifications
You must be signed in to change notification settings - Fork 459
Expand file tree
/
Copy pathCreateCustomerProfile.java
More file actions
67 lines (54 loc) · 3.02 KB
/
CreateCustomerProfile.java
File metadata and controls
67 lines (54 loc) · 3.02 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
package net.authorize.sample.CustomerProfiles;
import net.authorize.Environment;
import net.authorize.sample.SampleCodeTest.*;
import net.authorize.api.contract.v1.*;
import java.math.BigDecimal;
import net.authorize.api.controller.CreateCustomerProfileController;
import net.authorize.api.controller.base.ApiOperationBase;
public class CreateCustomerProfile {
public static ANetApiResponse run(String apiLoginId, String transactionKey, String eMail) {
if ( null == ApiOperationBase.getEnvironment() )
{
ApiOperationBase.setEnvironment(Environment.SANDBOX);
}
MerchantAuthenticationType merchantAuthenticationType = new MerchantAuthenticationType() ;
merchantAuthenticationType.setName(apiLoginId);
merchantAuthenticationType.setTransactionKey(transactionKey);
ApiOperationBase.setMerchantAuthentication(merchantAuthenticationType);
CreditCardType creditCard = new CreditCardType();
creditCard.setCardNumber("4111111111111111");
creditCard.setExpirationDate("1220");
PaymentType paymentType = new PaymentType();
paymentType.setCreditCard(creditCard);
CustomerPaymentProfileType customerPaymentProfileType = new CustomerPaymentProfileType();
customerPaymentProfileType.setCustomerType(CustomerTypeEnum.INDIVIDUAL);
customerPaymentProfileType.setPayment(paymentType);
CustomerProfileType customerProfileType = new CustomerProfileType();
customerProfileType.setMerchantCustomerId("M_" + eMail);
customerProfileType.setDescription("Profile description for " + eMail);
customerProfileType.setEmail(eMail);
customerProfileType.getPaymentProfiles().add(customerPaymentProfileType);
CreateCustomerProfileRequest apiRequest = new CreateCustomerProfileRequest();
apiRequest.setProfile(customerProfileType);
apiRequest.setValidationMode(ValidationModeEnum.TEST_MODE);
CreateCustomerProfileController controller = new CreateCustomerProfileController(apiRequest);
controller.execute();
CreateCustomerProfileResponse response = controller.getApiResponse();
if (response!=null) {
if (response.getMessages().getResultCode() == MessageTypeEnum.OK) {
System.out.println(response.getCustomerProfileId());
if(!response.getCustomerPaymentProfileIdList().getNumericString().isEmpty())
System.out.println(response.getCustomerPaymentProfileIdList().getNumericString().get(0));
if(!response.getCustomerShippingAddressIdList().getNumericString().isEmpty())
System.out.println(response.getCustomerShippingAddressIdList().getNumericString().get(0));
if(!response.getValidationDirectResponseList().getString().isEmpty())
System.out.println(response.getValidationDirectResponseList().getString().get(0));
}
else
{
System.out.println("Failed to create customer profile: " + response.getMessages().getResultCode());
}
}
return response;
}
}