developermypos/myPOS-Checkout-SDK-PHP

Process for AJAX calls

Opened this issue · 0 comments

Hello!

I'm a developer for almost 20 year now, and started to use your PHP API, with the PHP SDK. It work properly, but to suit my needs I had to change some parts of it.
My main problem was that I'm calling my backend with AJAX calls, and as I initiate a payment, the base.php _processHtmlPost function echoes out the HTML form, and exites. This is not good for AJAX calls.
It would be good, if there would be a change in the _processHtmlPost function to not echo the form out, but send it back as the result of the function. Also this has to change the purchase.php's, and purchasebyIcard.php's process function.

My solution was:
Base.php

protected function _processHtmlPost($echoReply = true) {
        #Add request signature
        $this->params['Signature'] = $this->_createSignature();
        $c = '<body onload="document.ipcForm.submit();">';

        $c .= '<form id="ipcForm" name="ipcForm" action="'.$this->getCnf()->getIpcURL().'" method="post">';
        foreach ($this->params as $k => $v) {
            $c .= "<input type=\"hidden\" name=\"".$k."\" value=\"".$v."\"  />\n";
        }
        $c .= '</form></body>';
        if($echoReply) {
            echo $c;
            exit;
        } else {
            return $c;
        }
    }

Purchase.php and PurchaseByIcard.php

public function process($echoReply = true)
    {
        .....
        $result = $this->_processHtmlPost($echoReply);
        return $result;
    }