Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:mysiar/omnipay-przelewy24v1
Browse files Browse the repository at this point in the history
 ## Added
 * Blik payment functionality
----
  • Loading branch information
mysiar committed Aug 4, 2022
2 parents 99ab91a + 0b78e95 commit 5122da7
Show file tree
Hide file tree
Showing 25 changed files with 979 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ composer.lock
tests-api/.env
var/
.phpunit.result.cache
.docker
index.php
.idea
44 changes: 44 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Przelewy24\Message\BlikAliasesByEmailCustomRequest;
use Omnipay\Przelewy24\Message\BlikAliasesByEmailRequest;
use Omnipay\Przelewy24\Message\BlikChargeByAliasRequest;
use Omnipay\Przelewy24\Message\BlikChargeByCodeRequest;
use Omnipay\Przelewy24\Message\CardChargeRequest;
use Omnipay\Przelewy24\Message\CardInfoRequest;
use Omnipay\Przelewy24\Message\CardPayRequest;
Expand Down Expand Up @@ -204,4 +208,44 @@ public function purchaseOffline(array $options = []): PurchaseOfflineRequest
{
return $this->createRequest(PurchaseOfflineRequest::class, $options);
}

/**
* @param string[] $options
*
* @return AbstractRequest|BlikAliasesByEmailRequest
*/
public function blikGetAliasesByEmail(array $options = []): BlikAliasesByEmailRequest
{
return $this->createRequest(BlikAliasesByEmailRequest::class, $options);
}

/**
* @param string[] $options
*
* @return AbstractRequest|BlikAliasesByEmailCustomRequest
*/
public function blikGetAliasesByEmailCustom(array $options = []): BlikAliasesByEmailCustomRequest
{
return $this->createRequest(BlikAliasesByEmailCustomRequest::class, $options);
}

/**
* @param string[] $options
*
* @return AbstractRequest|BlikChargeByCodeRequest
*/
public function blikChargeByCode(array $options = []): BlikChargeByCodeRequest
{
return $this->createRequest(BlikChargeByCodeRequest::class, $options);
}

/**
* @param string[] $options
*
* @return AbstractRequest|BlikChargeByAliasRequest
*/
public function blikChargeByAlias(array $options = []): BlikChargeByAliasRequest
{
return $this->createRequest(BlikChargeByAliasRequest::class, $options);
}
}
37 changes: 37 additions & 0 deletions src/Message/BlikAliasesByEmailCustomRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

class BlikAliasesByEmailCustomRequest extends AbstractRequest
{
public function getEmail(): string
{
return $this->getParameter('email');
}

public function setEmail(string $email): self
{
return $this->setParameter('email', $email);
}

public function getData(): array
{
$this->validate('email');

return [
'email' => $this->getEmail(),
];
}

public function sendData($data): BlikAliasesByEmailCustomResponse
{
$email = $data['email'];
$httpResponse = $this->sendRequest('GET', sprintf('paymentMethod/blik/getAliasesByEmail/%s/custom', $email), []);

$responseData = json_decode($httpResponse->getBody()->getContents(), true);

return $this->response = new BlikAliasesByEmailCustomResponse($this, $responseData);
}
}
28 changes: 28 additions & 0 deletions src/Message/BlikAliasesByEmailCustomResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

use Omnipay\Common\Message\RequestInterface;

class BlikAliasesByEmailCustomResponse extends AbstractResponse
{
/**
* @var string[]
*/
private $aliases = [];

public function __construct(RequestInterface $request, $data)
{
parent::__construct($request, $data);
if (isset($data['data'])) {
$this->aliases = $data['data'];
}
}

public function getAliases(): array
{
return $this->aliases;
}
}
37 changes: 37 additions & 0 deletions src/Message/BlikAliasesByEmailRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

class BlikAliasesByEmailRequest extends AbstractRequest
{
public function getEmail(): string
{
return $this->getParameter('email');
}

public function setEmail(string $email): self
{
return $this->setParameter('email', $email);
}

public function getData(): array
{
$this->validate('email');

return [
'email' => $this->getEmail(),
];
}

public function sendData($data): BlikAliasesByEmailResponse
{
$email = $data['email'];
$httpResponse = $this->sendRequest('GET', sprintf('paymentMethod/blik/getAliasesByEmail/%s', $email), []);

$responseData = json_decode($httpResponse->getBody()->getContents(), true);

return $this->response = new BlikAliasesByEmailResponse($this, $responseData);
}
}
28 changes: 28 additions & 0 deletions src/Message/BlikAliasesByEmailResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

use Omnipay\Common\Message\RequestInterface;

class BlikAliasesByEmailResponse extends AbstractResponse
{
/**
* @var string[]
*/
private $aliases = [];

public function __construct(RequestInterface $request, $data)
{
parent::__construct($request, $data);
if (isset($data['data'])) {
$this->aliases = $data['data'];
}
}

public function getAliases(): array
{
return $this->aliases;
}
}
82 changes: 82 additions & 0 deletions src/Message/BlikChargeByAliasRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

use Omnipay\Common\Exception\InvalidRequestException;

class BlikChargeByAliasRequest extends AbstractRequest
{
public function getAlternativeKey(): string
{
return $this->getParameter('alternativeKey');
}

public function setAlternativeKey(string $type): self
{
return $this->setParameter('alternativeKey', $type);
}

public function getType(): string
{
return $this->getParameter('type');
}

public function setType(string $type): self
{
return $this->setParameter('type', $type);
}

public function getAliasValue(): string
{
return $this->getParameter('aliasValue');
}

public function setAliasValue(string $aliasValue): self
{
return $this->setParameter('aliasValue', $aliasValue);
}

public function getAliasLabel(): string
{
return $this->getParameter('aliasLabel');
}

public function setAliasLabel(string $label): self
{
return $this->setParameter('aliasLabel', $label);
}

public function getData(): array
{
$this->validate('token', 'type');

if (! in_array($this->getType(), ['alias', 'alternativeKey'], true)) {
throw new InvalidRequestException(
"The `type` parameter is required, and allows only 'alias', 'alternativeKey' values"
);
}

if ($this->getType() === 'alternativeKey') {
$this->validate('alternativeKey');
}

return [
'token' => $this->getToken(),
'type' => $this->getType(),
'aliasLabel' => $this->getAliasLabel(),
'aliasValue' => $this->getAliasValue(),
'alternativeKey' => $this->getAlternativeKey(),
];
}

public function sendData($data): BlikChargeByAliasResponse
{
$httpResponse = $this->sendRequest('POST', 'paymentMethod/blik/chargeByAlias', $data);

$responseData = json_decode($httpResponse->getBody()->getContents(), true);

return $this->response = new BlikChargeByAliasResponse($this, $responseData);
}
}
39 changes: 39 additions & 0 deletions src/Message/BlikChargeByAliasResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

use Omnipay\Common\Message\RequestInterface;

class BlikChargeByAliasResponse extends AbstractResponse
{
/**
* @var string
*/
private $orderId;

/**
* @var string
*/
private $chargeMessage;

public function __construct(RequestInterface $request, $data)
{
parent::__construct($request, $data);
if (isset($data['data'])) {
$this->orderId = $data['data']['orderId'];
$this->chargeMessage = $data['data']['message'];
}
}

public function getOrderId(): string
{
return $this->orderId;
}

public function getChargeMessage(): string
{
return $this->chargeMessage;
}
}
59 changes: 59 additions & 0 deletions src/Message/BlikChargeByCodeRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

class BlikChargeByCodeRequest extends AbstractRequest
{
public function getBlikCode(): string
{
return $this->getParameter('blikCode');
}

public function setBlikCode(string $code): self
{
return $this->setParameter('blikCode', $code);
}

public function getAliasValue(): string
{
return $this->getParameter('aliasValue');
}

public function setAliasValue(string $aliasValue): self
{
return $this->setParameter('aliasValue', $aliasValue);
}

public function getAliasLabel(): string
{
return $this->getParameter('aliasLabel');
}

public function setAliasLabel(string $label): self
{
return $this->setParameter('aliasLabel', $label);
}

public function getData(): array
{
$this->validate('token', 'blikCode');

return [
'token' => $this->getToken(),
'blikCode' => $this->getBlikCode(),
'aliasLabel' => $this->getAliasLabel(),
'aliasValue' => $this->getAliasValue(),
];
}

public function sendData($data): BlikChargeByCodeResponse
{
$httpResponse = $this->sendRequest('POST', 'paymentMethod/blik/chargeByCode', $data);

$responseData = json_decode($httpResponse->getBody()->getContents(), true);

return $this->response = new BlikChargeByCodeResponse($this, $responseData);
}
}

0 comments on commit 5122da7

Please sign in to comment.