Skip to content

Commit 25e09a0

Browse files
committed
Merge tag 'v1.3.0' into 1.x
2 parents 3f8d203 + cff6800 commit 25e09a0

File tree

4 files changed

+77
-4
lines changed

4 files changed

+77
-4
lines changed

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
"keywords": [
55
"snap-bi",
66
"php-snap-bi",
7+
"sdk-snap-bca",
8+
"sdk-snap-mandiri",
9+
"sdk-snap-dana",
10+
"sdk-snap-bri",
11+
"php-snap-bca",
12+
"php-snap-mandiri",
13+
"php-snap-dana",
14+
"php-snap-bri",
715
"php"
816
],
917
"type": "library",
@@ -26,8 +34,8 @@
2634
"require": {
2735
"php": ">=7.4",
2836
"ext-curl": "*",
29-
"nesbot/carbon": "^2.69",
30-
"ramsey/uuid": "^4.7"
37+
"ramsey/uuid": "^4.7",
38+
"nesbot/carbon": "^2.71"
3139
},
3240
"require-dev": {
3341
"psy/psysh": "^0.11.20",

src/Services/DANA/Traits/HasAccessToken.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Otnansirk\SnapBI\Support\HttpResponse;
99
use Otnansirk\SnapBI\Support\Signature;
1010
use Otnansirk\SnapBI\Support\Http;
11+
use Ramsey\Uuid\Uuid;
1112

1213

1314
trait HasAccessToken
@@ -61,4 +62,38 @@ public static function accessTokenB2b(): HttpResponseInterface
6162
$body = ['grantType' => 'client_credentials'];
6263
return Http::withHeaders($headers)->post($path, $body);
6364
}
65+
66+
/**
67+
* Get oAuth url
68+
*
69+
* @param array $params
70+
* @param array $data
71+
* @param bool $sign
72+
*
73+
* @inheritDoc https://dashboard.dana.id/api-docs/read/125
74+
*/
75+
public static function oAuthUrl(array $params = [], array $data = [], bool $sign = false)
76+
{
77+
$seamlessData = count($data)
78+
? ['seamlessData' => json_encode($data)]
79+
: [];
80+
81+
$seamlessSign = $sign
82+
? ['seamlessSign' => Signature::signSHA256withRSA(DanaConfig::class, $data)]
83+
: [];
84+
85+
$queryParams = [
86+
'timestamp' => currentTimestamp()->toIso8601String(),
87+
'partnerId' => DanaConfig::get('partner_id'),
88+
'externalId' => Uuid::uuid4()->toString(),
89+
'channelId' => DanaConfig::get('channel_id'),
90+
'state' => int_rand(32),
91+
'scopes' => 'QUERY_BALANCE,PUBLIC_ID',
92+
'redirectUrl' => DanaConfig::get('redirect_url'),
93+
...$params,
94+
...$seamlessData,
95+
...$seamlessSign
96+
];
97+
return DanaConfig::get('web_url') . "/v1.0/get-auth-code?" . http_build_query($queryParams);
98+
}
6499
}

src/Support/Signature.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,22 @@ final public static function danaAsymetricTransaction(
123123
// X-SIGNATURE
124124
return base64_encode($signature);
125125
}
126+
127+
/**
128+
* Sign the seamlessData with generated privateKey and algorithm SHA256withRSA
129+
*
130+
* @param string $config
131+
* @param array $body
132+
* @return string
133+
*/
134+
final public static function signSHA256withRSA(string $config, array $body): string
135+
{
136+
137+
$privateKey = $config::get('ssh_private_key');
138+
$signature = "";
139+
if (!openssl_sign(json_encode($body), $signature, $privateKey, OPENSSL_ALGO_SHA256)) {
140+
throw new SignatureException("Failed to generate signature");
141+
}
142+
return base64_encode($signature);
143+
}
126144
}

src/Traits/HasConfig.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,23 @@ static function all(): array
5555
* Get single config
5656
*
5757
* @param string $name
58+
* @param mixed $default
5859
* @return mixed
5960
*/
60-
static function get(string $name): mixed
61+
static function get(string $name, mixed $default = null): mixed
6162
{
62-
return isset(self::$configs[$name]) ? self::$configs[$name] : null;
63+
$keys = explode('.', $name);
64+
$value = self::$configs;
65+
66+
foreach ($keys as $key) {
67+
if (isset($value[$key])) {
68+
$value = $value[$key];
69+
} else {
70+
return ($default) ? $default: null;
71+
}
72+
}
73+
74+
return $value;
6375
}
6476

6577
}

0 commit comments

Comments
 (0)