-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPensioProcessorAPI.java
More file actions
211 lines (178 loc) · 9.13 KB
/
PensioProcessorAPI.java
File metadata and controls
211 lines (178 loc) · 9.13 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package com.pensio.api;
import java.util.HashMap;
import com.pensio.api.generated.APIResponse;
import com.pensio.api.request.*;
public class PensioProcessorAPI extends PensioAbstractAPI
{
public PensioProcessorAPI(String baseURL, String username, String password)
{
super(baseURL, username, password);
}
protected String getAppAPIPath()
{
return "processor/API/";
}
public APIResponse initiateGiftCardPayment(PaymentReservationRequest paymentRequest)
throws PensioAPIException
{
if(paymentRequest.getGiftCard() == null && paymentRequest.getGiftCardToken() == null)
{
throw new PensioAPIException("A gift card must be supplied");
}
return getAPIResponse("initiateGiftCardPayment", setBaseInitiateParams(paymentRequest));
}
public APIResponse initiatePaymentRequest(PaymentReservationRequest paymentRequest)
throws PensioAPIException
{
if(paymentRequest.getCreditCard() == null)
{
throw new PensioAPIException("A credit card must be supplied");
}
return getAPIResponse("initiatePayment", setBaseInitiateParams(paymentRequest));
}
/**
*
* @deprecated use {@link #reservation(PaymentReservationRequest)} instead
*/
@Deprecated
public APIResponse reservationOfFixedAmount(PaymentReservationRequest paymentRequest)
throws PensioAPIException
{
if(paymentRequest.getCreditCard() == null)
{
throw new PensioAPIException("A credit card must be supplied");
}
return getAPIResponse("reservationOfFixedAmount", setBaseInitiateParams(paymentRequest));
}
public APIResponse reservation(PaymentReservationRequest paymentRequest)
throws PensioAPIException
{
if(paymentRequest.getCreditCard() == null)
{
throw new PensioAPIException("A credit card must be supplied");
}
return getAPIResponse("reservation", setBaseInitiateParams(paymentRequest));
}
public APIResponse reservationOfFixedAmountAndCapture(PaymentReservationRequest paymentRequest)
throws PensioAPIException
{
if(paymentRequest.getCreditCard() == null)
{
throw new PensioAPIException("A credit card must be supplied");
}
HashMap<String, String> params = new HashMap<>();
commonParams(params, paymentRequest);
addParam(params, "type", AuthType.paymentAndCapture.toString());
return getAPIResponse("reservationOfFixedAmountAndCapture", params);
}
public APIResponse verify3dSecure(Verify3dRequest request)
throws PensioAPIException
{
HashMap<String, String> params = new HashMap<String, String>();
addParam(params, "transactionId", request.getTransactionId());
addParam(params, "3DSecureRegular[paRes]", request.getPaRes());
addParam(params, "3DSecureRegular[MD]", request.getTransactionId());
addParam(params, "3DSecureV2[3ds_data]", request.getThreeDSecureData());
return getAPIResponse("verify3dSecure", params);
}
public void addCustomerInfoParams(PaymentReservationRequest paymentRequest, HashMap<String, String> params)
{
CustomerInfo customerInfo = paymentRequest.getCustomerInfo();
addParam(params, "customer_info[email]", customerInfo.getEmail());
addParam(params, "customer_info[customer_phone]", customerInfo.getCustomerPhone());
addParam(params, "customer_info[username]", customerInfo.getUsername());
addParam(params, "customer_info[bank_name]", customerInfo.getBankName());
addParam(params, "customer_info[bank_phone]", customerInfo.getBankPhone());
addParam(params, "customer_info[client_ip]", customerInfo.getClientIp());
CustomerInfoAddress shippingAddress = customerInfo.getShippingAddress();
addParam(params, "customer_info[shipping_firstname]", shippingAddress.getFirstname());
addParam(params, "customer_info[shipping_lastname]", shippingAddress.getLastname());
addParam(params, "customer_info[shipping_address]", shippingAddress.getAddress());
addParam(params, "customer_info[shipping_city]", shippingAddress.getCity());
addParam(params, "customer_info[shipping_region]", shippingAddress.getRegion());
addParam(params, "customer_info[shipping_postal]", shippingAddress.getPostal());
addParam(params, "customer_info[shipping_country]", shippingAddress.getCountry());
CustomerInfoAddress billingAddress = customerInfo.getBillingAddress();
addParam(params, "customer_info[billing_firstname]", billingAddress.getFirstname());
addParam(params, "customer_info[billing_lastname]", billingAddress.getLastname());
addParam(params, "customer_info[billing_address]", billingAddress.getAddress());
addParam(params, "customer_info[billing_city]", billingAddress.getCity());
addParam(params, "customer_info[billing_region]", billingAddress.getRegion());
addParam(params, "customer_info[billing_postal]", billingAddress.getPostal());
addParam(params, "customer_info[billing_country]", billingAddress.getCountry());
addParam(params, "customer_info[device_id]", customerInfo.getDeviceId());
BrowserData browserData = customerInfo.getBrowserData();
addParam(params, "customer_info[client_time_zone]", browserData.getTimeZone());
addParam(params, "customer_info[client_javascript_enabled]", browserData.getJavascriptEnabled());
addParam(params, "customer_info[client_screen_width]", browserData.getScreenWidth());
addParam(params, "customer_info[client_screen_height]", browserData.getScreenHeight());
addParam(params, "customer_info[client_color_depth]", browserData.getColorDepth());
addParam(params, "customer_info[client_java_enabled]", browserData.getJavaEnabled());
addParam(params, "customer_info[client_forwarded_ip]", browserData.getForwardedIp());
addParam(params, "customer_info[client_user_agent]", browserData.getUserAgent());
addParam(params, "customer_info[client_accept]", browserData.getAccept());
addParam(params, "customer_info[client_accept_language]", browserData.getAcceptLanguage());
}
private HashMap<String, String> setBaseInitiateParams(PaymentReservationRequest paymentRequest)
{
HashMap<String, String> params = new HashMap<>();
commonParams(params, paymentRequest);
if (paymentRequest.getAuthType() != null)
{
addParam(params, "type", paymentRequest.getAuthType().name());
}
if (paymentRequest.getCustomerInfo() != null)
{
addCustomerInfoParams(paymentRequest, params);
}
return params;
}
public void commonParams(HashMap<String, String> params, PaymentReservationRequest paymentRequest)
{
addParam(params, "terminal", paymentRequest.getTerminal());
if(paymentRequest.getAmount() != null)
{
addParam(params, "amount", paymentRequest.getAmount().getAmountString());
addParam(params, "currency", paymentRequest.getAmount().getCurrency().name());
}
addParam(params, "shop_orderid", paymentRequest.getShopOrderId());
if(paymentRequest.getSource() != null)
{
addParam(params, "payment_source", paymentRequest.getSource().name());
}
if(paymentRequest.getCreditCard() != null)
{
addParam(params, "cardnum", paymentRequest.getCreditCard().getCardNumber());
addParam(params, "eyear", paymentRequest.getCreditCard().getExpiryYear());
addParam(params, "emonth", paymentRequest.getCreditCard().getExpiryMonth());
addParam(params, "cvc", paymentRequest.getCreditCard().getCvc());
addParam(params, "cardholderName", paymentRequest.getCardholderName());
addParam(params, "cardholderAddress", paymentRequest.getCardholderAddress());
addParam(params, "issueNumber", paymentRequest.getIssueNumber());
addParam(params, "startMonth", paymentRequest.getStartMonth());
addParam(params, "startYear", paymentRequest.getStartYear());
}
if(paymentRequest.getAgreementConfig() != null)
{
addParam(params, "agreement[id]", paymentRequest.getAgreementConfig().getAgreementId());
addParam(params, "agreement[type]", paymentRequest.getAgreementConfig().getAgreementType() != null ? paymentRequest.getAgreementConfig().getAgreementType().name() : null);
addParam(params, "agreement[unscheduled_type]", paymentRequest.getAgreementConfig().getAgreementUnscheduledType() != null ? paymentRequest.getAgreementConfig().getAgreementUnscheduledType().name() : null);
addParam(params, "agreement[expiry]", paymentRequest.getAgreementConfig().getAgreementExpiry() != null ? DateHelper.formatDate("yyyyMMdd", paymentRequest.getAgreementConfig().getAgreementExpiry()) : null);
addParam(params, "agreement[frequency]", paymentRequest.getAgreementConfig().getAgreementFrequency());
addParam(params, "agreement[next_charge_date]", paymentRequest.getAgreementConfig().getAgreementNextChargeDate() != null ? DateHelper.formatDate("yyyyMMdd", paymentRequest.getAgreementConfig().getAgreementNextChargeDate()) : null);
addParam(params, "agreement[admin_url]", paymentRequest.getAgreementConfig().getAgreementAdminUrl());
addParam(params, "agreement[retention_period]", paymentRequest.getAgreementConfig().getRetentionPeriod());
}
if(paymentRequest.getGiftCard() != null)
{
addParam(params, "giftcard[account_identifier]", paymentRequest.getGiftCard().getAccountIdentifier());
addParam(params, "giftcard[account_authenticator]", paymentRequest.getGiftCard().getAccountAuthenticator());
addParam(params, "giftcard[provider]", paymentRequest.getGiftCard().getProvider());
}
else
{
addParam(params, "giftcard[token]", paymentRequest.getGiftCardToken());
}
addParam(params, "payment_request_id", paymentRequest.getPaymentRequestId());
}
}