rebill 1.0.1 → 1.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/index.js ADDED
@@ -0,0 +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.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_STYLES:"SET_STYLES",SET_CURRENCY:"SET_CURRENCY",SET_PAYMENT_METHODS:"SET_PAYMENT_METHODS",SET_PRICE:"SET_PRICE",SET_RENEW_CARD:"SET_RENEW_CARD"}},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,l=s(n(0)),d=n(986),h="https://sdk-iframe.rebill.dev/v3/index.html",f=function(){function t(t){var e=this;this.api_key=t,this.enableSync=!1,this.onSuccess=function(){},this.onError=function(){},this.metadataObject={},this.styles={},this.gateway={},window.addEventListener("message",(function(t){var n=t.data,r=n.type,i=n.detail;switch(r){case d.CONSTANTS.ON_SUCCESS:e.onSuccess(i);break;case d.CONSTANTS.ON_ERROR:e.onError(i)}}),!1),window.addEventListener(d.CONSTANTS.IFRAME_READY,(function(){var t,n,r,i=window.frames.rebill_elements;e.enableSync=!0,i.postMessage({type:d.CONSTANTS.SET_REQUEST,detail:e.getRequest()},h),i.postMessage({type:d.CONSTANTS.SET_CURRENCY,detail:null===(t=e.priceData)||void 0===t?void 0:t.price.currency},h),i.postMessage({type:d.CONSTANTS.SET_PAYMENT_METHODS,detail:null===(n=e.priceData)||void 0===n?void 0:n.price.priceSetting.paymentMethods},h),i.postMessage({type:d.CONSTANTS.SET_PRICE,detail:null===(r=e.priceData)||void 0===r?void 0:r.price},h)}))}return t.prototype.setUpdate=function(){window.frames.rebill_elements.postMessage({type:d.CONSTANTS.SET_REQUEST,detail:this.getRequest()},h)},t.prototype.getRequest=function(){var t,e;return{URI:"".concat("https://api.rebill.dev","/v2"),PAYLOAD:r(r({metadataObject:this.metadataObject,customer:r({},this.customer)},this.transaction),{priceData:{id:null===(t=this.priceData)||void 0===t?void 0:t.price.id,quantity:null===(e=this.priceData)||void 0===e?void 0:e.quantity},gateway:{type:this.gateway.type,country:this.gateway.country},subscriptionId:this.subscriptionId,customerId:this.customerId,styles:this.styles,text:this.text}),REBILL_DEVICE_ID:u,API_KEY:this.api_key}},t.prototype.setCustomer=function(t){this.customer=t,this.enableSync&&this.setUpdate()},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,d,h;return c(this,(function(c){switch(c.label){case 0:return e=t.id,n=t.currency,i=t.quantity,o=this.api_key,this.enableSync&&this.setUpdate(),[4,l.getItemData(e,n,o)];case 1:if(!(s=c.sent()))throw new Error("Neither product nor plan found with the given ID.");return a=s.price,u=a.priceSetting,(d=a.gateway).publicKey&&((h=document.createElement("script")).src="".concat("MISSING_ENV_VAR".SDK_REBILL_GATEWAY,"/v1/Scripts/Antifraud.js?key=").concat(d.publicKey),h.type="text/javascript",document.head.appendChild(h)),this.priceData=r(r({},s),{quantity:i}),this.gateway={type:d.type,country:d.country},this.setIframe(),[2,u]}}))}))},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)},t.prototype.setText=function(t){this.text=t,this.enableSync&&this.setUpdate()},t.prototype.setStyles=function(t){this.styles=t,this.enableSync&&this.setUpdate()},t.prototype.setElements=function(t){if(!t)throw new Error("Missing element id");if(!document.getElementById(t))throw new Error("HTMLElement invalid.");this.html_id=t},t.prototype.setIframe=function(){var t=this,e=this.html_id;if(!e)throw new Error("Missing element id");setTimeout((function(){var n;u=null===(n=null===window||void 0===window?void 0:window.fingerPrintModel)||void 0===n?void 0:n.sessionid;var r=document.getElementById(e);if(!r)throw new Error("HTMLElement invalid.");t.api_key&&t.getRequest(),window.setReady=function(){return dispatchEvent(new CustomEvent(d.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 ');r.innerHTML=i}),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.submit=function(t){return a(this,void 0,void 0,(function(){var t,e=this;return c(this,(function(n){switch(n.label){case 0:return t=this.getRequest(),[4,fetch(t.URI,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(t.PAYLOAD)}).then((function(t){if(t.ok)return t.json()})).then((function(t){return e.onSuccess(t)})).catch((function(t){return e.onError(t)}))];case 1:return n.sent(),[2]}}))}))},t}();e.setSdk=f,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.dev","/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.dev","/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.dev","/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.dev","/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,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())}))},r=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.getItemData=void 0,e.getItemData=function(t,e,i){return n(this,void 0,void 0,(function(){var n,o;return r(this,(function(r){switch(r.label){case 0:return n={itemId:t,currency:e},[4,fetch("".concat("https://api.rebill.dev","/v2/item/checkout"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(i)},body:JSON.stringify(n)})];case 1:if(!(o=r.sent()).ok)throw new Error("Network response was not ok");return[4,o.json()];case 2:return[2,r.sent()]}}))}))}}},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
@@ -1,44 +1,20 @@
1
1
  {
2
2
  "name": "rebill",
3
- "version": "1.0.1",
4
- "description": "Rebill API Wrapper.",
3
+ "version": "1.0.2",
4
+ "description": "A Pure JavaScript SDK to integrate Rebill into your web or ecosystem",
5
5
  "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/rebillto/rebill-node.git"
12
- },
6
+ "types": "./sdk/index.d.ts",
7
+ "files": [
8
+ "index.js",
9
+ "sdk/index.d.ts"
10
+ ],
11
+ "scripts": {},
13
12
  "keywords": [
14
- "Rebill",
15
- "rebill.to",
16
- "Rebill",
17
- "API",
18
- "recurring",
19
- "billing",
20
- "subscriptions",
21
- "memberships",
22
- "latam",
23
- "latin",
24
- "america",
25
- "recurring",
26
- "payments",
27
- "payments",
28
- "processing",
29
- "PCI",
30
- "compliance",
31
- "security",
32
- "credit",
33
- "cards",
34
- "bank",
35
- "accounts",
36
- "payments"
13
+ "rebill",
14
+ "sdk",
15
+ "checkout",
16
+ "javascript",
17
+ "typescript"
37
18
  ],
38
- "author": "Rebill, Inc.",
39
- "license": "MIT",
40
- "bugs": {
41
- "url": "https://github.com/rebillto/rebill-node/issues"
42
- },
43
- "homepage": "https://github.com/rebillto/rebill-node#readme"
19
+ "author": "Alejo Rojas"
44
20
  }
package/sdk/index.d.ts ADDED
@@ -0,0 +1,80 @@
1
+ import { IsoCountryEnum } from "../shared/enums/countriesEnum";
2
+ import { Callbacks } from "./schemas/callback.schema";
3
+ import { Card } from "./schemas/card.schema";
4
+ import { Text } from "./schemas/text.schema";
5
+ import { Customer } from "./schemas/customer.schema";
6
+ import { CardHolder } from "./schemas/cardHolder.schema";
7
+ import { Transaction } from "./schemas/transaction.schema";
8
+ import { Country } from "./schemas/country.schema";
9
+ import { Identification } from "./schemas/identification.schema";
10
+ import countryCode from "./schemas/countryCode.schema";
11
+ import { PriceData } from "./schemas/item.schema";
12
+ import State from "./schemas/states.schema";
13
+ import { Styles } from "./schemas/styles.schema";
14
+ export declare class setSdk {
15
+ api_key: string;
16
+ text?: Text;
17
+ customer?: Customer;
18
+ card_holder?: CardHolder;
19
+ transaction?: Transaction;
20
+ card?: Card;
21
+ enableSync?: boolean;
22
+ onSuccess: Function;
23
+ onError: Function;
24
+ metadataObject?: any;
25
+ styles?: Styles;
26
+ priceData?: PriceData;
27
+ gateway?: any;
28
+ subscriptionId?: string;
29
+ customerId?: string;
30
+ html_id?: string;
31
+ constructor(apiKey: string);
32
+ setUpdate(): void;
33
+ getRequest(): {
34
+ URI: string;
35
+ PAYLOAD: {
36
+ priceData: {
37
+ id: string | undefined;
38
+ quantity: number | undefined;
39
+ };
40
+ gateway: {
41
+ type: any;
42
+ country: any;
43
+ };
44
+ subscriptionId: string | undefined;
45
+ customerId: string | undefined;
46
+ styles: Styles | undefined;
47
+ text: Text | undefined;
48
+ id?: string | undefined;
49
+ currency?: import("./schemas/currencyEnum.schema").CurrencyTypeEnum | undefined;
50
+ quantity?: number | undefined;
51
+ metadataObject: any;
52
+ customer: {
53
+ firstName?: string | undefined;
54
+ lastName?: string | undefined;
55
+ email?: string | undefined;
56
+ birthday?: string | undefined;
57
+ phone?: import("./schemas/customer.schema").Phone | undefined;
58
+ personalId?: import("./schemas/personalId.schema").PersonalId | undefined;
59
+ address?: import("./schemas/address.schema").Address | undefined;
60
+ };
61
+ };
62
+ REBILL_DEVICE_ID: string | undefined;
63
+ API_KEY: string;
64
+ };
65
+ setCustomer(customer_data: Customer): void;
66
+ renewCard(subscriptionId: string): Promise<void>;
67
+ addCard(customerId: string): Promise<void>;
68
+ setTransaction(transaction: Transaction): Promise<import("./schemas/price.schema").PriceSetting>;
69
+ setCallbacks(callbacks: Callbacks): void;
70
+ setText(text: Text): void;
71
+ setStyles(value: Object): void;
72
+ setElements(html_id: string): void;
73
+ setIframe(): void;
74
+ setMetadata(metadata?: {}): void;
75
+ submit(card_values: Card): Promise<void>;
76
+ }
77
+ export declare function getIdentificationBy(isoCountryCode: IsoCountryEnum): Promise<Identification[]>;
78
+ export declare function getStatesBy(isoCountryCode: IsoCountryEnum): Promise<State[]>;
79
+ export declare function getCountries(): Promise<Country[]>;
80
+ export declare function getCountryCodes(): Promise<countryCode[]>;
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Rebill
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,24 +0,0 @@
1
- # Rebill Node.js Library
2
-
3
- The Rebill Node library provides convenient access to the Rebill API from
4
- applications written in server-side JavaScript.
5
-
6
- For collecting customer and payment information in the browser, use [Rebill.js][Rebill-js].
7
-
8
- ## Documentation
9
-
10
- See the [`Rebill-node` API docs](https://docs.rebill.to) for Node.js.
11
-
12
- ## Requirements
13
-
14
- Node 8, 10 or higher.
15
-
16
- ## Installation
17
-
18
- Install the package with:
19
-
20
- ```sh
21
- npm install Rebill --save
22
- # or
23
- yarn add Rebill
24
- ```