Object Merging

Realistically your application will generate the JWT when the page that includes Songbird.js is rendered. This page will most likely include JavaScript to allow the consumer to dynamically change order details without requiring a full page load. This means that the order details provided when you loaded the page within the JWT can be stale and out dated when you start the transaction with Songbird.js. Cardinal Cruise allows you to pass an updated or additional order data through Songbird.js to make sure the transactional data is always the latest. Cardinal will merge these objects server side automatically, always taking the browser data as the most recent and overrides the JWT order data.


Object merging is done automatically by the Centinel API. This feature will always occur with all requests and cannot be disabled or behavior changed.


Examples

Below are examples of how the merging can affect your objects in different ways.

Remember that all merging types are active at once. The examples are broken out to help explain the different ways things are merged.

Additive Merge

Additive merging will take unique fields from each object to create a fuller more complete object

JWT Order Object
{
  "OrderDetails":{
	"Amount":1500,
	"CurrencyCode": "840"
  }
}


Browser Order Object
{
  "OrderDetails":{
	"OrderDescription":"My new order"
  }
}


Merged Object
{
  "OrderDetails":{
	"Amount":1500,
	"CurrencyCode": "840",
    "OrderDescription":"My new order"
  }
}

Update Merging

Update merging will overwrite stale fields from the JWT order object with the more recent browser object

JWT Order Object
{
  "OrderDetails":{
	"Amount":1500
  }
}
Browser Order Object
{
  "OrderDetails":{
	"Amount":2500
  }
}
Merged Object
{
  "OrderDetails":{
	"Amount":2500
  }
}

Real World Example

You may not have all the data when you create the JWT, so most likely your JWT order object will be a bit more sparse than the browser object.

JWT Order Object
{
  "OrderDetails":{
	"Amount":2500,
	"CurrencyCode": "840",
	"OrderNumber":"sa4lj2kds34SAIu97sde12d3"
  },
  "Cart":[
	{
	  "Name":"Blue Jeans",
	  "Quantity":1
	}
  ],
  "Consumer":{
    "ShippingAddress":{
      "FirstName": "John",
      "LastName":"Smith",
	  "Address1":"8100 Tyler Blvd.",
	  "City": "Mentor",
	  "State":"Ohio",
	  "PostalCode":"44060"
	}
  }
}
Browser Order Object
{
  "Consumer":{
    "Account":{
	  "AccountNumber": 4000...0002,
	  "ExpirationMonth": 01,
	  "ExpirationYear": 2020,
	  "NameOnCard":"John Smith"
	},
    "BillingAddress":{
      "FirstName": "John",
      "LastName":"Smith",
	  "Address1":"8100 Tyler Blvd.",
	  "City": "Mentor",
	  "State":"Ohio",
	  "PostalCode":"44060"
	},
	"ShippingAddress":{
      "FirstName": "John",
      "LastName":"Smith",
	  "Address1":"123 Main Street",
	  "City": "Cleveland",
	  "State":"Ohio",
	  "PostalCode":"44091"
	}
  }
}
Merged Object
{
  "OrderDetails":{
	"Amount":2500,
	"CurrencyCode": "840",
	"OrderNumber":"sa4lj2kds34SAIu97sde12d3"
  },
  "Cart":[
	{
	  "Name":"Blue Jeans",
	  "Quantity":1
	}
  ],
  "Consumer":{
    "Account":{
	  "AccountNumber": 4000...0002,
	  "ExpirationMonth": 01,
	  "ExpirationYear": 2020,
	  "NameOnCard":"John Smith"
	},
    "BillingAddress":{
      "FirstName": "John",
      "LastName":"Smith",
	  "Address1":"8100 Tyler Blvd.",
	  "City": "Mentor",
	  "State":"Ohio",
	  "PostalCode":"44060"
	},
	"ShippingAddress":{
      "FirstName": "John",
      "LastName":"Smith",
	  "Address1":"123 Main Street",
	  "City": "Cleveland",
	  "State":"Ohio",
	  "PostalCode":"44091"
	}
  }
}