Skip to content

Commit

Permalink
Fallback client data to api
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuvrajhere committed Sep 7, 2022
1 parent 342ade8 commit b0245cb
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 202 deletions.
217 changes: 135 additions & 82 deletions dist/FlamSaasSDK.js

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions dist/FlamSaasSDK.min.esm.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/FlamSaasSDK.min.esm.js.map

This file was deleted.

9 changes: 0 additions & 9 deletions dist/FlamSaasSDK.min.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/FlamSaasSDK.min.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions examples/vanilla-js/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous" />
<!-- flam sdk lib and css below -->
<script src="https://unpkg.com/[email protected]/dist/FlamSaasSDK.min.js"></script>
<!-- <script src="../../dist/FlamSaasSDK.js"></script> -->
<!-- <script src="https://unpkg.com/[email protected]/dist/FlamSaasSDK.min.js"></script> -->
<script src="../../dist/FlamSaasSDK.js"></script>

<!-- your javascript -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
Expand Down
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const SDK_BASE_URL = 'https://saas-sdk-flam.vpercel.app';
// const SDK_BASE_URL = 'http://localhost:3000';
// const SDK_BASE_URL = 'https://saas-sdk-flam.vpercel.app';
const SDK_BASE_URL = 'http://localhost:3000';

export const PAGES = {
main: SDK_BASE_URL,
Expand Down
89 changes: 68 additions & 21 deletions src/placeOrder.js
Original file line number Diff line number Diff line change
@@ -1,53 +1,100 @@
import { PAGES } from './constants';
import assert from './helper/assert';

/**
* Runs the SDK for Placing Order
* @function
* @param {Object} options
* @param {String} options.key the API Key found on your Application settings page
* @param {String} [options.environment] enviornment sandbox | production
*/

// TODO: write the parameter descriptions

export default function placeOrder(order_details, callback) {
this.order_details = order_details;
try {
// validate client data
assert.check(
this.clientData,
{ type: 'object', message: 'init data is invalid' },
{
key: { type: 'string', message: 'key is required in init data' },
key: { type: 'string', message: "'key' is required string." },
environment: {
optional: true,
type: 'string',
message: 'environment must be a string in init data'
message: "'environment' must be string."
}
}
);

// validate order_details
assert.check(
order_details,
{
type: 'object',
message: 'options parameter is invalid'
message: "'order_details' is not valid."
},
{
productId: { type: 'string', message: 'productId is required!' }
},
{
refId: { type: 'string', message: 'refId is required!' }
productId: {
type: 'string',
message: "'productId' is required string."
},
refId: { type: 'string', message: "'refId' is required string." },
photo: {
optional: true,
type: 'string',
message: "'photo' must be string."
},
video: {
optional: true,
type: 'string',
message: "'video' must be string."
},
prefill: {
optional: true,
type: 'object',
message: "'prefill' must be object."
},
animation: {
optional: true,
type: 'string',
message: "'animation' must be string."
},
theme: {
optional: true,
type: 'object',
message: "'theme' must be object."
},
logo: {
optional: true,
type: 'object',
message: "'logo' must be string."
}
}
);

if (callback) {
let url = `${PAGES.main}`;
this.callback = callback;
this.renderWithRetry({ url, error: false });
} else {
throw new Error('callback function is required!');
}
// validate callback function
assert.check(callback, {
type: 'function',
message: "'callback' is required function."
});

// save order_details
this.order_details = order_details;

// render the success UI
let url = `${PAGES.main}`;
this.callback = callback;
this.renderWithRetry(url);
} catch (err) {
if (callback) {
if (callback && typeof callback === 'function') {
// render error UI
let url = `${PAGES.error}/Something went wrong!`;
this.renderWithRetry({
url,
error: true
});
this.renderWithRetry(url);
// callback to client with error
callback({ code: 400, message: err.message }, null);
} else {
throw new Error('callback function is required!');
throw "'callback' is required function.";
}
}
}
Loading

0 comments on commit b0245cb

Please sign in to comment.