@capawesome/capacitor-square-mobile-payments 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorSquareMobilePayments.podspec +17 -0
- package/Package.swift +30 -0
- package/README.md +1183 -0
- package/android/build.gradle +63 -0
- package/android/src/main/AndroidManifest.xml +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/SquareMobilePayments.java +774 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/SquareMobilePaymentsPlugin.java +460 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/CustomExceptions.java +41 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/AvailableCardInputMethodsDidChangeEvent.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/PaymentDidCancelEvent.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/PaymentDidFailEvent.java +34 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/PaymentDidFinishEvent.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/ReaderDidChangeEvent.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/ReaderPairingDidFailEvent.java +28 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/ReaderWasAddedEvent.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/events/ReaderWasRemovedEvent.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/AuthorizeOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/ForgetReaderOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/InitializeOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/Money.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/PaymentParameters.java +126 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/PromptParameters.java +47 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/RetryConnectionOptions.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/options/StartPaymentOptions.java +39 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/Card.java +51 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/CardPaymentDetails.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/GetAvailableCardInputMethodsResult.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/GetReadersResult.java +29 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/GetSettingsResult.java +28 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/IsAuthorizedResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/IsPairingInProgressResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/MoneyResult.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/Payment.java +87 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/ReaderInfo.java +82 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/classes/results/UnavailableReasonInfo.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/interfaces/NonEmptyCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/squaremobilepayments/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +2999 -0
- package/dist/esm/definitions.d.ts +1468 -0
- package/dist/esm/definitions.js +519 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +21 -0
- package/dist/esm/web.js +55 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +588 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +591 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Options/AuthorizeOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/ForgetReaderOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/InitializeOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/Money.swift +12 -0
- package/ios/Plugin/Classes/Options/PaymentParameters.swift +49 -0
- package/ios/Plugin/Classes/Options/PromptParameters.swift +17 -0
- package/ios/Plugin/Classes/Options/RetryConnectionOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/StartPaymentOptions.swift +19 -0
- package/ios/Plugin/Classes/Results/Card.swift +34 -0
- package/ios/Plugin/Classes/Results/CardPaymentDetails.swift +34 -0
- package/ios/Plugin/Classes/Results/GetAvailableCardInputMethodsResult.swift +16 -0
- package/ios/Plugin/Classes/Results/GetReadersResult.swift +16 -0
- package/ios/Plugin/Classes/Results/GetSettingsResult.swift +19 -0
- package/ios/Plugin/Classes/Results/IsAuthorizedResult.swift +16 -0
- package/ios/Plugin/Classes/Results/IsPairingInProgressResult.swift +16 -0
- package/ios/Plugin/Classes/Results/MoneyResult.swift +19 -0
- package/ios/Plugin/Classes/Results/Payment.swift +58 -0
- package/ios/Plugin/Classes/Results/ReaderInfo.swift +46 -0
- package/ios/Plugin/Classes/Results/UnavailableReasonInfo.swift +19 -0
- package/ios/Plugin/Enums/CustomError.swift +81 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Protocols/Result.swift +6 -0
- package/ios/Plugin/SquareMobilePayments.swift +632 -0
- package/ios/Plugin/SquareMobilePaymentsHelper.swift +212 -0
- package/ios/Plugin/SquareMobilePaymentsPlugin.swift +347 -0
- package/package.json +93 -0
|
@@ -0,0 +1,774 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments;
|
|
2
|
+
|
|
3
|
+
import android.app.Application;
|
|
4
|
+
import androidx.annotation.NonNull;
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
import com.getcapacitor.JSObject;
|
|
7
|
+
import com.squareup.sdk.mobilepayments.MobilePaymentsSdk;
|
|
8
|
+
import com.squareup.sdk.mobilepayments.authorization.AuthorizationManager;
|
|
9
|
+
import com.squareup.sdk.mobilepayments.cardreader.CardEntryMethod;
|
|
10
|
+
import com.squareup.sdk.mobilepayments.cardreader.ReaderChangedEvent;
|
|
11
|
+
import com.squareup.sdk.mobilepayments.cardreader.ReaderInfo;
|
|
12
|
+
import com.squareup.sdk.mobilepayments.cardreader.ReaderManager;
|
|
13
|
+
import com.squareup.sdk.mobilepayments.core.CallbackReference;
|
|
14
|
+
import com.squareup.sdk.mobilepayments.payment.AdditionalPaymentMethod;
|
|
15
|
+
import com.squareup.sdk.mobilepayments.payment.Card;
|
|
16
|
+
import com.squareup.sdk.mobilepayments.payment.CardPaymentDetails;
|
|
17
|
+
import com.squareup.sdk.mobilepayments.payment.CurrencyCode;
|
|
18
|
+
import com.squareup.sdk.mobilepayments.payment.DelayAction;
|
|
19
|
+
import com.squareup.sdk.mobilepayments.payment.Money;
|
|
20
|
+
import com.squareup.sdk.mobilepayments.payment.Payment;
|
|
21
|
+
import com.squareup.sdk.mobilepayments.payment.PaymentHandle;
|
|
22
|
+
import com.squareup.sdk.mobilepayments.payment.PaymentManager;
|
|
23
|
+
import com.squareup.sdk.mobilepayments.payment.PaymentParameters;
|
|
24
|
+
import com.squareup.sdk.mobilepayments.payment.ProcessingMode;
|
|
25
|
+
import com.squareup.sdk.mobilepayments.payment.PromptMode;
|
|
26
|
+
import com.squareup.sdk.mobilepayments.payment.PromptParameters;
|
|
27
|
+
import com.squareup.sdk.mobilepayments.settings.Environment;
|
|
28
|
+
import com.squareup.sdk.mobilepayments.settings.SdkSettings;
|
|
29
|
+
import com.squareup.sdk.mobilepayments.settings.SettingsManager;
|
|
30
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.CustomExceptions;
|
|
31
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events.*;
|
|
32
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.options.*;
|
|
33
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.*;
|
|
34
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.interfaces.*;
|
|
35
|
+
import java.time.Duration;
|
|
36
|
+
import java.util.ArrayList;
|
|
37
|
+
import java.util.List;
|
|
38
|
+
import java.util.Set;
|
|
39
|
+
import java.util.stream.Collectors;
|
|
40
|
+
|
|
41
|
+
public class SquareMobilePayments {
|
|
42
|
+
|
|
43
|
+
@NonNull
|
|
44
|
+
private final SquareMobilePaymentsPlugin plugin;
|
|
45
|
+
|
|
46
|
+
private boolean isInitialized = false;
|
|
47
|
+
private boolean isAuthorized = false;
|
|
48
|
+
|
|
49
|
+
@Nullable
|
|
50
|
+
private Object pairingHandle;
|
|
51
|
+
|
|
52
|
+
@Nullable
|
|
53
|
+
private PaymentHandle paymentHandle;
|
|
54
|
+
|
|
55
|
+
@Nullable
|
|
56
|
+
private CallbackReference readerChangedCallbackReference;
|
|
57
|
+
|
|
58
|
+
@Nullable
|
|
59
|
+
private CallbackReference availableCardInputMethodsCallbackReference;
|
|
60
|
+
|
|
61
|
+
public SquareMobilePayments(@NonNull SquareMobilePaymentsPlugin plugin) {
|
|
62
|
+
this.plugin = plugin;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private String locationId;
|
|
66
|
+
|
|
67
|
+
public void initialize(@NonNull InitializeOptions options, @NonNull EmptyCallback callback) {
|
|
68
|
+
try {
|
|
69
|
+
this.locationId = options.getLocationId();
|
|
70
|
+
Application application = (Application) plugin.getContext().getApplicationContext();
|
|
71
|
+
|
|
72
|
+
MobilePaymentsSdk.initialize(locationId, application);
|
|
73
|
+
|
|
74
|
+
isInitialized = true;
|
|
75
|
+
callback.success();
|
|
76
|
+
} catch (Exception exception) {
|
|
77
|
+
callback.error(exception);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public void authorize(@NonNull AuthorizeOptions options, @NonNull EmptyCallback callback) {
|
|
82
|
+
try {
|
|
83
|
+
if (!isInitialized) {
|
|
84
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
String accessToken = options.getAccessToken();
|
|
88
|
+
|
|
89
|
+
AuthorizationManager authManager = MobilePaymentsSdk.authorizationManager();
|
|
90
|
+
authManager.authorize(accessToken, locationId, result -> {
|
|
91
|
+
if (result.isSuccess()) {
|
|
92
|
+
isAuthorized = true;
|
|
93
|
+
callback.success();
|
|
94
|
+
} else {
|
|
95
|
+
callback.error(new Exception(result.errorMessage()));
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
} catch (Exception exception) {
|
|
99
|
+
callback.error(exception);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public void isAuthorized(@NonNull NonEmptyResultCallback<IsAuthorizedResult> callback) {
|
|
104
|
+
try {
|
|
105
|
+
if (!isInitialized) {
|
|
106
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
AuthorizationManager authManager = MobilePaymentsSdk.authorizationManager();
|
|
110
|
+
boolean authorized = authManager.getAuthorizationState().isAuthorized();
|
|
111
|
+
|
|
112
|
+
IsAuthorizedResult result = new IsAuthorizedResult(authorized);
|
|
113
|
+
callback.success(result);
|
|
114
|
+
} catch (Exception exception) {
|
|
115
|
+
callback.error(exception);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public void deauthorize(@NonNull EmptyCallback callback) {
|
|
120
|
+
try {
|
|
121
|
+
if (!isInitialized) {
|
|
122
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
AuthorizationManager authManager = MobilePaymentsSdk.authorizationManager();
|
|
126
|
+
authManager.deauthorize();
|
|
127
|
+
isAuthorized = false;
|
|
128
|
+
callback.success();
|
|
129
|
+
} catch (Exception exception) {
|
|
130
|
+
callback.error(exception);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public void showSettings(@NonNull EmptyCallback callback) {
|
|
135
|
+
try {
|
|
136
|
+
if (!isInitialized) {
|
|
137
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
138
|
+
}
|
|
139
|
+
if (!isAuthorized) {
|
|
140
|
+
throw CustomExceptions.NOT_AUTHORIZED;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
SettingsManager settingsManager = MobilePaymentsSdk.settingsManager();
|
|
144
|
+
settingsManager.showSettings(result -> {
|
|
145
|
+
if (result.isSuccess()) {
|
|
146
|
+
callback.success();
|
|
147
|
+
} else {
|
|
148
|
+
callback.error(new Exception(result.errorMessage()));
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
});
|
|
152
|
+
} catch (Exception exception) {
|
|
153
|
+
callback.error(exception);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public void getSettings(@NonNull NonEmptyResultCallback<GetSettingsResult> callback) {
|
|
158
|
+
try {
|
|
159
|
+
if (!isInitialized) {
|
|
160
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
SettingsManager settingsManager = MobilePaymentsSdk.settingsManager();
|
|
164
|
+
SdkSettings sdkSettings = settingsManager.getSdkSettings();
|
|
165
|
+
|
|
166
|
+
String version = sdkSettings.getSdkVersion();
|
|
167
|
+
String environment = convertSdkEnvironmentToString(sdkSettings.getSdkEnvironment());
|
|
168
|
+
|
|
169
|
+
GetSettingsResult result = new GetSettingsResult(version, environment);
|
|
170
|
+
callback.success(result);
|
|
171
|
+
} catch (Exception exception) {
|
|
172
|
+
callback.error(exception);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public void startPairing(@NonNull EmptyCallback callback) {
|
|
177
|
+
try {
|
|
178
|
+
if (!isInitialized) {
|
|
179
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
180
|
+
}
|
|
181
|
+
if (!isAuthorized) {
|
|
182
|
+
throw CustomExceptions.NOT_AUTHORIZED;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
ReaderManager readerManager = MobilePaymentsSdk.readerManager();
|
|
186
|
+
|
|
187
|
+
if (readerManager.isPairingInProgress()) {
|
|
188
|
+
throw CustomExceptions.PAIRING_ALREADY_IN_PROGRESS;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Notify that pairing has begun
|
|
192
|
+
plugin.notifyReaderPairingDidBeginListeners();
|
|
193
|
+
|
|
194
|
+
pairingHandle = readerManager.pairReader(result -> {
|
|
195
|
+
if (result.isSuccess()) {
|
|
196
|
+
// Notify that pairing succeeded
|
|
197
|
+
plugin.notifyReaderPairingDidSucceedListeners();
|
|
198
|
+
} else {
|
|
199
|
+
// Notify that pairing failed
|
|
200
|
+
ReaderPairingDidFailEvent event = new ReaderPairingDidFailEvent(
|
|
201
|
+
result.errorCode() != null ? result.errorCode().toString() : null,
|
|
202
|
+
result.errorMessage()
|
|
203
|
+
);
|
|
204
|
+
plugin.notifyReaderPairingDidFailListeners(event);
|
|
205
|
+
}
|
|
206
|
+
pairingHandle = null;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
callback.success();
|
|
210
|
+
} catch (Exception exception) {
|
|
211
|
+
callback.error(exception);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public void stopPairing(@NonNull EmptyCallback callback) {
|
|
216
|
+
try {
|
|
217
|
+
if (!isInitialized) {
|
|
218
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (pairingHandle != null) {
|
|
222
|
+
try {
|
|
223
|
+
pairingHandle.getClass().getMethod("stop").invoke(pairingHandle);
|
|
224
|
+
} catch (Exception e) {
|
|
225
|
+
// Ignore reflection errors
|
|
226
|
+
}
|
|
227
|
+
pairingHandle = null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
callback.success();
|
|
231
|
+
} catch (Exception exception) {
|
|
232
|
+
callback.error(exception);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public void isPairingInProgress(@NonNull NonEmptyResultCallback<IsPairingInProgressResult> callback) {
|
|
237
|
+
try {
|
|
238
|
+
if (!isInitialized) {
|
|
239
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
ReaderManager readerManager = MobilePaymentsSdk.readerManager();
|
|
243
|
+
boolean inProgress = readerManager.isPairingInProgress();
|
|
244
|
+
|
|
245
|
+
IsPairingInProgressResult result = new IsPairingInProgressResult(inProgress);
|
|
246
|
+
callback.success(result);
|
|
247
|
+
} catch (Exception exception) {
|
|
248
|
+
callback.error(exception);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public void getReaders(@NonNull NonEmptyResultCallback<GetReadersResult> callback) {
|
|
253
|
+
try {
|
|
254
|
+
if (!isInitialized) {
|
|
255
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
ReaderManager readerManager = MobilePaymentsSdk.readerManager();
|
|
259
|
+
List<ReaderInfo> sdkReaders = readerManager.getReaders();
|
|
260
|
+
|
|
261
|
+
List<io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.ReaderInfo> readers = new ArrayList<>();
|
|
262
|
+
for (ReaderInfo sdkReader : sdkReaders) {
|
|
263
|
+
io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.ReaderInfo reader = convertSdkReaderToReaderInfo(
|
|
264
|
+
sdkReader
|
|
265
|
+
);
|
|
266
|
+
readers.add(reader);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
GetReadersResult result = new GetReadersResult(readers);
|
|
270
|
+
callback.success(result);
|
|
271
|
+
} catch (Exception exception) {
|
|
272
|
+
callback.error(exception);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public void forgetReader(@NonNull ForgetReaderOptions options, @NonNull EmptyCallback callback) {
|
|
277
|
+
try {
|
|
278
|
+
if (!isInitialized) {
|
|
279
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
String serialNumber = options.getSerialNumber();
|
|
283
|
+
|
|
284
|
+
ReaderManager readerManager = MobilePaymentsSdk.readerManager();
|
|
285
|
+
ReaderInfo sdkReader = findReaderBySerialNumber(serialNumber);
|
|
286
|
+
|
|
287
|
+
if (sdkReader == null) {
|
|
288
|
+
throw CustomExceptions.READER_NOT_FOUND;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
readerManager.forget(sdkReader);
|
|
292
|
+
|
|
293
|
+
callback.success();
|
|
294
|
+
} catch (Exception exception) {
|
|
295
|
+
callback.error(exception);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public void retryConnection(@NonNull RetryConnectionOptions options, @NonNull EmptyCallback callback) {
|
|
300
|
+
try {
|
|
301
|
+
if (!isInitialized) {
|
|
302
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
String serialNumber = options.getSerialNumber();
|
|
306
|
+
|
|
307
|
+
ReaderManager readerManager = MobilePaymentsSdk.readerManager();
|
|
308
|
+
com.squareup.sdk.mobilepayments.cardreader.ReaderInfo sdkReader = findReaderBySerialNumber(serialNumber);
|
|
309
|
+
|
|
310
|
+
if (sdkReader == null) {
|
|
311
|
+
throw CustomExceptions.READER_NOT_FOUND;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
readerManager.retryConnection(sdkReader);
|
|
315
|
+
|
|
316
|
+
callback.success();
|
|
317
|
+
} catch (Exception exception) {
|
|
318
|
+
callback.error(exception);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
public void startPayment(@NonNull StartPaymentOptions options, @NonNull EmptyCallback callback) {
|
|
323
|
+
try {
|
|
324
|
+
if (!isInitialized) {
|
|
325
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
326
|
+
}
|
|
327
|
+
if (!isAuthorized) {
|
|
328
|
+
throw CustomExceptions.NOT_AUTHORIZED;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.options.PaymentParameters params =
|
|
332
|
+
options.getPaymentParameters();
|
|
333
|
+
io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.options.PromptParameters promptParams =
|
|
334
|
+
options.getPromptParameters();
|
|
335
|
+
|
|
336
|
+
PaymentManager paymentManager = MobilePaymentsSdk.paymentManager();
|
|
337
|
+
|
|
338
|
+
// Build Money object
|
|
339
|
+
Money amountMoney = new Money(params.getAmountMoney().getAmount(), CurrencyCode.valueOf(params.getAmountMoney().getCurrency()));
|
|
340
|
+
|
|
341
|
+
// Determine processing mode
|
|
342
|
+
ProcessingMode processingMode = ProcessingMode.AUTO_DETECT;
|
|
343
|
+
if (params.getProcessingMode() != null) {
|
|
344
|
+
processingMode = ProcessingMode.valueOf(params.getProcessingMode());
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Determine autocomplete
|
|
348
|
+
boolean autocomplete = params.getAutocomplete() != null ? params.getAutocomplete() : true;
|
|
349
|
+
|
|
350
|
+
// Build PaymentParameters
|
|
351
|
+
PaymentParameters.Builder paramsBuilder = new PaymentParameters.Builder(
|
|
352
|
+
amountMoney,
|
|
353
|
+
params.getPaymentAttemptId(),
|
|
354
|
+
processingMode,
|
|
355
|
+
false // allowCardSurcharge - not supported yet
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
paramsBuilder.autocomplete(autocomplete);
|
|
359
|
+
|
|
360
|
+
if (params.getReferenceId() != null) {
|
|
361
|
+
paramsBuilder.referenceId(params.getReferenceId());
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (params.getNote() != null) {
|
|
365
|
+
paramsBuilder.note(params.getNote());
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (params.getOrderId() != null) {
|
|
369
|
+
paramsBuilder.orderId(params.getOrderId());
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (params.getTipMoney() != null) {
|
|
373
|
+
Money tipMoney = new Money(params.getTipMoney().getAmount(), CurrencyCode.valueOf(params.getTipMoney().getCurrency()));
|
|
374
|
+
paramsBuilder.tipMoney(tipMoney);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if (params.getApplicationFee() != null) {
|
|
378
|
+
Money applicationFee = new Money(
|
|
379
|
+
params.getApplicationFee().getAmount(),
|
|
380
|
+
CurrencyCode.valueOf(params.getApplicationFee().getCurrency())
|
|
381
|
+
);
|
|
382
|
+
paramsBuilder.appFeeMoney(applicationFee);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
if (params.getDelayDuration() != null) {
|
|
386
|
+
Duration duration = Duration.parse(params.getDelayDuration());
|
|
387
|
+
paramsBuilder.delayDuration(duration.toMillis());
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (params.getDelayAction() != null) {
|
|
391
|
+
paramsBuilder.delayAction(DelayAction.valueOf(params.getDelayAction()));
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
PaymentParameters sdkPaymentParams = paramsBuilder.build();
|
|
395
|
+
|
|
396
|
+
// Build PromptParameters
|
|
397
|
+
PromptMode promptMode = PromptMode.DEFAULT;
|
|
398
|
+
if (promptParams.getMode() != null) {
|
|
399
|
+
promptMode = PromptMode.valueOf(promptParams.getMode());
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
List<AdditionalPaymentMethod.Type> additionalMethods = new ArrayList<>();
|
|
403
|
+
for (String method : promptParams.getAdditionalMethods()) {
|
|
404
|
+
additionalMethods.add(AdditionalPaymentMethod.Type.valueOf(method));
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
PromptParameters sdkPromptParams = new PromptParameters(promptMode, additionalMethods);
|
|
408
|
+
|
|
409
|
+
// Start payment
|
|
410
|
+
paymentHandle = paymentManager.startPaymentActivity(sdkPaymentParams, sdkPromptParams, result -> {
|
|
411
|
+
if (result.isSuccess()) {
|
|
412
|
+
Payment sdkPayment = result.value();
|
|
413
|
+
io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Payment payment = convertSdkPaymentToPayment(
|
|
414
|
+
sdkPayment
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
PaymentDidFinishEvent event = new PaymentDidFinishEvent(payment);
|
|
418
|
+
plugin.notifyPaymentDidFinishListeners(event);
|
|
419
|
+
} else {
|
|
420
|
+
PaymentDidFailEvent event = new PaymentDidFailEvent(
|
|
421
|
+
null,
|
|
422
|
+
result.errorCode() != null ? result.errorCode().toString() : null,
|
|
423
|
+
result.errorMessage()
|
|
424
|
+
);
|
|
425
|
+
plugin.notifyPaymentDidFailListeners(event);
|
|
426
|
+
}
|
|
427
|
+
paymentHandle = null;
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
callback.success();
|
|
431
|
+
} catch (Exception exception) {
|
|
432
|
+
callback.error(exception);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
public void cancelPayment(@NonNull EmptyCallback callback) {
|
|
437
|
+
try {
|
|
438
|
+
if (!isInitialized) {
|
|
439
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
if (paymentHandle != null) {
|
|
443
|
+
paymentHandle.cancel();
|
|
444
|
+
paymentHandle = null;
|
|
445
|
+
|
|
446
|
+
PaymentDidCancelEvent event = new PaymentDidCancelEvent(null);
|
|
447
|
+
plugin.notifyPaymentDidCancelListeners(event);
|
|
448
|
+
} else {
|
|
449
|
+
throw CustomExceptions.NO_PAYMENT_IN_PROGRESS;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
callback.success();
|
|
453
|
+
} catch (Exception exception) {
|
|
454
|
+
callback.error(exception);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
public void getAvailableCardInputMethods(@NonNull NonEmptyResultCallback<GetAvailableCardInputMethodsResult> callback) {
|
|
459
|
+
try {
|
|
460
|
+
if (!isInitialized) {
|
|
461
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
PaymentManager paymentManager = MobilePaymentsSdk.paymentManager();
|
|
465
|
+
Set<CardEntryMethod> methods = paymentManager.getAvailableCardEntryMethods();
|
|
466
|
+
|
|
467
|
+
List<String> cardInputMethods = methods.stream().map(this::convertCardEntryMethodToString).collect(Collectors.toList());
|
|
468
|
+
|
|
469
|
+
GetAvailableCardInputMethodsResult result = new GetAvailableCardInputMethodsResult(cardInputMethods);
|
|
470
|
+
callback.success(result);
|
|
471
|
+
} catch (Exception exception) {
|
|
472
|
+
callback.error(exception);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
public void setReaderChangedCallback() {
|
|
477
|
+
if (!isInitialized) {
|
|
478
|
+
return;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
ReaderManager readerManager = MobilePaymentsSdk.readerManager();
|
|
482
|
+
|
|
483
|
+
readerChangedCallbackReference = readerManager.setReaderChangedCallback(event -> {
|
|
484
|
+
com.squareup.sdk.mobilepayments.cardreader.ReaderInfo sdkReader = event.getReader();
|
|
485
|
+
ReaderChangedEvent.Change change = event.getChange();
|
|
486
|
+
|
|
487
|
+
io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.ReaderInfo reader = convertSdkReaderToReaderInfo(
|
|
488
|
+
sdkReader
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
// Notify based on change type
|
|
492
|
+
if (change == ReaderChangedEvent.Change.ADDED) {
|
|
493
|
+
ReaderWasAddedEvent addedEvent = new ReaderWasAddedEvent(reader);
|
|
494
|
+
plugin.notifyReaderWasAddedListeners(addedEvent);
|
|
495
|
+
} else if (change == ReaderChangedEvent.Change.REMOVED) {
|
|
496
|
+
ReaderWasRemovedEvent removedEvent = new ReaderWasRemovedEvent(reader);
|
|
497
|
+
plugin.notifyReaderWasRemovedListeners(removedEvent);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// Also notify general reader changed event
|
|
501
|
+
ReaderDidChangeEvent didChangeEvent = new ReaderDidChangeEvent(reader, convertReaderChangeToString(change));
|
|
502
|
+
plugin.notifyReaderDidChangeListeners(didChangeEvent);
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
public void clearReaderChangedCallback() {
|
|
507
|
+
if (readerChangedCallbackReference != null) {
|
|
508
|
+
readerChangedCallbackReference.clear();
|
|
509
|
+
readerChangedCallbackReference = null;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
public void setAvailableCardInputMethodsCallback() {
|
|
514
|
+
if (!isInitialized) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
PaymentManager paymentManager = MobilePaymentsSdk.paymentManager();
|
|
519
|
+
|
|
520
|
+
availableCardInputMethodsCallbackReference = paymentManager.setAvailableCardEntryMethodChangedCallback(methods -> {
|
|
521
|
+
List<String> cardInputMethods = methods.stream().map(this::convertCardEntryMethodToString).collect(Collectors.toList());
|
|
522
|
+
|
|
523
|
+
AvailableCardInputMethodsDidChangeEvent event = new AvailableCardInputMethodsDidChangeEvent(cardInputMethods);
|
|
524
|
+
plugin.notifyAvailableCardInputMethodsDidChangeListeners(event);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
public void clearAvailableCardInputMethodsCallback() {
|
|
529
|
+
if (availableCardInputMethodsCallbackReference != null) {
|
|
530
|
+
availableCardInputMethodsCallbackReference.clear();
|
|
531
|
+
availableCardInputMethodsCallbackReference = null;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Helper methods for converting SDK types to plugin types
|
|
536
|
+
|
|
537
|
+
@Nullable
|
|
538
|
+
private com.squareup.sdk.mobilepayments.cardreader.ReaderInfo findReaderBySerialNumber(@NonNull String serialNumber) {
|
|
539
|
+
ReaderManager readerManager = MobilePaymentsSdk.readerManager();
|
|
540
|
+
List<com.squareup.sdk.mobilepayments.cardreader.ReaderInfo> readers = readerManager.getReaders();
|
|
541
|
+
|
|
542
|
+
for (com.squareup.sdk.mobilepayments.cardreader.ReaderInfo reader : readers) {
|
|
543
|
+
if (reader.getSerialNumber().equals(serialNumber)) {
|
|
544
|
+
return reader;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
@NonNull
|
|
552
|
+
private io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.ReaderInfo convertSdkReaderToReaderInfo(
|
|
553
|
+
@NonNull com.squareup.sdk.mobilepayments.cardreader.ReaderInfo sdkReader
|
|
554
|
+
) {
|
|
555
|
+
String serialNumber = sdkReader.getSerialNumber();
|
|
556
|
+
String model = convertReaderModelToString(sdkReader.getModel());
|
|
557
|
+
String status = convertReaderStatusToString(sdkReader.getStatus());
|
|
558
|
+
String firmwareVersion = sdkReader.getFirmwareVersion();
|
|
559
|
+
Integer batteryLevel = sdkReader.getBatteryStatus().getPercent();
|
|
560
|
+
Boolean isCharging = sdkReader.getBatteryStatus().isCharging();
|
|
561
|
+
|
|
562
|
+
List<String> supportedCardInputMethods = sdkReader
|
|
563
|
+
.getSupportedCardEntryMethods()
|
|
564
|
+
.stream()
|
|
565
|
+
.map(this::convertCardEntryMethodToString)
|
|
566
|
+
.collect(Collectors.toList());
|
|
567
|
+
|
|
568
|
+
UnavailableReasonInfo unavailableReasonInfo = null;
|
|
569
|
+
if (sdkReader.getStatus() instanceof ReaderInfo.Status.ReaderUnavailable) {
|
|
570
|
+
ReaderInfo.Status.ReaderUnavailable unavailable = (ReaderInfo.Status.ReaderUnavailable) sdkReader.getStatus();
|
|
571
|
+
unavailableReasonInfo = new UnavailableReasonInfo(convertUnavailableReasonToString(unavailable.getReason()), null);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return new io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.ReaderInfo(
|
|
575
|
+
serialNumber,
|
|
576
|
+
model,
|
|
577
|
+
status,
|
|
578
|
+
firmwareVersion,
|
|
579
|
+
batteryLevel,
|
|
580
|
+
isCharging,
|
|
581
|
+
supportedCardInputMethods,
|
|
582
|
+
unavailableReasonInfo
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
@NonNull
|
|
587
|
+
private io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Payment convertSdkPaymentToPayment(
|
|
588
|
+
@NonNull Payment sdkPayment
|
|
589
|
+
) {
|
|
590
|
+
String id = null;
|
|
591
|
+
String type;
|
|
592
|
+
String status;
|
|
593
|
+
io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.CardPaymentDetails cardDetails = null;
|
|
594
|
+
|
|
595
|
+
if (sdkPayment instanceof Payment.OnlinePayment) {
|
|
596
|
+
Payment.OnlinePayment onlinePayment = (Payment.OnlinePayment) sdkPayment;
|
|
597
|
+
id = onlinePayment.getId();
|
|
598
|
+
type = "ONLINE";
|
|
599
|
+
status = convertPaymentStatusToString(onlinePayment.getStatus());
|
|
600
|
+
|
|
601
|
+
// Extract card details
|
|
602
|
+
com.squareup.sdk.mobilepayments.payment.CardPaymentDetails sdkCardDetails = onlinePayment.getCardDetails();
|
|
603
|
+
if (sdkCardDetails != null) {
|
|
604
|
+
cardDetails = convertSdkCardDetailsToCardPaymentDetails(sdkCardDetails);
|
|
605
|
+
}
|
|
606
|
+
} else if (sdkPayment instanceof Payment.OfflinePayment) {
|
|
607
|
+
Payment.OfflinePayment offlinePayment = (Payment.OfflinePayment) sdkPayment;
|
|
608
|
+
id = offlinePayment.getId();
|
|
609
|
+
type = "OFFLINE";
|
|
610
|
+
status = "PENDING";
|
|
611
|
+
|
|
612
|
+
// Extract card details
|
|
613
|
+
com.squareup.sdk.mobilepayments.payment.CardPaymentDetails sdkCardDetails = offlinePayment.getCardDetails();
|
|
614
|
+
if (sdkCardDetails != null) {
|
|
615
|
+
cardDetails = convertSdkCardDetailsToCardPaymentDetails(sdkCardDetails);
|
|
616
|
+
}
|
|
617
|
+
} else {
|
|
618
|
+
type = "ONLINE";
|
|
619
|
+
status = "PENDING";
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
MoneyResult amountMoney = new MoneyResult(
|
|
623
|
+
(int) sdkPayment.getTotalMoney().getAmount(),
|
|
624
|
+
sdkPayment.getTotalMoney().getCurrencyCode().toString()
|
|
625
|
+
);
|
|
626
|
+
|
|
627
|
+
MoneyResult tipMoney = sdkPayment.getTipMoney() != null
|
|
628
|
+
? new MoneyResult((int) sdkPayment.getTipMoney().getAmount(), sdkPayment.getTipMoney().getCurrencyCode().toString())
|
|
629
|
+
: null;
|
|
630
|
+
|
|
631
|
+
MoneyResult applicationFee = sdkPayment.getAppFeeMoney() != null
|
|
632
|
+
? new MoneyResult((int) sdkPayment.getAppFeeMoney().getAmount(), sdkPayment.getAppFeeMoney().getCurrencyCode().toString())
|
|
633
|
+
: null;
|
|
634
|
+
|
|
635
|
+
return new io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Payment(
|
|
636
|
+
id,
|
|
637
|
+
type,
|
|
638
|
+
status,
|
|
639
|
+
amountMoney,
|
|
640
|
+
tipMoney,
|
|
641
|
+
applicationFee,
|
|
642
|
+
sdkPayment.getReferenceId(),
|
|
643
|
+
sdkPayment.getOrderId(),
|
|
644
|
+
cardDetails,
|
|
645
|
+
sdkPayment.getCreatedAt() != null ? sdkPayment.getCreatedAt().toString() : null,
|
|
646
|
+
sdkPayment.getUpdatedAt() != null ? sdkPayment.getUpdatedAt().toString() : null
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
@NonNull
|
|
651
|
+
private io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.CardPaymentDetails convertSdkCardDetailsToCardPaymentDetails(
|
|
652
|
+
@NonNull com.squareup.sdk.mobilepayments.payment.CardPaymentDetails sdkCardDetails
|
|
653
|
+
) {
|
|
654
|
+
Card sdkCard = sdkCardDetails.getCard();
|
|
655
|
+
|
|
656
|
+
io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Card card =
|
|
657
|
+
new io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Card(
|
|
658
|
+
convertCardBrandToString(sdkCard.getBrand()),
|
|
659
|
+
sdkCard.getLastFourDigits(),
|
|
660
|
+
sdkCard.getCardholderName(),
|
|
661
|
+
sdkCard.getExpirationMonth(),
|
|
662
|
+
sdkCard.getExpirationYear()
|
|
663
|
+
);
|
|
664
|
+
|
|
665
|
+
String entryMethod = sdkCardDetails.getEntryMethod() != null ? sdkCardDetails.getEntryMethod().toString() : "KEYED";
|
|
666
|
+
|
|
667
|
+
return new io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.CardPaymentDetails(card, entryMethod);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
@NonNull
|
|
671
|
+
private String convertSdkEnvironmentToString(@NonNull Environment environment) {
|
|
672
|
+
return environment.toString().toLowerCase();
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
@NonNull
|
|
676
|
+
private String convertReaderModelToString(@NonNull ReaderInfo.Model model) {
|
|
677
|
+
return model.toString();
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
@NonNull
|
|
681
|
+
private String convertReaderStatusToString(@NonNull ReaderInfo.Status status) {
|
|
682
|
+
if (status instanceof ReaderInfo.Status.Ready) {
|
|
683
|
+
return "READY";
|
|
684
|
+
} else if (status instanceof ReaderInfo.Status.ConnectingToSquare) {
|
|
685
|
+
return "CONNECTING_TO_SQUARE";
|
|
686
|
+
} else if (status instanceof ReaderInfo.Status.ConnectingToDevice) {
|
|
687
|
+
return "CONNECTING_TO_DEVICE";
|
|
688
|
+
} else if (status instanceof ReaderInfo.Status.Faulty) {
|
|
689
|
+
return "FAULTY";
|
|
690
|
+
} else if (status instanceof ReaderInfo.Status.ReaderUnavailable) {
|
|
691
|
+
return "READER_UNAVAILABLE";
|
|
692
|
+
}
|
|
693
|
+
return "READER_UNAVAILABLE";
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
@NonNull
|
|
697
|
+
private String convertCardEntryMethodToString(@NonNull CardEntryMethod method) {
|
|
698
|
+
if (method == CardEntryMethod.CONTACTLESS) {
|
|
699
|
+
return "TAP";
|
|
700
|
+
} else if (method == CardEntryMethod.EMV) {
|
|
701
|
+
return "DIP";
|
|
702
|
+
} else if (method == CardEntryMethod.SWIPED) {
|
|
703
|
+
return "SWIPE";
|
|
704
|
+
}
|
|
705
|
+
return "UNKNOWN";
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
@NonNull
|
|
709
|
+
private String convertUnavailableReasonToString(@NonNull ReaderInfo.Status.ReaderUnavailable.ReaderUnavailableReason reason) {
|
|
710
|
+
if (reason == ReaderInfo.Status.ReaderUnavailable.ReaderUnavailableReason.BLOCKING_UPDATE) {
|
|
711
|
+
return "BLOCKING_UPDATE";
|
|
712
|
+
} else if (reason == ReaderInfo.Status.ReaderUnavailable.ReaderUnavailableReason.BLUETOOTH_DISABLED) {
|
|
713
|
+
return "BLUETOOTH_DISABLED";
|
|
714
|
+
} else if (reason == ReaderInfo.Status.ReaderUnavailable.ReaderUnavailableReason.READER_UNAVAILABLE_OFFLINE) {
|
|
715
|
+
return "READER_UNAVAILABLE_OFFLINE";
|
|
716
|
+
} else if (reason == ReaderInfo.Status.ReaderUnavailable.ReaderUnavailableReason.BLUETOOTH_FAILURE) {
|
|
717
|
+
return "BLUETOOTH_FAILURE";
|
|
718
|
+
} else if (reason == ReaderInfo.Status.ReaderUnavailable.ReaderUnavailableReason.DEVICE_DEVELOPER_MODE) {
|
|
719
|
+
return "DEVICE_DEVELOPER_MODE";
|
|
720
|
+
}
|
|
721
|
+
return "UNKNOWN";
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
@NonNull
|
|
725
|
+
private String convertReaderChangeToString(@NonNull ReaderChangedEvent.Change change) {
|
|
726
|
+
if (change == ReaderChangedEvent.Change.BATTERY_CHARGING) {
|
|
727
|
+
return "BATTERY_CHARGING";
|
|
728
|
+
} else if (change == ReaderChangedEvent.Change.ADDED) {
|
|
729
|
+
return "ADDED";
|
|
730
|
+
} else if (change == ReaderChangedEvent.Change.REMOVED) {
|
|
731
|
+
return "REMOVED";
|
|
732
|
+
}
|
|
733
|
+
// Default for any other status changes
|
|
734
|
+
return "STATUS_DID_CHANGE";
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
@NonNull
|
|
738
|
+
private String convertPaymentStatusToString(@NonNull Payment.OnlinePayment.Status status) {
|
|
739
|
+
if (status == Payment.OnlinePayment.Status.COMPLETED) {
|
|
740
|
+
return "COMPLETED";
|
|
741
|
+
} else if (status == Payment.OnlinePayment.Status.APPROVED) {
|
|
742
|
+
return "APPROVED";
|
|
743
|
+
} else if (status == Payment.OnlinePayment.Status.CANCELED) {
|
|
744
|
+
return "CANCELED";
|
|
745
|
+
} else if (status == Payment.OnlinePayment.Status.FAILED) {
|
|
746
|
+
return "FAILED";
|
|
747
|
+
} else if (status == Payment.OnlinePayment.Status.UNKNOWN) {
|
|
748
|
+
return "UNKNOWN";
|
|
749
|
+
}
|
|
750
|
+
return "UNKNOWN";
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
@NonNull
|
|
754
|
+
private String convertCardBrandToString(@NonNull Card.Brand brand) {
|
|
755
|
+
if (brand == Card.Brand.VISA) {
|
|
756
|
+
return "VISA";
|
|
757
|
+
} else if (brand == Card.Brand.MASTERCARD) {
|
|
758
|
+
return "MASTERCARD";
|
|
759
|
+
} else if (brand == Card.Brand.AMERICAN_EXPRESS) {
|
|
760
|
+
return "AMERICAN_EXPRESS";
|
|
761
|
+
} else if (brand == Card.Brand.DISCOVER) {
|
|
762
|
+
return "DISCOVER";
|
|
763
|
+
} else if (brand == Card.Brand.DISCOVER_DINERS) {
|
|
764
|
+
return "DISCOVER_DINERS";
|
|
765
|
+
} else if (brand == Card.Brand.JCB) {
|
|
766
|
+
return "JCB";
|
|
767
|
+
} else if (brand == Card.Brand.INTERAC) {
|
|
768
|
+
return "INTERAC";
|
|
769
|
+
} else if (brand == Card.Brand.EFTPOS) {
|
|
770
|
+
return "EFTPOS";
|
|
771
|
+
}
|
|
772
|
+
return "OTHER";
|
|
773
|
+
}
|
|
774
|
+
}
|