Skip to content

Commit

Permalink
Merge pull request #1 from siewmai/master
Browse files Browse the repository at this point in the history
Fix according api spec version 13.7 (10th Oct 2017)
  • Loading branch information
leesiongchan authored Jan 21, 2018
2 parents b3ac042 + 82199a6 commit 9332169
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 28 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
processing library for PHP 5.3+. This package implements MOLPay support for Omnipay.

[MOLPay](http://www.molpay.com) is a payment gateway offering from MOLPay Sdn Bhd. This package follows the **MOLPay API Specification (Version 12.1: Updated on 12 April 2015)**.
[MOLPay](http://www.molpay.com) is a payment gateway offering from MOLPay Sdn Bhd. This package follows the **MOLPay API Specification (Version 13.7: Updated on 10 Oct 2017)**.

## Installation

Expand Down Expand Up @@ -71,7 +71,7 @@ $options = [
$response = $gateway->purchase($options)->send();

// Get the MOLPay payment URL (https://www.onlinepayment.com.my/MOLPay/pay/...)
$redirectUrl = $response->getRedirectUrl();
$redirectUrl = $response->getRedirectUrl();
```

### Complete a purchase request
Expand All @@ -93,7 +93,7 @@ if ($response->isSuccessful()) {

## Out Of Scope

Omnipay does not cover recurring payments or billing agreements, and so those features are not included in this package. Extensions to this gateway are always welcome.
Omnipay does not cover recurring payments or billing agreements, and so those features are not included in this package. Extensions to this gateway are always welcome.

## Support

Expand Down
49 changes: 46 additions & 3 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getLocale()
* The default language is English.
*
* @param string $value
*
*
* @return $this
*/
public function setLocale($value)
Expand All @@ -92,7 +92,7 @@ public function getMerchantId()
* Set merchantId.
*
* @param string $value
*
*
* @return $this
*/
public function setMerchantId($value)
Expand All @@ -114,14 +114,57 @@ public function getVerifyKey()
* Set verifyKey.
*
* @param string $value
*
*
* @return $this
*/
public function setVerifyKey($value)
{
return $this->setParameter('verifyKey', $value);
}

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

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

/**
* Gets the test mode of the request from the gateway.
*
* @return boolean
*/
public function getTestMode()
{
return $this->getParameter('testMode');
}

/**
* Sets the test mode of the request.
*
* @param boolean $value True for test mode on.
* @return AbstractRequest
*/
public function setTestMode($value)
{
return $this->setParameter('testMode', $value);
}

/**
* Create a purchase request.
*
Expand Down
62 changes: 56 additions & 6 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

abstract class AbstractRequest extends BaseAbstractRequest
{
const API_VERSION = '12.1';
const API_VERSION = '13.7';

/**
* Endpoint URL.
Expand All @@ -19,6 +19,13 @@ abstract class AbstractRequest extends BaseAbstractRequest
*/
protected $endpoint = 'https://www.onlinepayment.com.my/MOLPay/pay/';

/**
* Sandbox Endpoint URL.
*
* @var string
*/
protected $sandboxEndpoint = 'https://sandbox.molpay.com/MOLPay/pay/';

/**
* MOLPay IPN (Instant Payment Notification) endpoint URL.
*
Expand All @@ -28,7 +35,7 @@ abstract class AbstractRequest extends BaseAbstractRequest

/**
* Get enableIPN.
*
*
* @return bool
*/
public function getEnableIPN()
Expand Down Expand Up @@ -62,7 +69,7 @@ public function getLocale()
* Set locale.
*
* @param string $value
*
*
* @return $this
*/
public function setLocale($value)
Expand All @@ -84,7 +91,7 @@ public function getMerchantId()
* Set merchantId.
*
* @param string $value
*
*
* @return $this
*/
public function setMerchantId($value)
Expand All @@ -106,14 +113,57 @@ public function getVerifyKey()
* Set verifyKey.
*
* @param string $value
*
*
* @return $this
*/
public function setVerifyKey($value)
{
return $this->setParameter('verifyKey', $value);
}

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

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

/**
* Gets the test mode of the request from the gateway.
*
* @return boolean
*/
public function getTestMode()
{
return $this->getParameter('testMode');
}

/**
* Sets the test mode of the request.
*
* @param boolean $value True for test mode on.
* @return AbstractRequest
*/
public function setTestMode($value)
{
return $this->setParameter('testMode', $value);
}

/**
* Get endpoint.
*
Expand All @@ -123,7 +173,7 @@ public function getEndpoint()
{
$this->validate('merchantId');

return $this->endpoint.$this->getMerchantId().'/';
return ($this->getTestMode() ? $this->sandboxEndpoint : $this->endpoint).$this->getMerchantId().'/';
}

/**
Expand Down
24 changes: 12 additions & 12 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* - 22 for pending payment
* * transactionId [required] - Invoice or order number from merchant system
* * transactionReference [required] - Transaction ID generated by MOLPay
* * verifyKey [required] - Encrypted key generated by MOLPay
* * secretKey [required] - Encrypted key generated by MOLPay
*/
class CompletePurchaseRequest extends AbstractRequest
{
Expand All @@ -39,7 +39,7 @@ public function getAppCode()
* Set appCode.
*
* @param string $value
*
*
* @return $this
*/
public function setAppCode($value)
Expand All @@ -61,7 +61,7 @@ public function getDomain()
* Set domain.
*
* @param string $value
*
*
* @return $this
*/
public function setDomain($value)
Expand All @@ -83,7 +83,7 @@ public function getErrorMessage()
* Set errorMessage.
*
* @param string $value
*
*
* @return $this
*/
public function setErrorMessage($value)
Expand All @@ -105,7 +105,7 @@ public function getPayDate()
* Set payDate.
*
* @param string $value
*
*
* @return $this
*/
public function setPayDate($value)
Expand All @@ -127,7 +127,7 @@ public function getSKey()
* Set sKey.
*
* @param string $value
*
*
* @return $this
*/
public function setSKey($value)
Expand All @@ -149,7 +149,7 @@ public function getStatus()
* Set status.
*
* @param string $value
*
*
* @return $this
*/
public function setStatus($value)
Expand All @@ -171,7 +171,7 @@ public function getTransactionReference()
* Set transactionReference.
*
* @param string $value
*
*
* @return $this
*/
public function setTransactionReference($value)
Expand Down Expand Up @@ -227,7 +227,7 @@ public function sendData($data)
* Generate pre-sKey - first hash encryption.
*
* @param bool $fallbackMode
*
*
* @return string
*/
protected function generatePreSKey($fallbackMode = false)
Expand All @@ -247,14 +247,14 @@ protected function generatePreSKey($fallbackMode = false)
* Generate sKey - final hash encryption.
*
* @param bool $fallbackMode
*
*
* @return string
*/
protected function generateSKey($fallbackMode = false)
{
$this->validate('appCode', 'domain', 'payDate', 'verifyKey');
$this->validate('appCode', 'domain', 'payDate', 'secretKey');

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

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function getData()
'langcode' => $this->getLocale(),
'orderid' => $this->getTransactionId(),
'vcode' => $this->generateVCode(),
'returnurl' => $this->getReturnUrl(),
'cancelurl' => $this->getCancelUrl(),
);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public function setUp()

$this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest());

$this->gateway->setTestMode(false);
$this->gateway->setCurrency('MYR');
$this->gateway->setLocale('en');
$this->gateway->setMerchantId('test1234');
$this->gateway->setVerifyKey('abcdefg');
$this->gateway->setSecretKey('hilkjmn');

$this->options = array(
'amount' => '10.00',
Expand Down Expand Up @@ -56,7 +58,7 @@ public function testCompletePurchaseSuccess()
'appcode' => 'abcdefg',
'domain' => 'test4321',
'paydate' => '2016-03-29 04:02:21',
'skey' => '9b8be764cc5bad1b4a5d58a3ba4daf58',
'skey' => '0be898400610105af17b3a462c44241b',
'status' => '00',
'tranID' => '000001',
));
Expand Down
7 changes: 4 additions & 3 deletions tests/Message/CompletePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ public function setUp()
'currency' => 'MYR',
'domain' => 'test4321',
'payDate' => '2016-03-29 04:02:21',
'sKey' => '9b8be764cc5bad1b4a5d58a3ba4daf58',
'sKey' => '2e684713b97a79721e347492ef75765e',
'status' => '00',
'transactionId' => '20160331082207680000',
'transactionReference' => '000001',
'verifyKey' => 'abcdefg',
'secretKey' => 'hilklmn',
));
}

Expand All @@ -35,7 +36,7 @@ public function testGetData()
public function testSendSuccess()
{
$this->request->setStatus('00');
$this->request->setSKey('9b8be764cc5bad1b4a5d58a3ba4daf58');
$this->request->setSKey('2e684713b97a79721e347492ef75765e');

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

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

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

Expand Down

0 comments on commit 9332169

Please sign in to comment.