Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dilab committed Nov 29, 2016
0 parents commit 30d931b
Show file tree
Hide file tree
Showing 33 changed files with 1,852 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Created by .ignore support plugin (hsz.mobi)
vendor
composer.lock
34 changes: 34 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "ngocnh/omnipay-onepay",
"type": "ngocnh-library",
"description": "OnePay gateway for Omnipay payment processing library",
"keywords": [
"gateway",
"merchant",
"omnipay",
"pay",
"onepay",
"noidia",
"quocte",
"onepay",
"payment",
"paypal",
"purchase"
],
"authors": [
{
"name": "xu ding",
"email": "[email protected]",
}
],
"minimum-stability": "stable",
"autoload": {
"psr-4": { "Omnipay\\OnePay\\" : "src/" }
},
"require": {
"omnipay/common": "~2.0"
},
"require-dev": {
"omnipay/tests": "~2.0"
}
}
162 changes: 162 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<?php
/**
* OnePay Abstract Request
*/

namespace Omnipay\OnePay\Message;

use \Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest;

abstract class AbstractRequest extends BaseAbstractRequest
{

const API_VERSION = '2';

protected $liveEndpoint = 'https://onepay.vn/onecomm-pay/vpc.op';

protected $testEndpoint = 'https://mtf.onepay.vn/onecomm-pay/vpc.op';


public function getVpcAccessCode()
{
return $this->getParameter('vpcAccessCode');
}


public function setVpcAccessCode($vpcAccessCode)
{
return $this->setParameter('vpcAccessCode', $vpcAccessCode);
}


public function getVpcMerchant()
{
return $this->getParameter('vpcMerchant');
}


public function setVpcMerchant($vpcMerchant)
{
return $this->setParameter('vpcMerchant', $vpcMerchant);
}


public function getSecureHash()
{
return $this->getParameter('secureHash');
}


public function setSecureHash($secureHash)
{
return $this->setParameter('secureHash', $secureHash);
}


public function getVpcUser()
{
return $this->getParameter('vpcUser');
}


public function setVpcUser($vpcUser)
{
return $this->setParameter('vpcUser', $vpcUser);
}


public function getVpcPassword()
{
return $this->getParameter('vpcPassword');
}


public function setVpcPassword($vpcPassword)
{
return $this->setParameter('vpcPassword', $vpcPassword);
}


public function getVpc_MerchTxnRef()
{
return $this->getParameter('vpc_MerchTxnRef');
}


public function setVpc_MerchTxnRef($value)
{
return $this->setParameter('vpc_MerchTxnRef', $value);
}


protected function getBaseData()
{
return [
'vpc_Merchant' => $this->getVpcMerchant(),
'vpc_AccessCode' => $this->getVpcAccessCode(),
];
}


public function sendData($data)
{
$url = $this->getEndpoint() . '?' . http_build_query($data, '', '&');
$httpResponse = $this->httpClient->get($url)->send();

return $this->createResponse($httpResponse->getBody());
}


protected function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}


protected function createResponse($data)
{
return $this->response = new Response($this, $data);
}


public function generateDataWithChecksum($data)
{
// sắp xếp dữ liệu theo thứ tự a-z trước khi nối lại
// arrange array data a-z before make a hash
ksort($data);
// Remove the Virtual Payment Client URL from the parameter hash as we
// do not want to send these fields to the Virtual Payment Client.
// bỏ giá trị url và nút submit ra khỏi mảng dữ liệu
unset( $data["virtualPaymentClientURL"] );
unset( $data["SubButL"] );
unset( $data["vpc_order_id"] );

//$stringHashData = $SECURE_SECRET; *****************************Khởi tạo chuỗi dữ liệu mã hóa trống*****************************
$stringHashData = "";

foreach ($data as $key => $value) {
// create the md5 input and URL leaving out any fields that have no value
// tạo chuỗi đầu dữ liệu những tham số có dữ liệu
if (strlen($value) > 0) {
//$stringHashData .= $value; *****************************sử dụng cả tên và giá trị tham số để mã hóa*****************************
if (( strlen($value) > 0 ) && ( ( substr($key, 0, 4) == "vpc_" ) || ( substr($key, 0,
5) == "user_" ) )
) {
$stringHashData .= $key . "=" . $value . "&";
}
}
}
//*****************************xóa ký tự & ở thừa ở cuối chuỗi dữ liệu mã hóa*****************************
$stringHashData = rtrim($stringHashData, "&");
// Create the secure hash and append it to the Virtual Payment Client Data if
// the merchant secret has been provided.

// thêm giá trị chuỗi mã hóa dữ liệu được tạo ra ở trên vào cuối url
//$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($stringHashData));
// *****************************Thay hàm mã hóa dữ liệu*****************************
$data['vpc_SecureHash'] = strtoupper(hash_hmac('SHA256', $stringHashData, pack('H*', $this->getSecureHash())));

return $data;
}

}
96 changes: 96 additions & 0 deletions src/Message/FetchQuocTeResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Omnipay\OnePay\Message;

/**
* FetchQuocTeResponse
*/
class FetchQuocTeResponse extends FetchResponse
{

/**
* @return string
*/
protected function getResponseDescription($responseCode)
{
switch ($responseCode) {
case "0" :
$result = "Transaction Successful";
break;
case "?" :
$result = "Transaction status is unknown";
break;
case "1" :
$result = "Bank system reject";
break;
case "2" :
$result = "Bank Declined Transaction";
break;
case "3" :
$result = "No Reply from Bank";
break;
case "4" :
$result = "Expired Card";
break;
case "5" :
$result = "Insufficient funds";
break;
case "6" :
$result = "Error Communicating with Bank";
break;
case "7" :
$result = "Payment Server System Error";
break;
case "8" :
$result = "Transaction Type Not Supported";
break;
case "9" :
$result = "Bank declined transaction (Do not contact Bank)";
break;
case "A" :
$result = "Transaction Aborted";
break;
case "C" :
$result = "Transaction Cancelled";
break;
case "D" :
$result = "Deferred transaction has been received and is awaiting processing";
break;
case "F" :
$result = "3D Secure Authentication failed";
break;
case "I" :
$result = "Card Security Code verification failed";
break;
case "L" :
$result = "Shopping Transaction Locked (Please try the transaction again later)";
break;
case "N" :
$result = "Cardholder is not enrolled in Authentication scheme";
break;
case "P" :
$result = "Transaction has been received by the Payment Adaptor and is being processed";
break;
case "R" :
$result = "Transaction was not processed - Reached limit of retry attempts allowed";
break;
case "S" :
$result = "Duplicate SessionID (OrderInfo)";
break;
case "T" :
$result = "Address Verification Failed";
break;
case "U" :
$result = "Card Security Code Failed";
break;
case "V" :
$result = "Address Verification and Card Security Code Failed";
break;
default :
$result = "Unable to be determined";
}

return $result;
}

}
71 changes: 71 additions & 0 deletions src/Message/FetchResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Omnipay\OnePay\Message;

use Omnipay\Common\Message\AbstractResponse;
use Omnipay\Common\Message\RequestInterface;

/**
* FetchResponse
*/
class FetchResponse extends AbstractResponse
{

public function __construct(RequestInterface $request, $data)
{
$this->request = $request;
parse_str($data, $this->data);
}


public function isSuccessful()
{
if (isset( $this->data['vpc_DRExists'] ) && $this->data['vpc_DRExists'] == 'Y' && isset( $this->data['vpc_TxnResponseCode'] ) && $this->data['vpc_TxnResponseCode'] == '0') {
return true;
} elseif ( ! isset( $this->data['vpc_DRExists'] ) && isset( $this->data['vpc_TxnResponseCode'] ) && $this->data['vpc_TxnResponseCode'] == '0') {
return true;
} elseif (isset( $this->data['vpc_ResponseCode'] ) && $this->data['vpc_ResponseCode'] == '0') {
return true;
}

return false;
}


/**
* @return string
*/
public function getMessage()
{
if (isset( $this->data['vpc_DRExists'] ) && $this->data['vpc_DRExists'] == 'N') {
return "Không tồn tại giao dịch";
} else {
if (isset( $this->data['vpc_TxnResponseCode'] )) {
return $this->getResponseDescription($this->data['vpc_TxnResponseCode']);
}

return isset( $this->data['vpc_Message'] ) ? $this->data['vpc_Message'] : '';
}
}


/**
* @return string
*/
protected function getResponseDescription($responseCode)
{
switch ($responseCode) {
case "0" :
$result = "Giao dịch thành công - Approved";
break;
case "300" :
$result = "Giao dịch đang chờ - Pending";
break;
default :
$result = "Giao dịch không thanh toán thành công - Failured";
}

return $result;
}

}
Loading

0 comments on commit 30d931b

Please sign in to comment.