Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace Omnipay\Windcave;

use Omnipay\Common\AbstractGateway;
use Omnipay\Windcave\Message\CompleteSessionRequest;
use Omnipay\Windcave\Message\CreateHppSessionRequest;
use Omnipay\Windcave\Message\CreateSessionRequest;
use Omnipay\Windcave\Message\GetHppSessionRequest;
use Omnipay\Windcave\Message\GetSessionRequest;
use Omnipay\Windcave\Message\PurchaseRequest;

Expand Down Expand Up @@ -152,4 +155,37 @@ public function getSession(array $parameters = array())
{
return $this->createRequest(GetSessionRequest::class, $parameters);
}

/**
* Complete a session.
*
* @param array $parameters
* @return \Omnipay\Windcave\Message\CompleteSessionRequest|\Omnipay\Common\Message\AbstractRequest
*/
public function completeSession(array $parameters = array())
{
return $this->createRequest(CompleteSessionRequest::class, $parameters);
}

/**
* Create a Hosted Payment Page session.
*
* @param array $parameters
* @return \Omnipay\Windcave\Message\CreateHppSessionRequest|\Omnipay\Common\Message\AbstractRequest
*/
public function createHppSession(array $parameters = array())
{
return $this->createRequest(CreateHppSessionRequest::class, $parameters);
}

/**
* Get a Hosted Payment Page session.
*
* @param array $parameters
* @return \Omnipay\Windcave\Message\GetHppSessionRequest|\Omnipay\Common\Message\AbstractRequest
*/
public function getHppSession(array $parameters = array())
{
return $this->createRequest(GetHppSessionRequest::class, $parameters);
}
}
16 changes: 16 additions & 0 deletions src/Message/CompleteSessionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Omnipay\Windcave\Message;

use Omnipay\Windcave\Message\CompleteSessionResponse;

class CompleteSessionRequest extends GetSessionRequest
{
/**
* @inheritDoc
*/
public function getResponseClass()
{
return CompleteSessionResponse::class;
}
}
22 changes: 22 additions & 0 deletions src/Message/CompleteSessionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Omnipay\Windcave\Message;

class CompleteSessionResponse extends GetSessionResponse
{
/**
* @inheritDoc
*/
public function isSuccessful()
{
return parent::isSuccessful() && $this->getTransactionAuthorised() === true;
}

/**
* @inheritDoc
*/
public function getMessage()
{
return $this->getTransactionData('responseText') ?? parent::getMessage();
}
}
17 changes: 17 additions & 0 deletions src/Message/CreateHppSessionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Omnipay\Windcave\Message;

use Omnipay\Windcave\Message\CreateSessionRequest;
use Omnipay\Windcave\Message\HppSessionRedirectResponse;

class CreateHppSessionRequest extends CreateSessionRequest
{
/**
* @inheritDoc
*/
public function getResponseClass()
{
return HppSessionRedirectResponse::class;
}
}
8 changes: 8 additions & 0 deletions src/Message/CreateSessionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ public function getPurchaseUrl()

return null;
}

/**
* @inheritDoc
*/
public function getTransactionReference()
{
return $this->getSessionId();
}
}
16 changes: 16 additions & 0 deletions src/Message/GetHppSessionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Omnipay\Windcave\Message;

use Omnipay\Windcave\Message\HppSessionRedirectResponse;

class GetHppSessionRequest extends GetSessionRequest
{
/**
* @inheritDoc
*/
public function getResponseClass()
{
return HppSessionRedirectResponse::class;
}
}
8 changes: 8 additions & 0 deletions src/Message/GetSessionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,12 @@ protected function getTransactionData($key)

return isset($transaction[$key]) ? $transaction[$key] : null;
}

/**
* @inheritDoc
*/
public function getTransactionReference()
{
return $this->getSessionId();
}
}
74 changes: 74 additions & 0 deletions src/Message/HppSessionRedirectResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Omnipay\Windcave\Message;

use Omnipay\Common\Message\RedirectResponseInterface;

class HppSessionRedirectResponse extends GetSessionResponse implements RedirectResponseInterface
{
/**
* Gets the redirect target url.
*
* @return string
*/
public function getRedirectUrl()
{
$redirectUrl = null;

$links = $this->getData()['links'] ?? [];
foreach ($links as $link) {
$href = $link['href'] ?? null;
$rel = $link['rel'] ?? null;
if ($href && $rel == 'hpp') {
$redirectUrl = $href;
}
}

return $redirectUrl;
}

/**
* Get the required redirect method (either GET or POST).
*
* @return string
*/
public function getRedirectMethod()
{
return 'GET';
}

/**
* Is the response successful?
*
* @return boolean
*/
public function isSuccessful()
{
return false;
}

/**
* Does the response require a redirect?
*
* @return boolean
*/
public function isRedirect()
{
return true;
}

/**
* Is the response a transparent redirect?
*
* @return boolean
*/
public function isTransparentRedirect()
{
return true;
}

public function getSessionId()
{
return $this->getData('id');
}
}