Added base plugin, in preperation for the API
This commit is contained in:
		@@ -48,7 +48,7 @@ repository.
 | 
				
			|||||||
    ));
 | 
					    ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Start the purchase
 | 
					    // Start the purchase
 | 
				
			||||||
    if (!isset($_GET['status'])) {
 | 
					    if (!isset($_GET['trxid'])) {
 | 
				
			||||||
        $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 | 
					        $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
 | 
				
			||||||
        $response = $gateway->purchase(array(
 | 
					        $response = $gateway->purchase(array(
 | 
				
			||||||
            'amount' => "1.50",
 | 
					            'amount' => "1.50",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,15 +4,13 @@ namespace Omnipay\Inforbank;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
use Omnipay\Common\AbstractGateway;
 | 
					use Omnipay\Common\AbstractGateway;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Gateway extends AbstractGateway {
 | 
					class Gateway extends AbstractGateway
 | 
				
			||||||
    public function getName() {
 | 
					{
 | 
				
			||||||
 | 
					    public function getName()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return 'Inforbank';
 | 
					        return 'Inforbank';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getDefaultParameters() {
 | 
					 | 
				
			||||||
        return array();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Start a purchase request.
 | 
					     * Start a purchase request.
 | 
				
			||||||
     * @param array $parameters An array of options
 | 
					     * @param array $parameters An array of options
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										20
									
								
								src/Message/AbstractRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								src/Message/AbstractRequest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Omnipay\Inforbank\Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					abstract class AbstractRequest extends BaseAbstractRequest
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    abstract protected function generateSignature();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getClientId()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->getParameter('clientId');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getClientSecret()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->getParameter('clientSecret');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										19
									
								
								src/Message/AbstractResponse.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/Message/AbstractResponse.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Omnipay\Inforbank\Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Omnipay\Common\Message\AbstractResponse as BaseAbstractResponse;
 | 
				
			||||||
 | 
					use Omnipay\Common\Message\RequestInterface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					abstract class AbstractResponse extends BaseAbstractResponse
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    protected $error;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function __construct(RequestInterface $request, $data)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        parent::__construct($request, $data);
 | 
				
			||||||
 | 
					        if (!$this->data->success) {
 | 
				
			||||||
 | 
					            $this->error = (string) $this->data->error;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										38
									
								
								src/Message/CompletePurchaseRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/Message/CompletePurchaseRequest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Omnipay\Inforbank\Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CompletePurchaseRequest extends AbstractRequest
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    protected $endpoint = "https://inforbank.nl/api/statusRequest";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function generateSignature()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return sha1(
 | 
				
			||||||
 | 
					            $this->getTransactionReference() . $this->getClientId() . $this->getClientSecret()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getTransactionReference()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->httpRequest->query->get('trxid');
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getData()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->validate('merchantId', 'merchantKey');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $data = array(
 | 
				
			||||||
 | 
					            "clientId" => $this->getClientId(),
 | 
				
			||||||
 | 
					            "clientSecret" => $this->getClientSecret(),
 | 
				
			||||||
 | 
					            "transactionId" => $this->getTransactionReference(),
 | 
				
			||||||
 | 
					            "sha1" => $this->generateSignature()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function sendData($data)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send();
 | 
				
			||||||
 | 
					        return $this->response = new CompletePurchaseResponse($this, $httpResponse->json());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										21
									
								
								src/Message/CompletePurchaseResponse.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/Message/CompletePurchaseResponse.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Omnipay\Inforbank\Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class CompletePurchaseResponse extends PurchaseResponse
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function isSuccessful()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return ($this->data->transaction->status === "Success");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function isRedirect()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getStatus()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->data->transaction->status;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										40
									
								
								src/Message/PurchaseRequest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								src/Message/PurchaseRequest.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Omnipay\Inforbank\Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PurchaseRequest extends AbstractRequest
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    protected $endpoint = "https://inforbank.nl/api/transactionRequest";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected function generateSignature()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return sha1(
 | 
				
			||||||
 | 
					            $this->getTransactionId() . $this->getAmountInteger() . $this->getClientId() . $this->getClientSecret()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getData()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $this->validate(
 | 
				
			||||||
 | 
					            'amount',
 | 
				
			||||||
 | 
					            'transactionId',
 | 
				
			||||||
 | 
					            'returnUrl'
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $data = array(
 | 
				
			||||||
 | 
					            "clientId" => $this->getClientId(),
 | 
				
			||||||
 | 
					            "clientSecret" => $this->getClientSecret(),
 | 
				
			||||||
 | 
					            "transactionId" => $this->getTransactionId(),
 | 
				
			||||||
 | 
					            "amount" => $this->getAmountInteger(),
 | 
				
			||||||
 | 
					            "description" => $this->getDescription(),
 | 
				
			||||||
 | 
					            "returnUrl" => $this->getReturnUrl(),
 | 
				
			||||||
 | 
					            "sha1" => $this->generateSignature()
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function sendData($data)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $httpResponse = $this->httpClient->post($this->endpoint, null, $data)->send();
 | 
				
			||||||
 | 
					        return $this->response = new PurchaseResponse($this, $httpResponse->json());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										38
									
								
								src/Message/PurchaseResponse.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								src/Message/PurchaseResponse.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Omnipay\Inforbank\Message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Omnipay\Common\Message\RedirectResponseInterface;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public function isSuccessful()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function isRedirect()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return is_null($this->error);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function isPending()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return true;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getRedirectUrl()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return $this->data->redirect;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getRedirectMethod()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return 'GET';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function getRedirectData()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        return null;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user