Skip to content

Commit

Permalink
feat: PhonePe Exception Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipesh79 committed May 4, 2024
1 parent b05dc32 commit 0afc37e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Exception/InvalidEnvironmentVariableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ public function __construct($message = "Invalid Environment Variable", $code =50
{
parent::__construct($message, $code, $previous);
}

}
12 changes: 12 additions & 0 deletions src/Exception/PhonePeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Dipesh79\LaravelPhonePe\Exception;

class PhonePeException extends \Exception
{

public function __construct($message = "PhonePe Exception", $code = 500, \Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
}
14 changes: 11 additions & 3 deletions src/LaravelPhonePe.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Dipesh79\LaravelPhonePe;

use Dipesh79\LaravelPhonePe\Exception\InvalidEnvironmentVariableException;
use Dipesh79\LaravelPhonePe\Exception\PhonePeException;

class LaravelPhonePe
{
Expand Down Expand Up @@ -49,7 +50,10 @@ public function checkEnvironment(): void
}
}

public function makePayment($amount, $phone, $redirectUrl, $merchantTransactionId)
/**
* @throws PhonePeException
*/
public function makePayment($amount, $phone, $redirectUrl, $merchantTransactionId): string
{
$data = array(
'merchantId' => $this->merchantId,
Expand Down Expand Up @@ -95,10 +99,14 @@ public function makePayment($amount, $phone, $redirectUrl, $merchantTransactionI
curl_close($curl);

$rData = json_decode($response);
return $rData->data->instrumentResponse->redirectInfo->url;
if ($rData->success) {
return $rData->data->instrumentResponse->redirectInfo->url;
} else {
throw new PhonePeException($rData->message);
}
}

public function getTransactionStatus(array $request)
public function getTransactionStatus(array $request): bool
{

$finalXHeader = hash('sha256','/pg/v1/status/' . $request['merchantId'] . '/' . $request['transactionId'] . $this->saltKey) . '###' . $this->saltIndex;
Expand Down

0 comments on commit 0afc37e

Please sign in to comment.