With Dynamic Integration warranties will need to be fetched, displayed and cataloged in your ecommerce platform in real time. The steps for this process are outlined below.
1. Respond to "Add Warranty" event
Regardless of whether you're using the Mulberry SDK or your own custom HTML to render protection plan offers, when the user selects to add a plan, the end result will likely be some type of JavaScript event.
An example of this would be the onWarrantySelect()
callback that gets fired from the mulberry.modal
. The object that gets passed to this callback might look something like the following:
{
"customer_cost":"189.00",
"duration_months":"36",
"product_title": "Sofa"
}
2. Send the warranty data to your backend API
Once you've captured the selected warranty object from the user, the next step is to send it to your API for processing. You'll likely write an ajax request that looks something like this:
fetch('https://www.your-api.com/api/warranty',
{
"customer_cost":"189.00",
"duration_months":"36",
"product_name": "Sofa"
}
)
3. Create the warranty SKU / product on the fly
The POST
payload above will then be received by your API. Your API will then be responsible for creating the warranty as a product in your ecommerce platform catalog so that it can then be returned to your front end. Some basic example code of how this might be accomplished can be found below:
from myecommerceplatform import app
from myecommerceplatform import Product
# Create warranty based on POSTed data on the fly
@app.route('/api/warranty', methods=['POST'])
def warranty():
warranty_product = Product({
"name": "Protection Plan for Sofa",
"price": "189.00"
})
warranty_product.save()
# Here we return the newly created warranty product ID
# to the front end.
return {
product_id: warranty_product.id
}
4. Adding the warranty to the cart
As a final step, after your API has responded with the newly created warranty product, we'll need to add it to the customers cart so that they can proceed to checkout.
const warranty_product_id = await fetch('https://www.your-api.com/api/warranty',
{
"customer_cost":"189.00",
"duration_months":"36",
"product_name": "Sofa"
}
)
await fetch('https://www.your-api.com/api/cart', {
product_id: warranty_product_id,
quantity: 1
})
console.log('warranty added to cart!')