index.php
<!DOCTYPE html>
<html lang="en">
<head>
<title>TagCash Pay Using Bank 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 Bank</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="#myModalBank">Pay Using Bank Demo</button>
<!-- Modal -->
<div class="modal fade" id="myModalBank" 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 Bank</h4>
</div>
<div class="modal-body">
<form method="POST" action="pay.php" enctype="multipart/form-data">
<div class="form-group">
<label for="bank_code">Email:</label>
<input type="email" class="form-control" name="payer_email" placeholder="Email" id="email" required="">
</div>
<div class="form-group">
<label for="wallet_type_id">Wallet Type:</label>
<select name="wallet_type_id" class="form-control" id="wallet_type_id" required="">
<option value="1">PHP</option>
</select>
</div>
<div class="form-group">
<label for="banking_method">Select Banking Method:</label>
<select class="form-control" name="banking_method" id="banking_method" onclick="checkBankingMethod()" required="">
<option value="">Select Banking Method</option>
<option value="ot">Online</option>
<option value="otc">Over-the-counter</option>
</select>
</div>
<div class="form-group">
<label for="bank_code">Bank Name:</label>
<select class="form-control" name="bank_code" id="bank_code" required="">
<option value="BDO">Banco De Oro</option>
<option value="BPI">Bank of the Philippine Islands</option>
<option value="UBP">Unionbank of the Philippines</option>
<option value="SBC">Security Bank Corporation</option>
<option value="MBTC">Metropolitan Bank and Trust Company</option>
<option value="CBC">China Banking Corporation</option>
<option value="EWBC">EastWest Banking Corporation</option>
<option value="PSB">Philippine Savings Bank (PS bank)</option>
<option value="PNB">Philippine National Bank </option>
</select>
</div>
<div id="image">
</div>
<div class="form-group">
<label for="amount">Amount:</label>
<input type="number" class="form-control" name="amount" id="amount" placeholder="Amount" required="">
</div>
<button type="submit" class="btn btn-default">Pay Now</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
function checkBankingMethod() {
var selectedValue = document.getElementById("banking_method").value;
if(selectedValue == "otc" && status == 0){
const parent = document.getElementById("image");
while (parent.firstChild) {
parent.firstChild.remove();
}
var div = document.createElement("div");
div.innerHTML = '<div class="form-group"><label for="bank_code">Deposit Receipt:</label><input type="file" class="form-control" name="image" id="image_data"></div>';
document.getElementById("image").appendChild(div);
status = 1;
}else if(selectedValue == "ot"){
status = 0;
const parent = document.getElementById("image");
while (parent.firstChild) {
parent.firstChild.remove();
}
var div = document.createElement("div");
div.innerHTML = '<div class="form-group"><label for="bank_code">Transaction Id:</label><input type="text" class="form-control" name="transaction_id" placeholder="Transaction Id" id="transaction_id"></div>';
document.getElementById('image').appendChild(div);
}
}
</script>
</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" => "0a9902bc2f7abae2",
"client_secret" => "3e04765712ae789183a4364318c774ca",
"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){
$_SESSION["message"] = "Merchant Access Token Is Not Found";
header("Location: payexample.php");
}
$image_data = '';
if($_FILES["image"]["tmp_name"]){
$image_data = base64_encode(file_get_contents( $_FILES["image"]["tmp_name"] ));
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://apibeta.tagcash.com/deposit/AddPayByBankDetails");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$data = array(
"access_token" => $accesstoken,
"payer_email" => $_POST["payer_email"],
"wallet_type_id" => $_POST["wallet_type_id"],
"banking_method" => $_POST["banking_method"],
"bank_code" => $_POST["bank_code"],
"amount" => $_POST["amount"],
"image" => $image_data,
"transaction_id" => $_POST["transaction_id"]
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$contents = curl_exec($ch);
curl_close($ch);
$response = json_decode($contents);
if($response->status == 'success'){
$status = "success";
$message = "Pay bank details are added successfully. An email is sent to ".$_POST["payer_email"].' for the confirmation';
}else if($response->error){
$status = "failed";
$message = $response->error;
}else{
$status = "failed";
$message = $response->error;
}
redirect($status, $message);
function redirect($status,$message){
$_SESSION["message"] = $message;
$_SESSION["status"] = $status;
header("Location: index.php");
die();
}
?>