-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathCreateCustomerProfileFromTransaction.java
83 lines (66 loc) · 3.66 KB
/
CreateCustomerProfileFromTransaction.java
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
package net.authorize.sample.CustomerProfiles;
import java.math.BigDecimal;
import java.math.RoundingMode;
import net.authorize.Environment;
import net.authorize.api.contract.v1.ANetApiResponse;
import net.authorize.api.contract.v1.CreateCustomerProfileFromTransactionRequest;
import net.authorize.api.contract.v1.CreateCustomerProfileResponse;
import net.authorize.api.contract.v1.CreateTransactionRequest;
import net.authorize.api.contract.v1.CreateTransactionResponse;
import net.authorize.api.contract.v1.CreditCardType;
import net.authorize.api.contract.v1.CustomerDataType;
import net.authorize.api.contract.v1.CustomerProfileBaseType;
import net.authorize.api.contract.v1.MerchantAuthenticationType;
import net.authorize.api.contract.v1.PaymentType;
import net.authorize.api.contract.v1.TransactionRequestType;
import net.authorize.api.controller.CreateCustomerProfileFromTransactionController;
import net.authorize.api.controller.CreateTransactionController;
import net.authorize.api.controller.base.ApiOperationBase;
import net.authorize.sample.SampleCodeTest.*;
public class CreateCustomerProfileFromTransaction {
public static ANetApiResponse run(String apiLoginId, String transactionKey, Double amount, 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("0621");
PaymentType paymentType = new PaymentType();
paymentType.setCreditCard(creditCard);
TransactionRequestType requestInternal = new TransactionRequestType();
requestInternal.setTransactionType("authOnlyTransaction");
requestInternal.setPayment(paymentType);
requestInternal.setAmount(new BigDecimal(amount).setScale(2, RoundingMode.CEILING));
CustomerDataType customer = new CustomerDataType();
customer.setEmail(email);
requestInternal.setCustomer(customer);
CreateTransactionRequest request = new CreateTransactionRequest();
request.setTransactionRequest(requestInternal);
CreateTransactionController controller = new CreateTransactionController(request);
controller.execute();
CreateTransactionResponse response = controller.getApiResponse();
CustomerProfileBaseType customerProfile = new CustomerProfileBaseType();
customerProfile.setMerchantCustomerId("123213");
customerProfile.setEmail("[email protected]");
customerProfile.setDescription("This is a sample customer profile");
CreateCustomerProfileFromTransactionRequest transaction_request = new CreateCustomerProfileFromTransactionRequest();
transaction_request.setTransId(response.getTransactionResponse().getTransId());
// You can either specify the customer information in form of customerProfileBaseType object
transaction_request.setCustomer(customerProfile);
// OR
// You can just provide the customer Profile ID
// transaction_request.setCustomerProfileId("1232132");
CreateCustomerProfileFromTransactionController createProfileController = new CreateCustomerProfileFromTransactionController(transaction_request);
createProfileController.execute();
CreateCustomerProfileResponse customer_response = createProfileController.getApiResponse();
if(customer_response != null) {
System.out.println(transaction_request.getTransId());
}
return customer_response;
}
}