Skip to content

Commit

Permalink
- [X] Added Inquiry option to the package
Browse files Browse the repository at this point in the history
  • Loading branch information
aemaddin committed Feb 27, 2024
1 parent 9176c55 commit 70916c3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
2 changes: 2 additions & 0 deletions config/knet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
'production_url' => env('KENT_PRODUCTION_URL', 'https://kpay.com.kw/kpg/PaymentHTTP.htm'),
'development_url' => env('KENT_DEVELOPMENT_URL', 'https://kpaytest.com.kw/kpg/PaymentHTTP.htm'),

'production_inquiry_url' => env('KENT_PRODUCTION_INQUIRY_URL', 'https://www.kpay.com.kw/kpg/tranPipe.htm'),
'development_inquiry_url' => env('KENT_DEVELOPMENT_INQUIRY_URL', 'https://www.kpaytest.com.kw/kpg/tranPipe.htm'),
/*
|--------------------------------------------------------------------------
| Knet Credentials
Expand Down
46 changes: 37 additions & 9 deletions src/KPayManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ private function getEnvUrl(): string
return $url.'?param=paymentInit';
}

private static function getEnvInquiryUrl(): string
{
$url = config('knet.development_inquiry_url');

if (App::environment(['production'])) {
if ( ! env('KNET_DEBUG')) {
$url = config('knet.production_inquiry_url');
}
}

return $url.'?param=tranInit';
}

private function setTranData()
{
$this->trandata = $this->encryptedParams();
Expand Down Expand Up @@ -158,16 +171,31 @@ public static function make($amount, array $options = []): static
/**
* @throws KnetException
*/
public static function inquiry($trackid, $options = []): self
public static function inquiry($amt, $trackid): array
{
// throw new Exception('this method not yet supported by api');

$options['trackid'] = $trackid;

$new_instance = (new self)->fillInquiryWithOptions($options);
$new_instance->action = 8;

return $new_instance;
$paymentUrl = self::getEnvInquiryUrl();
$xmlData = "<id>" .config('knet.transport.id') ."</id><password>" .config('knet.transport.password') ."</password><action>8</action><amt>" .$amt ."</amt><transid>" .$trackid ."</transid><udf5>" ."TrackID" ."</udf5><trackid>" .$trackid ."</trackid>";

$ch = curl_init($paymentUrl);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: text/xml"]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlData);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);

$xml = "<div>" . $output . "</div>";
$xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", '$1$2$3', $xml);
$xml = simplexml_load_string($xml);

$json = json_encode($xml);
return json_decode($json, true); // true to have an array, false for an object
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Knet.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Knet
/**
* The Knet library version.
*/
const VERSION = '2.5.1';
const VERSION = '2.6.0';

/**
* The KPay API version.
Expand Down

0 comments on commit 70916c3

Please sign in to comment.