/**
  * Confirmation
  *
  * @see http://www.gravityhelp.com/documentation/page/Gform_confirmation
  */
 public function confirmation($confirmation, $form, $lead, $ajax)
 {
     if ($this->is_processing($form) && $this->gateway && $this->payment && $this->payment->get_amount() > 0) {
         if (is_wp_error($this->error)) {
             $html = '';
             $html .= '<ul>';
             $html .= '<li>' . Pronamic_WP_Pay_Plugin::get_default_error_message() . '</li>';
             foreach ($this->error->get_error_messages() as $message) {
                 $html .= '<li>' . $message . '</li>';
             }
             $html .= '</ul>';
             $confirmation = $html;
         } else {
             $confirmation = array('redirect' => $this->payment->get_pay_redirect_url());
         }
         if ((headers_sent() || $ajax) && is_array($confirmation) && isset($confirmation['redirect'])) {
             $url = $confirmation['redirect'];
             // Using esc_js() and esc_url() on the URL is causing problems, the & in the URL is modified to &amp; or &#038;
             $confirmation = sprintf('<script>function gformRedirect(){document.location.href = %s;}', json_encode($url));
             if (!$ajax) {
                 $confirmation .= 'gformRedirect();';
             }
             $confirmation .= '</script>';
         }
     }
     return $confirmation;
 }