diff --git a/src/Payment.php b/src/Payment.php index 07c7e82..6f84986 100644 --- a/src/Payment.php +++ b/src/Payment.php @@ -14,12 +14,12 @@ InvalidArgumentException, LocaleNotSetException, RequestFailedException}; -use RKocak\Vallet\Traits\URLHelper; +use RKocak\Vallet\Traits\{HashesString, URLHelper}; use SensitiveParameter; class Payment implements Arrayable, PaymentContract { - use URLHelper; + use HashesString, URLHelper; const VALLET_URL = 'https://www.vallet.com.tr/api/v1/create-payment-link'; @@ -231,7 +231,7 @@ protected function generateHash(): string { $str = $this->data['orderId'].$this->data['currency'].$this->data['orderPrice'].$this->data['productsTotalPrice'].$this->data['productType'].$this->callbackOkUrl.$this->callbackFailUrl; - return base64_encode(pack('H*', sha1($this->username.$this->password.$this->shopCode.$str.$this->hash))); + return $this->generateHash($this->username.$this->password.$this->shopCode.$str.$this->hash); } protected function getCallbackOkUrl(): string diff --git a/src/Refund.php b/src/Refund.php index 29b8a5e..81898d1 100644 --- a/src/Refund.php +++ b/src/Refund.php @@ -7,10 +7,13 @@ use Illuminate\Support\Facades\Http; use RKocak\Vallet\Contracts\RefundContract; use RKocak\Vallet\Exceptions\{InvalidArgumentException, RequestFailedException}; +use RKocak\Vallet\Traits\HashesString; use SensitiveParameter; class Refund implements RefundContract { + use HashesString; + const VALLET_REFUND_URL = 'https://www.vallet.com.tr/api/v1/create-refund'; protected float|int $amount = 0; @@ -63,7 +66,7 @@ public function process(): RefundResponse } $hashStr = $this->username.$this->password.$this->shopCode.$this->valletOrderId.$this->orderId.$this->amount.$this->hash; - $hash = base64_encode(pack('H*', sha1($hashStr))); + $hash = $this->generateHash($hashStr); $request = Http::withoutVerifying()->asForm()->post(static::VALLET_REFUND_URL, [ 'userName' => $this->username, diff --git a/src/Traits/HashesString.php b/src/Traits/HashesString.php new file mode 100644 index 0000000..bf456a9 --- /dev/null +++ b/src/Traits/HashesString.php @@ -0,0 +1,13 @@ +