index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>TagCash Pay Using Tagcash Demo</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse" style="border-radius: 0px;">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="images/tagbond_logo.png" height="30" alt="">
</a>
<div class="navbar-header" style="padding-left: 220px;">
<a class="navbar-brand" href="#">
<img src="http://developer.tagcash.com/code/view/images/tagbond_logo.png" height="30" alt="">
</a>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron" style="padding-top: 10px;">
<h3>Pay Using Tagcash Demo</h3>
<hr/>
<?php session_start(); if($_SESSION["status"] == "Success") { ?>
<div class="alert alert-success">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<?php echo $_SESSION["message"];?>.
</div>
<?php }else if($_SESSION["status"] == "Failed"){ ?>
<div class="alert alert-danger">
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
<?php echo $_SESSION["message"]; ?>.
</div>
<?php } session_destroy();?>
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Pay using Tagcash Demo</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Pay Using Tagcash</h4>
</div>
<div class="modal-body">
<form method="POST" action="pay.php">
<div class="form-group">
<label for="email">Wallet:</label>
<select name="wallet" class="form-control" id="sel1" required="">
<option value="1">PHP</option>
<option value="7">TAG</option>
</select>
</div>
<div class="form-group">
<label for="pwd">Amount:</label>
<input type="text" class="form-control" name="amount" id="amount" required="">
</div>
<div class="form-group">
<label for="pwd">Email/User Id:</label>
<input type="text" class="form-control" name="email" id="email" required="">
</div>
<div class="form-group">
<label for="pwd">Pin:</label>
<input type="text" class="form-control" name="pin" id="email" required="">
</div>
<button type="submit" class="btn btn-default">Pay Now</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
pay.php
<?php
session_start();
header("Content-Type: application/json; charset=UTF-8");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://apibeta.tagcash.com/oauth/accesstoken");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$data = array(
"client_id" => "client_id",
"client_secret" => "client_secret",
"grant_type" => "client_credentials"
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$contents = curl_exec($ch);
$obj = json_decode($contents, false);
$result = $obj->result;
$accesstoken = $result->access_token;
if(!$accesstoken){
redirect("Failed","Merchant Access Token Is Not Found");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://apibeta.tagcash.com/wallet/charge");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$data = array(
"access_token" => $accesstoken,
"amount" => $_POST["amount"],
"pin" => $_POST["pin"],
"from_id" => $_POST["email"],
"wallet_id" => $_POST["wallet"]
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$contents = curl_exec($ch);
$contents = json_decode($contents);
if(isset($contents->error)){
redirect("Failed","Pay using tagcash failed");
}
if(isset($contents->result)){
redirect("Success","Pay using tagcash done successfully");
}
function redirect($status,$message){
session_start();
$_SESSION["message"] = $message;
$_SESSION["status"] = $status;
header("Location: index.php");
die();
}
?>