Skip to content

Instantly share code, notes, and snippets.

@kafkadev
Created September 23, 2022 21:31
Show Gist options
  • Save kafkadev/bbe6b22cb556b6c0181bd328ef1a6c6d to your computer and use it in GitHub Desktop.
Save kafkadev/bbe6b22cb556b6c0181bd328ef1a6c6d to your computer and use it in GitHub Desktop.
Example Matgaming MGC
<?php
/*EXAMPLE METHOD*/
function matGaminCallBack(){
$inputJSON = file_get_contents('php://input');
if ($inputJSON != '') {
$input = json_decode($inputJSON, TRUE); //convert JSON into array
if (count($input) != '') {
foreach ($input as $name => $value) {
$_POST[$name] = $value;
}
}
} else {
$apiresult = array(
"status" => "fail",
"error" => "101"
);
$response = json_encode($apiresult);
echo $response;
exit();
}
$cmd = $_POST['cmd'];
$player_token = explode("-",$_POST['player_token']);
if (isset($_POST['gameId'])) {
$gameId = $_POST['gameId'];
}
if (isset($_POST['betAmount'])) {
$betAmount = $_POST['betAmount'];
}
if (isset($_POST['winAmount'])) {
$betAmount = $_POST['winAmount'];
}
if($cmd) {
switch ($cmd) {
case 'getPlayerInfo':
$sql = "USER SELECT QUERY ";
$result = $this->db()->query($sql)->fetch(\PDO::FETCH_ASSOC);
if ($result) {
if ($result['USERTOKEN'] == $player_token) {
$userfound = true;
$apiresult = array(
"result" => true,
"err_desc" => "",
"err_code" => "",
"currency" => $result['USERCURRENCY'],
"display_name" => $result['USERNAME'],
"gender" => $result['USERGENDER'],
"country" => $result['USERNAME'],
"player_id" => $result['USERID'],
"balance" => $result['USERBALANCE']
);
} else {
$userfound = false;
$apiresult = array(
"err_code" => "8",
"err_desc" => "Authentication Failed"
);
}
} else {
$userfound = false;
$apiresult = array(
"err_code" => "13",
"err_desc" => "General Error"
);
}
if (!$userfound) {
$apiresult = array(
"err_code" => "13",
"err_desc" => "General Error"
);
}
break;
case 'withdraw':
$sql = "USER SELECT QUERY ";
$result = $this->db()->query($sql)->fetch(\PDO::FETCH_ASSOC);
if ($result) {
if ($result['USERTOKEN'] == $player_token) {
$sql = "GAME LIST SELECT QUERY ";
$res = $this->db()->query($sql)->fetch(\PDO::FETCH_OBJ);
if ($betAmount > 0) {
if ($result['USERBALANCE'] < $betAmount) {
$apiresult = array(
"err_code" => "2",
"err_desc" => "Not Enough Money"
);
}
$this->db()->begin();
$this->db()->execute("INSERT GAME WITHDRAW ROW",
[]);
$this->db()->commit();
$sql = "USER SELECT QUERY ";
$result = $this->db()->query($sql)->fetch(\PDO::FETCH_ASSOC);
$apiresult = array(
"result" => true,
"err_desc" => '',
"err_code" => '',
"transactionId" => $_POST['transactionId'],
"balance" => $result['USERBALANCE']
);
} else{
$apiresult = array(
"err_code" => "4",
"err_desc" => "Wrong Bet Amount "
);
}
} else {
$apiresult = array(
"err_code" => "8",
"err_desc" => "Authentication Failed "
);
}
} else {
$apiresult = array(
"err_code" => "1",
"err_desc" => "Invalid Token "
);
}
break;
case 'deposit':
$sql = "USER SELECT QUERY ";
$result = $this->db()->query($sql)->fetch(\PDO::FETCH_ASSOC);
if ($result) {
if ($result['USERTOKEN'] == $player_token) {
$sql = "GAME LIST SELECT QUERY ";
$res = $this->db()->query($sql)->fetch(\PDO::FETCH_OBJ);
if ($betAmount > 0) {
$this->db()->begin();
$this->db()->execute("INSERT GAME DEPOSIT ROW",
[]);
$this->db()->commit();
$sql = "USER SELECT QUERY ";
$result = $this->db()->query($sql)->fetch(\PDO::FETCH_ASSOC);
$apiresult = array(
"result" => true,
"err_desc" => '',
"err_code" => '',
"transactionId" => $_POST['transactionId'],
"balance" => $result['USERBALANCE']
);
} else{
$apiresult = array(
"err_code" => "4",
"err_desc" => "Wrong Bet Amount "
);
}
} else {
$apiresult = array(
"err_code" => "8",
"err_desc" => "Authentication Failed "
);
}
} else {
$apiresult = array(
"err_code" => "1",
"err_desc" => "Invalid Token "
);
}
break;
case 'rollback':
$sql = "USER SELECT QUERY ";
$result = $this->db()->query($sql)->fetch(\PDO::FETCH_ASSOC);
if ($result) {
if ($result['USERTOKEN'] == $player_token) {
$sql = "GAME LIST SELECT QUERY ";
$res = $this->db()->query($sql)->fetch(\PDO::FETCH_OBJ);
$this->db()->begin();
$this->db()->execute("UPDATE GAME ROW ".$_POST['transactionId'],
[]);
$this->db()->commit();
$sql = "USER SELECT QUERY ";
$result = $this->db()->query($sql)->fetch(\PDO::FETCH_ASSOC);
$apiresult = array(
"result" => true,
"err_desc" => '',
"err_code" => '',
"transactionId" => $_POST['transactionId'],
"balance" => $result['USERBALANCE']
);
} else {
$apiresult = array(
"err_code" => "8",
"err_desc" => "Authentication Failed "
);
}
} else {
$apiresult = array(
"err_code" => "1",
"err_desc" => "Invalid Token "
);
}
break;
}
}else{
$apiresult = array(
"err_code" => "200",
"err_desc" => "Incorrect Parameters Passed"
);
}
$response = json_encode($apiresult);
echo $response;
exit();
}
/* EXAMPLE DATA
*
*
$APP_ID = 'your_app_id';
$APP_KEY = 'your_app_key';
$errorCodes = [
"4" => "Wrong Bet Amount",
"7" => "Wrong Game ID",
"8" => "Authentication Failed",
"2" => "Not Enough Money",
"2" => "Player Is Blocked",
"3" => "Wrong Currency",
"6" => "Wrong Win Amount",
"8" => "Game is Blocked",
"1" => "Invalid Token",
"1" => "The transaction already exists",
"1" => "The transaction is already canceled",
"1" => "Token Expired",
"1" => "Transaction not found",
"1" => "Wrong Transaction Amount",
"11" => "Transaction Already Complete",
"11" => "The Deposit Transaction Already Received",
"11" => "Token not Found",
"12" => "Player Limit Exceeded",
"13" => "General Error",
"200" => "Incorrect Parameters Passed",
];
$getPlayerInfoActions = [
"request" => [
"cmd" => "getPlayerInfo",
"player_token" => "6985D93EF426B26FD606CC6E113F6310",
],
"response" => [
"result" => true,
"err_desc" => "",
"err_code" => "",
"currency" => "TRY",
"balance" => 100,
"display_name" => "",
"gender" => "",
"country" => "TR",
"player_id" => 123456,
],
];
$withdrawActions = [
"request" => [
"cmd" => "withdraw",
"player_token" => "6985D93EF426B26FD606CC6E113F6310",
"transactionId" => "100",
"roundId" => "",
"gameId" => "0",
"currencyId" => "TRY",
"betAmount" => 0,
"betInfo" => "TR",
],
"response" => [
"result" => true,
"err_desc" => "",
"err_code" => "",
"transactionId" => "100",
"balance" => 0,
],
];
$depositActions = [
"request" => [
"cmd" => "deposit",
"player_token" => "6985D93EF426B26FD606CC6E113F6310",
"transactionId" => "100",
"roundId" => "",
"gameId" => "0",
"currencyId" => "TRY",
"winAmount" => 0,
"betInfo" => "TR",
],
"response" => [
"result" => true,
"err_desc" => "",
"err_code" => "",
"transactionId" => "100",
"balance" => 0,
],
];
$refundActions = [
"request" => [
"cmd" => "rollback",
"player_token" => "6985D93EF426B26FD606CC6E113F6310",
"transactionId" => "10",
"gameId" => "0",
],
"response" => [
"result" => true,
"err_desc" => "",
"err_code" => "",
"transactionId" => "100",
"balance" => 0,
],
];
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment