@swirepay-developer/swirepay-ach-sdk 2.0.1 → 2.0.2

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