Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working razer with omnipay v3 #4

Open
wants to merge 7 commits into
base: 3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
}
],
"autoload": {
"psr-4": { "League\\Omnipay\\MOLPay\\" : "src/" }
"psr-4": { "Omnipay\\MOLPay\\" : "src/" }
},
"autoload-dev": {
"psr-4": { "League\\Omnipay\\MOLPay\\Tests\\": "tests/" }
"psr-4": { "Omnipay\\MOLPay\\Tests\\": "tests/" }
},
"require": {
"omnipay/omnipay": "~3.0@dev"
"omnipay/common": "^3"
},
"require-dev": {
"omnipay/tests": "~3.0@dev"
"omnipay/tests": "^3"
},
"extra": {
"branch-alias": {
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/InvalidCreditCardDetailsException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace League\Omnipay\MOLPay\Exception;
namespace Omnipay\MOLPay\Exception;

use League\Omnipay\Common\Exception\OmnipayException;
use Omnipay\Common\Exception\OmnipayException;

/**
* Invalid Credit Card Details Exception.
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/InvalidPaymentMethodException.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace League\Omnipay\MOLPay\Exception;
namespace Omnipay\MOLPay\Exception;

use League\Omnipay\Common\Exception\OmnipayException;
use Omnipay\Common\Exception\OmnipayException;

/**
* Invalid Payment Method Exception.
Expand Down
107 changes: 92 additions & 15 deletions src/Gateway.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace League\Omnipay\MOLPay;
namespace Omnipay\MOLPay;

use League\Omnipay\Common\AbstractGateway;
use Omnipay\Common\AbstractGateway;

class Gateway extends AbstractGateway
{
Expand All @@ -27,6 +27,7 @@ public function getDefaultParameters()
'enableIPN' => false,
'locale' => 'en',
'testMode' => false,
'httpMethod' => 'GET',
);
}

Expand Down Expand Up @@ -78,6 +79,18 @@ public function setLocale($value)
return $this->setParameter('locale', $value);
}

/**
* Set the HTTP Method.
*
*
* @param string $value
*
* @return $this
*/
public function setHttpMethod($value)
{
return $this->setParameter('httpMethod', $value);
}
/**
* Get merchantId.
*
Expand Down Expand Up @@ -122,43 +135,107 @@ 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.
*
* @param array $parameters
*
* @return \League\Omnipay\MOLPay\Message\PurchaseRequest
* @return \Omnipay\MOLPay\Message\PurchaseRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\League\Omnipay\MOLPay\Message\PurchaseRequest', $parameters);
return $this->createRequest('\Omnipay\MOLPay\Message\PurchaseRequest', $parameters);
}

/**
* Complete a purchase request.
*
* @param array $parameters
*
* @return \League\Omnipay\MOLPay\Message\CompletePurchaseRequest
* @return \Omnipay\MOLPay\Message\CompletePurchaseRequest
*/
public function completePurchase(array $parameters = array())
{
$parsedBody = $this->httpRequest->getParsedBody();

return $this->createRequest(
'\League\Omnipay\MOLPay\Message\CompletePurchaseRequest',
'\Omnipay\MOLPay\Message\CompletePurchaseRequest',
array_merge(
$parameters,
array(
'appCode' => isset($parsedBody['appcode']) ? $parsedBody['appcode'] : null,
'domain' => isset($parsedBody['domain']) ? $parsedBody['domain'] : null,
'errorMessage' => isset($parsedBody['error_desc']) && strlen($parsedBody['error_desc']) > 0 ? $parsedBody['error_desc'] : null,
'payDate' => isset($parsedBody['paydate']) ? $parsedBody['paydate'] : null,
'sKey' => isset($parsedBody['skey']) ? $parsedBody['skey'] : null,
'status' => isset($parsedBody['status']) ? $parsedBody['status'] : null,
'transactionReference' => isset($parsedBody['tranID']) ? $parsedBody['tranID'] : null,
'appCode' => $this->httpRequest->request->get('appcode'),
'domain' => $this->httpRequest->request->get('domain'),
'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'),
'transactionReference' => $this->httpRequest->request->get('tranID'),
'channel' => $this->httpRequest->request->get('channel')
)
)
);
}

/**
* Create a refund request
*
* @param array $parameters
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\MOLPay\Message\PartialRefundRequest', $parameters);
}

/**
* Create a void request
*
* @param array $parameters
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function void(array $parameters = array())
{
return $this->createRequest('\Omnipay\MOLPay\Message\ReversalRequest', $parameters);
}
}
127 changes: 93 additions & 34 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

namespace League\Omnipay\MOLPay\Message;
namespace Omnipay\MOLPay\Message;

use League\Omnipay\Common\Helper;
use League\Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
use League\Omnipay\MOLPay\Exception\InvalidCreditCardDetailsException;
use League\Omnipay\MOLPay\Exception\InvalidPaymentMethodException;
use League\Omnipay\MOLPay\PaymentMethod;
use Omnipay\Common\Helper;
use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;
use Omnipay\MOLPay\Exception\InvalidCreditCardDetailsException;
use Omnipay\MOLPay\Exception\InvalidPaymentMethodException;
use Omnipay\MOLPay\PaymentMethod;

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

/**
* 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.merchant.razer.com/MOLPay/pay/';

/**
* MOLPay IPN (Instant Payment Notification) endpoint URL.
*
Expand Down Expand Up @@ -70,6 +77,29 @@ public function setLocale($value)
return $this->setParameter('locale', $value);
}


/**
* Get HTTP Method.
*
* @return string
*/
public function getHttpMethod()
{
return $this->getParameter('httpMethod');
}

/**
* Set HTTP Method.
*
* @param string $value
*
* @return $this
*/
public function setHttpMethod($value)
{
return $this->setParameter('httpMethod', $value);
}

/**
* Get merchantId.
*
Expand Down Expand Up @@ -114,6 +144,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.
*
Expand All @@ -123,15 +196,15 @@ public function getEndpoint()
{
$this->validate('merchantId');

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

/**
* Send IPN (Instant Payment Notification).
*/
protected function sendIPN()
{
$data = $this->httpRequest->getQueryParams();
$data = $this->httpRequest->request->all();

$data['treq'] = 1; // Additional parameter required by IPN

Expand All @@ -149,46 +222,32 @@ protected function validateCreditCardDetails()
{
$this->validate('card');

$customer = $this->getCard()->getCustomer();

if (null === $customer) {
throw new InvalidCreditCardDetailsException('Customer is required');
}
$card = $this->getCard();

foreach (array('country', 'email', 'name', 'phone') as $key) {
$method = 'get'.ucfirst(Helper::camelCase($key));
$method = 'get' . ucfirst(Helper::camelCase($key));

if (null === $customer->$method()) {
if (null === $card->$method()) {
throw new InvalidCreditCardDetailsException("The $key parameter is required");
}
}
}

/**
* Validate payment method:
* - Affin Bank
* - AmOnline
* - CIMB Clicks
* - Credit Card
* - FPX
* - Hong Leong Connect
* - Maybank2u
* - RHB Now.
*/
protected function validatePaymentMethod()
{
$this->validate('paymentMethod');

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

if (PaymentMethod::AFFIN_BANK !== $paymentMethod &&
PaymentMethod::AM_ONLINE !== $paymentMethod &&
PaymentMethod::CIMB_CLICKS !== $paymentMethod &&
PaymentMethod::CREDIT_CARD !== $paymentMethod &&
PaymentMethod::FPX !== $paymentMethod &&
PaymentMethod::HONG_LEONG_CONNECT !== $paymentMethod &&
PaymentMethod::MAYBANK2U !== $paymentMethod &&
PaymentMethod::RHB_NOW !== $paymentMethod) {
$methods = PaymentMethod::supported();
$supported = false;
foreach ($methods as $method) {
if ($paymentMethod == strtolower($method)) {
$supported = true;
}
}
if (!$supported) {
throw new InvalidPaymentMethodException("The payment method ($paymentMethod) is not supported");
}
}
Expand Down
Loading