+
Order Id
+
Reference Id
+
diff --git a/examples/vanilla-js/index.js b/examples/vanilla-js/index.js
index 6b924d7..4be23b0 100644
--- a/examples/vanilla-js/index.js
+++ b/examples/vanilla-js/index.js
@@ -1,6 +1,6 @@
let key = document.getElementById('sdkkey').value;
-let resi;
+let sdkRes;
let random = uuidv4();
document.getElementById('refi').value = random;
@@ -27,7 +27,7 @@ function handleRandom() {
async function handleFinalize() {
try {
- if (!resi) {
+ if (!sdkRes) {
alert('Order not created. Please place an order');
return;
}
@@ -39,11 +39,11 @@ async function handleFinalize() {
'x-api-key': key
},
body: JSON.stringify({
- refId: resi
+ refId: sdkRes
})
},
- // `https://api.flamapp.com/saas/api/v1/orders/finalize`
- `https://dev.flamapp.com/saas/api/v1/orders/finalize`
+ `https://api.flamapp.com/saas/api/v1/orders/finalize`
+ // `https://dev.flamapp.com/saas/api/v1/orders/finalize`
);
alert('Order Finalized');
} catch (err) {
@@ -51,6 +51,38 @@ async function handleFinalize() {
}
}
+function handleOrderUpdate() {
+ if (!sdkRes) {
+ alert('Order not created. Please place an order');
+ return;
+ }
+
+ const flam = new FlamSaasSDK.init({
+ environment: 'sandbox',
+ key: key
+ });
+
+ let orderDetails = {
+ productId: sdkRes.productId,
+ refId: sdkRes.refId,
+ variantId: sdkRes.variantId,
+ orderId: sdkRes.orderId
+ };
+
+ flam.placeOrder(orderDetails, (err, res) => {
+ if (err) {
+ console.log('ERR at client side', err);
+ } else {
+ sdkRes = {
+ ...res.data,
+ variantId: sdkRes.variantId
+ };
+ console.log('RESSS', res);
+ alert('Card updated successfully');
+ }
+ });
+}
+
async function ApiCall(settings, url) {
try {
const data = await fetch(url, settings)
@@ -77,8 +109,8 @@ async function getProducts() {
'x-api-key': key
}
},
- // `https://api.flamapp.com/saas/api/v2/products`
- `https://dev.flamapp.com/saas/api/v2/products`
+ `https://api.flamapp.com/saas/api/v2/products`
+ // `https://dev.flamapp.com/saas/api/v2/products`
);
const x = data.data.filter(
@@ -157,6 +189,7 @@ function buyCard(productId, variantId) {
// color: '#234f55'
// },
// prefill: {
+ // hide: false,
// name: 'John Doe Prints',
// email: 'support@email.com',
// phone: '+91 98765 43210'
@@ -167,7 +200,12 @@ function buyCard(productId, variantId) {
let orderDetails = {
productId: productId,
refId: random,
- variantId: variantId
+ variantId: variantId,
+
+ theme: {
+ primaryColor: '#a62107',
+ secondaryColor: '#f2e0df'
+ }
// allowVideoLater: true
// animation: 'airplane'
};
@@ -176,10 +214,13 @@ function buyCard(productId, variantId) {
if (err) {
console.log('ERR at client side', err);
} else {
- resi = res.data.refId;
+ sdkRes = res.data;
+ sdkRes.variantId = orderDetails.variantId;
+ sdkRes.productId = orderDetails.productId;
document.getElementById('finalize').style.display = 'block';
alert('Card created successfully!');
- document.getElementById('refId').innerHTML = resi;
+ document.getElementById('refId').innerHTML = sdkRes.refId;
+ document.getElementById('orderId').innerHTML = sdkRes.orderId;
console.log('RESSS', res);
}
});
diff --git a/examples/vanilla-js/style.css b/examples/vanilla-js/style.css
index e87facd..7319524 100644
--- a/examples/vanilla-js/style.css
+++ b/examples/vanilla-js/style.css
@@ -6,4 +6,5 @@
.finalize {
margin-top: 50px;
+ margin-bottom: 50px;
}
diff --git a/src/placeOrder.js b/src/placeOrder.js
index 62f9a84..04ebbc4 100644
--- a/src/placeOrder.js
+++ b/src/placeOrder.js
@@ -34,6 +34,11 @@ export default async function placeOrder(order_details, callback) {
message: "'variantId' is required string."
},
refId: { type: 'string', message: "'refId' is required string." },
+ orderId: {
+ optional: true,
+ type: 'string',
+ message: "'orderId' must be string."
+ },
photo: {
optional: true,
type: 'string',
@@ -81,15 +86,20 @@ export default async function placeOrder(order_details, callback) {
message: "'prefill' is not valid."
},
{
+ hide: {
+ optional: true,
+ type: 'boolean',
+ message: "'hide' must be boolean."
+ },
name: {
optional: true,
type: 'string',
- message: "'name' is required string."
+ message: "'name' mus be string."
},
email: {
optional: true,
type: 'string',
- message: "'email' is required string."
+ message: "'email' mus be string."
},
phone: {
optional: true,
@@ -109,10 +119,17 @@ export default async function placeOrder(order_details, callback) {
message: "'theme' is not valid."
},
{
- color: {
+ primaryColor: {
+ optional: true,
+ type: 'string',
+ message: "'primary' must be string."
+ }
+ },
+ {
+ secondaryColor: {
optional: true,
type: 'string',
- message: "'name' is required string."
+ message: "'secondary' must be string."
}
}
);
diff --git a/src/receiveMessage.js b/src/receiveMessage.js
index dd1ff5a..e84d294 100644
--- a/src/receiveMessage.js
+++ b/src/receiveMessage.js
@@ -43,6 +43,14 @@ export default function receiveMessage(event) {
});
this.close();
break;
+ case 'UPDATED':
+ this.callback(null, {
+ code: 201,
+ data: event.data.payload,
+ message: 'Order updated successfully!'
+ });
+ this.close();
+ break;
case 'ERROR':
this.callback(
{
diff --git a/src/renderWithRetry.js b/src/renderWithRetry.js
index 4d903f4..54c85fa 100644
--- a/src/renderWithRetry.js
+++ b/src/renderWithRetry.js
@@ -100,11 +100,20 @@ export default async function renderWithRetry(url) {
if (
this.order_details &&
this.order_details.theme &&
- this.order_details.theme.color &&
- RegExp.test(this.order_details.theme.color)
+ this.order_details.theme.primaryColor &&
+ this.order_details.theme.secondaryColor &&
+ RegExp.test(this.order_details.theme.primaryColor) &&
+ RegExp.test(this.order_details.theme.secondaryColor)
) {
- const x = '/?theme=';
- return url + x + encodeURIComponent(this.order_details.theme.color);
+ const color1 = '/?color1=';
+ const color2 = '&color2=';
+ return (
+ url +
+ color1 +
+ encodeURIComponent(this.order_details.theme.primaryColor) +
+ color2 +
+ encodeURIComponent(this.order_details.theme.secondaryColor)
+ );
}
return url;
};
@@ -113,22 +122,37 @@ export default async function renderWithRetry(url) {
-
+
`;
body.appendChild(UI);
const iFrame = document.getElementById('flam-sdk-iframe');
+ try {
+ // check if website online
+ const res = await fetch(PAGES.main);
+ iFrame.src = newUrl();
+ } catch (err) {
+ if (err.message === 'Failed to fetch') {
+ this.close();
+ this.callback({
+ code: 500,
+ message: 'Unable to access SDK Website!'
+ });
+ } else {
+ this.callback({
+ code: 500,
+ message: 'Something went wrong!'
+ });
+ }
+ return;
+ }
+
iFrame.addEventListener('load', async e => {
e.preventDefault();
try {
- // check if website available in PRODUCTION
- if (this.clientData.environment == 'PRODUCTION') {
- await fetch(PAGES.main);
- }
-
// hide initial loading
document.getElementById('flam-sdk-loading-wrapper').style.display =
'none';
@@ -151,7 +175,7 @@ export default async function renderWithRetry(url) {
this.close();
this.callback({
code: 500,
- message: 'Unable to acess SDK Website!'
+ message: 'Unable to access SDK Website!'
});
return;
}
diff --git a/web b/web
index 61080ed..eb774ee 160000
--- a/web
+++ b/web
@@ -1 +1 @@
-Subproject commit 61080edb44ac22a4285d0f5e62c22d16d34d47d6
+Subproject commit eb774ee6eeb5d8390c37787625bcc767008ada94