<commit_before><?php

namespace Omnipay\Flo2cash\Message;

use DOMDocument;
use Guzzle\Http\ClientInterface;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use SimpleXMLElement;

use Omnipay\Flo2cash;

/**
 * Flo2cash Abstract Request
 */
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
    protected $namespace = "http://www.flo2cash.co.nz/webservices/paymentwebservice";

    const LIVE_ENDPOINT = 'https://secure.flo2cash.co.nz/ws/paymentws.asmx';
    const TEST_ENDPOINT = 'https://demo.flo2cash.co.nz/ws/paymentws.asmx';

    const VERSION = '0.1';


    public function sendData($data)
    {
        $TransactionType = $data['Transaction'];
        $Data = $data['Data'];

        $document = new DOMDocument('1.0', 'UTF-8');
        $envelope = $document->appendChild(
            $document->createElementNS(
                'http://schemas.xmlsoap.org/soap/envelope/',
                'soap:Envelope'
            )
        );
        $envelope->setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema-instance');
        $envelope->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema');
        $body = $envelope->appendChild($document->createElement('soap:Body'));
        $body->appendChild($document->importNode(dom_import_simplexml($Data), true));
        $document->preserveWhiteSpace = false;
        $document->formatOutput = true;

        $xml = $document->saveXML();
        $xml = trim($xml);
        $headers = array(
            "Content-type" => "text/xml;charset=utf-8",
            "Accept" => "text/xml",
            "Cache-Control" => "no-cache",
            "Pragma" => "no-cache",
            "SOAPAction" => $this->getNamespace() . '/' . $TransactionType ,
            "Content-length" => strlen($xml));

        $httpRequest = $this->httpClient->post(
            $this->getEndpoint(),
            $headers,
            $xml
        );
        $req = (string) $httpRequest;
        $file = 'log.txt';
        // Write the contents to the file,
        $data = array('The Request:'. "\n", $req . "\n\n");
        // using the FILE_APPEND flag to append the content to the end of the file
        // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
        file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
        $httpResponse = $httpRequest->send();
        $request = (string) $httpResponse;
        $file = 'log.txt';
        // Write the contents to the file,
        $data = array('The Response:'. "\n", $request . "\n\n");
        // using the FILE_APPEND flag to append the content to the end of the file
        // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
        file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
        return $this->response = new Response($this, $httpResponse->getBody());

    }

    /**
     * Set the AccountID.
     *
     * @param number $AccountId Your Flo2Cash AccountId
     */
    public function setAccountId($AccountId)
    {
        $this->setParameter('AccountId', $AccountId);
    }

    /**
     * Get the AccountID.
     *
     * @returns string $AccountId Your Flo2Cash AccountId
     */
    public function getAccountId()
    {<commit_msg>Added listener to catch 500 errors thrown by gateway<commit_after><?php

namespace Omnipay\Flo2cash\Message;

use DOMDocument;
use Guzzle\Http\ClientInterface;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use SimpleXMLElement;

use Omnipay\Flo2cash;

/**
 * Flo2cash Abstract Request
 */
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
    protected $namespace = "http://www.flo2cash.co.nz/webservices/paymentwebservice";

    const LIVE_ENDPOINT = 'https://secure.flo2cash.co.nz/ws/paymentws.asmx';
    const TEST_ENDPOINT = 'https://demo.flo2cash.co.nz/ws/paymentws.asmx';

    const VERSION = '0.1';


    public function sendData($data)
    {
        $TransactionType = $data['Transaction'];
        $Data = $data['Data'];

        $document = new DOMDocument('1.0', 'UTF-8');
        $envelope = $document->appendChild(
            $document->createElementNS(
                'http://schemas.xmlsoap.org/soap/envelope/',
                'soap:Envelope'
            )
        );
        $envelope->setAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema-instance');
        $envelope->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema');
        $body = $envelope->appendChild($document->createElement('soap:Body'));
        $body->appendChild($document->importNode(dom_import_simplexml($Data), true));
        $document->preserveWhiteSpace = false;
        $document->formatOutput = true;

        $xml = $document->saveXML();
        $xml = trim($xml);
        $headers = array(
            "Content-type" => "text/xml;charset=utf-8",
            "Accept" => "text/xml",
            "Cache-Control" => "no-cache",
            "Pragma" => "no-cache",
            "SOAPAction" => $this->getNamespace() . '/' . $TransactionType ,
            "Content-length" => strlen($xml));

        # Catch naughty 500 errors thrown by the gateway
        $this->httpClient->getEventDispatcher()->addListener(
            'request.error',
            function ($event) {
                if ($event['response']->isServerError()) {
                    $event->stopPropagation();
                }
            }
        );

        $httpRequest = $this->httpClient->post(
            $this->getEndpoint(),
            $headers,
            $xml
        );

        $request = (string) $httpRequest;
        $file = 'log.txt';
        // Write the contents to the file,
        $data = array('The Request:'. "\n", $req . "\n\n");
        // using the FILE_APPEND flag to append the content to the end of the file
        // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
        file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
        
        $httpResponse = $httpRequest->send();
        $request = (string) $httpResponse;
        $file = 'log.txt';
        // Write the contents to the file,
        $data = array('The Response:'. "\n", $request . "\n\n");
        // using the FILE_APPEND flag to append the content to the end of the file
        // and the LOCK_EX flag to prevent anyone else writing to the file at the same time
        file_put_contents($file, $data, FILE_APPEND | LOCK_EX);
        return $this->response = new Response($this, $httpResponse->getBody());

    }

    /**
     * Set the AccountID.
     *
     * @param number $AccountId Your Flo2Cash AccountId
     */
    public function setAccountId($AccountId)
    {
        $this->setParameter('AccountId', $AccountId);
    }

    /**
     * Get the AccountID.
     *
     * @returns string $AccountId Your Flo2Cash AccountId
     */
    public function getAccountId()
    {
{'fraction_non_alphanumeric': 0.14128387190262282, 'fraction_numerical': 0.007824952905376032, 'mean_word_length': 2.36518771331058, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, 'https://': 4, 'lorem ipsum': 0, 'www.': 6, 'xml': 22}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2207641', 'n_tokens_mistral': 2088, 'n_tokens_neox': 2013, 'n_words': 467}