Skip to content

Commit

Permalink
cardCharge3ds & purchaseOffline
Browse files Browse the repository at this point in the history
cardCharge3ds & purchaseOffline
  • Loading branch information
mysiar committed May 21, 2022
2 parents a855df2 + 14e7dba commit d43d606
Show file tree
Hide file tree
Showing 62 changed files with 1,482 additions and 116 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ 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.5.0](https://github.com/mysiar/omnipay-przelewy24v1/compare/0.4.0...0.5.0)

> 21 May 2022
- [/api/v1/transaction/registerOffline] [`#23`](https://github.com/mysiar/omnipay-przelewy24v1/pull/23)
- [/api/v1/card/chargeWith3ds] [`#22`](https://github.com/mysiar/omnipay-przelewy24v1/pull/22)
- additional-tests [`#21`](https://github.com/mysiar/omnipay-przelewy24v1/pull/21)
- cardPay & cardCharge [`#20`](https://github.com/mysiar/omnipay-przelewy24v1/pull/20)
- cardCharge3ds & purchaseOffline [`a1fe2d8`](https://github.com/mysiar/omnipay-przelewy24v1/commit/a1fe2d8694077bc88a4c7aa4cb7f4e4ce626c519)
- additional-tests: Methods tests [`ad009c1`](https://github.com/mysiar/omnipay-przelewy24v1/commit/ad009c18ef068f67bd5df206fbe0b67151fe32df)
- additional-tests: TestAccess tests [`fb17f0a`](https://github.com/mysiar/omnipay-przelewy24v1/commit/fb17f0abba02b3620a9b3abc2a7ea9e8df944335)

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

> 20 May 2022
Expand Down
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@

## API endpoints implemented

| API endpoint | Gateway method |
|:---------------------------------|:-----------------|
| /api/v1/testAccess | testAccess |
| /api/v1/payment/methods | methods |
| /api/v1/transaction/register | purchase |
| /api/v1/transaction/verify | completePurchase |
| /api/v1/transaction/refund | refund |
| /api/v1/transaction/by/sessionId | purchaseInfo |
| /api/v1/card/info | cardInfo |
| /api/v1/card/pay | cardPay |
| /api/v1/card/charge | cardCharge |
| API endpoint | Gateway method |
|:------------------------------------|:-----------------|
| /api/v1/testAccess | testAccess |
| /api/v1/payment/methods | methods |
| /api/v1/transaction/register | purchase |
| /api/v1/transaction/verify | completePurchase |
| /api/v1/transaction/refund | refund |
| /api/v1/transaction/by/sessionId | purchaseInfo |
| /api/v1/card/info | cardInfo |
| /api/v1/card/pay | cardPay |
| /api/v1/card/charge | cardCharge |
| /api/v1/card/chargeWith3ds | cardCharge3ds |
| /api/v1/transaction/registerOffline | purchaseOffline |

## Install

Expand All @@ -39,7 +41,7 @@ The following gateways are provided by this package:

* Przelewy24

Reference official documentation https://developers.przelewy24.pl/index.php
Reference official documentation https://developers.przelewy24.pl/index.php?en

## Example

Expand Down
1 change: 1 addition & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
]]);

$ecsConfig->import(SetList::SPACES);
$ecsConfig->import(SetList::STRICT);
$ecsConfig->import(SetList::ARRAY);
$ecsConfig->import(SetList::DOCBLOCK);
$ecsConfig->import(SetList::PSR_12);
Expand Down
16 changes: 16 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Omnipay\Przelewy24\Message\CompletePurchaseRequest;
use Omnipay\Przelewy24\Message\MethodsRequest;
use Omnipay\Przelewy24\Message\PurchaseInfoRequest;
use Omnipay\Przelewy24\Message\PurchaseOfflineRequest;
use Omnipay\Przelewy24\Message\PurchaseRequest;
use Omnipay\Przelewy24\Message\RefundsRequest;
use Omnipay\Przelewy24\Message\TestAccessRequest;
Expand Down Expand Up @@ -130,6 +131,7 @@ public function methods(string $lang = 'en'): MethodsRequest

/**
* @param string[] $options
*
* @return AbstractRequest|PurchaseRequest
*/
public function purchase(array $options = []): PurchaseRequest
Expand All @@ -139,6 +141,7 @@ public function purchase(array $options = []): PurchaseRequest

/**
* @param string[] $options
*
* @return AbstractRequest|CompletePurchaseRequest
*/
public function completePurchase(array $options = []): CompletePurchaseRequest
Expand Down Expand Up @@ -168,6 +171,7 @@ public function cardInfo(string $transactionId): CardInfoRequest

/**
* @param string[] $options
*
* @return AbstractRequest|RefundsRequest
*/
public function refund(array $options = []): RefundsRequest
Expand All @@ -177,6 +181,7 @@ public function refund(array $options = []): RefundsRequest

/**
* @param string[] $options
*
* @return AbstractRequest|CardPayRequest
*/
public function cardPay(array $options): CardPayRequest
Expand All @@ -186,10 +191,21 @@ public function cardPay(array $options): CardPayRequest

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

/**
* @param string[] $options
*
* @return AbstractRequest|PurchaseOfflineRequest
*/
public function purchaseOffline(array $options): PurchaseOfflineRequest
{
return $this->createRequest(PurchaseOfflineRequest::class, $options);
}
}
5 changes: 3 additions & 2 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

abstract class AbstractRequest extends BaseAbstractRequest
{
protected const SIGN_ALGO = 'sha384';

protected $liveEndpoint = 'https://secure.przelewy24.pl/api/v1/';

protected $testEndpoint = 'https://sandbox.przelewy24.pl/api/v1/';
Expand All @@ -17,8 +19,6 @@ abstract class AbstractRequest extends BaseAbstractRequest

protected $testRedirectEndpoint = 'https://sandbox.przelewy24.pl/';

protected const SIGN_ALGO = 'sha384';

public function getMerchantId()
{
return $this->getParameter('merchantId');
Expand Down Expand Up @@ -111,6 +111,7 @@ protected function sendRequest(string $method, string $endpoint, $data): Respons

/**
* @param mixed $value
*
* @throws
*/
protected function internalAmountValue($value = null): int
Expand Down
21 changes: 19 additions & 2 deletions src/Message/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,42 @@ public function getCode(): int
return (int) $this->data['code'];
}

if (
! isset($this->data['code'])
&& isset($this->data['responseCode'])
&& 0 !== (int) $this->data['responseCode']
) {
return (int) $this->data['responseCode'];
}

return Response::HTTP_OK;
}

/**
* @return array|string|null
* @return null|array|string
*/
public function getMessage()
{
if (isset($this->data['error'])) {
return $this->data['error'];
}

if (
Response::HTTP_NOT_FOUND === $this->getCode()
&& isset($this->data['data'])
&& ! is_array($this->data['data'])
) {
return $this->data['data'];
}

return '';
}

public function isSuccessful(): bool
{
$code = $this->getCode();

return in_array($code, [Response::HTTP_CREATED, Response::HTTP_OK]);
return in_array($code, [Response::HTTP_CREATED, Response::HTTP_OK], true);
}

protected function getAmountFromInternal(int $amount): string
Expand All @@ -53,6 +69,7 @@ protected function getAmountFromInternal(int $amount): string

/**
* @param string[] $data
*
* @return string[]
*/
protected function replaceInfoKeys(array $data, string $oldKey, string $newKey): array
Expand Down
26 changes: 26 additions & 0 deletions src/Message/CardCharge3dsRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

class CardCharge3dsRequest extends AbstractRequest
{
public function getData(): array
{
$this->validate('token');

return [
'token' => $this->getToken(),
];
}

public function sendData($data): CardCharge3dsResponse
{
$httpResponse = $this->sendRequest('POST', 'card/chargeWith3ds', $data);

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

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

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

use Omnipay\Common\Message\RequestInterface;

class CardCharge3dsResponse extends AbstractResponse
{
/**
* @var null|string
*/
private $transactionId = null;

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

public function getTransactionId(): ?string
{
return $this->transactionId;
}
}
2 changes: 1 addition & 1 deletion src/Message/CardChargeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CardChargeResponse extends AbstractResponse
/**
* @var null|string
*/
private $transactionId = null;
private $transactionId;

public function __construct(RequestInterface $request, $data)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Message/CardInfoResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getInfo(): array

/**
* @param string[] $data
*
* @return string[]
*/
private function formatInfo(array $data): array
Expand All @@ -39,8 +40,7 @@ private function formatInfo(array $data): array

// replace keys
$formatted = $this->replaceInfoKeys($formatted, 'cardType', 'brand');
$formatted = $this->replaceInfoKeys($formatted, 'cardDate', 'expiry');

return $formatted;
return $this->replaceInfoKeys($formatted, 'cardDate', 'expiry');
}
}
4 changes: 2 additions & 2 deletions src/Message/CardPayResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class CardPayResponse extends AbstractResponse
/**
* @var null|string
*/
private $transactionId = null;
private $transactionId;

/**
* @var null
*/
private $redirectUrl = null;
private $redirectUrl;

public function __construct(RequestInterface $request, $data)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Message/MethodsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function getData(): array

/**
* @param string[] $data
* @return ResponseInterface|MethodsResponse
*
* @return MethodsResponse|ResponseInterface
*/
public function sendData($data): ResponseInterface
{
Expand Down
6 changes: 3 additions & 3 deletions src/Message/PurchaseInfoResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getInfo(): array

public function getCode(): int
{
if (isset($this->data['responseCode']) && isset($this->data['error']) && strlen($this->data['error']) > 0) {
if (isset($this->data['responseCode'], $this->data['error']) && strlen($this->data['error']) > 0) {
return Response::HTTP_NOT_FOUND;
}

Expand All @@ -45,6 +45,7 @@ public function getCode(): int

/**
* @param string[] $data
*
* @return string[]
*/
private function formatInfo(array $data): array
Expand All @@ -61,8 +62,7 @@ private function formatInfo(array $data): array
$formatted = $this->replaceInfoKeys($formatted, 'clientName', 'name');
$formatted = $this->replaceInfoKeys($formatted, 'clientAddress', 'address');
$formatted = $this->replaceInfoKeys($formatted, 'clientCity', 'city');
$formatted = $this->replaceInfoKeys($formatted, 'clientPostcode', 'postcode');

return $formatted;
return $this->replaceInfoKeys($formatted, 'clientPostcode', 'postcode');
}
}
26 changes: 26 additions & 0 deletions src/Message/PurchaseOfflineRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Omnipay\Przelewy24\Message;

class PurchaseOfflineRequest extends AbstractRequest
{
public function getData(): array
{
$this->validate('token');

return [
'token' => $this->getToken(),
];
}

public function sendData($data): PurchaseOfflineResponse
{
$httpResponse = $this->sendRequest('POST', 'transaction/registerOffline', $data);

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

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

0 comments on commit d43d606

Please sign in to comment.