Skip to content

Commit

Permalink
Add: HashesString Trait
Browse files Browse the repository at this point in the history
  • Loading branch information
remzikocak committed Oct 27, 2023
1 parent fe552b3 commit e4cac0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/Traits/HashesString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace RKocak\Vallet\Traits;

trait HashesString
{
public function generateHash(string $str): string
{
return base64_encode(pack('H*', sha1($str)));
}
}

0 comments on commit e4cac0d

Please sign in to comment.