Skip to content

Commit 5b6f7ae

Browse files
authored
Merge pull request #18 from sudiptpa/fix/payment-verify-bug
Added a Fix for Transaction Verify Bug
2 parents fee0f71 + 9f36f99 commit 5b6f7ae

File tree

7 files changed

+40
-13
lines changed

7 files changed

+40
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ composer require league/omnipay sudiptpa/omnipay-esewa
2929

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

32-
$gateway->setMerchantCode('test_merchant');
32+
$gateway->setMerchantCode('epay_payment');
3333
$gateway->setTestMode(true);
3434

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

60-
$gateway->setMerchantCode('test_merchant');
60+
$gateway->setMerchantCode('epay_payment');
6161
$gateway->setTestMode(true);
6262

6363
$response = $gateway->verifyPayment([

demo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

9-
$gateway->setMerchantCode('test_merchant');
9+
$gateway->setMerchantCode('epay_payment');
1010
$gateway->setTestMode(true);
1111

1212
$response = $gateway->purchase([

src/Message/VerifyPaymentRequest.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ class VerifyPaymentRequest extends AbstractRequest
1414
*/
1515
protected $verifyEndPoint = 'epay/transrec';
1616

17+
/**
18+
* @var string
19+
*/
20+
protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36';
21+
1722
/**
1823
* @return string
1924
*/
@@ -27,20 +32,40 @@ public function getData()
2732
];
2833
}
2934

35+
/**
36+
* @return string
37+
*/
38+
public function getUserAgent()
39+
{
40+
$userAgent = $this->userAgent;
41+
42+
if (isset($_SERVER['HTTP_USER_AGENT'])) {
43+
$userAgent = $_SERVER['HTTP_USER_AGENT'];
44+
}
45+
46+
return $userAgent;
47+
}
48+
3049
/**
3150
* @param $data
3251
*
33-
* @return \Omnipay\Esewa\Message\OrderResponse
52+
* @return \Omnipay\Esewa\Message\VerifyPaymentResponse
3453
*/
3554
public function sendData($data)
3655
{
37-
$endPoint = $this->getEndpoint().'?'.http_build_query($data);
56+
$endPoint = $this->getEndpoint();
57+
58+
$headers = [
59+
'User-Agent' => $this->getUserAgent(),
60+
'Accept' => 'application/xml',
61+
'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
62+
];
3863

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

41-
$data = new SimpleXMLElement($httpResponse->getBody()->getContents());
66+
$content = new SimpleXMLElement($httpResponse->getBody()->getContents());
4267

43-
return $this->response = new VerifyPaymentResponse($this, $data);
68+
return $this->response = new VerifyPaymentResponse($this, $content);
4469
}
4570

4671
/**

src/Message/VerifyPaymentResponse.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ public function __construct(RequestInterface $request, $data)
2525
*/
2626
public function getResponseText()
2727
{
28-
return (string) $this->data->response_code;
28+
return (string) trim($this->data->response_code);
2929
}
3030

3131
/**
3232
* @return bool
3333
*/
3434
public function isSuccessful()
3535
{
36-
return in_array($this->getResponseText(), ['Success']);
36+
$string = strtolower($this->getResponseText());
37+
38+
return in_array($string, ['success']);
3739
}
3840
}

tests/Message/PurchaseRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setUp()
1414
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
1515

1616
$this->request->initialize([
17-
'merchantCode' => 'test_merchant',
17+
'merchantCode' => 'epay_payment',
1818
'amount' => 100,
1919
'deliveryCharge' => 0,
2020
'serviceCharge' => 0,

tests/Message/VerifyPaymentRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setUp()
1414
$this->request = new VerifyPaymentRequest($this->getHttpClient(), $this->getHttpRequest());
1515

1616
$this->request->initialize([
17-
'merchantCode' => 'test_merchant',
17+
'merchantCode' => 'epay_payment',
1818
'testMode' => true,
1919
'amount' => 100,
2020
'referenceNumber' => 'GDFG89',

tests/SecureGatewayTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function setUp()
1414
parent::setUp();
1515

1616
$this->gateway = new SecureGateway($this->getHttpClient(), $this->getHttpRequest());
17-
$this->gateway->setMerchantCode('test_merchant');
17+
$this->gateway->setMerchantCode('epay_payment');
1818
}
1919

2020
public function testPurchase()

0 commit comments

Comments
 (0)