-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZoozAPIManager.cls
182 lines (168 loc) · 7.07 KB
/
ZoozAPIManager.cls
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
public class ZoozAPIManager {
//TODO: Refactor/Imporove wrapper farm
// TODO: manager can call commands with default tokens if flow is appropriate
public String CustomerToken {get; private set;}
public String PaymentMethodToken {get; private set;}
public PaymentResponseWrapper PaymentResponse {get;private set;}
public ZoozAPiManager(){
CustomerToken = '';
PaymentMethodToken = '';
PaymentResponse = new PaymentResponseWrapper();
}
/*
getToken request
API command: getToken
Description
The getToken request establishes a secure session with the Zooz server, and returns a customerToken
which represents a customer in the Zooz system. Merchants can use the getToken to add, verify, or
remove a credit card, or tokenize a credit card for future use
*/
public JsonResponseParser getToken(String customerLoginID,
String customerLoginName,
GetTokenZoozCommand.GetTokenCommandWrapper config){
JsonResponseParser result = new ZoozAPIRequest()
.send(new GetTokenZoozCommand()
.setCustomerDetailsConfig(config)
.setCustomerLoginID(customerLoginID)
.setCustomerLoginName(customerLoginName))
.getResponseMap();
if(Integer.valueOf(result.getValue('responseStatus')) == 0){
CustomerToken = result.getObject('responseObject').getValue('customerToken');//(String)((Map<String, Object>)((result.get('responseObject')))).get('customerToken');
System.debug('ZoozAPiManager.getToken - customerToken: ' + CustomerToken);
}else{
System.debug('ZoozAPiManager.getToken - customerToken: response status: -1');
}
return result;
}
public JsonResponseParser getToken(String customerLoginID, String customerLoginName){
return this.getToken(customerLoginID, customerLoginName, null);
}
/*
addPaymentMethod request (Server Side Request for PCI Compliant Merchants Only)
API command: addPaymentMethod
Description
To add a credit card to the existing payment methods, use the addPaymentMethod request.
*/
public JsonResponseParser addPaymentMethod(String expDate,
String cardNumber,
String cvvNumber,
String email,
String cardHolderName,
String paymentToken,
AddPaymentMethodZoozCommand.AddPaymentMethodCommandWrapper config){
JsonResponseParser result = new ZoozAPIRequest()
.send(new AddPaymentMethodZoozCommand()
.setPaymentMethodConfig(config)
.setExpirationDate(expDate)
.setCardNumber(cardNumber)
.setCvvNumber(cvvNumber)
.setEmail(email)
.setCardHolderName(cardHolderName)
.setpaymentToken(paymentToken))
.getResponseMap();
if(Integer.valueOf(result.getVAlue('responseStatus')) == 0){
PaymentMethodToken = result.getObject('responseObject').getValue('paymentMethodToken');//(String)((Map<String, Object>)((result.get('responseObject')))).get('paymentMethodToken');
System.debug('ZoozAPiManager.AddPaymentMethod - PaymentMethodToken: ' + PaymentMethodToken);
}else{
System.debug('ZoozAPiManager.AddPaymentMethod - PaymentMethodToken: response status: -1');
}
return result;
}
public JsonResponseParser addPaymentMethod(String expDate,
String cardNumber,
String cvvNumber,
String email,
String cardHolderName,
String paymentToken){
return this.addPaymentMethod(expDate, cardNumber, cvvNumber, email, cardHolderName, paymentToken, null);
}
/*
openPayment request
API command: openPayment
Description
The openPayment request is used to begin the payment process. This opens a request to the Zooz
server using a secure channel.
The openPayment request returns a unique paymentToken, that is used to initiate payments,
authorizations, refunds, voids, and identify the transaction for future actions, etc.
*/
public JsonResponseParser getPaymentDetails(String paymentToken){
JsonResponseParser result = new ZoozAPIRequest()
.send(new GetPaymentDetailsZoozCommand(paymentToken))
.getResponseMap();
if(Integer.valueOf(result.getVAlue('responseStatus')) == 0){
}else{
System.debug('ZoozAPiManager.AddPaymentMethod - PaymentMethodToken: response status: -1');
}
return result;
}
/*
openPayment request
API command: openPayment
Description
The openPayment request is used to begin the payment process. This opens a request to the Zooz
server using a secure channel.
The openPayment request returns a unique paymentToken, that is used to initiate payments,
authorizations, refunds, voids, and identify the transaction for future actions, etc.
*/
public JsonResponseParser openPayment(Decimal amount,
String customerLoginID,
OpenPaymentZoozCommand.OpenPaymentCommandWrapper config){
JsonResponseParser result = new ZoozAPIRequest()
.send(new OpenPaymentZoozCommand()
.setPaymentInfoConfig(config)
.setAmount(amount)
.setCustomerLoginID(customerLoginID))
.getResponseMap();
if(Integer.valueOf(result.getValue('responseStatus')) == 0){
JsonResponseParser resultTokens = result.getObject('responseObject');
PaymentResponse = new PaymentResponseWrapper(resultTokens.getValue('paymentId'), resultTokens.getValue('paymentToken'));//(PaymentResponseWrapper)JSON.deserialize(JSON.serialize(result.get('responseObject')), PaymentResponseWrapper.class);
System.debug('ZoozAPiManager.openPayment - PaymentResponse: ' + PaymentResponse);
}else{
System.debug('ZoozAPiManager.openPayment - PaymentResponse: response status: -1');
}
return result;
}
public JsonResponseParser openPayment(Decimal amount, String customerLoginID){
return this.openPayment(amount, customerLoginID, null);
}
/*
sale request
API command: sale
Description
This request authorizes and captures the specified amount for a specific credit card or another
payment source.
Params
paymentToken - token from openPayment request
paymentMethodToken - token from addPaymentMethod
*/
public JsonResponseParser sale(String paymentToken,
String paymentMethodToken,
SaleZoozCommand.SaleCommandWrapper config){
JsonResponseParser result = new ZoozAPIRequest()
.send(new SaleZoozCommand()
.setSaleInfoConfig(config)
.setPaymentToken(paymentToken)
.setPaymentMethodToken(paymentMethodToken))
.getResponseMap();
if(Integer.valueOf(result.getValue('responseStatus')) == 0){
System.debug('ZoozAPiManager.Sale - res: ' + result.getObject('responseObject') );
}else{
System.debug('ZoozAPiManager.Sale - res: response status: -1');
}
return result;
}
public JsonResponseParser sale(String paymentToken,
String paymentMethodToken){
return this.sale(paymentToken, paymentMethodToken, null);
}
public class PaymentResponseWrapper{
public String paymentId {get;set;}
public String paymentToken {get;set;}
public PaymentResponseWrapper(String paymentId, String paymentToken){
this.paymentId = paymentId;
this.paymentToken = paymentToken;
}
public PaymentResponseWrapper(){
}
}
}