Skip to content

Commit

Permalink
Merge pull request #18 from sudiptpa/fix/payment-verify-bug
Browse files Browse the repository at this point in the history
Added a Fix for Transaction Verify Bug
  • Loading branch information
sudiptpa authored Jul 14, 2020
2 parents fee0f71 + 9f36f99 commit 5b6f7ae
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ composer require league/omnipay sudiptpa/omnipay-esewa

$gateway = Omnipay::create('Esewa_Secure');

$gateway->setMerchantCode('test_merchant');
$gateway->setMerchantCode('epay_payment');
$gateway->setTestMode(true);

try {
Expand Down Expand Up @@ -57,7 +57,7 @@ composer require league/omnipay sudiptpa/omnipay-esewa
```php
$gateway = Omnipay::create('Esewa_Secure');

$gateway->setMerchantCode('test_merchant');
$gateway->setMerchantCode('epay_payment');
$gateway->setTestMode(true);

$response = $gateway->verifyPayment([
Expand Down
2 changes: 1 addition & 1 deletion demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

$gateway = Omnipay::create('Esewa_Secure');

$gateway->setMerchantCode('test_merchant');
$gateway->setMerchantCode('epay_payment');
$gateway->setTestMode(true);

$response = $gateway->purchase([
Expand Down
35 changes: 30 additions & 5 deletions src/Message/VerifyPaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class VerifyPaymentRequest extends AbstractRequest
*/
protected $verifyEndPoint = 'epay/transrec';

/**
* @var string
*/
protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';

/**
* @return string
*/
Expand All @@ -27,20 +32,40 @@ public function getData()
];
}

/**
* @return string
*/
public function getUserAgent()
{
$userAgent = $this->userAgent;

if (isset($_SERVER['HTTP_USER_AGENT'])) {
$userAgent = $_SERVER['HTTP_USER_AGENT'];
}

return $userAgent;
}

/**
* @param $data
*
* @return \Omnipay\Esewa\Message\OrderResponse
* @return \Omnipay\Esewa\Message\VerifyPaymentResponse
*/
public function sendData($data)
{
$endPoint = $this->getEndpoint().'?'.http_build_query($data);
$endPoint = $this->getEndpoint();

$headers = [
'User-Agent' => $this->getUserAgent(),
'Accept' => 'application/xml',
'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
];

$httpResponse = $this->httpClient->request('GET', $endPoint);
$httpResponse = $this->httpClient->request('POST', $endPoint, $headers, http_build_query($data));

$data = new SimpleXMLElement($httpResponse->getBody()->getContents());
$content = new SimpleXMLElement($httpResponse->getBody()->getContents());

return $this->response = new VerifyPaymentResponse($this, $data);
return $this->response = new VerifyPaymentResponse($this, $content);
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Message/VerifyPaymentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ public function __construct(RequestInterface $request, $data)
*/
public function getResponseText()
{
return (string) $this->data->response_code;
return (string) trim($this->data->response_code);
}

/**
* @return bool
*/
public function isSuccessful()
{
return in_array($this->getResponseText(), ['Success']);
$string = strtolower($this->getResponseText());

return in_array($string, ['success']);
}
}
2 changes: 1 addition & 1 deletion tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function setUp()
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());

$this->request->initialize([
'merchantCode' => 'test_merchant',
'merchantCode' => 'epay_payment',
'amount' => 100,
'deliveryCharge' => 0,
'serviceCharge' => 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/Message/VerifyPaymentRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function setUp()
$this->request = new VerifyPaymentRequest($this->getHttpClient(), $this->getHttpRequest());

$this->request->initialize([
'merchantCode' => 'test_merchant',
'merchantCode' => 'epay_payment',
'testMode' => true,
'amount' => 100,
'referenceNumber' => 'GDFG89',
Expand Down
2 changes: 1 addition & 1 deletion tests/SecureGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function setUp()
parent::setUp();

$this->gateway = new SecureGateway($this->getHttpClient(), $this->getHttpRequest());
$this->gateway->setMerchantCode('test_merchant');
$this->gateway->setMerchantCode('epay_payment');
}

public function testPurchase()
Expand Down

0 comments on commit 5b6f7ae

Please sign in to comment.