-
Notifications
You must be signed in to change notification settings - Fork 0
/
Charge.java
171 lines (135 loc) · 3.96 KB
/
Charge.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
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
package com.gurpster.cordova.pagarme.mpos.entity;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.gurpster.cordova.pagarme.mpos.PaymentParameter;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.Locale;
import java.util.Map;
public class Charge extends PaymentParameter implements Serializable {
@JSONField(name = "amount")
protected String amount = "";
@JSONField(name = "card_hash")
private String cardHash = "";
@JSONField(name = "is_online")
private boolean isOnline;
@JSONField(name = "payment_method")
protected int paymentMethod;
@JSONField(name = "card_brand")
protected String cardBrand = "";
@JSONField(name = "encryption_key")
private String encryptionKey = "";
@JSONField(name = "remoteApi")
private RemoteApi remoteApi;
public Charge() {
}
public Charge(String cardHash, String amount, boolean isOnline) {
this.cardHash = cardHash;
this.amount = amount;
this.isOnline = isOnline;
}
public Charge(String cardHash, String amount, int clientId, int merchantId, boolean isOnline) {
this.cardHash = cardHash;
this.amount = amount;
this.isOnline = isOnline;
}
public String getCardHash() {
return cardHash.trim();
}
public void setCardHash(String cardHash) {
this.cardHash = cardHash;
}
public String getAmount() {
return amount.trim();
}
public void setAmount(String amount) {
this.amount = amount;
}
public boolean isOnline() {
return isOnline;
}
public void setOnline(boolean online) {
isOnline = online;
}
@Override
public int getPaymentMethod() {
return paymentMethod;
}
@Override
public void setPaymentMethod(int paymentMethod) {
this.paymentMethod = paymentMethod;
}
public String getCardBrand() {
return cardBrand;
}
public void setCardBrand(String cardBrand) {
this.cardBrand = cardBrand;
}
public String getEncryptionKey() {
return encryptionKey;
}
public void setEncryptionKey(String encryptionKey) {
this.encryptionKey = encryptionKey;
}
public RemoteApi getRemoteApi() {
return remoteApi;
}
public void setRemoteApi(RemoteApi remoteApi) {
this.remoteApi = remoteApi;
}
public JSONObject toJson() {
try {
String string = JSON.toJSONString(this);
return new JSONObject(string);
} catch (JSONException e) {
return null;
}
}
public int getAmountInt() {
return (int) (Float.parseFloat(amount) * 100);
}
public String getAmountFormatted() {
return String.format(
Locale.getDefault(),
"%.2f",
Float.parseFloat(amount)
);
}
public static class RemoteApi {
@JSONField(name = "type")
private String type;
@JSONField(name = "url")
private String url;
@JSONField(name = "headers")
private Map<String, String> headers;
@JSONField(name = "params")
private Map<String, String> params;
public RemoteApi() {
}
public String getType() {
return type.trim();
}
public void setType(String type) {
this.type = type;
}
public String getUrl() {
return url.trim();
}
public void setUrl(String url) {
this.url = url;
}
public Map<String, String> getHeaders() {
return headers;
}
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
public Map<String, String> getParams() {
return params;
}
public void setParams(Map<String, String> params) {
this.params = params;
}
}
}