-
Notifications
You must be signed in to change notification settings - Fork 7
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
Showing
10 changed files
with
664 additions
and
226 deletions.
There are no files selected for viewing
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
28 changes: 28 additions & 0 deletions
28
packages/apps/galaxpay/src/functions-lib/ecom/request-api.ts
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import api from '@cloudcommerce/api'; | ||
|
||
const findOrderById = async (orderId: string) => { | ||
const { data } = await api.get(`orders/${orderId}`); | ||
return data; | ||
}; | ||
|
||
const getProductsById = async (productId:string) => { | ||
const { data } = await api.get(`products/${productId}`); | ||
return data; | ||
}; | ||
|
||
const getOrderWithQueryString = async (queryString:string) => { | ||
const { data } = await api.get(`orders?${queryString}`); | ||
return data; | ||
}; | ||
|
||
const getOrderIntermediatorTId = (tId: string) => { | ||
const queryString = `?transactions.intermediator.transaction_id=${tId}`; | ||
return getOrderWithQueryString(queryString); | ||
}; | ||
|
||
export { | ||
findOrderById, | ||
getOrderIntermediatorTId, | ||
getOrderWithQueryString, | ||
getProductsById, | ||
}; |
80 changes: 80 additions & 0 deletions
80
packages/apps/galaxpay/src/functions-lib/firestore/utils.ts
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import type { Orders } from '@cloudcommerce/types'; | ||
import logger from 'firebase-functions/logger'; | ||
|
||
const getDocSubscription = ( | ||
orderId, | ||
collectionSubscription, | ||
) => new Promise((resolve, reject) => { | ||
const subscription = collectionSubscription.doc(orderId); | ||
|
||
subscription.get() | ||
.then((documentSnapshot) => { | ||
if (documentSnapshot.exists) { | ||
const data = documentSnapshot.data(); | ||
if (data.storeId) { | ||
resolve(data); | ||
} else { | ||
reject(new Error('StoreId property not found in document')); | ||
} | ||
} else { | ||
reject(new Error('Document does not exist Firestore')); | ||
} | ||
}).catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
|
||
const updateDocSubscription = async ( | ||
collectionSubscription, | ||
body, | ||
subscriptionId, | ||
) => { | ||
const updatedAt = new Date().toISOString(); | ||
body.updatedAt = updatedAt; | ||
|
||
await collectionSubscription.doc(subscriptionId) | ||
.set(body, { merge: true }) | ||
.catch(logger.error); | ||
}; | ||
|
||
const createItemsAndAmount = ( | ||
amount: Orders['amount'], | ||
items: Orders['items'], | ||
) => { | ||
const itemsAndAmount = { | ||
amount, | ||
items: items?.reduce(( | ||
accumulator: { | ||
sku?: string, | ||
final_price?: number, | ||
price:number, | ||
quantity: number, | ||
product_id: string & {length: 24} | ||
}[], | ||
itemOrder, | ||
) => { | ||
const item = { | ||
sku: itemOrder.sku, | ||
final_price: itemOrder.final_price, | ||
price: itemOrder.price, | ||
quantity: itemOrder.quantity, | ||
product_id: itemOrder.product_id, | ||
}; | ||
|
||
if (itemOrder.variation_id) { | ||
Object.assign(item, { variation_id: itemOrder.variation_id }); | ||
} | ||
|
||
accumulator.push(item); | ||
return accumulator; | ||
}, []), | ||
}; | ||
|
||
return itemsAndAmount; | ||
}; | ||
|
||
export { | ||
getDocSubscription, | ||
updateDocSubscription, | ||
createItemsAndAmount, | ||
}; |
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
Oops, something went wrong.