Skip to content

Commit

Permalink
fixed banktest urls
Browse files Browse the repository at this point in the history
  • Loading branch information
samuraee committed Dec 29, 2022
1 parent 727f041 commit 12f7fd2
Show file tree
Hide file tree
Showing 10 changed files with 299 additions and 318 deletions.
152 changes: 73 additions & 79 deletions src/Adapter/Idpay.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace PhpMonsters\Larapay\Adapter;
Expand All @@ -13,15 +14,65 @@
*/
class Idpay extends AdapterAbstract implements AdapterInterface
{
public $endPointVerify = 'https://api.idpay.ir/v1.1/payment/verify';
public $reverseSupport = false;
protected $WSDL = 'https://api.idpay.ir/v1.1/payment';
protected $endPoint = 'https://idpay.ir/p/ws/{order-id}';

protected $endPoint = 'https://idpay.ir/p/ws/{order-id}';
protected $testWSDL = 'https://api.idpay.ir/v1.1/payment';
protected $testEndPoint = 'https://idpay.ir/p/ws-sandbox/{order-id}';

public $endPointVerify = 'https://api.idpay.ir/v1.1/payment/verify';
/**
* @return array
* @throws Exception
* @throws \PhpMonsters\Larapay\Adapter\Exception
*/
public function formParams(): array
{
$authority = $this->requestToken();

public $reverseSupport = false;
return [
'endPoint' => strtr($this->getEndPoint(), ['{authority}' => $authority]),
];
}

/**
* @return bool
*/
public function canContinueWithCallbackParameters(): bool
{
if (!empty($this->transaction['gate_refid'])) {
return true;
}

return false;
}

public function getGatewayReferenceId(): string
{
$this->checkRequiredParameters([
'merchant_id',
]);

return strval($this->transaction['gate_refid']);
}

/**
* @return string
* @throws Exception
* @throws \PhpMonsters\Larapay\Adapter\Exception
*/
protected function generateForm(): string
{
$authority = $this->requestToken();

$form = view('larapay::idpay-form', [
'endPoint' => strtr($this->getEndPoint(), ['{order-id}' => $authority]),
'submitLabel' => !empty($this->submit_label) ? $this->submit_label : trans("larapay::larapay.goto_gate"),
'autoSubmit' => boolval($this->auto_submit),
]);

return $form->__toString();
}

/**
* @return string
Expand All @@ -30,7 +81,7 @@ class Idpay extends AdapterAbstract implements AdapterInterface
*/
protected function requestToken(): string
{
if ($this->getTransaction()->checkForRequestToken() == false) {
if ($this->getTransaction()->checkForRequestToken() === false) {
throw new Exception('larapay::larapay.could_not_request_payment');
}

Expand All @@ -41,25 +92,25 @@ protected function requestToken(): string
]);

$sendParams = [
'order_id' => $this->getTransaction()->bank_order_id,
'amount' => intval($this->amount),
'order_id' => $this->getTransaction()->bank_order_id,
'amount' => intval($this->amount),
'desc' => $this->description ? $this->description : '',
'mail' => $this->email ? $this->email : '',
'phone' => $this->mobile ? $this->mobile : '',
'mail' => $this->email ? $this->email : '',
'phone' => $this->mobile ? $this->mobile : '',
'callback' => $this->redirect_url,
];

$header = [
'Content-Type: application/json',
'X-API-KEY:' .$this->merchant_id,
'X-SANDBOX:' .$this->getSandbox()
'X-API-KEY:'.$this->merchant_id,
'X-SANDBOX:'.$this->getSandbox()
];
try {
XLog::debug('PaymentRequest call', $sendParams);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->WSDL);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sendParams));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
$ch_error = curl_error($ch);
Expand All @@ -73,47 +124,14 @@ protected function requestToken(): string
XLog::info('PaymentRequest response', $this->obj2array($result));
$this->getTransaction()->setGatewayToken(strval($result->id)); // update transaction reference id
return $result->id;
} catch(\Exception $e) {
} catch (\Exception $e) {
throw new Exception($e->getMessage());
};
}


/**
* @return string
* @throws Exception
* @throws \PhpMonsters\Larapay\Adapter\Exception
*/
protected function generateForm(): string
{
$authority = $this->requestToken();

$form = view('larapay::idpay-form', [
'endPoint' => strtr($this->getEndPoint(), ['{order-id}' => $authority]),
'submitLabel' => !empty($this->submit_label) ? $this->submit_label : trans("larapay::larapay.goto_gate"),
'autoSubmit' => boolval($this->auto_submit),
]);

return $form->__toString();
}

/**
* @return array
* @throws Exception
* @throws \PhpMonsters\Larapay\Adapter\Exception
*/
public function formParams(): array
{
$authority = $this->requestToken();

return [
'endPoint' => strtr($this->getEndPoint(), ['{authority}' => $authority]),
];
}

public function getSandbox(): string
{
if (config('larapay.mode') == 'production') {
if (config('larapay.mode') === 'production') {
return "0";
} else {
return "1";
Expand All @@ -127,8 +145,7 @@ public function getSandbox(): string
*/
protected function verifyTransaction(): bool
{

if ($this->getTransaction()->checkForVerify() == false) {
if ($this->getTransaction()->checkForVerify() === false) {
throw new Exception('larapay::larapay.could_not_verify_payment');
}

Expand All @@ -137,21 +154,21 @@ protected function verifyTransaction(): bool
]);

$sendParams = [
'id' => $this->getTransaction()->gate_refid,
'order_id' => $this->getTransaction()->bank_order_id,
'id' => $this->getTransaction()->gate_refid,
'order_id' => $this->getTransaction()->bank_order_id,
];

$header = [
'Content-Type: application/json',
'X-API-KEY:' .$this->merchant_id,
'X-SANDBOX:' .$this->getSandbox()
'X-API-KEY:'.$this->merchant_id,
'X-SANDBOX:'.$this->getSandbox()
];

try {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->endPointVerify);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($sendParams));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
$ch_error = curl_error($ch);
Expand All @@ -161,41 +178,18 @@ protected function verifyTransaction(): bool
XLog::info('PaymentVerification response', $this->obj2array($result));

if (isset($result->status)) {

if ($result->status == 100 || $result->status == 101) {
$this->getTransaction()->setVerified();
$this->getTransaction()->setReferenceId((string)$result->id);
$this->getTransaction()->setReferenceId((string) $result->id);
return true;
} else {
throw new Exception($result->status);
}
} else {
throw new Exception($result->error_code);
}

} catch(\Exception $e) {
} catch (\Exception $e) {
throw new Exception($e->getMessage());
}
}

/**
* @return bool
*/
public function canContinueWithCallbackParameters(): bool
{
if (!empty($this->transaction['gate_refid'])) {
return true;
}

return false;
}

public function getGatewayReferenceId(): string
{
$this->checkRequiredParameters([
'merchant_id',
]);

return strval($this->transaction['gate_refid']);
}
}
14 changes: 7 additions & 7 deletions src/Adapter/Mellat.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class Mellat extends AdapterAbstract implements AdapterInterface
protected $WSDL = 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl';
protected $endPoint = 'https://bpm.shaparak.ir/pgwchannel/startpay.mellat';

protected $testWSDL = 'https://banktest.ir/gateway/mellat/ws?wsdl';
protected $testEndPoint = 'https://banktest.ir/gateway/mellat/gate';
protected $testWSDL = 'https://sandbox.banktest.ir/mellat/bpm.shaparak.ir/pgwchannel/services/pgw?wsdl';
protected $testEndPoint = 'https://sandbox.banktest.ir/mellat/bpm.shaparak.ir/pgwchannel/startpay.mellat';

protected $reverseSupport = true;

Expand All @@ -28,7 +28,7 @@ class Mellat extends AdapterAbstract implements AdapterInterface
*/
protected function requestToken()
{
if ($this->getTransaction()->checkForRequestToken() == false) {
if ($this->getTransaction()->checkForRequestToken() === false) {
throw new Exception('larapay::larapay.could_not_request_payment');
}

Expand Down Expand Up @@ -120,7 +120,7 @@ public function formParams(): array
*/
protected function verifyTransaction()
{
if ($this->getTransaction()->checkForVerify() == false) {
if ($this->getTransaction()->checkForVerify() === false) {
throw new Exception('larapay::larapay.could_not_verify_payment');
}

Expand Down Expand Up @@ -182,7 +182,7 @@ protected function verifyTransaction()
*/
public function inquiryTransaction()
{
if ($this->getTransaction()->checkForInquiry() == false) {
if ($this->getTransaction()->checkForInquiry() === false) {
throw new Exception('larapay::larapay.could_not_inquiry_payment');
}

Expand Down Expand Up @@ -244,7 +244,7 @@ public function inquiryTransaction()
*/
protected function settleTransaction()
{
if ($this->getTransaction()->checkForAfterVerify() == false) {
if ($this->getTransaction()->checkForAfterVerify() === false) {
throw new Exception('larapay::larapay.could_not_settle_payment');
}

Expand Down Expand Up @@ -302,7 +302,7 @@ protected function settleTransaction()
*/
protected function reverseTransaction(): bool
{
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
if ($this->reverseSupport === false || $this->getTransaction()->checkForReverse() === false) {
throw new Exception('larapay::larapay.could_not_reverse_payment');
}

Expand Down
Loading

0 comments on commit 12f7fd2

Please sign in to comment.