|
|
@@ -0,0 +1,390 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: leo
|
|
|
+ * Date: 2018/2/24
|
|
|
+ * Time: 下午12:48
|
|
|
+ */
|
|
|
+namespace backendApi\modules\v1\controllers;
|
|
|
+
|
|
|
+use backendApi\modules\v1\models\Admin;
|
|
|
+use backendApi\modules\v1\models\lists\user\IndexList;
|
|
|
+use common\models\AdLocation;
|
|
|
+use common\models\FlowBonus;
|
|
|
+use common\models\User;
|
|
|
+
|
|
|
+class DemoController extends BaseController
|
|
|
+{
|
|
|
+
|
|
|
+ public $modelClass = User::class;
|
|
|
+
|
|
|
+ public function actions()
|
|
|
+ {
|
|
|
+ return parent::actions(); // TODO: Change the autogenerated stub
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付demo
|
|
|
+ * @return mixed
|
|
|
+ * @throws \yii\web\HttpException
|
|
|
+ */
|
|
|
+ public function actionPay()
|
|
|
+ {
|
|
|
+ $money = \Yii::$app->request->post('money');
|
|
|
+
|
|
|
+ $data['vpc_Currency'] = 'VND';
|
|
|
+ $data['vpc_Version'] = 2;
|
|
|
+ $data['vpc_Command'] = 'pay';
|
|
|
+ $data['vpc_AccessCode'] = '6BEB2546';
|
|
|
+ $data['vpc_Merchant'] = 'TESTONEPAY';
|
|
|
+ $data['vpc_Locale'] = 'en';
|
|
|
+ $data['vpc_ReturnURL'] = 'http://16.163.228.151:8040/v1/demo/payments';
|
|
|
+ $data['vpc_MerchTxnRef'] = rand(10000, 99999);
|
|
|
+ $data['vpc_OrderInfo'] = '123456';
|
|
|
+ $data['vpc_Amount'] = $money*100;
|
|
|
+ $data['vpc_TicketNo'] = $_SERVER ['REMOTE_ADDR'];
|
|
|
+ $data['AgainLink'] = 'http://16.163.228.151:8040/v1/demo/payments'; //跳转回当前页面地址
|
|
|
+ $data['Title'] = 'pay';
|
|
|
+ ksort($data);
|
|
|
+ $url = "https://mtf.onepay.vn/paygate/vpcpay.op?";
|
|
|
+ $md5HashData = '';
|
|
|
+ foreach ($data as $key => $value) {
|
|
|
+
|
|
|
+ $url .= urlencode($key) . '=' . urlencode($value) . '&';
|
|
|
+
|
|
|
+ if ((strlen($value) > 0) && ((substr($key, 0, 4) == "vpc_") || (substr($key, 0, 5) == "user_"))) {
|
|
|
+ $md5HashData .= $key . "=" . $value . "&";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $SECURE_SECRET = "6D0870CDE5F24F34F3915FB0045120DB";
|
|
|
+ $md5HashData = rtrim($md5HashData, "&");
|
|
|
+
|
|
|
+ $url .= "vpc_SecureHash=" . strtoupper(hash_hmac('SHA256', $md5HashData, pack('H*', $SECURE_SECRET)));
|
|
|
+// $listObj = new IndexList();
|
|
|
+// $res = $listObj->curl_get($url);
|
|
|
+// print_r($res);
|
|
|
+// die;
|
|
|
+ return static::notice($url);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function actionPayments($vpc_MerchTxnRef){
|
|
|
+ file_put_contents('./text.txt',$vpc_MerchTxnRef);
|
|
|
+ $params = array(
|
|
|
+ 'vpc_Version' => '1',
|
|
|
+ 'vpc_Command' => 'queryDR',
|
|
|
+ 'vpc_MerchTxnRef' => $vpc_MerchTxnRef,
|
|
|
+ 'vpc_User' => 'op01',
|
|
|
+ 'vpc_Password' => 'op123456',
|
|
|
+ );
|
|
|
+
|
|
|
+ //if($this->gateway === 'Inland'){
|
|
|
+ $vpcURL = 'https://mtf.onepay.vn/onecomm-pay/Vpcdps.op';
|
|
|
+ $params['vpc_AccessCode'] = '6BEB2546';
|
|
|
+ $params['vpc_Merchant'] = 'TESTONEPAY';
|
|
|
+// }else
|
|
|
+// {
|
|
|
+// $vpcURL = 'https://mtf.onepay.vn/vpcpay/Vpcdps.op';
|
|
|
+// $params['vpc_AccessCode'] = '6BEB2546';
|
|
|
+// $params['vpc_Merchant'] = 'TESTONEPAY';
|
|
|
+// }
|
|
|
+
|
|
|
+ $postData = "";
|
|
|
+ $ampersand = "";
|
|
|
+
|
|
|
+ foreach ($params as $key => $value) {
|
|
|
+ if (strlen($value) > 0) {
|
|
|
+ $postData .= $ampersand . urlencode($key) . '=' . urlencode($value);
|
|
|
+ $ampersand = "&";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ob_start();
|
|
|
+
|
|
|
+ $ch = curl_init();
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $vpcURL);
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
|
+
|
|
|
+
|
|
|
+ curl_exec($ch);
|
|
|
+
|
|
|
+ $response = ob_get_contents();
|
|
|
+
|
|
|
+
|
|
|
+ ob_end_clean();
|
|
|
+
|
|
|
+ $message = "";
|
|
|
+
|
|
|
+ if (strchr($response, "<html>") || strchr($response, "<html>")) {
|
|
|
+ $message = $response;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if (curl_error($ch))
|
|
|
+ $message = "%s: s" . curl_errno($ch) . "<br/>" . curl_error($ch);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ $map = array();
|
|
|
+
|
|
|
+ if (strlen($message) == 0) {
|
|
|
+ $pairArray = explode("&", $response);
|
|
|
+ foreach ($pairArray as $pair) {
|
|
|
+ $param = explode("=", $pair);
|
|
|
+ $map[urldecode($param[0])] = urldecode($param[1]);
|
|
|
+ }
|
|
|
+ $message = $this->null2unknown($map, "vpc_Message");
|
|
|
+ }
|
|
|
+
|
|
|
+ $amount = $this->null2unknown($map, "vpc_Amount");
|
|
|
+ $locale = $this->null2unknown($map, "vpc_Locale");
|
|
|
+ $batchNo = $this->null2unknown($map, "vpc_BatchNo");
|
|
|
+ $command = $this->null2unknown($map, "vpc_Command");
|
|
|
+ $version = $this->null2unknown($map, "vpc_Version");
|
|
|
+ $cardType = $this->null2unknown($map, "vpc_Card");
|
|
|
+ $orderInfo = $this->null2unknown($map, "vpc_OrderInfo");
|
|
|
+ $receiptNo = $this->null2unknown($map, "vpc_ReceiptNo");
|
|
|
+ $merchantID = $this->null2unknown($map, "vpc_Merchant");
|
|
|
+ $authorizeID = $this->null2unknown($map, "vpc_AuthorizeId");
|
|
|
+ $transactionNo = $this->null2unknown($map, "vpc_TransactionNo");
|
|
|
+ $acqResponseCode = $this->null2unknown($map, "vpc_AcqResponseCode");
|
|
|
+ $txnResponseCode = $this->null2unknown($map, "vpc_TxnResponseCode");
|
|
|
+
|
|
|
+ $drExists = $this->null2unknown($map, "vpc_DRExists");
|
|
|
+ $multipleDRs = $this->null2unknown($map, "vpc_FoundMultipleDRs");
|
|
|
+
|
|
|
+ $verType = $this->null2unknown($map, "vpc_VerType");
|
|
|
+ $verStatus = $this->null2unknown($map, "vpc_VerStatus");
|
|
|
+ $token = $this->null2unknown($map, "vpc_VerToken");
|
|
|
+ $verSecurLevel = $this->null2unknown($map, "vpc_VerSecurityLevel");
|
|
|
+ $enrolled = $this->null2unknown($map, "vpc_3DSenrolled");
|
|
|
+ $xid = $this->null2unknown($map, "vpc_3DSXID");
|
|
|
+ $acqECI = $this->null2unknown($map, "vpc_3DSECI");
|
|
|
+ $authStatus = $this->null2unknown($map, "vpc_3DSstatus");
|
|
|
+
|
|
|
+ $shopTransNo = $this->null2unknown($map, "vpc_ShopTransactionNo");
|
|
|
+ $authorisedAmount = $this->null2unknown($map, "vpc_AuthorisedAmount");
|
|
|
+ $capturedAmount = $this->null2unknown($map, "vpc_CapturedAmount");
|
|
|
+ $refundedAmount = $this->null2unknown($map, "vpc_RefundedAmount");
|
|
|
+ $ticketNumber = $this->null2unknown($map, "vpc_TicketNo");
|
|
|
+
|
|
|
+ $errorTxt = "";
|
|
|
+ if ($txnResponseCode == "7" || $txnResponseCode == "No Value Returned") {
|
|
|
+ $errorTxt = "Error";
|
|
|
+ }
|
|
|
+
|
|
|
+ $transStatus = "";
|
|
|
+ if ($txnResponseCode == "0") {
|
|
|
+ $transStatus = "Giao dịch thành công";
|
|
|
+ } elseif ($txnResponseCode != "0") {
|
|
|
+ $transStatus = "Giao dịch thất bại";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $result = array(
|
|
|
+ 'OnePay' => array(
|
|
|
+ 'errorTxt' => $errorTxt,
|
|
|
+ 'resCode' => $txnResponseCode,
|
|
|
+ 'resDescription' => $this->getResponseDescription($txnResponseCode)
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ return json_encode($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ private 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function null2unknown($map, $key)
|
|
|
+ {
|
|
|
+ if (array_key_exists($key, $map)) {
|
|
|
+ if (!is_null($map[$key])) {
|
|
|
+ return $map[$key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "No Value Returned";
|
|
|
+ }
|
|
|
+
|
|
|
+ public function actionIpay(){
|
|
|
+ $data = array(
|
|
|
+ 'ApiVersion' => '2.0',
|
|
|
+ 'MerchantCode' => 'ID00001',
|
|
|
+ 'PaymentId' => '71',
|
|
|
+ 'Currency' => 'IDR',
|
|
|
+ 'RefNo' => 'A00000001',
|
|
|
+ 'Amount' => '3000',
|
|
|
+ 'ProdDesc' => 'test',
|
|
|
+ 'UserName' => 'Thoriq',
|
|
|
+ 'UserEmail' => 'thoriq@ipay88.co.id',
|
|
|
+ 'UserContact' => '08123123123',
|
|
|
+ 'Lang' => 'UTF-8',
|
|
|
+ 'ResponseURL' => 'http://16.163.228.151:8040/v1/demo/ipayments',
|
|
|
+ 'BackendURL' => 'http://16.163.228.151:8040/v1/demo/ipay',
|
|
|
+ 'ItemTransactions' => array(
|
|
|
+ "Id" => "00001",
|
|
|
+ "Name" => "Smartphone Wireless Charger",
|
|
|
+ "Quantity" => "1",
|
|
|
+ "Amount" => "3000",
|
|
|
+ "ParentType" => "SELLER",
|
|
|
+ "ParentId" => "SELLER123",
|
|
|
+ ),
|
|
|
+ 'ShippingAddress' => array(
|
|
|
+ "FirstName" => "Techsupp",
|
|
|
+ "LastName" => "Alpha",
|
|
|
+ "Address" => "Jl. Test BlokRNo.1",
|
|
|
+ "City" => "Jakarta",
|
|
|
+ "State" => "DKI Jakarta",
|
|
|
+ "PostalCode" => "18800",
|
|
|
+ "Phone" => "08123456789",
|
|
|
+ "CountryCode" => "1",
|
|
|
+ ),
|
|
|
+ 'BillingAddress' => array(
|
|
|
+ "FirstName" => 'test',
|
|
|
+ "LastName" => "test",
|
|
|
+ "Address" => "test",
|
|
|
+ "City" => "test",
|
|
|
+ "State" => "test",
|
|
|
+ "PostalCode" => "11480",
|
|
|
+ "Phone" => "08788888888",
|
|
|
+ "CountryCode" => "2222",
|
|
|
+ ),
|
|
|
+ 'Sellers' => array(
|
|
|
+ "Id" => "SELLER123",
|
|
|
+ "Name" => "Sellername",
|
|
|
+ "LegalId" => "3274011001900001",
|
|
|
+ "SellerIdNumber" => null,
|
|
|
+ "Email" => "sellername@gmail.com",
|
|
|
+ "Url" => "www.sunrise.com",
|
|
|
+ "address" => array(
|
|
|
+ "FirstName" => 'test',
|
|
|
+ "LastName" => "test",
|
|
|
+ "Address" => "test",
|
|
|
+ "City" => "test",
|
|
|
+ "State" => "test",
|
|
|
+ "PostalCode" => "11480",
|
|
|
+ "Phone" => "08788888888",
|
|
|
+ "CountryCode" => "2222",
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ "SettingField" => array(
|
|
|
+ "Name" => 'TenorInstallment',
|
|
|
+ "Value" => '3',
|
|
|
+ ),
|
|
|
+ );
|
|
|
+ $MerchantKey = 'apple';
|
|
|
+ $url = "https://sandbox.ipay88.co.id/ePayment/WebService/PaymentAPI/Checkout";
|
|
|
+ $str = "||" . $MerchantKey . "||" . $data['MerchantCode'] . "||" . $data['RefNo'] . "||" . $data['Amount'] . "||" . $data['Currency'] . "||";
|
|
|
+ $data['Signature'] = hash('sha256', $str);
|
|
|
+ $res = $this->curl_post($url,json_encode($data));
|
|
|
+ print_r($res);die;
|
|
|
+ //return static::notice($res);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function curl_post($url,$param){
|
|
|
+ if (empty($url) || empty($param)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $postUrl = $url;
|
|
|
+ $curlPost = $param;
|
|
|
+ $ch = curl_init();//初始化curl
|
|
|
+ curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
|
|
|
+ $data = curl_exec($ch);//运行curl
|
|
|
+ curl_close($ch);
|
|
|
+ print_r($data);die;
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function actionIpayments(){
|
|
|
+ $data = file_get_contents('php://input');
|
|
|
+ file_put_contents('./text1.txt',$data);
|
|
|
+ }
|
|
|
+}
|