Skip to content

Commit 7fc9b57

Browse files
Update Payments constructor and encrypt data before sending
1 parent f599468 commit 7fc9b57

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/Helpers/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class Helper
1616
// return self::encrypt3Des($data, $key);
1717
// }
1818

19-
public static function encrypt3Des($data, $key)
19+
public static function encrypt3Des(array $data, $key)
2020
{
21-
$encData = openssl_encrypt($data, 'DES-EDE3', $key, OPENSSL_RAW_DATA);
21+
$encData = openssl_encrypt(json_encode($data), 'DES-EDE3', $key, OPENSSL_RAW_DATA);
2222
return base64_encode($encData);
2323
}
2424

src/Helpers/Payments.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ class Payments
2020
/**
2121
* Construct
2222
*/
23-
function __construct(String $publicKey, String $secretKey, String $baseUrl)
23+
function __construct(String $publicKey, String $secretKey, String $baseUrl, $secretHash = '')
2424
{
2525

2626
$this->publicKey = $publicKey;
2727
$this->secretKey = $secretKey;
2828
$this->baseUrl = $baseUrl;
29+
$this->secretHash = $secretHash;
2930
}
3031

3132

@@ -226,9 +227,12 @@ public function momoFranc(array $data)
226227
*/
227228
public function card(array $data)
228229
{
230+
$encryptedData = [];
231+
$encryptedData['client'] = Helper::encrypt3Des($data, $this->secretHash);
232+
229233
$payment = Http::withToken($this->secretKey)->post(
230234
$this->baseUrl . '/charges?type=card',
231-
$data
235+
$encryptedData
232236
)->json();
233237

234238
if ($payment['status'] === 'success') {

src/Rave.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function verifyWebhook()
135135
*/
136136
public function payments()
137137
{
138-
$payments = new Payments($this->publicKey, $this->secretKey, $this->baseUrl);
138+
$payments = new Payments($this->publicKey, $this->secretKey, $this->baseUrl, $this->secretHash);
139139
return $payments;
140140
}
141141

0 commit comments

Comments
 (0)