-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
342ade8
commit b0245cb
Showing
14 changed files
with
359 additions
and
202 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."; | ||
} | ||
} | ||
} |
Oops, something went wrong.