Skip to content

Commit 77aa166

Browse files
committed
feat : πŸ›€πŸ½ get oAuth url for DANA
1 parent 7ba3c7d commit 77aa166

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

β€Žcomposer.jsonβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"require": {
3535
"php": ">=7.4",
3636
"ext-curl": "*",
37-
"nesbot/carbon": "^2.69",
38-
"ramsey/uuid": "^4.7"
37+
"ramsey/uuid": "^4.7",
38+
"nesbot/carbon": "^2.71"
3939
},
4040
"require-dev": {
4141
"psy/psysh": "^0.11.20",
@@ -59,4 +59,4 @@
5959
]
6060
}
6161
}
62-
}
62+
}

β€Ž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
@@ -111,4 +111,22 @@ final public static function danaAsymetricTransaction(
111111
// X-SIGNATURE
112112
return base64_encode($signature);
113113
}
114+
115+
/**
116+
* Sign the seamlessData with generated privateKey and algorithm SHA256withRSA
117+
*
118+
* @param string $config
119+
* @param array $body
120+
* @return string
121+
*/
122+
final public static function signSHA256withRSA(string $config, array $body): string
123+
{
124+
125+
$privateKey = $config::get('ssh_private_key');
126+
$signature = "";
127+
if (!openssl_sign(json_encode($body), $signature, $privateKey, OPENSSL_ALGO_SHA256)) {
128+
throw new SignatureException("Failed to generate signature");
129+
}
130+
return base64_encode($signature);
131+
}
114132
}

0 commit comments

Comments
Β (0)