Skip to content

Commit

Permalink
Fix currency issue
Browse files Browse the repository at this point in the history
- MOLPay returns currency as 'RM' instead of 'MYR' causing the skey generation failed.
- Remove callback notification as it should not be part of Omnipay, user should handle it themselves.
  • Loading branch information
Lee Siong Chan committed Apr 15, 2016
1 parent b626d82 commit cc5e044
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 64 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ $options = [
'amount' => '10.00',
'card' => new CreditCard(array(
'country' => 'MY',
'email' => 'ahlee2326@me.com',
'email' => 'abc@example.com',
'name' => 'Lee Siong Chan',
'phone' => '0123456789',
)),
Expand All @@ -86,16 +86,9 @@ if ($response->isSuccessful()) {
echo $response->getTransactionReference();
} elseif ($response->isPending()) {
// Do something
} elseif ($response->isCancelled()) {
// Do something
} else {
// Error
}

// Check if is a callback notification
if ($response->isCallbackNotification()) {
// Do something
}
```

## Out Of Scope
Expand Down
3 changes: 1 addition & 2 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ public function completePurchase(array $parameters = array())
array(
'appCode' => $this->httpRequest->request->get('appcode'),
'domain' => $this->httpRequest->request->get('domain'),
'errorMessage' => $this->httpRequest->request->get('error_desc'),
'nbcb' => $this->httpRequest->request->get('nbcb'),
'errorMessage' => strlen($this->httpRequest->request->get('error_desc')) > 0 ? $this->httpRequest->request->get('error_desc') : null,
'payDate' => $this->httpRequest->request->get('paydate'),
'sKey' => $this->httpRequest->request->get('skey'),
'status' => $this->httpRequest->request->get('status'),
Expand Down
2 changes: 1 addition & 1 deletion src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function validatePaymentMethod()
{
$this->validate('paymentMethod');

$paymentMethod = $this->getPaymentMethod();
$paymentMethod = strtolower($this->getPaymentMethod());

if (
PaymentMethod::AFFIN_BANK !== $paymentMethod &&
Expand Down
39 changes: 12 additions & 27 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* * domain [required] - Merchant ID in MOLPay system
* * errorMessage - Error message
* * payDate [required] - Date/Time of the transaction
* * nbcb - Notification from MOLPay
* - 1 for callback notification
* - 2 for notification
* * sKey [required] - Data integrity protection hash string.
* * status [required] - Payment status
* - 00 for successful payment
Expand Down Expand Up @@ -116,28 +113,6 @@ public function setPayDate($value)
return $this->setParameter('payDate', $value);
}

/**
* Get nbcb.
*
* @return string
*/
public function getNBCB()
{
return $this->getParameter('nbcb');
}

/**
* Set nbcb.
*
* @param string $value
*
* @return $this
*/
public function setNBCB($value)
{
return $this->setParameter('nbcb', $value);
}

/**
* Get sKey.
*
Expand Down Expand Up @@ -224,7 +199,6 @@ public function getData()
}

return array(
'nbcb' => $this->getNBCB(),
'status' => $this->getStatus(),
'transactionId' => $this->getTransactionId(),
'transactionReference' => $this->getTransactionReference(),
Expand Down Expand Up @@ -253,7 +227,7 @@ protected function generatePreSKey()
{
$this->validate('amount', 'currency', 'domain', 'status', 'transactionId', 'transactionReference');

return md5($this->getTransactionReference().$this->getTransactionId().$this->getStatus().$this->getDomain().$this->getAmount().$this->getCurrency());
return md5($this->getTransactionReference().$this->getTransactionId().$this->getStatus().$this->getDomain().$this->getAmount().$this->convertCurrency());
}

/**
Expand All @@ -267,4 +241,15 @@ protected function generateSKey()

return md5($this->getPayDate().$this->getDomain().$this->generatePreSKey().$this->getAppCode().$this->getVerifyKey());
}

/**
* Convert currency to 'MOLPay''s style currency.
* @NOTE Funny enough, MOLPay returns currency as 'RM' not 'MYR'. And I am not sure about other currencies though.
*
* @return string
*/
private function convertCurrency()
{
return $this->getCurrency() !== 'MYR' ? $this->getCurrency() : 'RM';
}
}
10 changes: 0 additions & 10 deletions src/Message/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ public function getTransactionReference()
return $this->getRequest()->getTransactionReference();
}

/**
* Check if the request is a callback notification.
*
* @return bool
*/
public function isCallbackNotification()
{
return '1' === $this->getRequest()->getNBCB();
}

/**
* {@inheritdoc}
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function setUp()
'amount' => '10.00',
'card' => new CreditCard(array(
'country' => 'MY',
'email' => 'ahlee2326@me.com',
'email' => 'abc@example.com',
'name' => 'Lee Siong Chan',
'phone' => '0123456789',
)),
Expand All @@ -45,7 +45,7 @@ public function testPurchase()
$this->assertTrue($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertEquals(
'https://www.onlinepayment.com.my/MOLPay/pay/test1234/?amount=10.00&bill_desc=Test+Payment&bill_email=ahlee2326%40me.com&bill_mobile=0123456789&bill_name=Lee+Siong+Chan&channel=credit&country=MY&currency=MYR&langcode=en&orderid=20160331082207680000&vcode=f3d5496b444ae3d11e09fa92a753ac60',
'https://www.onlinepayment.com.my/MOLPay/pay/test1234/?amount=10.00&bill_desc=Test+Payment&bill_email=abc%40example.com&bill_mobile=0123456789&bill_name=Lee+Siong+Chan&channel=credit&country=MY&currency=MYR&langcode=en&orderid=20160331082207680000&vcode=f3d5496b444ae3d11e09fa92a753ac60',
$response->getRedirectUrl()
);
}
Expand All @@ -56,7 +56,7 @@ public function testCompletePurchaseSuccess()
'appcode' => 'abcdefg',
'domain' => 'test4321',
'paydate' => '2016-03-29 04:02:21',
'skey' => '0c1e98d6d58f9a30b919bcaeb9790852',
'skey' => '9b8be764cc5bad1b4a5d58a3ba4daf58',
'status' => '00',
'tranID' => '000001',
));
Expand Down
6 changes: 3 additions & 3 deletions tests/Message/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUp()
'currency' => 'MYR',
'domain' => 'test4321',
'payDate' => '2016-03-29 04:02:21',
'sKey' => '0c1e98d6d58f9a30b919bcaeb9790852',
'sKey' => '9b8be764cc5bad1b4a5d58a3ba4daf58',
'status' => '00',
'transactionId' => '20160331082207680000',
'transactionReference' => '000001',
Expand All @@ -35,7 +35,7 @@ public function testGetData()
public function testSendSuccess()
{
$this->request->setStatus('00');
$this->request->setSKey('0c1e98d6d58f9a30b919bcaeb9790852');
$this->request->setSKey('9b8be764cc5bad1b4a5d58a3ba4daf58');

$response = $this->request->send();

Expand All @@ -49,7 +49,7 @@ public function testSendSuccess()
public function testSendPending()
{
$this->request->setStatus('22');
$this->request->setSKey('8192eb5627012f236fc36e73f5d49a5e');
$this->request->setSKey('9d65ed0b785fea1c8fc80b8316555ee3');

$response = $this->request->send();

Expand Down
7 changes: 0 additions & 7 deletions tests/Message/CompletePurchaseResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,4 @@ public function testCompletePurchasePending()

$this->assertTrue($this->response->isPending());
}

public function testCompletePurchaseCallbackNotification()
{
$this->getMockRequest()->shouldReceive('getNBCB')->andReturn('1');

$this->assertTrue($this->response->isCallbackNotification());
}
}
6 changes: 3 additions & 3 deletions tests/Message/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function setUp()
'amount' => '10.00',
'card' => new CreditCard(array(
'country' => 'MY',
'email' => 'ahlee2326@me.com',
'email' => 'abc@example.com',
'name' => 'Lee Siong Chan',
'phone' => '0123456789',
)),
Expand All @@ -35,7 +35,7 @@ public function testGetData()

$this->assertEquals('10.00', $data['amount']);
$this->assertEquals('MY', $data['country']);
$this->assertEquals('ahlee2326@me.com', $data['bill_email']);
$this->assertEquals('abc@example.com', $data['bill_email']);
$this->assertEquals('Lee Siong Chan', $data['bill_name']);
$this->assertEquals('0123456789', $data['bill_mobile']);
$this->assertEquals('MYR', $data['currency']);
Expand All @@ -54,7 +54,7 @@ public function testSendSuccess()
$this->assertTrue($response->isRedirect());
$this->assertNull($response->getTransactionReference());
$this->assertEquals(
'https://www.onlinepayment.com.my/MOLPay/pay/test1234/?amount=10.00&bill_desc=Test+Payment&bill_email=ahlee2326%40me.com&bill_mobile=0123456789&bill_name=Lee+Siong+Chan&channel=credit&country=MY&currency=MYR&langcode=en&orderid=20160331082207680000&vcode=f3d5496b444ae3d11e09fa92a753ac60',
'https://www.onlinepayment.com.my/MOLPay/pay/test1234/?amount=10.00&bill_desc=Test+Payment&bill_email=abc%40example.com&bill_mobile=0123456789&bill_name=Lee+Siong+Chan&channel=credit&country=MY&currency=MYR&langcode=en&orderid=20160331082207680000&vcode=f3d5496b444ae3d11e09fa92a753ac60',
$response->getRedirectUrl()
);
}
Expand Down

0 comments on commit cc5e044

Please sign in to comment.