-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of github.com:mysiar/omnipay-przelewy24v1
- Loading branch information
Showing
17 changed files
with
554 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Omnipay\Przelewy24\Message; | ||
|
||
class PurchaseInfoRequest extends AbstractRequest | ||
{ | ||
public function getSessionId(): string | ||
{ | ||
return $this->getParameter('sessionId'); | ||
} | ||
|
||
public function setSessionId(string $value): self | ||
{ | ||
return $this->setParameter('sessionId', $value); | ||
} | ||
|
||
public function getData(): array | ||
{ | ||
$this->validate('sessionId'); | ||
|
||
return [ | ||
'sessionId' => $this->getSessionId(), | ||
]; | ||
} | ||
|
||
public function sendData($data) | ||
{ | ||
$httpResponse = $this->sendRequest('GET', sprintf('transaction/by/sessionId/%s', $data['sessionId']), []); | ||
|
||
$responseData = json_decode($httpResponse->getBody()->getContents(), true); | ||
|
||
return $this->response = new PurchaseInfoResponse($this, $responseData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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\Message\RequestInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class PurchaseInfoResponse extends AbstractResponse | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $info = []; | ||
|
||
public function __construct(RequestInterface $request, $data) | ||
{ | ||
parent::__construct($request, $data); | ||
if (isset($data['data'])) { | ||
$this->info = $this->formatInfo($data['data']); | ||
} | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getInfo(): array | ||
{ | ||
return $this->info; | ||
} | ||
|
||
public function getCode(): int | ||
{ | ||
if (isset($this->data['responseCode']) && isset($this->data['error']) && strlen($this->data['error']) > 0) { | ||
return Response::HTTP_NOT_FOUND; | ||
} | ||
|
||
if (isset($this->data['code'])) { | ||
return $this->data['code']; | ||
} | ||
|
||
return self::HTTP_OK; | ||
} | ||
|
||
/** | ||
* @param string[] $data | ||
* @return string[] | ||
*/ | ||
private function formatInfo(array $data): array | ||
{ | ||
$formatted = $data; | ||
|
||
// format | ||
if (isset($formatted['amount'])) { | ||
$formatted['amount'] = $this->getAmountFromInternal((int) $formatted['amount']); | ||
} | ||
|
||
// replace keys | ||
$formatted = $this->replaceInfoKeys($formatted, 'clientEmail', 'email'); | ||
$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; | ||
} | ||
|
||
/** | ||
* @param string[] $data | ||
* @return string[] | ||
*/ | ||
private function replaceInfoKeys(array $data, string $oldKey, string $newKey): array | ||
{ | ||
if (isset($data[$oldKey])) { | ||
$data[$newKey] = $data[$oldKey]; | ||
unset($data[$oldKey]); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.