@tonder.io/ionic-lite-sdk 0.0.14 → 0.0.16
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/README.md
CHANGED
|
@@ -31,7 +31,7 @@ import { LiteCheckout } from "@tonder/ionic-lite-sdk"
|
|
|
31
31
|
const liteCheckout = new LiteCheckout({
|
|
32
32
|
signal,
|
|
33
33
|
baseUrlTonder,
|
|
34
|
-
apiKeyTonder
|
|
34
|
+
apiKeyTonder
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
@@ -41,6 +41,7 @@ const liteCheckout = new LiteCheckout({
|
|
|
41
41
|
| baseUrlTonder | string | Live server: http://stage.tonder.io |
|
|
42
42
|
| | | Mock Server: https://stoplight.io/mocks/tonder/tonder-api-v1-2/3152148 |
|
|
43
43
|
| apiKeyTonder | string | You can take this from you Tonder Dashboard |
|
|
44
|
+
| | | |
|
|
44
45
|
|
|
45
46
|
# Class methods
|
|
46
47
|
|
|
@@ -98,7 +99,8 @@ const { openpay_keys } = merchantData;
|
|
|
98
99
|
|
|
99
100
|
const deviceSessionIdTonder = await liteCheckout.getOpenpayDeviceSessionID(
|
|
100
101
|
openpay_keys.merchant_id,
|
|
101
|
-
openpay_keys.public_key
|
|
102
|
+
openpay_keys.public_key,
|
|
103
|
+
is_sandbox: true
|
|
102
104
|
);
|
|
103
105
|
```
|
|
104
106
|
|
|
@@ -17,7 +17,7 @@ export declare class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
17
17
|
baseUrlTonder: string;
|
|
18
18
|
apiKeyTonder: string;
|
|
19
19
|
constructor({ signal, baseUrlTonder, apiKeyTonder, }: LiteCheckoutConstructor);
|
|
20
|
-
getOpenpayDeviceSessionID(merchant_id: string, public_key: string): Promise<string | ErrorResponse>;
|
|
20
|
+
getOpenpayDeviceSessionID(merchant_id: string, public_key: string, is_sandbox: boolean): Promise<string | ErrorResponse>;
|
|
21
21
|
getBusiness(): Promise<GetBusinessResponse | ErrorResponse>;
|
|
22
22
|
customerRegister(email: string): Promise<CustomerRegisterResponse | ErrorResponse>;
|
|
23
23
|
createOrder(orderItems: CreateOrderRequest): Promise<CreateOrderResponse | ErrorResponse>;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"skyflow-js";function t(e,t,o,i){return new(o||(o=Promise))((function(r,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,d)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class o{constructor({code:e,body:t,name:o,message:i,stack:r}){this.code=e,this.body=t,this.name=o,this.message=i,this.stack=r}}class i{constructor({signal:e,baseUrlTonder:t,apiKeyTonder:o}){this.baseUrlTonder=t,this.signal=e,this.apiKeyTonder=o}getOpenpayDeviceSessionID(e,o){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(o),t.setSandboxMode(
|
|
1
|
+
import e from"skyflow-js";function t(e,t,o,i){return new(o||(o=Promise))((function(r,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,d)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;class o{constructor({code:e,body:t,name:o,message:i,stack:r}){this.code=e,this.body=t,this.name=o,this.message=i,this.stack=r}}class i{constructor({signal:e,baseUrlTonder:t,apiKeyTonder:o}){this.baseUrlTonder=t,this.signal=e,this.apiKeyTonder=o}getOpenpayDeviceSessionID(e,o,i){return t(this,void 0,void 0,(function*(){try{let t=yield window.OpenPay;return t.setId(e),t.setApiKey(o),t.setSandboxMode(i),yield t.deviceData.setup({signal:this.signal})}catch(e){throw this.buildErrorResponseFromCatch(e)}}))}getBusiness(){return t(this,void 0,void 0,(function*(){try{const e=yield fetch(`${this.baseUrlTonder}/api/v1/payments/business/${this.apiKeyTonder}`,{headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});return e.ok?yield e.json():yield this.buildErrorResponse(e)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}customerRegister(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/customer/`,o={email:e},i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal,body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}createOrder(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/orders/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}createPayment(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/business/${e.business_pk}/payments/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}startCheckoutRouter(e){return t(this,void 0,void 0,(function*(){try{const t=`${this.baseUrlTonder}/api/v1/checkout-router/`,o=e,i=yield fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Token ${this.apiKeyTonder}`},body:JSON.stringify(o)});return i.ok?yield i.json():yield this.buildErrorResponse(i)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getSkyflowTokens({vault_id:o,vault_url:i,data:r}){return t(this,void 0,void 0,(function*(){const n=e.init({vaultID:o,vaultURL:i,getBearerToken:()=>t(this,void 0,void 0,(function*(){return yield this.getVaultToken()})),options:{logLevel:e.LogLevel.ERROR,env:e.Env.DEV}}).container(e.ContainerType.COLLECT),s=yield this.getFieldsPromise(r,n);if((yield Promise.all(s)).some((e=>!e)))return this.buildErrorResponseFromCatch(Error("Ocurrió un error al montar los campos de la tarjeta"));try{const e=yield n.collect();return e?e.records[0].fields:this.buildErrorResponseFromCatch(Error("Por favor, verifica todos los campos de tu tarjeta"))}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getVaultToken(){var e;return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/vault-token/`,{method:"GET",headers:{Authorization:`Token ${this.apiKeyTonder}`},signal:this.signal});if(t.ok)return null===(e=yield t.json())||void 0===e?void 0:e.token;throw new Error(`HTTPCODE: ${t.status}`)}catch(e){throw new Error(`Failed to retrieve bearer token; ${"string"==typeof e?e:e.message}`)}}))}getFieldsPromise(e,o){return t(this,void 0,void 0,(function*(){const t=yield this.getFields(e,o);return t?t.map((t=>new Promise((o=>{var i;const r=document.createElement("div");r.hidden=!0,r.id=`id-${t.key}`,null===(i=document.querySelector("body"))||void 0===i||i.appendChild(r),setTimeout((()=>{t.element.mount(`#id-${t.key}`),setInterval((()=>{if(t.element.isMounted()){const i=e[t.key];return t.element.update({value:i}),o(t.element.isMounted())}}),120)}),120)})))):[]}))}registerCustomerCard(e,o){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/`,{method:"POST",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal,body:JSON.stringify(o)});return t.ok?yield t.json():yield this.buildErrorResponse(t)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}getCustomerCards(e,o=""){return t(this,void 0,void 0,(function*(){try{const t=yield fetch(`${this.baseUrlTonder}/api/v1/cards/${o}`,{method:"GET",headers:{Authorization:`Token ${e}`,"Content-Type":"application/json"},signal:this.signal});return t.ok?yield t.json():yield this.buildErrorResponse(t)}catch(e){return this.buildErrorResponseFromCatch(e)}}))}buildErrorResponseFromCatch(e){return new o({code:void 0,body:void 0,name:"string"==typeof e?"catch":e.name,message:"string"==typeof e?e:e.message,stack:"string"==typeof e?void 0:e.stack})}buildErrorResponse(e,i=void 0){var r,n,s,d,a,l;return t(this,void 0,void 0,(function*(){return new o({code:null===(n=null===(r=e.status)||void 0===r?void 0:r.toString)||void 0===n?void 0:n.call(r),body:yield null===(s=null==e?void 0:e.json)||void 0===s?void 0:s.call(e),name:null===(a=null===(d=e.status)||void 0===d?void 0:d.toString)||void 0===a?void 0:a.call(d),message:yield null===(l=null==e?void 0:e.text)||void 0===l?void 0:l.call(e),stack:i})}))}getFields(o,i){return t(this,void 0,void 0,(function*(){return yield Promise.all(Object.keys(o).map((o=>t(this,void 0,void 0,(function*(){return{element:yield i.create({table:"cards",column:o,type:e.ElementType.INPUT_FIELD}),key:o}})))))}))}}export{i as LiteCheckout};
|
package/package.json
CHANGED
|
@@ -35,13 +35,14 @@ export class LiteCheckout implements LiteCheckoutConstructor {
|
|
|
35
35
|
|
|
36
36
|
async getOpenpayDeviceSessionID(
|
|
37
37
|
merchant_id: string,
|
|
38
|
-
public_key: string
|
|
38
|
+
public_key: string,
|
|
39
|
+
is_sandbox: boolean
|
|
39
40
|
): Promise<string | ErrorResponse> {
|
|
40
41
|
try {
|
|
41
42
|
let openpay = await window.OpenPay;
|
|
42
43
|
openpay.setId(merchant_id);
|
|
43
44
|
openpay.setApiKey(public_key);
|
|
44
|
-
openpay.setSandboxMode(
|
|
45
|
+
openpay.setSandboxMode(is_sandbox);
|
|
45
46
|
return await openpay.deviceData.setup({
|
|
46
47
|
signal: this.signal,
|
|
47
48
|
}) as string;
|
|
@@ -47,9 +47,9 @@ describe("getOpenpayDeviceSessionID", () => {
|
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
expect(
|
|
50
|
-
liteCheckout.getOpenpayDeviceSessionID("4321", "1234")
|
|
50
|
+
liteCheckout.getOpenpayDeviceSessionID("4321", "1234", true)
|
|
51
51
|
).resolves.toBe("test");
|
|
52
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith("4321", "1234");
|
|
52
|
+
expect(liteCheckoutSpy).toHaveBeenCalledWith("4321", "1234", true);
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
it("getOpenpayDeviceSessionID empty", async () => {
|
|
@@ -65,9 +65,9 @@ describe("getOpenpayDeviceSessionID", () => {
|
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
expect(
|
|
68
|
-
liteCheckout.getOpenpayDeviceSessionID("", "")
|
|
68
|
+
liteCheckout.getOpenpayDeviceSessionID("", "", true)
|
|
69
69
|
).resolves.toBeUndefined();
|
|
70
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith("", "");
|
|
70
|
+
expect(liteCheckoutSpy).toHaveBeenCalledWith("", "", true);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("getOpenpayDeviceSessionID error", async () => {
|
|
@@ -83,10 +83,10 @@ describe("getOpenpayDeviceSessionID", () => {
|
|
|
83
83
|
};
|
|
84
84
|
|
|
85
85
|
try {
|
|
86
|
-
await liteCheckout.getOpenpayDeviceSessionID("", "");
|
|
86
|
+
await liteCheckout.getOpenpayDeviceSessionID("", "", true);
|
|
87
87
|
} catch (e) {
|
|
88
88
|
const error: IErrorResponse = e as IErrorResponse;
|
|
89
|
-
expect(liteCheckoutSpy).toHaveBeenCalledWith("", "");
|
|
89
|
+
expect(liteCheckoutSpy).toHaveBeenCalledWith("", "", true);
|
|
90
90
|
expect(liteCheckoutSpy).toHaveReturned();
|
|
91
91
|
expect(error.message).toStrictEqual("error");
|
|
92
92
|
expect(error).toBeInstanceOf(ErrorResponse);
|