@@ -187,6 +187,8 @@ private function sendRequest ( $data ) {
187187 );
188188 $ context = stream_context_create ($ opts );
189189 $ from_nexmo = file_get_contents ($ this ->nx_uri , false , $ context );
190+ // TODO: data for test cast.
191+ // $from_nexmo = '{"message-count":"1","messages":[{"to":"15079934320","message-id":"030000004090C3EF","status":"0","remaining-balance":"1.97600000","message-price":"0.00480000","network":"310004"}]}';
190192 } else {
191193 // No way of sending a HTTP post :(
192194 return false ;
@@ -231,22 +233,23 @@ private function normaliseKeys ($obj) {
231233 */
232234 private function nexmoParse ( $ from_nexmo ) {
233235 $ response = json_decode ($ from_nexmo );
234-
235236 // Copy the response data into an object, removing any '-' characters from the key
236237 $ response_obj = $ this ->normaliseKeys ($ response );
237238
238239 if ($ response_obj ) {
239- $ this ->nexmo_response = $ response_obj ;
240+ $ this ->nexmo_response = ( array ) $ response_obj ;
240241
241242 // Find the total cost of this message
242- $ response_obj-> cost = $ total_cost = 0 ;
243- if (is_array ($ response_obj-> messages )) {
244- foreach ($ response_obj-> messages as $ msg ) {
243+ $ response_obj[ ' cost ' ] = $ total_cost = 0 ;
244+ if (is_array ($ response_obj[ ' messages ' ] )) {
245+ foreach ($ response_obj[ ' messages ' ] as $ msg ) {
245246 if (property_exists ($ msg , "messageprice " )) {
246247 $ total_cost = $ total_cost + (float )$ msg ->messageprice ;
248+ } elseif (array_key_exists ('messageprice ' ,$ msg )) {
249+ $ total_cost = $ total_cost + (float )$ response_obj ['messageprice ' ];
247250 }
248251 }
249- $ response_obj-> cost = $ total_cost ;
252+ $ response_obj[ ' cost ' ] = $ total_cost ;
250253 }
251254 return $ response_obj ;
252255
0 commit comments