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 49ebfd4
Show file tree
Hide file tree
Showing 26 changed files with 988 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
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [0.7.0](https://github.com/mysiar/omnipay-przelewy24v1/compare/0.6.0...0.7.0)

> 4 August 2022
- Blik request handles for Przelewy24 [`#32`](https://github.com/mysiar/omnipay-przelewy24v1/pull/32)
- test-gh-self-hosted-action-runner [`#26`](https://github.com/mysiar/omnipay-przelewy24v1/pull/26)
- self hosted runners & tests sequence for PHP-7.3 [`99ab91a`](https://github.com/mysiar/omnipay-przelewy24v1/commit/99ab91ab88ccd83e32371d4804d60e6fadff5d73)
- refactor gateway methods to array $options [`f26f759`](https://github.com/mysiar/omnipay-przelewy24v1/commit/f26f759e3b5070512919f4fc583a9a9a3fff72cc)

#### [0.6.0](https://github.com/mysiar/omnipay-przelewy24v1/compare/0.5.1...0.6.0)

> 23 May 2022
Expand Down
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);
}
}
Loading

0 comments on commit 49ebfd4

Please sign in to comment.