raw_body); $message = isset($jsonResponse->message) ? $jsonResponse->message : null; if (isset($jsonResponse->errors)) { foreach($jsonResponse->errors as $attribute => $content) { if (is_array($content)) { $content = implode(" ", $content); } if (is_object($content)) { $content = json_encode($content); } $message .= sprintf( '%s: %s%s', $attribute, $content, PHP_EOL ); } return sprintf( '%sResponse Code: %d%sError Message: %s%s', PHP_EOL, isset($response->code) ? $response->code : 0, PHP_EOL, $message, PHP_EOL ); } return null; } /** * Seeks a key within a simple or multidimensional array, * and returns its value. * Returns null if invalid params are supplied, or false if * the key is not found. * * @param scalar $needle Key name being sought * @param array $array Input array * * @return string */ public static function arrayValueByKeyRecursive($needle, array $array) { if (!is_scalar($needle)) { if (PromisePay::isDebug()) { throw new \InvalidArgumentException( sprintf( 'First argument for %s should be a scalar value.', __METHOD__ ) ); } else { return null; } } $iterator = new \RecursiveIteratorIterator( new \RecursiveArrayIterator($array), \RecursiveIteratorIterator::SELF_FIRST ); foreach ($iterator as $key => $value) { if ($key === $needle) { return $value; } } return false; } public static function waitForServerToBecomeResponsiveAgain() { // the 503 lockout is usually 120 seconds $start = microtime(true); while (true) { try { $getList = PromisePay::Transaction()->getList( array( 'limit' => 1, 'offset' => 0 ) ); break; } catch (\PromisePay\Exception\Api $e) { sleep(5); } } if (PromisePay::isDebug()) { fwrite( STDOUT, sprintf( 'Amount of time server was unresponsive: %f seconds' . PHP_EOL, microtime(true) - $start ) ); } } }