Overview
Before placing orders, check product details to get real-time pricing, available denominations (types), and stock levels. This endpoint returns wholesale prices personalized to your account.
Never show wholesale prices to customers. Apply your markup before
displaying.
API Reference
GET /v3/gift-cards/checkProduct/{productId} Complete endpoint documentation
Basic Product Check
async function checkProduct ( productId ) {
const response = await fetch (
`https://api.oneclickdz.com/v3/gift-cards/checkProduct/ ${ productId } ` ,
{
headers: {
"X-Access-Token" : process . env . API_KEY ,
},
}
);
if ( ! response . ok ) {
throw new Error ( `Failed to check product: ${ response . status } ` );
}
const result = await response . json ();
return result . data ;
}
// Usage
const productId = "507f1f77bcf86cd799439011" ;
const product = await checkProduct ( productId );
console . log ( `Product: ${ product . productTitle } ` );
console . log ( `Available types: ${ product . types . length } ` );
product . types . forEach (( type ) => {
console . log ( ` - ${ type . name } : ${ type . price } DA (stock: ${ type . quantity } )` );
});
Response Structure
{
"success" : true ,
"data" : {
"productId" : "507f1f77bcf86cd799439011" ,
"productTitle" : "PlayStation Network" ,
"types" : [
{
"id" : "type_001" ,
"name" : "PSN 500 DA" ,
"price" : 490 ,
"quantity" : 150
},
{
"id" : "type_002" ,
"name" : "PSN 1000 DA" ,
"price" : 980 ,
"quantity" : 87
},
{
"id" : "type_003" ,
"name" : "PSN 2000 DA" ,
"price" : 1960 ,
"quantity" : 0
}
]
}
}
Filtering Available Stock
Only show types that are in stock:
function getAvailableTypes ( product ) {
return product . types . filter (( type ) => type . quantity > 0 );
}
// Usage
const product = await checkProduct ( productId );
const available = getAvailableTypes ( product );
if ( available . length === 0 ) {
console . log ( "Product currently out of stock" );
} else {
console . log ( ` ${ available . length } denominations available` );
}
Applying Customer Markup
Add your profit margin to wholesale prices:
function applyMarkup ( types , markupPercent = 5 ) {
return types
. filter (( type ) => type . quantity > 0 )
. map (( type ) => ({
id: type . id ,
name: type . name ,
wholesalePrice: type . price , // Store but don't show
customerPrice: Math . ceil ( type . price * ( 1 + markupPercent / 100 )),
available: true ,
}));
}
// Usage
const product = await checkProduct ( productId );
const customerPrices = applyMarkup ( product . types , 5 ); // 5% markup
customerPrices . forEach (( type ) => {
console . log ( ` ${ type . name } : ${ type . customerPrice } DA` );
// Don't log wholesalePrice in production!
});
Stock Validation Before Ordering
Always verify stock before allowing orders:
async function validateStock ( productId , typeId , quantity ) {
const product = await checkProduct ( productId );
const type = product . types . find (( t ) => t . id === typeId );
if ( ! type ) {
throw new Error ( "Invalid type ID" );
}
if ( type . quantity === 0 ) {
throw new Error ( "Product out of stock" );
}
if ( type . quantity < quantity ) {
throw new Error (
`Insufficient stock. Available: ${ type . quantity } , Requested: ${ quantity } `
);
}
return {
valid: true ,
type ,
totalCost: type . price * quantity ,
};
}
// Usage
try {
const validation = await validateStock ( productId , "type_001" , 5 );
console . log ( `Order valid. Total cost: ${ validation . totalCost } DA` );
} catch ( error ) {
console . error ( "Validation failed:" , error . message );
}
Best Practices
Check Before Order Always verify stock before placing orders
Hide Wholesale Prices Never display raw price values to customers
Cache Briefly Cache for 1-2 minutes during checkout flow
Handle Out of Stock Gracefully handle zero quantity scenarios
Error Handling
async function checkProductSafely ( productId ) {
try {
return await checkProduct ( productId );
} catch ( error ) {
if ( error . message . includes ( "404" )) {
throw new Error ( "Product not found or disabled" );
}
if ( error . message . includes ( "401" )) {
throw new Error ( "Invalid API key" );
}
console . error ( "Failed to check product:" , error );
throw new Error ( "Unable to load product details. Please try again." );
}
}
Next Steps