<?php
class Flutterwave {

    var $fields = array();

    function __construct() {
        $this->api_url="https://checkout.flutterwave.com/v3/hosted/pay";
    }
    function add_field($field, $value) {
        $this->fields["$field"] = $value;
    }

    function submit() {
        echo "<html>\n";
        echo "<body onLoad=\"document.forms['flutterwave_form'].submit();\">\n";
        echo "<form method=\"post\" name=\"flutterwave_form\" ";
        echo "action=\"" . $this->api_url . "\">\n";
        foreach ($this->fields as $name => $value) {
            echo "<input type=\"hidden\" name=\"$name\" value=\"$value\"/>\n";
        }
        echo "</form>\n";
        echo "</body></html>\n";
    }

    function submit_old($data) {

        $public_key=$data['public_key'];
        $email=$data['email'];
        $name=$data['name'];
        $tx_ref=$data['tx_ref'];
        $amount=$data['amount'];
        $currency=$data['currency'];
        $token=$data['token'];
        $redirect_url=$data['redirect_url'];

        echo "<html>\n";
        echo "<body>\n";
        //echo "<body onLoad=\"document.getElementById('start-payment-button').click();\">\n";
        echo '<form method="POST" action="https://checkout.flutterwave.com/v3/hosted/pay">
  <input type="hidden" name="public_key" value="'.$public_key.'" />
  <input type="hidden" name="customer[email]" value="'.$email.'" />
  <input type="hidden" name="customer[name]" value="'.$name.'" />
  <input type="hidden" name="tx_ref" value="'.$tx_ref.'" />
  <input type="hidden" name="amount" value='.$amount.' />
  <input type="hidden" name="currency" value='.$currency.' />
  <input type="hidden" name="meta[token]" value='.$token.' />
  <input type="hidden" name="redirect_url" value='.$redirect_url.' />
  <button type="submit" id="start-payment-button">Pro</button>
</form>';
        echo "</body></html>\n";
    }

}
