Skip to content

Commit 4ae3995

Browse files
authored
Merge pull request #9 from dachcom-digital/transaction_details
add GetTransactionDetailsAction
2 parents ac2cb26 + 3c6a434 commit 4ae3995

8 files changed

+85
-21
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace DachcomDigital\Payum\PostFinance\Flex\Action\Api;
4+
5+
use DachcomDigital\Payum\PostFinance\Flex\Api;
6+
use DachcomDigital\Payum\PostFinance\Flex\Request\Api\GetTransactionDetails;
7+
use Payum\Core\Action\ActionInterface;
8+
use Payum\Core\ApiAwareInterface;
9+
use Payum\Core\ApiAwareTrait;
10+
use Payum\Core\Bridge\Spl\ArrayObject;
11+
use Payum\Core\Exception\LogicException;
12+
use Payum\Core\Exception\RequestNotSupportedException;
13+
use Payum\Core\GatewayAwareInterface;
14+
use Payum\Core\GatewayAwareTrait;
15+
16+
class GetTransactionDetailsAction implements ActionInterface, GatewayAwareInterface, ApiAwareInterface
17+
{
18+
use GatewayAwareTrait;
19+
use ApiAwareTrait {
20+
setApi as _setApi;
21+
}
22+
23+
public function __construct()
24+
{
25+
$this->apiClass = Api::class;
26+
}
27+
28+
public function setApi($api)
29+
{
30+
$this->_setApi($api);
31+
}
32+
33+
/**
34+
* @param $request GetTransactionDetails
35+
*/
36+
public function execute($request)
37+
{
38+
RequestNotSupportedException::assertSupports($this, $request);
39+
$model = ArrayObject::ensureArrayObject($request->getModel());
40+
41+
if ($model['transaction_id'] === null) {
42+
throw new LogicException('transaction_id must be set.');
43+
}
44+
45+
$transaction = $this->api->getEntity($model['transaction_id']);
46+
47+
$model->replace($this->api->createTransactionInfo($transaction));
48+
}
49+
50+
public function supports($request): bool
51+
{
52+
return
53+
$request instanceof GetTransactionDetails &&
54+
$request->getModel() instanceof \ArrayAccess;
55+
}
56+
}

Action/NotifyNullAction.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
namespace DachcomDigital\Payum\PostFinance\Flex\Action;
44

55
use DachcomDigital\Payum\PostFinance\Flex\Api;
6+
use DachcomDigital\Payum\PostFinance\Flex\Request\Api\GetTransactionDetails;
67
use Payum\Core\Action\ActionInterface;
78
use Payum\Core\ApiAwareInterface;
89
use Payum\Core\ApiAwareTrait;
10+
use Payum\Core\Bridge\Spl\ArrayObject;
911
use Payum\Core\Exception\RequestNotSupportedException;
1012
use Payum\Core\GatewayAwareInterface;
1113
use Payum\Core\GatewayAwareTrait;
1214
use Payum\Core\Reply\HttpResponse;
1315
use Payum\Core\Request\GetHttpRequest;
1416
use Payum\Core\Request\GetToken;
1517
use Payum\Core\Request\Notify;
16-
use PostFinanceCheckout\Sdk\Model\Transaction;
1718

1819
class NotifyNullAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface
1920
{
@@ -53,13 +54,12 @@ public function execute($request)
5354
return;
5455
}
5556

56-
$transaction = $this->api->getEntity($body['entityId']);
57+
$model = new ArrayObject([]);
58+
$model['transaction_id'] = $body['entityId'];
5759

58-
if (!$transaction instanceof Transaction) {
59-
return;
60-
}
60+
$this->gateway->execute(new GetTransactionDetails($model));
6161

62-
$tokenHash = $transaction->getMetaData()['paymentToken'] ?? null;
62+
$tokenHash = $model['meta_paymentToken'] ?? null;
6363

6464
} catch (\Throwable $e) {
6565
throw new HttpResponse($e->getMessage(), 500, ['Content-Type' => 'text/plain', 'X-Notify-Message' => $e->getMessage()]);

Action/StatusAction.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace DachcomDigital\Payum\PostFinance\Flex\Action;
44

55
use DachcomDigital\Payum\PostFinance\Flex\Api;
6+
use DachcomDigital\Payum\PostFinance\Flex\Request\Api\GetTransactionDetails;
67
use Payum\Core\Action\ActionInterface;
78
use Payum\Core\ApiAwareInterface;
89
use Payum\Core\ApiAwareTrait;
@@ -11,7 +12,6 @@
1112
use Payum\Core\GatewayAwareInterface;
1213
use Payum\Core\GatewayAwareTrait;
1314
use Payum\Core\Request\GetStatusInterface;
14-
use PostFinanceCheckout\Sdk\Model\Transaction;
1515
use PostFinanceCheckout\Sdk\Model\TransactionState;
1616

1717
class StatusAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface
@@ -46,14 +46,9 @@ public function execute($request)
4646
return;
4747
}
4848

49-
$transaction = $this->api->getEntity($model['transaction_id']);
50-
if (!$transaction instanceof Transaction) {
51-
$request->markUnknown();
52-
53-
return;
54-
}
49+
$this->gateway->execute(new GetTransactionDetails($model));
5550

56-
$state = $transaction->getState();
51+
$state = $model['State'] ?? null;
5752

5853
// @see https://checkout.postfinance.ch/doc/api/web-service#_transactionstate
5954

Action/SyncAction.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace DachcomDigital\Payum\PostFinance\Flex\Action;
44

55
use DachcomDigital\Payum\PostFinance\Flex\Api;
6+
use DachcomDigital\Payum\PostFinance\Flex\Request\Api\GetTransactionDetails;
67
use Payum\Core\Action\ActionInterface;
78
use Payum\Core\ApiAwareInterface;
89
use Payum\Core\ApiAwareTrait;
@@ -11,7 +12,6 @@
1112
use Payum\Core\GatewayAwareInterface;
1213
use Payum\Core\GatewayAwareTrait;
1314
use Payum\Core\Request\Sync;
14-
use PostFinanceCheckout\Sdk\Model\Transaction;
1515

1616
class SyncAction implements ActionInterface, ApiAwareInterface, GatewayAwareInterface
1717
{
@@ -43,12 +43,7 @@ public function execute($request)
4343
return;
4444
}
4545

46-
$transaction = $this->api->getEntity($model['transaction_id']);
47-
if (!$transaction instanceof Transaction) {
48-
return;
49-
}
50-
51-
$model->replace($this->api->createTransactionInfo($transaction));
46+
$this->gateway->execute(new GetTransactionDetails($model));
5247
}
5348

5449
public function supports($request): bool

Api.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public function createTransactionInfo(Transaction $transaction): array
105105
'getters'
106106
];
107107

108+
$metaData = $transaction->getMetaData();
109+
110+
$data['meta_paymentToken'] = $metaData['paymentToken'] ?? null;
111+
108112
foreach ($ref->getMethods() as $method) {
109113

110114
$methodName = $method->getName();

PostFinanceFlexGatewayFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace DachcomDigital\Payum\PostFinance\Flex;
44

5+
use DachcomDigital\Payum\PostFinance\Flex\Action\Api\GetTransactionDetailsAction;
56
use DachcomDigital\Payum\PostFinance\Flex\Action\Api\RenderIframeAction;
67
use DachcomDigital\Payum\PostFinance\Flex\Action\Api\RenderLightboxAction;
78
use DachcomDigital\Payum\PostFinance\Flex\Action\Api\TransactionExtenderAction;
@@ -33,6 +34,7 @@ protected function populateConfig(ArrayObject $config): void
3334
'payum.action.convert_payment' => new ConvertPaymentAction(),
3435
'payum.action.sync' => new SyncAction(),
3536

37+
'payum.action.api.get_transaction_details' => new GetTransactionDetailsAction(),
3638
'payum.action.api.transaction_extender' => new TransactionExtenderAction(),
3739
'payum.action.api.initialize_transaction' => new CreateTransactionAction(),
3840
'payum.action.api.capture_offsite' => new CaptureOffsiteAction(),

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ You need to define a global webhook: `https://your-domain.com/payment/notify/uns
2323

2424
## Changelog
2525

26+
### 1.3.0
27+
- introduce `GetTransactionDetailsAction`
28+
2629
### 1.2.0
2730
- dependency `postfinancecheckout/sdk:^4.1` added
2831
- added `totalTaxes` to transaction extender to allow tax rates submission to line item

Request/Api/GetTransactionDetails.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace DachcomDigital\Payum\PostFinance\Flex\Request\Api;
4+
5+
use Payum\Core\Request\Generic;
6+
7+
class GetTransactionDetails extends Generic
8+
{
9+
}

0 commit comments

Comments
 (0)