index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>TagCash Pay Using Voucher 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 Voucher</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="#myModalVoucher">Pay using Voucher Demo</button>
<!-- Modal -->
<div class="modal fade" id="myModalVoucher" 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 Voucher</h4>
</div>
<div class="modal-body">
<form method="POST" action="pay.php">
<div class="form-group">
<label for="pwd">Voucher Code:</label>
<input type="text" class="form-control" name="voucher_code" id="amount" required="">
</div>
<div class="form-group">
<label for="pwd">Amount:</label>
<input type="text" class="form-control" name="amount" id="email" required="">
</div>
<div class="form-group">
<label for="pwd">Email:</label>
<input type="email" class="form-control" name="email" id="email" required="">
</div>
<div class="form-group">
<label for="pwd">Narration:</label>
<input type="text" class="form-control" name="narration" 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);
curl_close($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/Voucher/PayUsingVoucher");
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"],
"voucher" => $_POST["voucher_code"],
"narration" => $_POST["narration"],
"email" => $_POST["email"]
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$contents = curl_exec($ch);
curl_close($ch);
$response = json_decode($contents);
redirect($response->status, $response->message);
function redirect($status,$message){
session_start();
$_SESSION["message"] = $message;
$_SESSION["status"] = $status;
header("Location: index.php");
die();
}
?>