PK       ! B;ȁ    8  omnipay-billplz/src/Message/CompletePurchaseResponse.phpnu [        <?php

namespace Omnipay\Billplz\Message;

use Omnipay\Common\Message\AbstractResponse;

class CompletePurchaseResponse extends AbstractResponse
{
    protected $statusCode;

    public function __construct($request, $data, $statusCode = 200)
    {
        parent::__construct($request, $data);
        $this->statusCode = $statusCode;
    }

    public function isSuccessful()
    {
        return (isset($this->data['state']) && $this->data['state'] == 'paid');
    }
}
PK       ! #     0  omnipay-billplz/src/Message/PurchaseResponse.phpnu [        <?php

namespace Omnipay\Billplz\Message;

use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RequestInterface;
use Omnipay\Common\Message\RedirectResponseInterface;

/**
 * Stripe Response
 */
class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface
{
    protected $statusCode;

    public function __construct($request, $data, $statusCode = 200)
    {
        parent::__construct($request, $data);
        $this->statusCode = $statusCode;
    }

    /**
     * Has the call to the processor succeeded?
     * When we need to redirect the browser we return false as the transaction is not yet complete
     *
     * @return bool
     */
    public function isSuccessful()
    {
        return false;
    }

    /**
     * Should the user's browser be redirected?
     *
     * @return bool
     */
    public function isRedirect()
    {
        return isset($this->data['url'])?true:false;
    }

    /**
     * Transparent redirect is the mode whereby a form is presented to the user that POSTs to the payment
     * processor site directly. If this returns true the site will need to provide a form for this
     *
     * @return bool
     */
    public function isTransparentRedirect()
    {
        return false;
    }

    public function getRedirectUrl()
    {
        return $this->data['url'];
    }

    /**
     * Should the browser redirect using GET or POST
     * @return string
     */
    public function getRedirectMethod()
    {
        return 'GET';
    }

    public function getRedirectData()
    {
        return $this->getData();
    }

    public function getMessage()
    {
        if(is_array($this->data['error'])){
            return implode(", ",$this->data['error']['message']);
        }else{
            return $this->data['error'];
        }
    }

    public function getTransactionReference()
    {
        return isset($this->data['id'])?$this->data['id']:null;
    }
}
PK       ! ԓ    /  omnipay-billplz/src/Message/AbstractRequest.phpnu [        <?php

namespace Omnipay\Billplz\Message;

use Omnipay\Common\Exception\InvalidRequestException;
use Omnipay\Common\Exception\InvalidResponseException;
use GuzzleHttp\Middleware;

/**
 * Abstract Request
 */
abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest
{
    private $liveEndpoint = "www.billplz.com/api/v3/";
    private $testEndpoint = "billplz-staging.herokuapp.com/api/v3/";

    private function getEndpoint()
    {
        $url = ($this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint);
        $base = 'https://'.$this->getAPIKey().':@'. $url . $this->getAPI();
        return $base;
    }

    public function sendData($data)
    {
        // don't throw exceptions for 4xx errors
        /*$this->httpClient->getEventDispatcher()->addListener(
            'request.error',
            function ($event) {
                if ($event['response']->isClientError()) {
                    $event->stopPropagation();
                }
            }
        );*/

        try {

        // Guzzle HTTP Client createRequest does funny things when a GET request
        // has attached data, so don't send the data if the method is GET.
        if ($this->getHttpMethod() == 'GET') {
            $httpResponse = $this->httpClient->request(
                $this->getHttpMethod(),
                $this->getEndpoint() . '?' . http_build_query($data),
                array(
                    'Accept' => 'application/json',
                    'Authorization' => 'Basic ' . $this->getToken(),
                    'Content-type' => 'application/json',
                    'curl' => array(
                        CURLOPT_SSLVERSION => 6
                    ),
                    'http_errors' => false
                )
            );
        } else {
            $httpResponse = $this->httpClient->request(
                $this->getHttpMethod(),
                $this->getEndpoint(),
                array(
                    'Accept' => 'application/json',
                    'Authorization' => 'Basic ' . $this->getToken(),
                    'Content-type' => 'application/json',
                    'curl' => array(
                        CURLOPT_SSLVERSION => 6
                    ),
                    'http_errors' => false
                ),
                $this->toJSON($data)
            );
        }

        // Might be useful to have some debug code here, PayPal especially can be
        // a bit fussy about data formats and ordering.  Perhaps hook to whatever
        // logging engine is being used.
        // echo "Data == " . json_encode($data) . "\n";

        
            //$httpRequest->getOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2 for libcurl < 7.35
            //$httpResponse = $httpRequest->send();
            // Empty response body should be parsed also as and empty array
            $body = $httpResponse->getBody()->getContents();
            $jsonToArrayResponse = !empty($body) ? json_decode($body, true) : array();
            return $this->response = $this->createResponse($jsonToArrayResponse, $httpResponse->getStatusCode());
        } catch (\Exception $e) {
            throw new InvalidResponseException(
                'Error communicating with payment gateway: ' . $e->getMessage(),
                $e->getCode()
            );
        }
    }

    public function toJSON($data, $options = 0)
    {
	    return json_encode($data, $options | 64);
    }

    public function getToken()
    {
        return base64_encode($this->getAPIKey().":");
    }
    
    // essenstial parameters
    public function getName()
    {
        return $this->getParameter('name');
    }

    public function setName($value)
    {
        return $this->setParameter('name', $value);
    }

    public function getEmail()
    {
        return $this->getParameter('email');
    }

    public function setEmail($value)
    {
        return $this->setParameter('email', $value);
    }

    public function getCollectionId()
    {
        return $this->getParameter('collectionId');
    }

    public function setCollectionId($value)
    {
        return $this->setParameter('collectionId', $value);
    }

    public function getAPIKey()
    {
        return $this->getParameter('apikey');
    }

    public function setAPIKey($value)
    {
        return $this->setParameter('apikey', $value);
    }

    public function getId()
    {
        return $this->getParameter('id');
    }

    public function setId($value)
    {
        return $this->setParameter('id', $value);
    }
}
PK       !     /  omnipay-billplz/src/Message/PurchaseRequest.phpnu [        <?php

namespace Omnipay\Billplz\Message;

/**
 * Purchase Request
 */
class PurchaseRequest extends AbstractRequest
{
    protected function createResponse($data, $statusCode)
    {
        return $this->response = new PurchaseResponse($this, $data, $statusCode);
    }

    public function getHttpMethod()
    {
        return 'POST';
    }

    public function getAPI()
    {
        return 'bills';
    }

    public function getData()
    {
        $data = [];

        $data['collection_id'] = $this->getParameter('collectionId');
        $data['description'] = $this->getParameter('description');
        $data['email'] = $this->getParameter('email');
        $data['name'] = $this->getParameter('name');
        $data['amount'] = intval($this->getParameter('amount')*100);
        $data['callback_url'] = $this->getParameter('notifyUrl');
        $data['redirect_url'] = $this->getParameter('returnUrl');
        return $data;
    }
}
PK       ! ݎ    7  omnipay-billplz/src/Message/CompletePurchaseRequest.phpnu [        <?php

namespace Omnipay\Billplz\Message;

/**
 * Authorize Request
 */
class CompletePurchaseRequest extends AbstractRequest
{
    protected function createResponse($data, $statusCode)
    {
        return $this->response = new CompletePurchaseResponse($this, $data, $statusCode);
    }

    public function getHttpMethod()
    {
        return 'GET';
    }

    public function getAPI()
    {
        return 'bills/'.$this->getId();
    }

    public function getData()
    {
        return [];
    }
}
PK       ! 2I
  I
    omnipay-billplz/src/Gateway.phpnu [        <?php
namespace Omnipay\Billplz;

use Omnipay\Common\AbstractGateway;

class Gateway extends AbstractGateway
{

  /**
   * get the name of your processor. This will be the name used w
   * @return string
   */
    public function getName()
    {
        return 'Billplz';
    }

  /**
   * declare the parameters that will be used to authenticate with the site
   * You will need to create a function for each of these. e.g getUsername for username
   * @return array
   */
    public function getDefaultParameters()
    {
        return array(
            'apikey' => '',
            'collectionId' => '',
            'testMode' => false,
        );
    }

    /**
     *
     * @param array $parameters
     * @return \Omnipay\Billplz\Message\AuthorizeRequest
     */
    // public function authorize(array $parameters = array())
    // {
    //     return $this->createRequest('\Omnipay\Billplz\Message\AuthorizeRequest', $parameters);
    // }

    /**
     *
     * @param array $parameters
     * @return \Omnipay\Billplz\Message\CaptureRequest
     */
    // public function capture(array $parameters = array())
    // {
    //     return $this->createRequest('\Omnipay\Billplz\Message\CaptureRequest', $parameters);
    // }

    /**
     *
     * @param array $parameters
     * @return \Omnipay\Billplz\Message\PurchaseRequest
     */
    public function purchase(array $parameters = array())
    {
        return $this->createRequest('\Omnipay\Billplz\Message\PurchaseRequest', $parameters);
    }

    /**
     *
     * @param array $parameters
     * @return \Omnipay\Billplz\Message\CompletePurchaseRequest
     */
    public function completePurchase(array $parameters = array())
    {
        return $this->createRequest('\Omnipay\Billplz\Message\CompletePurchaseRequest', $parameters);
    }

    /**
     * @param array $parameters
     * @return \Omnipay\Billplz\Message\CompleteAuthorizeRequest
     */
    // public function completeAuthorize(array $parameters = array())
    // {
    //     return $this->createRequest('\Omnipay\Billplz\Message\CompleteAuthorizeRequest', $parameters);
    // }
    public function getCollectionId()
    {
        return $this->getParameter('collectionId');
    }

    public function setCollectionId($value)
    {
        return $this->setParameter('collectionId', $value);
    }

    public function getAPIKey()
    {
        return $this->getParameter('apikey');
    }

    public function setAPIKey($value)
    {
        return $this->setParameter('apikey', $value);
    }
}
PK         ! B;ȁ    8                omnipay-billplz/src/Message/CompletePurchaseResponse.phpnu [        PK         ! #     0            U  omnipay-billplz/src/Message/PurchaseResponse.phpnu [        PK         ! ԓ    /            
  omnipay-billplz/src/Message/AbstractRequest.phpnu [        PK         !     /              omnipay-billplz/src/Message/PurchaseRequest.phpnu [        PK         ! ݎ    7            !  omnipay-billplz/src/Message/CompletePurchaseRequest.phpnu [        PK         ! 2I
  I
              ?$  omnipay-billplz/src/Gateway.phpnu [        PK        .    