@swirepay-developer/swirepay-ach-sdk 2.0.2 → 2.0.4
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/package.json +1 -1
- package/web-component/swirepay-checkout.js +146 -96
package/package.json
CHANGED
|
@@ -182,38 +182,31 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
182
182
|
return await response.json();
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
async
|
|
185
|
+
async connectedCallback() {
|
|
186
|
+
this.amount = parseInt(this.getAttribute("amount")) || 0;
|
|
187
|
+
this.test = this.getAttribute("mode") === "test";
|
|
188
|
+
this.currencyCode = this.getAttribute("currencycode");
|
|
189
|
+
this.apiKey = this.getAttribute("api-key");
|
|
190
|
+
this.isAddressRequired = this.getAttribute("isaddressrequired") === "true";
|
|
191
|
+
this.inventory = this.getAttribute("inventory") === "true";
|
|
192
|
+
this.frequency = this.getAttribute("frequency");
|
|
193
|
+
this.description = this.getAttribute("description");
|
|
194
|
+
this.accountGid = this.getAttribute('accountGid');
|
|
195
|
+
this.totalPayments = this.getAttribute('totalPayments');
|
|
186
196
|
try {
|
|
187
|
-
this.amount = parseInt(this.getAttribute("amount")) || 0;
|
|
188
|
-
this.test = this.getAttribute("mode") === "test";
|
|
189
|
-
this.currencyCode = this.getAttribute("currencycode");
|
|
190
|
-
this.apiKey = this.getAttribute("api-key");
|
|
191
|
-
this.isAddressRequired = this.getAttribute("isaddressrequired") === "true";
|
|
192
|
-
this.inventory = this.getAttribute("inventory") === "true";
|
|
193
|
-
this.planGid = this.getAttribute("plangid");
|
|
194
|
-
this.productName = this.getAttribute("productname");
|
|
195
|
-
this.frequency = this.getAttribute("frequency");
|
|
196
|
-
this.description = this.getAttribute("description");
|
|
197
|
-
this.totalPayments = this.getAttribute("totalpayments");
|
|
198
|
-
this.accountGid = this.getAttribute("accountgid");
|
|
199
197
|
const customerAttr = this.getAttribute("customer");
|
|
200
198
|
this.customer = customerAttr ? JSON.parse(customerAttr) : {};
|
|
201
|
-
|
|
202
|
-
const inventoryOrders = this.getAttribute("inventoryorders");
|
|
199
|
+
const inventoryOrders = this.getAttribute("inventoryOrders");
|
|
203
200
|
this.inventoryOrder = inventoryOrders ? JSON.parse(inventoryOrders) : {};
|
|
204
|
-
if (this.inventory
|
|
201
|
+
if (this.inventory) {
|
|
205
202
|
const splitUpInfo = await this.getSplitUpDetails(this.inventoryOrder);
|
|
206
203
|
this.splitUp = splitUpInfo?.entity;
|
|
207
204
|
}
|
|
208
|
-
|
|
209
205
|
} catch (e) {
|
|
210
|
-
console.error("
|
|
206
|
+
console.error("Invalid JSON", e);
|
|
207
|
+
this.customer = {};
|
|
208
|
+
this.inventoryOrder = {};
|
|
211
209
|
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async connectedCallback() {
|
|
215
|
-
await this.updateFromAttributes();
|
|
216
|
-
|
|
217
210
|
await Promise.all([
|
|
218
211
|
loadScript(SDK_CONFIG.elliptic),
|
|
219
212
|
loadScript(SDK_CONFIG.crypto),
|
|
@@ -231,8 +224,6 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
231
224
|
"api-key",
|
|
232
225
|
"isaddressrequired",
|
|
233
226
|
"inventory",
|
|
234
|
-
"plangid",
|
|
235
|
-
"productname",
|
|
236
227
|
"frequency",
|
|
237
228
|
"description",
|
|
238
229
|
"totalpayments",
|
|
@@ -241,34 +232,93 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
241
232
|
];
|
|
242
233
|
}
|
|
243
234
|
|
|
244
|
-
|
|
235
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
245
236
|
if (oldValue === newValue) return;
|
|
246
237
|
|
|
247
|
-
|
|
238
|
+
try {
|
|
239
|
+
switch (name) {
|
|
240
|
+
case "amount":
|
|
241
|
+
this.amount = parseInt(newValue) || 0;
|
|
242
|
+
break;
|
|
243
|
+
|
|
244
|
+
case "mode":
|
|
245
|
+
this.test = newValue === "test";
|
|
246
|
+
break;
|
|
248
247
|
|
|
249
|
-
|
|
250
|
-
|
|
248
|
+
case "currencycode":
|
|
249
|
+
this.currencyCode = newValue;
|
|
250
|
+
break;
|
|
251
|
+
|
|
252
|
+
case "api-key":
|
|
253
|
+
this.apiKey = newValue;
|
|
254
|
+
break;
|
|
255
|
+
|
|
256
|
+
case "isaddressrequired":
|
|
257
|
+
this.isAddressRequired = newValue === "true";
|
|
258
|
+
break;
|
|
259
|
+
|
|
260
|
+
case "frequency":
|
|
261
|
+
this.frequency = newValue;
|
|
262
|
+
break;
|
|
263
|
+
|
|
264
|
+
case "description":
|
|
265
|
+
this.description = newValue;
|
|
266
|
+
break;
|
|
267
|
+
|
|
268
|
+
case "totalpayments":
|
|
269
|
+
this.totalPayments = newValue;
|
|
270
|
+
break;
|
|
271
|
+
|
|
272
|
+
case "customer":
|
|
273
|
+
this.customer = newValue ? JSON.parse(newValue) : {};
|
|
274
|
+
break;
|
|
275
|
+
|
|
276
|
+
case "inventoryorders":
|
|
277
|
+
this.inventoryOrder = newValue ? JSON.parse(newValue) : {};
|
|
278
|
+
break;
|
|
279
|
+
|
|
280
|
+
case "inventory":
|
|
281
|
+
this.inventory = newValue === "true";
|
|
282
|
+
|
|
283
|
+
if (this.inventory && this.inventoryOrder) {
|
|
284
|
+
this.getSplitUpDetails(this.inventoryOrder).then(res => {
|
|
285
|
+
this.splitUp = res?.entity;
|
|
286
|
+
this.render();
|
|
287
|
+
});
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
break;
|
|
291
|
+
|
|
292
|
+
default:
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
if (this.shadowRoot) {
|
|
296
|
+
this.render();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
} catch (e) {
|
|
300
|
+
console.error(`Invalid value for ${name}`, e);
|
|
251
301
|
}
|
|
252
302
|
}
|
|
253
303
|
|
|
254
304
|
setError(id, message) {
|
|
255
|
-
|
|
256
|
-
|
|
305
|
+
const input = this.shadow.getElementById(id);
|
|
306
|
+
const errorEl = this.shadow.getElementById(`error-${id}`);
|
|
257
307
|
|
|
258
|
-
|
|
308
|
+
if (errorEl) errorEl.textContent = message || "";
|
|
259
309
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}
|
|
310
|
+
if (input) {
|
|
311
|
+
if (message) input.classList.add("input-error");
|
|
312
|
+
else input.classList.remove("input-error");
|
|
264
313
|
}
|
|
314
|
+
}
|
|
265
315
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
316
|
+
clearErrors() {
|
|
317
|
+
this.shadow.querySelectorAll(".error").forEach(e => e.textContent = "");
|
|
318
|
+
this.shadow.querySelectorAll("input, select").forEach(el => {
|
|
319
|
+
el.classList.remove("input-error");
|
|
320
|
+
});
|
|
321
|
+
}
|
|
272
322
|
|
|
273
323
|
async encryptData(data, serverPublicKey, clientPrivateKey, keyId) {
|
|
274
324
|
try {
|
|
@@ -592,8 +642,8 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
592
642
|
<div class="field">
|
|
593
643
|
<select id="country" required>
|
|
594
644
|
${COUNTRIES_LIST.map(c =>
|
|
595
|
-
|
|
596
|
-
|
|
645
|
+
`<option value="${c.code}" ${c.code === "US" ? "selected" : ""}>${c.name}</option>`
|
|
646
|
+
).join("")}
|
|
597
647
|
</select>
|
|
598
648
|
<label class="floating">Country *</label>
|
|
599
649
|
</div>
|
|
@@ -610,26 +660,26 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
610
660
|
}
|
|
611
661
|
|
|
612
662
|
validate() {
|
|
613
|
-
|
|
614
|
-
|
|
663
|
+
this.clearErrors();
|
|
664
|
+
let isValid = true;
|
|
615
665
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
666
|
+
const get = id => this.shadow.getElementById(id)?.value?.trim();
|
|
667
|
+
if (!get("name")) {
|
|
668
|
+
this.setError("name", "Name required");
|
|
669
|
+
isValid = false;
|
|
670
|
+
}
|
|
621
671
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
672
|
+
const email = get("email");
|
|
673
|
+
if (!email) {
|
|
674
|
+
this.setError("email", "Email required");
|
|
675
|
+
isValid = false;
|
|
676
|
+
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
|
|
677
|
+
this.setError("email", "Invalid email");
|
|
678
|
+
isValid = false;
|
|
679
|
+
}
|
|
630
680
|
|
|
631
|
-
|
|
632
|
-
|
|
681
|
+
const phone = get("phone")?.replace(/\D/g, "");
|
|
682
|
+
const code = get("phone-code");
|
|
633
683
|
if (!phone || !code) {
|
|
634
684
|
this.setError("phone", "Phone number required");
|
|
635
685
|
isValid = false;
|
|
@@ -640,49 +690,49 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
640
690
|
isValid = false;
|
|
641
691
|
}
|
|
642
692
|
}
|
|
643
|
-
|
|
644
|
-
|
|
693
|
+
if (!this.processorToken) {
|
|
694
|
+
this.setError("bank", "Please link bank account");
|
|
645
695
|
isValid = false;
|
|
646
696
|
}
|
|
647
|
-
|
|
648
|
-
|
|
697
|
+
if (!get("business-type")) {
|
|
698
|
+
this.setError("business-type", "Select business type");
|
|
699
|
+
isValid = false;
|
|
700
|
+
}
|
|
701
|
+
if (this.isAddressRequired) {
|
|
702
|
+
if (!get("street")) {
|
|
703
|
+
this.setError("street", "Street required");
|
|
649
704
|
isValid = false;
|
|
650
705
|
}
|
|
651
|
-
if (this.isAddressRequired) {
|
|
652
|
-
if (!get("street")) {
|
|
653
|
-
this.setError("street", "Street required");
|
|
654
|
-
isValid = false;
|
|
655
|
-
}
|
|
656
706
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
707
|
+
if (!get("city")) {
|
|
708
|
+
this.setError("city", "City required");
|
|
709
|
+
isValid = false;
|
|
710
|
+
}
|
|
661
711
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
712
|
+
if (!get("state")) {
|
|
713
|
+
this.setError("state", "State required");
|
|
714
|
+
isValid = false;
|
|
715
|
+
}
|
|
666
716
|
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
717
|
+
if (!get("country")) {
|
|
718
|
+
this.setError("country", "Country required");
|
|
719
|
+
isValid = false;
|
|
720
|
+
}
|
|
671
721
|
|
|
672
|
-
|
|
722
|
+
const zip = get("zip");
|
|
673
723
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
}
|
|
724
|
+
if (!zip) {
|
|
725
|
+
this.setError("zip", "ZIP required");
|
|
726
|
+
isValid = false;
|
|
727
|
+
} else if (postalCodes.validate(get("country"), zip) !== true) {
|
|
728
|
+
this.setError("zip", "Invalid ZIP code");
|
|
729
|
+
isValid = false;
|
|
681
730
|
}
|
|
682
|
-
|
|
683
|
-
return isValid;
|
|
684
731
|
}
|
|
685
732
|
|
|
733
|
+
return isValid;
|
|
734
|
+
}
|
|
735
|
+
|
|
686
736
|
formatAccountNumber(v) {
|
|
687
737
|
return v.replace(/\D/g, "").slice(0, 18);
|
|
688
738
|
}
|
|
@@ -691,7 +741,7 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
691
741
|
return v.replace(/\D/g, "").slice(0, 9);
|
|
692
742
|
}
|
|
693
743
|
|
|
694
|
-
|
|
744
|
+
async oneTimePayment() {
|
|
695
745
|
try {
|
|
696
746
|
const values = await this.getServerEncription();
|
|
697
747
|
if (values?.public_key) {
|
|
@@ -793,7 +843,7 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
793
843
|
}
|
|
794
844
|
}
|
|
795
845
|
|
|
796
|
-
async recurringPayment() {
|
|
846
|
+
async recurringPayment () {
|
|
797
847
|
try {
|
|
798
848
|
const values = await this.getServerEncription();
|
|
799
849
|
if (values?.public_key) {
|
|
@@ -840,8 +890,8 @@ export class SwirepayCheckout extends HTMLElement {
|
|
|
840
890
|
if (itemInfo?.entity?.content[0]?.gid) {
|
|
841
891
|
product = itemInfo?.entity?.content[0];
|
|
842
892
|
} else {
|
|
843
|
-
|
|
844
|
-
|
|
893
|
+
const newItemInfo = await this.addedItemInfo();
|
|
894
|
+
product = newItemInfo?.entity;
|
|
845
895
|
}
|
|
846
896
|
let plan;
|
|
847
897
|
const planInfo = await this.getPlan();
|