From a68b751ae6c9263017edc70704f9d11d0224f3fb Mon Sep 17 00:00:00 2001 From: Siew-Mai Chan Date: Sat, 20 Jan 2018 18:18:23 +0800 Subject: [PATCH 1/3] Fix according api spec version 13.7 (10th Oct 2017) --- src/Gateway.php | 49 ++++++++++++++- src/Message/AbstractRequest.php | 60 +++++++++++++++++-- src/Message/CompletePurchaseRequest.php | 24 ++++---- src/Message/PurchaseRequest.php | 2 + tests/GatewayTest.php | 4 +- tests/Message/CompletePurchaseRequestTest.php | 7 ++- 6 files changed, 122 insertions(+), 24 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index 9dc731a..9d829ca 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -70,7 +70,7 @@ public function getLocale() * The default language is English. * * @param string $value - * + * * @return $this */ public function setLocale($value) @@ -92,7 +92,7 @@ public function getMerchantId() * Set merchantId. * * @param string $value - * + * * @return $this */ public function setMerchantId($value) @@ -114,7 +114,7 @@ public function getVerifyKey() * Set verifyKey. * * @param string $value - * + * * @return $this */ public function setVerifyKey($value) @@ -122,6 +122,49 @@ 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. * diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index 0d503d8..bb0ab1e 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -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. * @@ -28,7 +35,7 @@ abstract class AbstractRequest extends BaseAbstractRequest /** * Get enableIPN. - * + * * @return bool */ public function getEnableIPN() @@ -62,7 +69,7 @@ public function getLocale() * Set locale. * * @param string $value - * + * * @return $this */ public function setLocale($value) @@ -84,7 +91,7 @@ public function getMerchantId() * Set merchantId. * * @param string $value - * + * * @return $this */ public function setMerchantId($value) @@ -106,7 +113,7 @@ public function getVerifyKey() * Set verifyKey. * * @param string $value - * + * * @return $this */ public function setVerifyKey($value) @@ -114,6 +121,49 @@ 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. * @@ -123,7 +173,7 @@ public function getEndpoint() { $this->validate('merchantId'); - return $this->endpoint.$this->getMerchantId().'/'; + return ($this->getTestMode() ? $this->sandboxEndpoint : $this->endpoint).$this->getMerchantId().'/'; } /** diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php index e42b462..b8a14e3 100644 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/CompletePurchaseRequest.php @@ -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 { @@ -39,7 +39,7 @@ public function getAppCode() * Set appCode. * * @param string $value - * + * * @return $this */ public function setAppCode($value) @@ -61,7 +61,7 @@ public function getDomain() * Set domain. * * @param string $value - * + * * @return $this */ public function setDomain($value) @@ -83,7 +83,7 @@ public function getErrorMessage() * Set errorMessage. * * @param string $value - * + * * @return $this */ public function setErrorMessage($value) @@ -105,7 +105,7 @@ public function getPayDate() * Set payDate. * * @param string $value - * + * * @return $this */ public function setPayDate($value) @@ -127,7 +127,7 @@ public function getSKey() * Set sKey. * * @param string $value - * + * * @return $this */ public function setSKey($value) @@ -149,7 +149,7 @@ public function getStatus() * Set status. * * @param string $value - * + * * @return $this */ public function setStatus($value) @@ -171,7 +171,7 @@ public function getTransactionReference() * Set transactionReference. * * @param string $value - * + * * @return $this */ public function setTransactionReference($value) @@ -227,7 +227,7 @@ public function sendData($data) * Generate pre-sKey - first hash encryption. * * @param bool $fallbackMode - * + * * @return string */ protected function generatePreSKey($fallbackMode = false) @@ -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()); } /** diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index b062287..8dfe53a 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -42,6 +42,8 @@ public function getData() 'langcode' => $this->getLocale(), 'orderid' => $this->getTransactionId(), 'vcode' => $this->generateVCode(), + 'returnurl' => $this->getReturnUrl(), + 'cancelurl' => $this->getCancelUrl(), ); } diff --git a/tests/GatewayTest.php b/tests/GatewayTest.php index e84e379..bd94b9f 100644 --- a/tests/GatewayTest.php +++ b/tests/GatewayTest.php @@ -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', @@ -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', )); diff --git a/tests/Message/CompletePurchaseRequestTest.php b/tests/Message/CompletePurchaseRequestTest.php index 8856cb9..c55b238 100644 --- a/tests/Message/CompletePurchaseRequestTest.php +++ b/tests/Message/CompletePurchaseRequestTest.php @@ -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', )); } @@ -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(); @@ -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(); From b32c9eccf46ffff15503397b9431db23933aaeac Mon Sep 17 00:00:00 2001 From: Siew-Mai Chan Date: Sun, 21 Jan 2018 17:39:16 +0800 Subject: [PATCH 2/3] Update API_VERSION --- src/Message/AbstractRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index bb0ab1e..f1e1f82 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -10,7 +10,7 @@ abstract class AbstractRequest extends BaseAbstractRequest { - const API_VERSION = '12.1'; + const API_VERSION = '13.7'; /** * Endpoint URL. From 82199a6459194f5256505e755b0e07813739d73f Mon Sep 17 00:00:00 2001 From: Siew-Mai Chan Date: Sun, 21 Jan 2018 17:44:36 +0800 Subject: [PATCH 3/3] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 79ac007..095201d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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