Skip to content

Commit

Permalink
Add support for dev api (#271)
Browse files Browse the repository at this point in the history
* Add support for dev api

* Fix: some api's require two different versions, append api version where neccessary

* Fix double https appended to web-token endpoint

* fix e-signature test
  • Loading branch information
ayinloya authored Jun 24, 2024
1 parent 43dce44 commit 6904d53
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 67 deletions.
6 changes: 3 additions & 3 deletions example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,28 @@ const vite = await createViteServer({
});
app.use(vite.middlewares);

const SID_SERVER_MAPPING = {
0: 'sandbox',
1: 'production',
};

app.post('/token', async (req, res, next) => {
try {
const { PARTNER_ID, API_KEY, SID_SERVER } = process.env;
const environmentServer = SID_SERVER_MAPPING[SID_SERVER] || SID_SERVER;
let baseServer = environmentServer;
// the smile-identity-core client appears to append https:// to the baseServer
// this is a workaround to prevent the client from appending https:// twice
if (baseServer.startsWith('https://')) {
baseServer = `${baseServer.slice(8)}/v1`;
}

console.log(PARTNER_ID, API_KEY, SID_SERVER);
const connection = new SIDWebAPI(
PARTNER_ID,
'https://webhook.site/0ffa8d44-160a-46f2-b2d1-497a16fd6d787',
API_KEY,
SID_SERVER,
baseServer,
);

const request_params = {
Expand All @@ -40,14 +53,16 @@ app.post('/token', async (req, res, next) => {
};

const result = await connection.get_web_token(request_params);
console.log('result', result);
res.status(201).json({

const response = {
...result,
environment: SID_SERVER === '0' ? 'sandbox' : 'production',
environment: environmentServer,
product: req.body.product,
partner_id: PARTNER_ID,
callback_url: 'https://webhook.site/0ffa8d44-160a-46f2-b2d1-497a16fd6d78',
});
};

res.status(201).json(response);
} catch (e) {
console.error(e);
res.status(500).json({ error: e.message });
Expand Down
2 changes: 1 addition & 1 deletion packages/embed/cypress/pages/e_signature.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
],
callback_url:
'https://webhook.site/1aaa7a7b-accb-40ac-8643-fd8a8703e9be',
environment: 'development',
environment: 'sandbox',
partner_details: {
name: 'Test Org',
logo_url: 'https://portal.usesmileid.com/favicon.ico',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}

body {
max-width: 100%;
min-height: 100%;
}
</style>
</head>

<body>
<script src="js/script.min.js"></script>

<script>
SmileIdentity({
token:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJwYXJ0bmVyX3BhcmFtcyI6eyJ1c2VyX2lkIjoidXNlci1mZTIwY2JkYS1jMjJiLTRmZmUtOWRlZC05YjZhZGI2MDE1ZmIiLCJqb2JfaWQiOiJqb2ItNjYzY2VhNTUtZWIxYy00MjI2LWI1N2YtOGEwMTAwOTc4ZjViIiwiam9iX3R5cGUiOjF9LCJjYWxsYmFja191cmwiOiJodHRwczovL3dlYmhvb2suc2l0ZS9iZTM0YzkzZC1hOTFmLTQzZGItYWVmMi05MDZjNWNkOTVkNDciLCJpYXQiOjE2MzQyODE0MTAsImV4cCI6MTYzNTkxNTY4NH0.B4JaP4UWbNs38hV9nQ_9_Pnpos0fM3qu2nGG7Eymjs8',
product: 'enhanced_document_verification',
callback_url:
'https://portal.usesmileid.com/api/v2/007/postback/update_status',
environment: 'sandbox',
partner_details: {
name: 'Test Org',
logo_url: 'https://portal.usesmileid.com/favicon.ico',
partner_id: '007',
policy_url: 'https://usesmileid.com/privacy-policy',
theme_color: '#000',
},
onSuccess: () => {},
onClose: () => {},
});
</script>
</body>
</html>
32 changes: 17 additions & 15 deletions packages/embed/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,22 @@ Cypress.Commands.add('getIFrameBody', () => {
.then((body) => cy.wrap(body, { log: false }));
});

Cypress.Commands.add('loadIDOptions', () => {
Cypress.Commands.add('loadIDOptions', (baseApiUrl = '**/v1') => {
cy.log('loadingIDOptions');

cy.intercept('GET', '**/v1/services', { fixture: 'services.json' });
cy.intercept('GET', `${baseApiUrl}/services`, {
fixture: 'services.json',
});

cy.intercept('POST', '**/v1/valid_documents', {
cy.intercept('POST', `${baseApiUrl}/valid_documents`, {
fixture: 'valid_documents.json',
});

cy.intercept('POST', '**/v1/products_config', {
cy.intercept('POST', `${baseApiUrl}/products_config`, {
fixture: 'products_config.json',
});

cy.intercept('POST', '**/v1/totp_consent', {
cy.intercept('POST', `${baseApiUrl}/totp_consent`, {
statusCode: 200,
body: {
message: 'Select OTP Delivery Mode',
Expand All @@ -67,15 +69,15 @@ Cypress.Commands.add('loadIDOptions', () => {
},
});

cy.intercept('POST', '**/v1/totp_consent/mode', {
cy.intercept('POST', `${baseApiUrl}/totp_consent/mode`, {
statusCode: 200,
body: {
message: 'OTP Delivery Mode Selected',
success: true,
},
});

cy.intercept('POST', '**/v1/totp_consent/otp', {
cy.intercept('POST', `${baseApiUrl}/totp_consent/otp`, {
statusCode: 200,
body: {
message: 'OTP Confirmed',
Expand All @@ -85,7 +87,7 @@ Cypress.Commands.add('loadIDOptions', () => {
});

Cypress.Commands.add('selectBVNIDType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectingBVNIDType');

Expand All @@ -97,7 +99,7 @@ Cypress.Commands.add('selectBVNIDType', () => {
});

Cypress.Commands.add('selectBVNMFAIDType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectingBVNMFAIDType');

Expand All @@ -109,7 +111,7 @@ Cypress.Commands.add('selectBVNMFAIDType', () => {
});

Cypress.Commands.add('selectNINIDType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectingNINIDType');

Expand All @@ -121,7 +123,7 @@ Cypress.Commands.add('selectNINIDType', () => {
});

Cypress.Commands.add('selectVOTERIDType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectingVoterIdType');

Expand All @@ -133,7 +135,7 @@ Cypress.Commands.add('selectVOTERIDType', () => {
});

Cypress.Commands.add('selectPASSPORTIDType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectingPASSPORTIDType');

Expand All @@ -149,7 +151,7 @@ Cypress.Commands.add('selectPASSPORTIDType', () => {
});

Cypress.Commands.add('selectZAGREENBOOKIDType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectingPASSPORTIDType');

Expand All @@ -169,7 +171,7 @@ Cypress.Commands.add('selectZAGREENBOOKIDType', () => {
});

Cypress.Commands.add('selectKRAType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectKRAType');

Expand All @@ -181,7 +183,7 @@ Cypress.Commands.add('selectKRAType', () => {
});

Cypress.Commands.add('selectKEDriversLicenseType', () => {
cy.loadIDOptions();
cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.log('selectDriversLicenseType');

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
describe('enhanced document verification', () => {
beforeEach(() => {
cy.intercept(
{
method: 'POST',
url: '*upload*',
},
{
upload_url:
'https://smile-uploads-development01.s3.us-west-2.amazonaws.com/videos/212/212-0000060103-0gdzke3mdtlco5k0sdfh6vifzcrd3n/ekyc_smartselfie.zip',
},
).as('getUploadURL');

cy.intercept(
{
method: 'PUT',
url: 'https://smile-uploads-development01.s3.us-west-2.amazonaws.com/videos/212/212-0000060103-0gdzke3mdtlco5k0sdfh6vifzcrd3n/ekyc_smartselfie.zip',
},
{
statusCode: 200,
},
).as('successfulUpload');

cy.loadIDOptions('https://example.smileidentity.com/v1');

cy.visit('/enhanced_document_verification_dev');

cy.selectVOTERIDType();

cy.navigateThroughCameraScreens();
});

it('should capture selfie and id image', () => {
cy.getIFrameBody()
.find('smart-camera-web')
.invoke('attr', 'document-type')
.should('eq', 'VOTER_ID');

cy.getIFrameBody()
.find('smart-camera-web')
.shadow()
.find('#id-entry-screen')
.should('be.visible');

cy.getIFrameBody()
.find('smart-camera-web')
.shadow()
.find('#id-entry-screen #take-photo')
.click();

cy.getIFrameBody()
.find('smart-camera-web')
.shadow()
.find('#id-camera-screen')
.should('be.visible');

cy.getIFrameBody()
.find('smart-camera-web')
.shadow()
.find('#capture-id-image')
.click();

cy.wait(2000);

cy.getIFrameBody()
.find('smart-camera-web')
.shadow()
.find('#id-camera-screen')
.should('not.be.visible');

cy.getIFrameBody()
.find('smart-camera-web')
.shadow()
.find('#select-id-image')
.click();

cy.getIFrameBody()
.find('smart-camera-web')
.shadow()
.find('#id-review-screen')
.should('not.be.visible');

cy.wait('@getUploadURL');

cy.wait('@successfulUpload');

cy.getIFrameBody().find('#complete-screen').should('be.visible');
});
});
15 changes: 8 additions & 7 deletions packages/embed/src/js/basic-kyc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { version as sdkVersion } from '../../package.json';
// NOTE: In order to support prior integrations, we have `live` and
// `production` pointing to the same URL
const endpoints = {
development: 'https://devapi.smileidentity.com',
sandbox: 'https://testapi.smileidentity.com',
live: 'https://api.smileidentity.com',
production: 'https://api.smileidentity.com',
};

const getEndpoint = (environment) => endpoints[environment] || environment;

const referenceWindow = window.parent;
referenceWindow.postMessage('SmileIdentity::ChildPageReady', '*');

Expand Down Expand Up @@ -57,15 +58,15 @@ import { version as sdkVersion } from '../../package.json';
partner_params,
};

const productsConfigUrl = `${
endpoints[config.environment]
}/v1/products_config`;
const productsConfigUrl = `${getEndpoint(
config.environment,
)}/v1/products_config`;
const productsConfigPromise = postData(
productsConfigUrl,
productsConfigPayload,
);
const servicesPromise = fetch(
`${endpoints[config.environment]}/v1/services`,
`${getEndpoint(config.environment)}/v1/services`,
);
const [productsConfigResponse, servicesResponse] = await Promise.all([
productsConfigPromise,
Expand Down Expand Up @@ -360,7 +361,7 @@ import { version as sdkVersion } from '../../package.json';
EndUserConsent = document.createElement('end-user-consent');
EndUserConsent.setAttribute(
'base-url',
`${endpoints[config.environment] || config.environment}/v1`,
`${getEndpoint(config.environment)}/v1`,
);
EndUserConsent.setAttribute('country', id_info.country);
EndUserConsent.setAttribute(
Expand Down Expand Up @@ -801,7 +802,7 @@ import { version as sdkVersion } from '../../package.json';
source_sdk_version: config.sdk_version || sdkVersion,
};

const URL = `${endpoints[config.environment]}/v2/verify_async`;
const URL = `${getEndpoint(config.environment)}/v2/verify_async`;
const response = await postData(URL, payload);
const json = await response.json();

Expand Down
Loading

0 comments on commit 6904d53

Please sign in to comment.