44
55namespace PayNL \Sdk \Model \Request ;
66
7+ use PayNL \Sdk \Config \Config ;
78use PayNL \Sdk \Exception \PayException ;
89use PayNL \Sdk \Request \RequestData ;
910use PayNL \Sdk \Model \Pay \PayOrder ;
1011use PayNL \Sdk \Request \RequestInterface ;
12+ use PayNL \Sdk \Helpers \StaticCacheTrait ;
13+ use PayNL \Sdk \Util \PayCache ;
1114
1215/**
1316 * Class TransactionStatusRequest
1720 */
1821class TransactionStatusRequest extends RequestData
1922{
23+ use StaticCacheTrait;
24+
2025 private string $ orderId ;
2126
2227 /**
23- * @param $orderid
28+ * @param string $orderId
2429 */
25- public function __construct ($ orderId )
30+ public function __construct (string $ orderId )
2631 {
2732 $ this ->orderId = $ orderId ;
2833 parent ::__construct ('TransactionStatus ' , '/transactions/%transactionId%/status ' , RequestInterface::METHOD_GET );
@@ -48,12 +53,29 @@ public function getBodyParameters(): array
4853
4954 /**
5055 * @return PayOrder
51- * @throws PayException
56+ * @throws \Exception
5257 */
5358 public function start (): PayOrder
5459 {
55- # Always use rest.pay.nl for this status request
56- $ this ->config ->setCore ('https://rest.pay.nl ' );
57- return parent ::start ();
60+ $ cacheKey = 'transaction_status_ ' . md5 (json_encode ([$ this ->config ->getUsername (), $ this ->orderId ]));
61+
62+ if ($ this ->hasStaticCache ($ cacheKey )) {
63+ return $ this ->getStaticCacheValue ($ cacheKey );
64+ }
65+
66+ if ($ this ->config ->isCacheEnabled ()) {
67+ $ cache = new PayCache ();
68+ return $ cache ->get ($ cacheKey , function () use ($ cacheKey ) {
69+ return $ this ->staticCache ($ cacheKey , function () {
70+ $ this ->config ->setCore ('https://rest.pay.nl ' );
71+ return parent ::start ();
72+ });
73+ }, 3 ); # 3 seconds file caching
74+ }
75+
76+ return $ this ->staticCache ($ cacheKey , function () {
77+ $ this ->config ->setCore ('https://rest.pay.nl ' );
78+ return parent ::start ();
79+ });
5880 }
59- }
81+ }
0 commit comments