Answered
Encode Json Object to Base64
In an api that I add to my application (payment platform), I have to convert a Json object to Base64. When I use the ToBase64 function. I have this error message. Can anybody help me. Thanks in advance. Cordially,
<cfset card_firstname = "Jeremy">
<cfset dataDirectory = getDirectoryFromPath(
getCurrentTemplatePath()
) />
<!--- Create a basic ColdFusion object. --->
<cfset test = {
"billing":{
"firstName":"#card_firstname#", "lastName":"Grimm", "addressLine1":"3 rue de l'église", "city":"Ostheim", "postalCode":"68150", "country":"FR"
}, "shipping":{
"firstName":"Jérémy", "lastName":"Grimm", "addressLine1":"3 rue de l'église", "city":"Ostheim", "postalCode":"68150", "country":"FR", "email":"jerem68@hotmail.com", "phone":"+33-612345678", "shipIndicator":"billing_address", "deliveryTimeframe":"two_day", "firstUseDate":"2017-01-25", "matchBillingAddress":true
}, "client":{
"email":"jerem68@hotmail.com", "phone":"+33-612345678", "birthCity":"Colmar", "birthPostalCode":"68000", "birthCountry":"FR", "birthdate":"1987-03-27"
} } />
<cfset fileWrite(
"#dataDirectory#data.json",
serializeJSON( test )
) />
<cfset testFromJSON = deserializeJSON(
fileRead( "#dataDirectory#data.json" )
) />
<cfset test64=ToBase64(testFromJSON) />
writeOutput(test64)

