1+ <?php
2+
3+ namespace Otnansirk \SnapBI \Services \BRI \Traits ;
4+
5+ use Otnansirk \SnapBI \Interfaces \HttpResponseInterface ;
6+ use Otnansirk \SnapBI \Services \BRI \BriConfig ;
7+ use Otnansirk \SnapBI \Support \Signature ;
8+ use Otnansirk \SnapBI \Support \Http ;
9+ use Ramsey \Uuid \Uuid ;
10+
11+
12+ trait HasTransaction
13+ {
14+ /**
15+ * Get list of bank statment
16+ *
17+ * @param string $startDate | Format ISO-8601 "2023-08-22T00:00:00+07:00"
18+ * @param string $endDate | Format ISO-8601 "2023-08-22T00:00:00+07:00"
19+ * @return HttpResponseInterface
20+ */
21+ public static function bankStatement (string $ startDate , string $ endDate ): HttpResponseInterface
22+ {
23+ // Required access token
24+ self ::authenticated ();
25+ $ path = "/openapi/transactions/v2.0/bank-statement " ;
26+
27+ $ timestamp = currentTimestamp ()->toIso8601String ();
28+ $ accessToken = self ::$ token ;
29+
30+ $ body = array_merge ([
31+ "partnerReferenceNo " => Uuid::uuid4 (),
32+ "accountNo " => BriConfig::get ('account_id ' ),
33+ "fromDateTime " => $ startDate ,
34+ "toDateTime " => $ endDate ,
35+ "bankCardToken " => BriConfig::get ('bank_card_token ' )
36+ ], self ::$ body );
37+
38+ $ headers = array_merge ([
39+ 'X-TIMESTAMP ' => $ timestamp ,
40+ 'X-SIGNATURE ' => Signature::symmetric (BriConfig::class, 'POST ' , $ path , $ body , $ timestamp , $ accessToken ),
41+ 'CHANNEL-ID ' => BriConfig::get ('channel_id ' ),
42+ 'X-PARTNER-ID ' => BriConfig::get ('partner_id ' ),
43+ 'X-EXTERNAL-ID ' => int_rand (16 ),
44+ ], self ::$ headers );
45+
46+ $ url = BriConfig::get ('base_url ' ) . $ path ;
47+ return Http::withToken ($ accessToken )
48+ ->withHeaders ($ headers )
49+ ->post ($ url , $ body );
50+ }
51+ }
0 commit comments