@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,460 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import androidx.annotation.NonNull;
|
|
5
|
+
import androidx.annotation.Nullable;
|
|
6
|
+
import com.getcapacitor.JSObject;
|
|
7
|
+
import com.getcapacitor.Logger;
|
|
8
|
+
import com.getcapacitor.Plugin;
|
|
9
|
+
import com.getcapacitor.PluginCall;
|
|
10
|
+
import com.getcapacitor.PluginMethod;
|
|
11
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
12
|
+
import com.getcapacitor.annotation.Permission;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events.*;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.options.*;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.*;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.interfaces.*;
|
|
17
|
+
|
|
18
|
+
@CapacitorPlugin(
|
|
19
|
+
name = "SquareMobilePayments",
|
|
20
|
+
permissions = {
|
|
21
|
+
@Permission(strings = { Manifest.permission.ACCESS_FINE_LOCATION }, alias = SquareMobilePaymentsPlugin.PERMISSION_LOCATION),
|
|
22
|
+
@Permission(strings = { Manifest.permission.RECORD_AUDIO }, alias = SquareMobilePaymentsPlugin.PERMISSION_RECORD_AUDIO),
|
|
23
|
+
@Permission(strings = { Manifest.permission.BLUETOOTH_CONNECT }, alias = SquareMobilePaymentsPlugin.PERMISSION_BLUETOOTH_CONNECT),
|
|
24
|
+
@Permission(strings = { Manifest.permission.BLUETOOTH_SCAN }, alias = SquareMobilePaymentsPlugin.PERMISSION_BLUETOOTH_SCAN),
|
|
25
|
+
@Permission(strings = { Manifest.permission.READ_PHONE_STATE }, alias = SquareMobilePaymentsPlugin.PERMISSION_READ_PHONE_STATE)
|
|
26
|
+
}
|
|
27
|
+
)
|
|
28
|
+
public class SquareMobilePaymentsPlugin extends Plugin {
|
|
29
|
+
|
|
30
|
+
public static final String TAG = "SquareMobilePayments";
|
|
31
|
+
public static final String ERROR_UNKNOWN_ERROR = "An unknown error occurred.";
|
|
32
|
+
public static final String PERMISSION_LOCATION = "location";
|
|
33
|
+
public static final String PERMISSION_RECORD_AUDIO = "recordAudio";
|
|
34
|
+
public static final String PERMISSION_BLUETOOTH_CONNECT = "bluetoothConnect";
|
|
35
|
+
public static final String PERMISSION_BLUETOOTH_SCAN = "bluetoothScan";
|
|
36
|
+
public static final String PERMISSION_READ_PHONE_STATE = "readPhoneState";
|
|
37
|
+
|
|
38
|
+
private SquareMobilePayments implementation;
|
|
39
|
+
|
|
40
|
+
@Override
|
|
41
|
+
public void load() {
|
|
42
|
+
implementation = new SquareMobilePayments(this);
|
|
43
|
+
implementation.setReaderChangedCallback();
|
|
44
|
+
implementation.setAvailableCardInputMethodsCallback();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@Override
|
|
48
|
+
protected void handleOnDestroy() {
|
|
49
|
+
if (implementation != null) {
|
|
50
|
+
implementation.clearReaderChangedCallback();
|
|
51
|
+
implementation.clearAvailableCardInputMethodsCallback();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@PluginMethod
|
|
56
|
+
public void initialize(PluginCall call) {
|
|
57
|
+
try {
|
|
58
|
+
InitializeOptions options = new InitializeOptions(call);
|
|
59
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
60
|
+
@Override
|
|
61
|
+
public void success() {
|
|
62
|
+
resolveCall(call);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Override
|
|
66
|
+
public void error(@NonNull Exception exception) {
|
|
67
|
+
rejectCall(call, exception);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
assert implementation != null;
|
|
72
|
+
implementation.initialize(options, callback);
|
|
73
|
+
} catch (Exception exception) {
|
|
74
|
+
rejectCall(call, exception);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@PluginMethod
|
|
79
|
+
public void authorize(PluginCall call) {
|
|
80
|
+
try {
|
|
81
|
+
AuthorizeOptions options = new AuthorizeOptions(call);
|
|
82
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
83
|
+
@Override
|
|
84
|
+
public void success() {
|
|
85
|
+
resolveCall(call);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Override
|
|
89
|
+
public void error(@NonNull Exception exception) {
|
|
90
|
+
rejectCall(call, exception);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
assert implementation != null;
|
|
95
|
+
implementation.authorize(options, callback);
|
|
96
|
+
} catch (Exception exception) {
|
|
97
|
+
rejectCall(call, exception);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@PluginMethod
|
|
102
|
+
public void isAuthorized(PluginCall call) {
|
|
103
|
+
try {
|
|
104
|
+
NonEmptyResultCallback<IsAuthorizedResult> callback = new NonEmptyResultCallback<>() {
|
|
105
|
+
@Override
|
|
106
|
+
public void success(@NonNull IsAuthorizedResult result) {
|
|
107
|
+
resolveCall(call, result);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@Override
|
|
111
|
+
public void error(@NonNull Exception exception) {
|
|
112
|
+
rejectCall(call, exception);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
assert implementation != null;
|
|
117
|
+
implementation.isAuthorized(callback);
|
|
118
|
+
} catch (Exception exception) {
|
|
119
|
+
rejectCall(call, exception);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@PluginMethod
|
|
124
|
+
public void deauthorize(PluginCall call) {
|
|
125
|
+
try {
|
|
126
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
127
|
+
@Override
|
|
128
|
+
public void success() {
|
|
129
|
+
resolveCall(call);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@Override
|
|
133
|
+
public void error(@NonNull Exception exception) {
|
|
134
|
+
rejectCall(call, exception);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
assert implementation != null;
|
|
139
|
+
implementation.deauthorize(callback);
|
|
140
|
+
} catch (Exception exception) {
|
|
141
|
+
rejectCall(call, exception);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@PluginMethod
|
|
146
|
+
public void showSettings(PluginCall call) {
|
|
147
|
+
try {
|
|
148
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
149
|
+
@Override
|
|
150
|
+
public void success() {
|
|
151
|
+
resolveCall(call);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@Override
|
|
155
|
+
public void error(@NonNull Exception exception) {
|
|
156
|
+
rejectCall(call, exception);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
assert implementation != null;
|
|
161
|
+
implementation.showSettings(callback);
|
|
162
|
+
} catch (Exception exception) {
|
|
163
|
+
rejectCall(call, exception);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@PluginMethod
|
|
168
|
+
public void getSettings(PluginCall call) {
|
|
169
|
+
try {
|
|
170
|
+
NonEmptyResultCallback<GetSettingsResult> callback = new NonEmptyResultCallback<>() {
|
|
171
|
+
@Override
|
|
172
|
+
public void success(@NonNull GetSettingsResult result) {
|
|
173
|
+
resolveCall(call, result);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@Override
|
|
177
|
+
public void error(@NonNull Exception exception) {
|
|
178
|
+
rejectCall(call, exception);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
assert implementation != null;
|
|
183
|
+
implementation.getSettings(callback);
|
|
184
|
+
} catch (Exception exception) {
|
|
185
|
+
rejectCall(call, exception);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@PluginMethod
|
|
190
|
+
public void startPairing(PluginCall call) {
|
|
191
|
+
try {
|
|
192
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
193
|
+
@Override
|
|
194
|
+
public void success() {
|
|
195
|
+
resolveCall(call);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
@Override
|
|
199
|
+
public void error(@NonNull Exception exception) {
|
|
200
|
+
rejectCall(call, exception);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
assert implementation != null;
|
|
205
|
+
implementation.startPairing(callback);
|
|
206
|
+
} catch (Exception exception) {
|
|
207
|
+
rejectCall(call, exception);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@PluginMethod
|
|
212
|
+
public void stopPairing(PluginCall call) {
|
|
213
|
+
try {
|
|
214
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
215
|
+
@Override
|
|
216
|
+
public void success() {
|
|
217
|
+
resolveCall(call);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@Override
|
|
221
|
+
public void error(@NonNull Exception exception) {
|
|
222
|
+
rejectCall(call, exception);
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
assert implementation != null;
|
|
227
|
+
implementation.stopPairing(callback);
|
|
228
|
+
} catch (Exception exception) {
|
|
229
|
+
rejectCall(call, exception);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@PluginMethod
|
|
234
|
+
public void isPairingInProgress(PluginCall call) {
|
|
235
|
+
try {
|
|
236
|
+
NonEmptyResultCallback<IsPairingInProgressResult> callback = new NonEmptyResultCallback<>() {
|
|
237
|
+
@Override
|
|
238
|
+
public void success(@NonNull IsPairingInProgressResult result) {
|
|
239
|
+
resolveCall(call, result);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
@Override
|
|
243
|
+
public void error(@NonNull Exception exception) {
|
|
244
|
+
rejectCall(call, exception);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
assert implementation != null;
|
|
249
|
+
implementation.isPairingInProgress(callback);
|
|
250
|
+
} catch (Exception exception) {
|
|
251
|
+
rejectCall(call, exception);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
@PluginMethod
|
|
256
|
+
public void getReaders(PluginCall call) {
|
|
257
|
+
try {
|
|
258
|
+
NonEmptyResultCallback<GetReadersResult> callback = new NonEmptyResultCallback<>() {
|
|
259
|
+
@Override
|
|
260
|
+
public void success(@NonNull GetReadersResult result) {
|
|
261
|
+
resolveCall(call, result);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
@Override
|
|
265
|
+
public void error(@NonNull Exception exception) {
|
|
266
|
+
rejectCall(call, exception);
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
assert implementation != null;
|
|
271
|
+
implementation.getReaders(callback);
|
|
272
|
+
} catch (Exception exception) {
|
|
273
|
+
rejectCall(call, exception);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
@PluginMethod
|
|
278
|
+
public void forgetReader(PluginCall call) {
|
|
279
|
+
try {
|
|
280
|
+
ForgetReaderOptions options = new ForgetReaderOptions(call);
|
|
281
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
282
|
+
@Override
|
|
283
|
+
public void success() {
|
|
284
|
+
resolveCall(call);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@Override
|
|
288
|
+
public void error(@NonNull Exception exception) {
|
|
289
|
+
rejectCall(call, exception);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
assert implementation != null;
|
|
294
|
+
implementation.forgetReader(options, callback);
|
|
295
|
+
} catch (Exception exception) {
|
|
296
|
+
rejectCall(call, exception);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
@PluginMethod
|
|
301
|
+
public void retryConnection(PluginCall call) {
|
|
302
|
+
try {
|
|
303
|
+
RetryConnectionOptions options = new RetryConnectionOptions(call);
|
|
304
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
305
|
+
@Override
|
|
306
|
+
public void success() {
|
|
307
|
+
resolveCall(call);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
@Override
|
|
311
|
+
public void error(@NonNull Exception exception) {
|
|
312
|
+
rejectCall(call, exception);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
assert implementation != null;
|
|
317
|
+
implementation.retryConnection(options, callback);
|
|
318
|
+
} catch (Exception exception) {
|
|
319
|
+
rejectCall(call, exception);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
@PluginMethod
|
|
324
|
+
public void startPayment(PluginCall call) {
|
|
325
|
+
try {
|
|
326
|
+
StartPaymentOptions options = new StartPaymentOptions(call);
|
|
327
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
328
|
+
@Override
|
|
329
|
+
public void success() {
|
|
330
|
+
resolveCall(call);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
@Override
|
|
334
|
+
public void error(@NonNull Exception exception) {
|
|
335
|
+
rejectCall(call, exception);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
assert implementation != null;
|
|
340
|
+
implementation.startPayment(options, callback);
|
|
341
|
+
} catch (Exception exception) {
|
|
342
|
+
rejectCall(call, exception);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
@PluginMethod
|
|
347
|
+
public void cancelPayment(PluginCall call) {
|
|
348
|
+
try {
|
|
349
|
+
EmptyCallback callback = new EmptyCallback() {
|
|
350
|
+
@Override
|
|
351
|
+
public void success() {
|
|
352
|
+
resolveCall(call);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
@Override
|
|
356
|
+
public void error(@NonNull Exception exception) {
|
|
357
|
+
rejectCall(call, exception);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
assert implementation != null;
|
|
362
|
+
implementation.cancelPayment(callback);
|
|
363
|
+
} catch (Exception exception) {
|
|
364
|
+
rejectCall(call, exception);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
@PluginMethod
|
|
369
|
+
public void getAvailableCardInputMethods(PluginCall call) {
|
|
370
|
+
try {
|
|
371
|
+
NonEmptyResultCallback<GetAvailableCardInputMethodsResult> callback = new NonEmptyResultCallback<>() {
|
|
372
|
+
@Override
|
|
373
|
+
public void success(@NonNull GetAvailableCardInputMethodsResult result) {
|
|
374
|
+
resolveCall(call, result);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
@Override
|
|
378
|
+
public void error(@NonNull Exception exception) {
|
|
379
|
+
rejectCall(call, exception);
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
assert implementation != null;
|
|
384
|
+
implementation.getAvailableCardInputMethods(callback);
|
|
385
|
+
} catch (Exception exception) {
|
|
386
|
+
rejectCall(call, exception);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
@PluginMethod
|
|
391
|
+
public void checkPermissions(PluginCall call) {
|
|
392
|
+
super.checkPermissions(call);
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
@PluginMethod
|
|
396
|
+
public void requestPermissions(PluginCall call) {
|
|
397
|
+
super.requestPermissions(call);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
|
|
401
|
+
String message = exception.getMessage();
|
|
402
|
+
if (message == null) {
|
|
403
|
+
message = ERROR_UNKNOWN_ERROR;
|
|
404
|
+
}
|
|
405
|
+
Logger.error(TAG, message, exception);
|
|
406
|
+
call.reject(message);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private void resolveCall(@NonNull PluginCall call) {
|
|
410
|
+
call.resolve();
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
|
|
414
|
+
if (result == null) {
|
|
415
|
+
call.resolve();
|
|
416
|
+
} else {
|
|
417
|
+
call.resolve(result.toJSObject());
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
public void notifyReaderPairingDidBeginListeners() {
|
|
422
|
+
notifyListeners("readerPairingDidBegin", new JSObject());
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
public void notifyReaderPairingDidSucceedListeners() {
|
|
426
|
+
notifyListeners("readerPairingDidSucceed", new JSObject());
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
public void notifyReaderPairingDidFailListeners(@NonNull ReaderPairingDidFailEvent event) {
|
|
430
|
+
notifyListeners("readerPairingDidFail", event.toJSObject());
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
public void notifyReaderWasAddedListeners(@NonNull ReaderWasAddedEvent event) {
|
|
434
|
+
notifyListeners("readerWasAdded", event.toJSObject());
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
public void notifyReaderWasRemovedListeners(@NonNull ReaderWasRemovedEvent event) {
|
|
438
|
+
notifyListeners("readerWasRemoved", event.toJSObject());
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
public void notifyReaderDidChangeListeners(@NonNull ReaderDidChangeEvent event) {
|
|
442
|
+
notifyListeners("readerDidChange", event.toJSObject());
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
public void notifyAvailableCardInputMethodsDidChangeListeners(@NonNull AvailableCardInputMethodsDidChangeEvent event) {
|
|
446
|
+
notifyListeners("availableCardInputMethodsDidChange", event.toJSObject());
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
public void notifyPaymentDidFinishListeners(@NonNull PaymentDidFinishEvent event) {
|
|
450
|
+
notifyListeners("paymentDidFinish", event.toJSObject());
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
public void notifyPaymentDidFailListeners(@NonNull PaymentDidFailEvent event) {
|
|
454
|
+
notifyListeners("paymentDidFail", event.toJSObject());
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
public void notifyPaymentDidCancelListeners(@NonNull PaymentDidCancelEvent event) {
|
|
458
|
+
notifyListeners("paymentDidCancel", event.toJSObject());
|
|
459
|
+
}
|
|
460
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
|
|
6
|
+
public class CustomException extends Exception {
|
|
7
|
+
|
|
8
|
+
@Nullable
|
|
9
|
+
private final String code;
|
|
10
|
+
|
|
11
|
+
public CustomException(@Nullable String code, @NonNull String message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@Nullable
|
|
17
|
+
public String getCode() {
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes;
|
|
2
|
+
|
|
3
|
+
public class CustomExceptions {
|
|
4
|
+
|
|
5
|
+
public static final CustomException LOCATION_ID_MISSING = new CustomException("LOCATION_ID_MISSING", "locationId must be provided.");
|
|
6
|
+
public static final CustomException ACCESS_TOKEN_MISSING = new CustomException("ACCESS_TOKEN_MISSING", "accessToken must be provided.");
|
|
7
|
+
public static final CustomException SERIAL_NUMBER_MISSING = new CustomException(
|
|
8
|
+
"SERIAL_NUMBER_MISSING",
|
|
9
|
+
"serialNumber must be provided."
|
|
10
|
+
);
|
|
11
|
+
public static final CustomException PAYMENT_PARAMETERS_MISSING = new CustomException(
|
|
12
|
+
"PAYMENT_PARAMETERS_MISSING",
|
|
13
|
+
"paymentParameters must be provided."
|
|
14
|
+
);
|
|
15
|
+
public static final CustomException PROMPT_PARAMETERS_MISSING = new CustomException(
|
|
16
|
+
"PROMPT_PARAMETERS_MISSING",
|
|
17
|
+
"promptParameters must be provided."
|
|
18
|
+
);
|
|
19
|
+
public static final CustomException AMOUNT_MONEY_MISSING = new CustomException("AMOUNT_MONEY_MISSING", "amountMoney must be provided.");
|
|
20
|
+
public static final CustomException PAYMENT_ATTEMPT_ID_MISSING = new CustomException(
|
|
21
|
+
"PAYMENT_ATTEMPT_ID_MISSING",
|
|
22
|
+
"paymentAttemptId must be provided."
|
|
23
|
+
);
|
|
24
|
+
public static final CustomException NOT_INITIALIZED = new CustomException(
|
|
25
|
+
"NOT_INITIALIZED",
|
|
26
|
+
"The SDK is not initialized. Call initialize() first."
|
|
27
|
+
);
|
|
28
|
+
public static final CustomException NOT_AUTHORIZED = new CustomException(
|
|
29
|
+
"NOT_AUTHORIZED",
|
|
30
|
+
"The SDK is not authorized. Call authorize() first."
|
|
31
|
+
);
|
|
32
|
+
public static final CustomException PAIRING_ALREADY_IN_PROGRESS = new CustomException(
|
|
33
|
+
"PAIRING_ALREADY_IN_PROGRESS",
|
|
34
|
+
"A pairing process is already in progress."
|
|
35
|
+
);
|
|
36
|
+
public static final CustomException NO_PAYMENT_IN_PROGRESS = new CustomException(
|
|
37
|
+
"NO_PAYMENT_IN_PROGRESS",
|
|
38
|
+
"No payment is currently in progress."
|
|
39
|
+
);
|
|
40
|
+
public static final CustomException READER_NOT_FOUND = new CustomException("READER_NOT_FOUND", "Reader not found.");
|
|
41
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import java.util.List;
|
|
7
|
+
|
|
8
|
+
public class AvailableCardInputMethodsDidChangeEvent {
|
|
9
|
+
|
|
10
|
+
@NonNull
|
|
11
|
+
private final List<String> cardInputMethods;
|
|
12
|
+
|
|
13
|
+
public AvailableCardInputMethodsDidChangeEvent(@NonNull List<String> cardInputMethods) {
|
|
14
|
+
this.cardInputMethods = cardInputMethods;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@NonNull
|
|
18
|
+
public JSObject toJSObject() {
|
|
19
|
+
JSObject result = new JSObject();
|
|
20
|
+
JSArray array = new JSArray();
|
|
21
|
+
for (String method : cardInputMethods) {
|
|
22
|
+
array.put(method);
|
|
23
|
+
}
|
|
24
|
+
result.put("cardInputMethods", array);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Payment;
|
|
7
|
+
import org.json.JSONObject;
|
|
8
|
+
|
|
9
|
+
public class PaymentDidCancelEvent {
|
|
10
|
+
|
|
11
|
+
@Nullable
|
|
12
|
+
private final Payment payment;
|
|
13
|
+
|
|
14
|
+
public PaymentDidCancelEvent(@Nullable Payment payment) {
|
|
15
|
+
this.payment = payment;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@NonNull
|
|
19
|
+
public JSObject toJSObject() {
|
|
20
|
+
JSObject result = new JSObject();
|
|
21
|
+
result.put("payment", payment == null ? JSONObject.NULL : payment.toJSObject());
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Payment;
|
|
7
|
+
import org.json.JSONObject;
|
|
8
|
+
|
|
9
|
+
public class PaymentDidFailEvent {
|
|
10
|
+
|
|
11
|
+
@Nullable
|
|
12
|
+
private final Payment payment;
|
|
13
|
+
|
|
14
|
+
@Nullable
|
|
15
|
+
private final String code;
|
|
16
|
+
|
|
17
|
+
@NonNull
|
|
18
|
+
private final String message;
|
|
19
|
+
|
|
20
|
+
public PaymentDidFailEvent(@Nullable Payment payment, @Nullable String code, @NonNull String message) {
|
|
21
|
+
this.payment = payment;
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.message = message;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@NonNull
|
|
27
|
+
public JSObject toJSObject() {
|
|
28
|
+
JSObject result = new JSObject();
|
|
29
|
+
result.put("payment", payment == null ? JSONObject.NULL : payment.toJSObject());
|
|
30
|
+
result.put("code", code == null ? JSONObject.NULL : code);
|
|
31
|
+
result.put("message", message);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.Payment;
|
|
6
|
+
|
|
7
|
+
public class PaymentDidFinishEvent {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final Payment payment;
|
|
11
|
+
|
|
12
|
+
public PaymentDidFinishEvent(@NonNull Payment payment) {
|
|
13
|
+
this.payment = payment;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@NonNull
|
|
17
|
+
public JSObject toJSObject() {
|
|
18
|
+
JSObject result = new JSObject();
|
|
19
|
+
result.put("payment", payment.toJSObject());
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.results.ReaderInfo;
|
|
6
|
+
|
|
7
|
+
public class ReaderDidChangeEvent {
|
|
8
|
+
|
|
9
|
+
@NonNull
|
|
10
|
+
private final ReaderInfo reader;
|
|
11
|
+
|
|
12
|
+
@NonNull
|
|
13
|
+
private final String change;
|
|
14
|
+
|
|
15
|
+
public ReaderDidChangeEvent(@NonNull ReaderInfo reader, @NonNull String change) {
|
|
16
|
+
this.reader = reader;
|
|
17
|
+
this.change = change;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@NonNull
|
|
21
|
+
public JSObject toJSObject() {
|
|
22
|
+
JSObject result = new JSObject();
|
|
23
|
+
result.put("reader", reader.toJSObject());
|
|
24
|
+
result.put("change", change);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.squaremobilepayments.classes.events;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import androidx.annotation.Nullable;
|
|
5
|
+
import com.getcapacitor.JSObject;
|
|
6
|
+
import org.json.JSONObject;
|
|
7
|
+
|
|
8
|
+
public class ReaderPairingDidFailEvent {
|
|
9
|
+
|
|
10
|
+
@Nullable
|
|
11
|
+
private final String code;
|
|
12
|
+
|
|
13
|
+
@NonNull
|
|
14
|
+
private final String message;
|
|
15
|
+
|
|
16
|
+
public ReaderPairingDidFailEvent(@Nullable String code, @NonNull String message) {
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.message = message;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@NonNull
|
|
22
|
+
public JSObject toJSObject() {
|
|
23
|
+
JSObject result = new JSObject();
|
|
24
|
+
result.put("code", code == null ? JSONObject.NULL : code);
|
|
25
|
+
result.put("message", message);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
}
|