<?php
   /**
    * form
    *
    * @package Wojo Framework
    * @author wojoscripts.com
    * @copyright 2023
    * @version 5.00: form.tpl.php, v1.00 7/18/2023 8:34 AM Gewa Exp $
    *
    */
   if (!defined('_WOJO')) {
      die('Direct access to this location is not allowed.');
   }
?>
<?php $url = ($this->gateway->live)? 'www.payfast.co.za' : 'sandbox.payfast.co.za'; ?>
<form action="https://<?php echo $url; ?>/eng/process" method="post" id="pf_form" name="pf_form" class="margin-top center-align">
   <a id="gSubmit" class="wojo white shadow icon button">
      <img class="wojo medium image" src="<?php echo SITEURL . '/gateways/payfast/payfast_logo.svg'; ?>" alt="<?php echo $this->gateway->displayname; ?>">
   </a>
   <?php
      $html = '';
      $string = '';
      $array = array(
        'merchant_id' => $this->gateway->extra,
        'merchant_key' => $this->gateway->extra2,
        'return_url' => Url::url('/dashboard'),
        'cancel_url' => Url::url('/dashboard'),
        'notify_url' => SITEURL . '/gateways/' . $this->gateway->dir . '/shop/ipn.php',
        'name_first' => Auth::$userdata->fname,
        'name_last' => Auth::$userdata->lname,
        'email_address' => Auth::$userdata->email,
        'm_payment_id' => time(),
        'amount' => Utility::numberParse($this->cart->grand),
        'item_name' => $this->core->company . ' - ' . Language::$word->CHECKOUT,
        'custom_int1' => Utility::encode(App::Auth()->uid . '_' . App::Auth()->sesid),
      );
      foreach ($array as $k => $v) {
         $html .= '<input type="hidden" name="' . $k . '" value="' . $v . '" />';
         $string .= $k . '=' . urlencode(trim($v)) . '&';
      }
      $string = substr($string, 0, -1);
      $sig = md5($string);
      $html .= '<input type="hidden" name="signature" value="' . $sig . '" />';

      print $html;
   ?>
</form>
<script>
   $('#gSubmit').on('click', function () {
      $('#pf_form').submit();
   });
</script>