Skip to content

Commit

Permalink
removed extra transaction check in LaraPay initalization
Browse files Browse the repository at this point in the history
  • Loading branch information
samuraee committed Jun 6, 2019
1 parent 63d9b11 commit 382fe91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 30 deletions.
4 changes: 0 additions & 4 deletions src/Adapter/AdapterAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public function __construct(TransactionInterface $transaction, array $configs =
{
$this->transaction = $transaction;

if ($this->transaction->checkForRequestToken() == false) {
throw new Exception('Due to checkForRequestToken() result, could not handle this transaction`s payment process');
}

$this->setParameters($configs);
$this->init();
}
Expand Down
59 changes: 33 additions & 26 deletions src/Adapter/Mellat.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Tartan\Larapay\Adapter;

use SoapFault;
Expand All @@ -11,10 +12,10 @@
*/
class Mellat extends AdapterAbstract implements AdapterInterface
{
protected $WSDL = 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl';
protected $WSDL = 'https://bpm.shaparak.ir/pgwchannel/services/pgw?wsdl';
protected $endPoint = 'https://bpm.shaparak.ir/pgwchannel/startpay.mellat';

protected $testWSDL = 'http://banktest.ir/gateway/mellat/ws?wsdl';
protected $testWSDL = 'http://banktest.ir/gateway/mellat/ws?wsdl';
protected $testEndPoint = 'http://banktest.ir/gateway/mellat/gate';

protected $reverseSupport = true;
Expand All @@ -26,7 +27,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 @@ -66,9 +67,9 @@ protected function requestToken()

if ($response[0] == 0) {
$this->getTransaction()->setGatewayToken($response[1]); // update transaction reference id

return $response[1];
}
else {
} else {
throw new Exception($response[0]);
}
} else {
Expand All @@ -83,15 +84,15 @@ protected function requestToken()
* @return mixed
* @throws Exception
*/
protected function generateForm ()
protected function generateForm()
{
$refId = $this->requestToken();

return view('larapay::mellat-form', [
'endPoint' => $this->getEndPoint(),
'refId' => $refId,
'submitLabel' => !empty($this->submit_label) ? $this->submit_label : trans("larapay::larapay.goto_gate"),
'autoSubmit' => boolval($this->auto_submit)
'autoSubmit' => boolval($this->auto_submit),
]);
}

Expand All @@ -100,9 +101,9 @@ protected function generateForm ()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function verifyTransaction ()
protected function verifyTransaction()
{
if($this->getTransaction()->checkForVerify() == false) {
if ($this->getTransaction()->checkForVerify() == false) {
throw new Exception('larapay::larapay.could_not_verify_payment');
}

Expand All @@ -114,7 +115,7 @@ protected function verifyTransaction ()
'ResCode',
'SaleOrderId',
'SaleReferenceId',
'CardHolderInfo'
'CardHolderInfo',
]);

$sendParams = [
Expand All @@ -123,7 +124,7 @@ protected function verifyTransaction ()
'userPassword' => $this->password,
'orderId' => intval($this->SaleOrderId), // same as SaleOrderId
'saleOrderId' => intval($this->SaleOrderId),
'saleReferenceId' => intval($this->SaleReferenceId)
'saleReferenceId' => intval($this->SaleReferenceId),
];

$this->getTransaction()->setCardNumber($this->CardHolderInfo);
Expand All @@ -134,15 +135,16 @@ protected function verifyTransaction ()
Log::debug('bpVerifyRequest call', $sendParams);

//$response = $soapClient->__soapCall('bpVerifyRequest', $sendParams);
$response = $soapClient->bpVerifyRequest($sendParams);
$response = $soapClient->bpVerifyRequest($sendParams);

if (isset($response->return)) {
Log::info('bpVerifyRequest response', ['return' => $response->return]);

if($response->return != '0') {
if ($response->return != '0') {
throw new Exception($response->return);
} else {
$this->getTransaction()->setVerified();

return true;
}
} else {
Expand All @@ -160,9 +162,9 @@ protected function verifyTransaction ()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
public function inquiryTransaction ()
public function inquiryTransaction()
{
if($this->getTransaction()->checkForInquiry() == false) {
if ($this->getTransaction()->checkForInquiry() == false) {
throw new Exception('larapay::larapay.could_not_inquiry_payment');
}

Expand All @@ -174,7 +176,7 @@ public function inquiryTransaction ()
'ResCode',
'SaleOrderId',
'SaleReferenceId',
'CardHolderInfo'
'CardHolderInfo',
]);

$sendParams = [
Expand All @@ -183,7 +185,7 @@ public function inquiryTransaction ()
'userPassword' => $this->password,
'orderId' => intval($this->SaleOrderId), // same as SaleOrderId
'saleOrderId' => intval($this->SaleOrderId),
'saleReferenceId' => intval($this->SaleReferenceId)
'saleReferenceId' => intval($this->SaleReferenceId),
];

$this->getTransaction()->setCardNumber($this->CardHolderInfo);
Expand All @@ -193,14 +195,15 @@ public function inquiryTransaction ()

Log::debug('bpInquiryRequest call', $sendParams);
//$response = $soapClient->__soapCall('bpInquiryRequest', $sendParams);
$response = $soapClient->bpInquiryRequest($sendParams);
$response = $soapClient->bpInquiryRequest($sendParams);

if (isset($response->return)) {
Log::info('bpInquiryRequest response', ['return' => $response->return]);
if($response->return != '0') {
if ($response->return != '0') {
throw new Exception($response->return);
} else {
$this->getTransaction()->setVerified();

return true;
}
} else {
Expand Down Expand Up @@ -235,7 +238,7 @@ protected function settleTransaction()
'ResCode',
'SaleOrderId',
'SaleReferenceId',
'CardHolderInfo'
'CardHolderInfo',
]);

$sendParams = [
Expand All @@ -244,7 +247,7 @@ protected function settleTransaction()
'userPassword' => $this->password,
'orderId' => intval($this->SaleOrderId), // same as orderId
'saleOrderId' => intval($this->SaleOrderId),
'saleReferenceId' => intval($this->SaleReferenceId)
'saleReferenceId' => intval($this->SaleReferenceId),
];

try {
Expand All @@ -257,8 +260,9 @@ protected function settleTransaction()
if (isset($response->return)) {
Log::info('bpSettleRequest response', ['return' => $response->return]);

if($response->return == '0' || $response->return == '45') {
if ($response->return == '0' || $response->return == '45') {
$this->getTransaction()->setAfterVerified();

return true;
} else {
throw new Exception($response->return);
Expand All @@ -278,7 +282,7 @@ protected function settleTransaction()
* @throws Exception
* @throws \Tartan\Larapay\Adapter\Exception
*/
protected function reverseTransaction ()
protected function reverseTransaction()
{
if ($this->reverseSupport == false || $this->getTransaction()->checkForReverse() == false) {
throw new Exception('larapay::larapay.could_not_reverse_payment');
Expand All @@ -292,7 +296,7 @@ protected function reverseTransaction ()
'ResCode',
'SaleOrderId',
'SaleReferenceId',
'CardHolderInfo'
'CardHolderInfo',
]);

$sendParams = [
Expand All @@ -301,7 +305,7 @@ protected function reverseTransaction ()
'userPassword' => $this->password,
'orderId' => intval($this->SaleOrderId), // same as orderId
'saleOrderId' => intval($this->SaleOrderId),
'saleReferenceId' => intval($this->SaleReferenceId)
'saleReferenceId' => intval($this->SaleReferenceId),
];

try {
Expand All @@ -313,9 +317,10 @@ protected function reverseTransaction ()

Log::info('bpReversalRequest response', ['return' => $response->return]);

if (isset($response->return)){
if (isset($response->return)) {
if ($response->return == '0' || $response->return == '45') {
$this->getTransaction()->setRefunded();

return true;
} else {
throw new Exception($response->return);
Expand All @@ -338,6 +343,7 @@ public function canContinueWithCallbackParameters(): bool
if ($this->ResCode === "0" || $this->ResCode === 0) {
return true;
}

return false;
}

Expand All @@ -346,6 +352,7 @@ public function getGatewayReferenceId(): string
$this->checkRequiredParameters([
'RefId',
]);

return $this->RefId;
}

Expand Down

0 comments on commit 382fe91

Please sign in to comment.