bison-web-components 1.5.0 → 1.7.0
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/api.js +1 -1
- package/bison-operator-payments.js +126 -25
- package/package.json +1 -1
- package/wio-payment.js +0 -5
package/api.js
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
* onUnlinkError(error) – called when unlinking bank account(s) fails
|
|
26
26
|
*
|
|
27
27
|
* @author @kfajardo
|
|
28
|
-
* @version 1.
|
|
28
|
+
* @version 1.6.0
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
31
|
const BOP_BISON_LOGO =
|
|
@@ -742,6 +742,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
742
742
|
this._linkedAccount = null;
|
|
743
743
|
this._isFetchingAccounts = false;
|
|
744
744
|
this._pendingLinkedAccount = null;
|
|
745
|
+
this._isOpen = false;
|
|
745
746
|
|
|
746
747
|
// Unlink state
|
|
747
748
|
this._unlinkTarget = null;
|
|
@@ -772,24 +773,108 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
772
773
|
this._isOperatorLookupPending = false;
|
|
773
774
|
this._componentDisabled = true;
|
|
774
775
|
|
|
775
|
-
// Consumer callbacks
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
this.onLookupError = null;
|
|
780
|
-
this.onBankFetchSuccess = null;
|
|
781
|
-
this.onBankFetchError = null;
|
|
782
|
-
this.onLinkSuccess = null;
|
|
783
|
-
this.onLinkError = null;
|
|
784
|
-
this.onUnlinkSuccess = null;
|
|
785
|
-
this.onUnlinkError = null;
|
|
776
|
+
// Consumer callbacks — intentionally NOT set to null here.
|
|
777
|
+
// Setting them in the constructor would clobber values the consumer
|
|
778
|
+
// assigned before the element upgraded. They are rescued via
|
|
779
|
+
// _upgradeProperty() in connectedCallback instead.
|
|
786
780
|
}
|
|
787
781
|
|
|
788
782
|
static get observedAttributes() {
|
|
789
|
-
return [
|
|
783
|
+
return [
|
|
784
|
+
"org-number",
|
|
785
|
+
"op-org-id",
|
|
786
|
+
"x-embeddable-key",
|
|
787
|
+
"api-base-url",
|
|
788
|
+
// Callback attributes — resolved from window globals by name
|
|
789
|
+
"on-open",
|
|
790
|
+
"on-close",
|
|
791
|
+
"on-lookup-success",
|
|
792
|
+
"on-lookup-error",
|
|
793
|
+
"on-bank-fetch-success",
|
|
794
|
+
"on-bank-fetch-error",
|
|
795
|
+
"on-link-success",
|
|
796
|
+
"on-link-error",
|
|
797
|
+
"on-unlink-success",
|
|
798
|
+
"on-unlink-error",
|
|
799
|
+
];
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/** Attribute name → JS property name mapping for consumer callbacks */
|
|
803
|
+
static get _callbackAttrMap() {
|
|
804
|
+
return {
|
|
805
|
+
"on-open": "onOpen",
|
|
806
|
+
"on-close": "onClose",
|
|
807
|
+
"on-lookup-success": "onLookupSuccess",
|
|
808
|
+
"on-lookup-error": "onLookupError",
|
|
809
|
+
"on-bank-fetch-success": "onBankFetchSuccess",
|
|
810
|
+
"on-bank-fetch-error": "onBankFetchError",
|
|
811
|
+
"on-link-success": "onLinkSuccess",
|
|
812
|
+
"on-link-error": "onLinkError",
|
|
813
|
+
"on-unlink-success": "onUnlinkSuccess",
|
|
814
|
+
"on-unlink-error": "onUnlinkError",
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/**
|
|
819
|
+
* Resolves a callback attribute value to a window-global function and assigns
|
|
820
|
+
* it to the corresponding JS property.
|
|
821
|
+
*
|
|
822
|
+
* @param {string} attrName - e.g. "on-lookup-success"
|
|
823
|
+
* @param {string|null} fnName - e.g. "handleLookup"
|
|
824
|
+
*/
|
|
825
|
+
_resolveCallbackAttr(attrName, fnName) {
|
|
826
|
+
const propName = BisonOperatorPayments._callbackAttrMap[attrName];
|
|
827
|
+
if (!propName) return;
|
|
828
|
+
if (!fnName) {
|
|
829
|
+
this[propName] = null;
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
const fn = typeof window !== "undefined" ? window[fnName] : undefined;
|
|
833
|
+
if (typeof fn === "function") {
|
|
834
|
+
this[propName] = fn;
|
|
835
|
+
this._log(`Callback attribute "${attrName}" → window.${fnName}`);
|
|
836
|
+
} else {
|
|
837
|
+
this._log(`Warning: "${fnName}" not found on window for attribute "${attrName}"`);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/** Seeds all callback attributes declared in HTML at connect time. */
|
|
842
|
+
_seedCallbackAttributes() {
|
|
843
|
+
for (const attrName of Object.keys(BisonOperatorPayments._callbackAttrMap)) {
|
|
844
|
+
const val = this.getAttribute(attrName);
|
|
845
|
+
if (val) this._resolveCallbackAttr(attrName, val.trim());
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/**
|
|
850
|
+
* Rescues a property that was set on the element before it was upgraded
|
|
851
|
+
* by customElements.define. Without this, the constructor's field
|
|
852
|
+
* initializations would silently overwrite the consumer's pre-set values.
|
|
853
|
+
*
|
|
854
|
+
* @param {string} prop - Property name, e.g. 'onLookupSuccess'
|
|
855
|
+
*/
|
|
856
|
+
_upgradeProperty(prop) {
|
|
857
|
+
if (Object.prototype.hasOwnProperty.call(this, prop)) {
|
|
858
|
+
const value = this[prop];
|
|
859
|
+
delete this[prop];
|
|
860
|
+
this[prop] = value;
|
|
861
|
+
}
|
|
790
862
|
}
|
|
791
863
|
|
|
792
864
|
connectedCallback() {
|
|
865
|
+
// Rescue any callback properties set on the element before upgrade.
|
|
866
|
+
// Must run first — before anything else could overwrite them.
|
|
867
|
+
this._upgradeProperty("onOpen");
|
|
868
|
+
this._upgradeProperty("onClose");
|
|
869
|
+
this._upgradeProperty("onLookupSuccess");
|
|
870
|
+
this._upgradeProperty("onLookupError");
|
|
871
|
+
this._upgradeProperty("onBankFetchSuccess");
|
|
872
|
+
this._upgradeProperty("onBankFetchError");
|
|
873
|
+
this._upgradeProperty("onLinkSuccess");
|
|
874
|
+
this._upgradeProperty("onLinkError");
|
|
875
|
+
this._upgradeProperty("onUnlinkSuccess");
|
|
876
|
+
this._upgradeProperty("onUnlinkError");
|
|
877
|
+
|
|
793
878
|
// Seed embeddable key from initial attribute
|
|
794
879
|
const initialKey = (this.getAttribute("x-embeddable-key") || "").trim();
|
|
795
880
|
if (initialKey) {
|
|
@@ -797,6 +882,10 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
797
882
|
this._disabledReason = null;
|
|
798
883
|
}
|
|
799
884
|
|
|
885
|
+
// Seed any callback attributes declared directly in HTML.
|
|
886
|
+
// Attribute values take lower priority — only apply if JS property not already set.
|
|
887
|
+
this._seedCallbackAttributes();
|
|
888
|
+
|
|
800
889
|
this._injectStyles();
|
|
801
890
|
this._renderTrigger();
|
|
802
891
|
// Evaluate initial attribute state on connect
|
|
@@ -827,11 +916,28 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
827
916
|
this._log(`Attribute changed: ${name} → "${newVal}" (was "${oldVal}")`);
|
|
828
917
|
this._evaluateOperatorAttributes();
|
|
829
918
|
}
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
// Callback attributes: resolve the named window function and wire it up
|
|
922
|
+
if (name in BisonOperatorPayments._callbackAttrMap) {
|
|
923
|
+
this._resolveCallbackAttr(name, (newVal || "").trim() || null);
|
|
830
924
|
}
|
|
831
925
|
}
|
|
832
926
|
|
|
927
|
+
open() {
|
|
928
|
+
this._isOpen = true;
|
|
929
|
+
this._isClosing = false;
|
|
930
|
+
this._render();
|
|
931
|
+
if (typeof this.onOpen === "function") this.onOpen();
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/** Programmatic close */
|
|
935
|
+
close() {
|
|
936
|
+
this._handleClose();
|
|
937
|
+
}
|
|
938
|
+
|
|
833
939
|
get isOpen() {
|
|
834
|
-
return this.
|
|
940
|
+
return this._isOpen;
|
|
835
941
|
}
|
|
836
942
|
|
|
837
943
|
/** Resolves the API instance and syncs the current embeddable key. */
|
|
@@ -957,7 +1063,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
957
1063
|
this._componentDisabled = false;
|
|
958
1064
|
this._dispatchLookupEvent({ status: "success", data: result });
|
|
959
1065
|
if (typeof this.onLookupSuccess === "function")
|
|
960
|
-
this.onLookupSuccess(result);
|
|
1066
|
+
this.onLookupSuccess(result.data);
|
|
961
1067
|
|
|
962
1068
|
// Fetch operator bank accounts
|
|
963
1069
|
if (this._operatorId) {
|
|
@@ -1010,8 +1116,6 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
1010
1116
|
const companyName = this._operatorData?.companyName || "";
|
|
1011
1117
|
if (this._isOperatorLookupPending) {
|
|
1012
1118
|
btn.innerHTML = `${loaderSvg} Initializing...`;
|
|
1013
|
-
} else if (companyName) {
|
|
1014
|
-
btn.innerHTML = `${logoImg} <span class="bop-trigger-company" key="${companyName}">${companyName}</span> <span class="bop-trigger-sep">·</span> Manage Bank Accounts`;
|
|
1015
1119
|
} else {
|
|
1016
1120
|
btn.innerHTML = `${logoImg} Manage Bank Accounts`;
|
|
1017
1121
|
}
|
|
@@ -1061,7 +1165,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
1061
1165
|
|
|
1062
1166
|
this._log("Fetched bank accounts successfully", this._accounts);
|
|
1063
1167
|
if (typeof this.onBankFetchSuccess === "function")
|
|
1064
|
-
this.onBankFetchSuccess(
|
|
1168
|
+
this.onBankFetchSuccess(response.data);
|
|
1065
1169
|
} catch (err) {
|
|
1066
1170
|
const errData = err?.data || err;
|
|
1067
1171
|
this._log("Error fetching bank accounts", errData);
|
|
@@ -1200,7 +1304,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
1200
1304
|
"animationend",
|
|
1201
1305
|
() => {
|
|
1202
1306
|
this._isClosing = false;
|
|
1203
|
-
this.
|
|
1307
|
+
this._isOpen = false;
|
|
1204
1308
|
setTimeout(() => this._resetState(), 50);
|
|
1205
1309
|
this._render();
|
|
1206
1310
|
this.dispatchEvent(
|
|
@@ -1212,7 +1316,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
1212
1316
|
);
|
|
1213
1317
|
} else {
|
|
1214
1318
|
this._isClosing = false;
|
|
1215
|
-
this.
|
|
1319
|
+
this._isOpen = false;
|
|
1216
1320
|
this._resetState();
|
|
1217
1321
|
this._render();
|
|
1218
1322
|
this.dispatchEvent(
|
|
@@ -1613,7 +1717,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
1613
1717
|
this._linkModalResult = "success";
|
|
1614
1718
|
this._renderLinkModal();
|
|
1615
1719
|
if (typeof this.onLinkSuccess === "function")
|
|
1616
|
-
this.onLinkSuccess(
|
|
1720
|
+
this.onLinkSuccess(response.data);
|
|
1617
1721
|
} catch (err) {
|
|
1618
1722
|
this._log("Error linking account:", err);
|
|
1619
1723
|
const errData = err?.data || err;
|
|
@@ -2138,10 +2242,7 @@ class BisonOperatorPayments extends HTMLElement {
|
|
|
2138
2242
|
if (this._componentDisabled) btn.setAttribute("aria-disabled", "true");
|
|
2139
2243
|
btn.addEventListener("click", () => {
|
|
2140
2244
|
if (this._componentDisabled) return;
|
|
2141
|
-
this.
|
|
2142
|
-
this._isClosing = false;
|
|
2143
|
-
this._render();
|
|
2144
|
-
if (typeof this.onOpen === "function") this.onOpen();
|
|
2245
|
+
this.open();
|
|
2145
2246
|
});
|
|
2146
2247
|
|
|
2147
2248
|
const tooltip = document.createElement("span");
|
package/package.json
CHANGED
package/wio-payment.js
CHANGED
|
@@ -81,7 +81,6 @@ class WioPayment extends HTMLElement {
|
|
|
81
81
|
"redirect-url",
|
|
82
82
|
"on-success",
|
|
83
83
|
"on-error",
|
|
84
|
-
"open",
|
|
85
84
|
"api-base-url",
|
|
86
85
|
"embeddable-key",
|
|
87
86
|
];
|
|
@@ -268,10 +267,6 @@ class WioPayment extends HTMLElement {
|
|
|
268
267
|
}
|
|
269
268
|
break;
|
|
270
269
|
|
|
271
|
-
case "open":
|
|
272
|
-
this.open = newValue !== null;
|
|
273
|
-
break;
|
|
274
|
-
|
|
275
270
|
case "api-base-url":
|
|
276
271
|
this.apiBaseURL = newValue;
|
|
277
272
|
this.api = new BisonJibPayAPI(this.apiBaseURL, this.embeddableKey);
|