rebill 1.0.26 → 1.0.27
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/index.js +1 -1
- package/package.json +1 -1
- package/sdk/index.d.ts +3 -1
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Rebill=e():t.Rebill=e()}(this,(()=>(()=>{"use strict";var t={986:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.skeletonOptions=e.skeletonLight=e.skeletonDark=e.CONSTANTS=void 0,e.CONSTANTS={IFRAME_READY:"IFRAME_READY",ON_SUCCESS:"ON_SUCCESS",ON_ERROR:"ON_ERROR",SET_TEXT:"SET_TEXT",SET_REQUEST:"SET_REQUEST",SET_CARDHOLDER:"SET_CARDHOLDER",SET_STYLES:"SET_STYLES",SET_CURRENCY:"SET_CURRENCY",TRANSACTION_USE_CASE:"TRANSACTION_USE_CASE",SET_PRICE:"SET_PRICE",RENEW_CARD_USE_CASE:"RENEW_CARD_USE_CASE",ADD_CARD_USE_CASE:"ADD_CARD_USE_CASE",SET_CONFIG_OPTIONS:"SET_CONFIG_OPTIONS",SET_CUSTOMER:"SET_CUSTOMER",SET_HEIGHT:"SET_HEIGHT",SUBMIT_ACTION:"SUBMIT_ACTION",SET_DISABLED:"SET_DISABLED",SET_LOADING:"SET_LOADING"},e.skeletonDark=' <div\n style="\n width: 100%;\n height: 450px;\n margin-left: auto;\n margin-right: auto;\n overflow: hidden;\n "\n >\n <div\n id="1"\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n style="\n display: flex;\n gap: 1rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 25%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 75%; border-radius: 0.375rem"\n ></div>\n </div>\n <div\n class="skeleton"\n style="\n height: 3.5rem;\n width: 100%;\n border-radius: 0.375rem;\n margin-top: 1rem;\n "\n ></div>\n <div\n class="skeleton"\n style="\n height: 0.7rem;\n width: 30%;\n margin: 0 auto;\n border-radius: 0.2rem;\n margin-top: 2rem;\n "\n ></div>\n <div\n style="\n display: flex;\n width: 100%;\n flex-direction: column;\n gap: 2rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n </div>\n </div>\n <style>\n @keyframes pulse {\n 0% {\n background-position: 200% 50%;\n }\n 100% {\n background-position: -100% 50%;\n }\n }\n\n .skeleton {\n background: #121212; /* Darker background for skeleton */\n background-image: linear-gradient(\n 90deg,\n #121212 25%,\n #1c1c1c 50%,\n #121212 75%\n );\n background-size: 200% 100%;\n background-position: 100% 50%;\n animation: pulse 1.5s infinite ease-in-out;\n }\n </style>',e.skeletonLight=' <div\n style="\n width: 100%;\n height: 450px;\n margin-left: auto;\n margin-right: auto;\n overflow: hidden;\n "\n >\n <div\n id="1"\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n style="\n display: flex;\n gap: 1rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 25%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 75%; border-radius: 0.375rem"\n ></div>\n </div>\n <div\n class="skeleton"\n style="\n height: 3.5rem;\n width: 100%;\n border-radius: 0.375rem;\n margin-top: 1rem;\n "\n ></div>\n <div\n class="skeleton"\n style="\n height: 0.7rem;\n width: 30%;\n margin: 0 auto;\n border-radius: 0.2rem;\n margin-top: 2rem;\n "\n ></div>\n <div\n style="\n display: flex;\n width: 100%;\n flex-direction: column;\n gap: 2rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n </div>\n </div>\n <style>\n @keyframes pulse {\n 0% {\n background-position: 200% 50%;\n }\n 100% {\n background-position: -100% 50%;\n }\n }\n\n .skeleton {\n background: #cccccc;\n background-image: linear-gradient(\n 90deg,\n #cccccc 25%,\n #e2e2e2 50%,\n #cccccc 75%\n );\n background-size: 200% 100%;\n background-position: 100% 50%;\n animation: pulse 1.5s infinite ease-in-out;\n }\n </style>',e.skeletonOptions={dark:e.skeletonDark,light:e.skeletonLight,DEFAULT:e.skeletonLight}},607:function(t,e,n){var i=this&&this.__assign||function(){return i=Object.assign||function(t){for(var e,n=1,i=arguments.length;n<i;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},i.apply(this,arguments)},r=this&&this.__createBinding||(Object.create?function(t,e,n,i){void 0===i&&(i=n);var r=Object.getOwnPropertyDescriptor(e,n);r&&!("get"in r?!e.__esModule:r.writable||r.configurable)||(r={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,i,r)}:function(t,e,n,i){void 0===i&&(i=n),t[i]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&r(e,t,n);return o(e,t),e},a=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((i=i.apply(t,e||[])).next())}))},c=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,i&&(r=2&a[0]?i.return:a[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,a[1])).done)return r;switch(i=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],i=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.getCountryCodes=e.getCountries=e.getStatesBy=e.getIdentificationBy=e.setSdk=void 0;var l,d=s(n(0)),u=n(986),h="https://sdk-iframe.rebill.to/v3/index.html",p=function(){function t(t){var e=this;this.api_key=t,this.enableSync=!1,this.onSuccess=function(){},this.onError=function(){},this.onDisabled=function(){},this.onLoading=function(){},this.metadataObject={},this.styles={},this.gateway={},this.iframeHeight="450px",this.submitTransaction=!1,this.disabled=!1,window.addEventListener("message",(function(t){var n=t.data,i=n.type,r=n.detail;switch(i){case u.CONSTANTS.ON_SUCCESS:e.onSuccess(r);break;case u.CONSTANTS.ON_ERROR:e.onError(r);break;case u.CONSTANTS.SET_HEIGHT:var o=document.getElementById(e.html_id||"");o&&r&&(o.style.height=r);break;case u.CONSTANTS.SET_LOADING:e.onLoading(r);break;case u.CONSTANTS.SET_DISABLED:e.onDisabled(r)}}),!1),window.addEventListener(u.CONSTANTS.IFRAME_READY,(function(){var t,n,i,r,o=window.frames.rebill_elements;e.enableSync=!0,o.postMessage({type:u.CONSTANTS.TRANSACTION_USE_CASE,detail:null===(t=e.priceData)||void 0===t?void 0:t.price.priceSetting.paymentMethods},h),o.postMessage({type:u.CONSTANTS.ADD_CARD_USE_CASE,detail:e.customerId},h),o.postMessage({type:u.CONSTANTS.RENEW_CARD_USE_CASE,detail:e.subscriptionId},h),o.postMessage({type:u.CONSTANTS.SET_REQUEST,detail:e.getRequest()},h),o.postMessage({type:u.CONSTANTS.SET_CURRENCY,detail:null===(n=e.priceData)||void 0===n?void 0:n.price.currency},h),o.postMessage({type:u.CONSTANTS.SET_PRICE,detail:{id:null===(i=e.priceData)||void 0===i?void 0:i.price.id,quantity:null===(r=e.priceData)||void 0===r?void 0:r.quantity}},h),o.postMessage({type:u.CONSTANTS.SET_CONFIG_OPTIONS,detail:e.config},h),o.postMessage({type:u.CONSTANTS.SET_TEXT,detail:e.text},h),o.postMessage({type:u.CONSTANTS.SET_STYLES,detail:e.styles},h),o.postMessage({type:u.CONSTANTS.SET_CARDHOLDER,detail:e.cardHolder},h),o.postMessage({type:u.CONSTANTS.SET_CUSTOMER,detail:e.customer},h),o.postMessage({type:u.CONSTANTS.SUBMIT_ACTION,detail:e.submitTransaction},h)}))}return t.prototype.setUpdate=function(){window.frames.rebill_elements.postMessage({type:u.CONSTANTS.SET_REQUEST,detail:this.getRequest()},h)},t.prototype.getRequest=function(){return{PAYLOAD:i(i({metadataObject:this.metadataObject},this.transaction),{priceData:this.priceData,gateway:{type:this.gateway.type,country:this.gateway.country}}),REBILL_DEVICE_ID:l,API_KEY:this.api_key}},t.prototype.setCustomer=function(t){this.customer=t},t.prototype.renewCard=function(t){return a(this,void 0,void 0,(function(){return c(this,(function(e){return this.subscriptionId=t,this.setIframe(),[2]}))}))},t.prototype.addCard=function(t){return a(this,void 0,void 0,(function(){return c(this,(function(e){return this.customerId=t,this.setIframe(),[2]}))}))},t.prototype.setTransaction=function(t){return a(this,void 0,void 0,(function(){var e,n,r,o,s,a,l,h,p,f,y,S,v,m,g,E;return c(this,(function(c){switch(c.label){case 0:return e=t.id,n=t.currency,r=t.quantity,o=r||1,s=this.api_key,this.enableSync&&this.setUpdate(),this.html_id&&(a=document.getElementById(this.html_id))&&(l=null===(E=this.styles)||void 0===E?void 0:E.rebill_skeleton_theme,h=u.skeletonOptions[l]||u.skeletonOptions.DEFAULT,a.innerHTML=h),[4,d.getItemData(e,n,s)];case 1:return p=c.sent(),[4,d.getOrganizationData(s)];case 2:if(!(f=c.sent()))throw new Error("The organization attached to this API key doesn't exist");if(!p)throw new Error("Neither product nor plan found with the given ID.");return y=p.price,S=y.priceSetting,v=y.gateway,m=f.alias.toUpperCase().includes("SANDBOX"),(g=document.createElement("script")).src=m?"https://secure.rebill.dev/v1/Scripts/Antifraud.js?key=".concat(v.publicKey):"".concat("https://secure.rebill.com","/v1/Scripts/Antifraud.js?key=").concat(v.publicKey),g.type="text/javascript",document.head.appendChild(g),this.priceData=i(i({},p),{quantity:o}),this.gateway={type:v.type,country:v.country},this.setIframe(),[2,S]}}))}))},t.prototype.setCallbacks=function(t){(null==t?void 0:t.onSuccess)&&(this.onSuccess=t.onSuccess),(null==t?void 0:t.onError)&&(this.onError=t.onError),(null==t?void 0:t.onLoading)&&(this.onLoading=t.onLoading),(null==t?void 0:t.onDisabled)&&(this.onDisabled=t.onDisabled)},t.prototype.setText=function(t){this.text=t,this.enableSync&&this.setUpdate()},t.prototype.setStyles=function(t){this.styles=t},t.prototype.setElements=function(t){var e;this.html_id=t;var n=document.getElementById(t);if(n){var i=null===(e=this.styles)||void 0===e?void 0:e.rebill_skeleton_theme,r=u.skeletonOptions[i]||u.skeletonOptions.DEFAULT;n.innerHTML=r}},t.prototype.setIframe=function(){var t=this.html_id;if(!t)throw new Error("Missing element id");setTimeout((function(){var e;l=null===(e=null===window||void 0===window?void 0:window.fingerPrintModel)||void 0===e?void 0:e.sessionid;var n=document.getElementById(t);if(!n)throw new Error("HTMLElement invalid.");window.setReady=function(){dispatchEvent(new CustomEvent(u.CONSTANTS.IFRAME_READY))};var i='\n <iframe\n id="rebill_elements"\n title="rebill_elements"\n name="rebill_elements"\n src="'.concat(h,'"\n onLoad="setReady()"\n style="height: 100%; width: 100%; border: unset; overflow: visible;"\n allow="clipboard-read; clipboard-write"\n />\n ');n.innerHTML=i}),1500)},t.prototype.setMetadata=function(t){void 0===t&&(t={});var e=i(i({},this.metadataObject),t);this.metadataObject=e,this.enableSync&&this.setUpdate()},t.prototype.setConfigOptions=function(t){this.config=t,this.enableSync&&this.setUpdate()},t.prototype.setCardHolder=function(t){this.cardHolder=t,this.enableSync&&this.setUpdate()},t.prototype.submitPaymentWithCard=function(){return a(this,void 0,void 0,(function(){return c(this,(function(t){return this.submitTransaction=!0,window.frames.rebill_elements.postMessage({type:u.CONSTANTS.SUBMIT_ACTION,detail:this.submitTransaction},h),[2]}))}))},t}();e.setSdk=p,e.getIdentificationBy=function(t){return a(this,void 0,void 0,(function(){var e;return c(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/identification/").concat(t))];case 1:if(!(e=n.sent()).ok)throw new Error("Error fetching identification data: ".concat(e.status));return[4,e.json()];case 2:return[2,n.sent()]}}))}))},e.getStatesBy=function(t){return a(this,void 0,void 0,(function(){var e;return c(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/states/").concat(t))];case 1:if(!(e=n.sent()).ok)throw new Error("Error fetching states data: ".concat(e.status));return[4,e.json()];case 2:return[2,n.sent()]}}))}))},e.getCountries=function(){return a(this,void 0,void 0,(function(){var t;return c(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/countries"))];case 1:if(!(t=e.sent()).ok)throw new Error("Error fetching countries data: ".concat(t.status));return[4,t.json()];case 2:return[2,e.sent()]}}))}))},e.getCountryCodes=function(){return a(this,void 0,void 0,(function(){var t;return c(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/countrycode"))];case 1:if(!(t=e.sent()).ok)throw new Error("Error fetching countries code data: ".concat(t.status));return[4,t.json()];case 2:return[2,e.sent()]}}))}))}},0:function(t,e){var n=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function s(t){try{c(i.next(t))}catch(t){o(t)}}function a(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((i=i.apply(t,e||[])).next())}))},i=this&&this.__generator||function(t,e){var n,i,r,o,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,i&&(r=2&a[0]?i.return:a[0]?i.throw||((r=i.return)&&r.call(i),0):i.next)&&!(r=r.call(i,a[1])).done)return r;switch(i=0,r&&(a=[2&a[0],r.value]),a[0]){case 0:case 1:r=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,i=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(r=s.trys,(r=r.length>0&&r[r.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!r||a[1]>r[0]&&a[1]<r[3])){s.label=a[1];break}if(6===a[0]&&s.label<r[1]){s.label=r[1],r=a;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(a);break}r[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],i=0}finally{n=r=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.getOrganizationData=e.getItemData=void 0,e.getItemData=function(t,e,r){return n(this,void 0,void 0,(function(){var n,o;return i(this,(function(i){switch(i.label){case 0:return n={itemId:t,currency:e},[4,fetch("".concat("https://api.rebill.com","/v2/item/checkout"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(r)},body:JSON.stringify(n)})];case 1:if(!(o=i.sent()).ok)throw new Error("Network response was not ok");return[4,o.json()];case 2:return[2,i.sent()]}}))}))},e.getOrganizationData=function(t){return n(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/organization/"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)}})];case 1:if(!(e=n.sent()).ok)throw new Error("Network response was not ok");return[4,e.json()];case 2:return[2,n.sent()]}}))}))}}},e={};var n=function n(i){var r=e[i];if(void 0!==r)return r.exports;var o=e[i]={exports:{}};return t[i].call(o.exports,o,o.exports,n),o.exports}(607);return n})()));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Rebill=e():t.Rebill=e()}(this,(()=>(()=>{"use strict";var t={986:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.skeletonOptions=e.skeletonLight=e.skeletonDark=e.currencyByCountry=e.CONSTANTS=void 0,e.CONSTANTS={IFRAME_READY:"IFRAME_READY",ON_SUCCESS:"ON_SUCCESS",ON_ERROR:"ON_ERROR",SET_TEXT:"SET_TEXT",SET_REQUEST:"SET_REQUEST",SET_CARDHOLDER:"SET_CARDHOLDER",SET_STYLES:"SET_STYLES",SET_CURRENCY:"SET_CURRENCY",TRANSACTION_USE_CASE:"TRANSACTION_USE_CASE",SET_PRICE:"SET_PRICE",RENEW_CARD_USE_CASE:"RENEW_CARD_USE_CASE",ADD_CARD_USE_CASE:"ADD_CARD_USE_CASE",SET_CONFIG_OPTIONS:"SET_CONFIG_OPTIONS",SET_CUSTOMER:"SET_CUSTOMER",SET_HEIGHT:"SET_HEIGHT",SUBMIT_ACTION:"SUBMIT_ACTION",SET_DISABLED:"SET_DISABLED",SET_LOADING:"SET_LOADING"},e.currencyByCountry={AR:"ARS",BO:"BOB",CL:"CLP",UY:"UYU",MX:"MXN",CO:"COP",PE:"PEN",BR:"BRL",USD:"USD",INDIFFERENT:"USD"},e.skeletonDark=' <div\n style="\n width: 100%;\n height: 450px;\n margin-left: auto;\n margin-right: auto;\n overflow: hidden;\n "\n >\n <div\n id="1"\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n style="\n display: flex;\n gap: 1rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 25%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 75%; border-radius: 0.375rem"\n ></div>\n </div>\n <div\n class="skeleton"\n style="\n height: 3.5rem;\n width: 100%;\n border-radius: 0.375rem;\n margin-top: 1rem;\n "\n ></div>\n <div\n class="skeleton"\n style="\n height: 0.7rem;\n width: 30%;\n margin: 0 auto;\n border-radius: 0.2rem;\n margin-top: 2rem;\n "\n ></div>\n <div\n style="\n display: flex;\n width: 100%;\n flex-direction: column;\n gap: 2rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n </div>\n </div>\n <style>\n @keyframes pulse {\n 0% {\n background-position: 200% 50%;\n }\n 100% {\n background-position: -100% 50%;\n }\n }\n\n .skeleton {\n background: #121212; /* Darker background for skeleton */\n background-image: linear-gradient(\n 90deg,\n #121212 25%,\n #1c1c1c 50%,\n #121212 75%\n );\n background-size: 200% 100%;\n background-position: 100% 50%;\n animation: pulse 1.5s infinite ease-in-out;\n }\n </style>',e.skeletonLight=' <div\n style="\n width: 100%;\n height: 450px;\n margin-left: auto;\n margin-right: auto;\n overflow: hidden;\n "\n >\n <div\n id="1"\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n style="\n display: flex;\n gap: 1rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 25%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 75%; border-radius: 0.375rem"\n ></div>\n </div>\n <div\n class="skeleton"\n style="\n height: 3.5rem;\n width: 100%;\n border-radius: 0.375rem;\n margin-top: 1rem;\n "\n ></div>\n <div\n class="skeleton"\n style="\n height: 0.7rem;\n width: 30%;\n margin: 0 auto;\n border-radius: 0.2rem;\n margin-top: 2rem;\n "\n ></div>\n <div\n style="\n display: flex;\n width: 100%;\n flex-direction: column;\n gap: 2rem;\n align-items: center;\n margin-top: 1rem;\n "\n >\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n <div\n class="skeleton"\n style="height: 3rem; width: 100%; border-radius: 0.375rem"\n ></div>\n </div>\n </div>\n <style>\n @keyframes pulse {\n 0% {\n background-position: 200% 50%;\n }\n 100% {\n background-position: -100% 50%;\n }\n }\n\n .skeleton {\n background: #cccccc;\n background-image: linear-gradient(\n 90deg,\n #cccccc 25%,\n #e2e2e2 50%,\n #cccccc 75%\n );\n background-size: 200% 100%;\n background-position: 100% 50%;\n animation: pulse 1.5s infinite ease-in-out;\n }\n </style>',e.skeletonOptions={dark:e.skeletonDark,light:e.skeletonLight,DEFAULT:e.skeletonLight}},815:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e._propertyOrder=e.getValidPaymentMethodsStructure=e._GroupByPaymentMethod=void 0;var r=n(686);e._GroupByPaymentMethod=function(t){var e={};return t.forEach((function(t){var n=t.type,r=t.metadata;e[n]||(e[n]=[]),e[n].push(r)})),e};e.getValidPaymentMethodsStructure=function(t){if(!t)return{};var n={},r=(0,e._GroupByPaymentMethod)(t);return e._propertyOrder.forEach((function(t){r.hasOwnProperty(t)&&(n[t]=r[t])})),n||{}},e._propertyOrder=[r.PaymentMethodType.CARD,r.PaymentMethodType.TRANSFER,r.PaymentMethodType.CASH]},607:function(t,e,n){var r=this&&this.__assign||function(){return r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},r.apply(this,arguments)},i=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),o=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),s=this&&this.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(null!=t)for(var n in t)"default"!==n&&Object.prototype.hasOwnProperty.call(t,n)&&i(e,t,n);return o(e,t),e},a=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},c=this&&this.__generator||function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.getCountryCodes=e.getCountries=e.getStatesBy=e.getIdentificationBy=e.setSdk=void 0;var u,d=s(n(160)),l=n(986),h=s(n(815)),p="https://sdk-iframe.rebill.to/v3/index.html",y=function(){function t(t){var e=this;this.api_key=t,this.enableSync=!1,this.onSuccess=function(){},this.onError=function(){},this.onDisabled=function(){},this.onLoading=function(){},this.metadataObject={},this.styles={},this.gateway={},this.iframeHeight="450px",this.submitTransaction=!1,this.disabled=!1,window.addEventListener("message",(function(t){var n=t.data,r=n.type,i=n.detail;switch(r){case l.CONSTANTS.ON_SUCCESS:e.onSuccess(i);break;case l.CONSTANTS.ON_ERROR:e.onError(i);break;case l.CONSTANTS.SET_HEIGHT:var o=document.getElementById(e.html_id||"");o&&i&&(o.style.height=i);break;case l.CONSTANTS.SET_LOADING:e.onLoading(i);break;case l.CONSTANTS.SET_DISABLED:e.onDisabled(i)}}),!1),window.addEventListener(l.CONSTANTS.IFRAME_READY,(function(){var t,n,r,i=window.frames.rebill_elements;e.enableSync=!0,i.postMessage({type:l.CONSTANTS.TRANSACTION_USE_CASE,detail:e.paymentMethods},p),i.postMessage({type:l.CONSTANTS.ADD_CARD_USE_CASE,detail:e.customerId},p),i.postMessage({type:l.CONSTANTS.RENEW_CARD_USE_CASE,detail:e.subscriptionId},p),i.postMessage({type:l.CONSTANTS.SET_REQUEST,detail:e.getRequest()},p),i.postMessage({type:l.CONSTANTS.SET_CURRENCY,detail:null===(t=e.priceData)||void 0===t?void 0:t.price.currency},p),i.postMessage({type:l.CONSTANTS.SET_PRICE,detail:{id:null===(n=e.priceData)||void 0===n?void 0:n.price.id,quantity:null===(r=e.priceData)||void 0===r?void 0:r.quantity}},p),i.postMessage({type:l.CONSTANTS.SET_CONFIG_OPTIONS,detail:e.config},p),i.postMessage({type:l.CONSTANTS.SET_TEXT,detail:e.text},p),i.postMessage({type:l.CONSTANTS.SET_STYLES,detail:e.styles},p),i.postMessage({type:l.CONSTANTS.SET_CARDHOLDER,detail:e.cardHolder},p),i.postMessage({type:l.CONSTANTS.SET_CUSTOMER,detail:e.customer},p),i.postMessage({type:l.CONSTANTS.SUBMIT_ACTION,detail:e.submitTransaction},p)}))}return t.prototype.setUpdate=function(){window.frames.rebill_elements.postMessage({type:l.CONSTANTS.SET_REQUEST,detail:this.getRequest()},p)},t.prototype.getRequest=function(){return{PAYLOAD:r(r({metadataObject:this.metadataObject},this.transaction),{priceData:this.priceData,gateway:{type:this.gateway.type,country:this.gateway.country}}),REBILL_DEVICE_ID:u,API_KEY:this.api_key}},t.prototype.setCustomer=function(t){this.customer=t},t.prototype.renewCard=function(t){return a(this,void 0,void 0,(function(){return c(this,(function(e){return this.subscriptionId=t,this.setIframe(),[2]}))}))},t.prototype.addCard=function(t){return a(this,void 0,void 0,(function(){return c(this,(function(e){return this.customerId=t,this.setIframe(),[2]}))}))},t.prototype.setTransaction=function(t){return a(this,void 0,void 0,(function(){var e,n,i,o,s,a,u,p,y,f,S,m,v,E,g,T,b,_;return c(this,(function(c){switch(c.label){case 0:return e=t.id,n=t.currency,i=t.quantity,o=this.api_key,s=i||1,(a=n)?[3,2]:[4,d.getCurrencyByCustomerLocation()];case 1:a=c.sent(),c.label=2;case 2:return this.enableSync&&this.setUpdate(),this.html_id&&(u=document.getElementById(this.html_id))&&(p=null===(_=this.styles)||void 0===_?void 0:_.rebill_skeleton_theme,y=l.skeletonOptions[p]||l.skeletonOptions.DEFAULT,u.innerHTML=y),[4,d.getItemData(e,a,o)];case 3:return f=c.sent(),[4,d.getOrganizationData(o)];case 4:if(!(S=c.sent()))throw new Error("The organization attached to this API key doesn't exist");if(!f)throw new Error("Neither product nor plan found with the given ID.");return m=f.price,v=m.priceSetting,E=m.gateway,g=v.paymentMethods,this.paymentMethods=h.getValidPaymentMethodsStructure(g),T=S.alias.toUpperCase().includes("SANDBOX"),(b=document.createElement("script")).src=T?"https://secure.rebill.dev/v1/Scripts/Antifraud.js?key=".concat(E.publicKey):"".concat("https://secure.rebill.com","/v1/Scripts/Antifraud.js?key=").concat(E.publicKey),b.type="text/javascript",document.head.appendChild(b),this.priceData=r(r({},f),{quantity:s}),this.gateway={type:E.type,country:E.country},this.setIframe(),[2,this.paymentMethods]}}))}))},t.prototype.setCallbacks=function(t){(null==t?void 0:t.onSuccess)&&(this.onSuccess=t.onSuccess),(null==t?void 0:t.onError)&&(this.onError=t.onError),(null==t?void 0:t.onLoading)&&(this.onLoading=t.onLoading),(null==t?void 0:t.onDisabled)&&(this.onDisabled=t.onDisabled)},t.prototype.setText=function(t){this.text=t,this.enableSync&&this.setUpdate()},t.prototype.setStyles=function(t){this.styles=t},t.prototype.setElements=function(t){var e;this.html_id=t;var n=document.getElementById(t);if(n){var r=null===(e=this.styles)||void 0===e?void 0:e.rebill_skeleton_theme,i=l.skeletonOptions[r]||l.skeletonOptions.DEFAULT;n.innerHTML=i}},t.prototype.setIframe=function(){var t=this.html_id;if(!t)throw new Error("Missing element id");setTimeout((function(){var e;u=null===(e=null===window||void 0===window?void 0:window.fingerPrintModel)||void 0===e?void 0:e.sessionid;var n=document.getElementById(t);if(!n)throw new Error("HTMLElement invalid.");window.setReady=function(){dispatchEvent(new CustomEvent(l.CONSTANTS.IFRAME_READY))};var r='\n <iframe\n id="rebill_elements"\n title="rebill_elements"\n name="rebill_elements"\n src="'.concat(p,'"\n onLoad="setReady()"\n style="height: 100%; width: 100%; border: unset; overflow: visible;"\n allow="clipboard-read; clipboard-write"\n />\n ');n.innerHTML=r}),1500)},t.prototype.setMetadata=function(t){void 0===t&&(t={});var e=r(r({},this.metadataObject),t);this.metadataObject=e,this.enableSync&&this.setUpdate()},t.prototype.setConfigOptions=function(t){this.config=t,this.enableSync&&this.setUpdate()},t.prototype.setCardHolder=function(t){this.cardHolder=t,this.enableSync&&this.setUpdate()},t.prototype.submitPaymentWithCard=function(){return a(this,void 0,void 0,(function(){return c(this,(function(t){return this.submitTransaction=!0,window.frames.rebill_elements.postMessage({type:l.CONSTANTS.SUBMIT_ACTION,detail:this.submitTransaction},p),[2]}))}))},t}();e.setSdk=y,e.getIdentificationBy=function(t){return a(this,void 0,void 0,(function(){var e;return c(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/identification/").concat(t))];case 1:if(!(e=n.sent()).ok)throw new Error("Error fetching identification data: ".concat(e.status));return[4,e.json()];case 2:return[2,n.sent()]}}))}))},e.getStatesBy=function(t){return a(this,void 0,void 0,(function(){var e;return c(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/states/").concat(t))];case 1:if(!(e=n.sent()).ok)throw new Error("Error fetching states data: ".concat(e.status));return[4,e.json()];case 2:return[2,n.sent()]}}))}))},e.getCountries=function(){return a(this,void 0,void 0,(function(){var t;return c(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/countries"))];case 1:if(!(t=e.sent()).ok)throw new Error("Error fetching countries data: ".concat(t.status));return[4,t.json()];case 2:return[2,e.sent()]}}))}))},e.getCountryCodes=function(){return a(this,void 0,void 0,(function(){var t;return c(this,(function(e){switch(e.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/data/countrycode"))];case 1:if(!(t=e.sent()).ok)throw new Error("Error fetching countries code data: ".concat(t.status));return[4,t.json()];case 2:return[2,e.sent()]}}))}))}},686:(t,e)=>{var n;Object.defineProperty(e,"__esModule",{value:!0}),e.PaymentMethodType=void 0,function(t){t.CARD="CARD",t.CASH="CASH",t.TRANSFER="TRANSFER",t.WALLET="WALLET"}(n||(e.PaymentMethodType=n={}))},160:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))},i=this&&this.__generator||function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.getCurrencyByCustomerLocation=e.getOrganizationData=e.getItemData=void 0;var o=n(986);e.getItemData=function(t,e,n){return r(this,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return r={itemId:t,currency:e},[4,fetch("".concat("https://api.rebill.com","/v2/item/checkout"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(n)},body:JSON.stringify(r)})];case 1:if(!(o=i.sent()).ok)throw new Error("Network response was not ok");return[4,o.json()];case 2:return[2,i.sent()]}}))}))},e.getOrganizationData=function(t){return r(this,void 0,void 0,(function(){var e;return i(this,(function(n){switch(n.label){case 0:return[4,fetch("".concat("https://api.rebill.com","/v2/organization/"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(t)}})];case 1:if(!(e=n.sent()).ok)throw new Error("Network response was not ok");return[4,e.json()];case 2:return[2,n.sent()]}}))}))},e.getCurrencyByCustomerLocation=function(){return r(this,void 0,void 0,(function(){var t,e,n;return i(this,(function(r){switch(r.label){case 0:return r.trys.push([0,5,,6]),[4,fetch("https://api.ipify.org/?format=json")];case 1:return[4,r.sent().json()];case 2:return t=r.sent(),[4,fetch("https://ipapi.co/".concat(t.ip,"/country_code/"))];case 3:return[4,r.sent().text()];case 4:return e=r.sent(),[2,o.currencyByCountry[e]||o.currencyByCountry.INDIFFERENT];case 5:return n=r.sent(),console.error(n),[2,o.currencyByCountry.INDIFFERENT];case 6:return[2]}}))}))}}},e={};var n=function n(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,n),o.exports}(607);return n})()));
|
package/package.json
CHANGED
package/sdk/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ import countryCode from "./schemas/countryCode.schema";
|
|
|
12
12
|
import { PriceData } from "./schemas/item.schema";
|
|
13
13
|
import State from "./schemas/states.schema";
|
|
14
14
|
import { Styles } from "./schemas/styles.schema";
|
|
15
|
+
import { PaymentMethodsByType } from "./schemas/paymentMethod.schema";
|
|
15
16
|
export declare class setSdk {
|
|
16
17
|
api_key: string;
|
|
17
18
|
text?: Text;
|
|
@@ -35,6 +36,7 @@ export declare class setSdk {
|
|
|
35
36
|
config?: Config;
|
|
36
37
|
submitTransaction: boolean;
|
|
37
38
|
disabled: boolean;
|
|
39
|
+
paymentMethods?: Partial<PaymentMethodsByType>;
|
|
38
40
|
constructor(apiKey: string);
|
|
39
41
|
setUpdate(): void;
|
|
40
42
|
getRequest(): {
|
|
@@ -55,7 +57,7 @@ export declare class setSdk {
|
|
|
55
57
|
setCustomer(customer_data: Customer): void;
|
|
56
58
|
renewCard(subscriptionId: string): Promise<void>;
|
|
57
59
|
addCard(customerId: string): Promise<void>;
|
|
58
|
-
setTransaction(transaction: Transaction): Promise<
|
|
60
|
+
setTransaction(transaction: Transaction): Promise<Partial<PaymentMethodsByType>>;
|
|
59
61
|
setCallbacks(callbacks: Callbacks): void;
|
|
60
62
|
setText(text: Text): void;
|
|
61
63
|
setStyles(value: Object): void;
|