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

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