데모코드 : index.php

index.php
<?php
// This is sample for how you can get QR and get payment post.
header("Content-type: text/html; charset=utf-8");
require_once 'warapay.php';
// When you get new QR code, you can use this code.
if (!empty($_POST['out_trade_no'])&& trim($_POST['out_trade_no'])!=""){
// (Need) When you make your own number for billing, you must need to use unique value
// for example>
// $outTradeNo = "qrpay".date('Ymdhis').mt_rand(100,1000);
$data['out_trade_no']=trim($_POST['out_trade_no']);
// (Need) Payment method, 微信:'wechat', 支付宝:'alipay', WaraPay:others
$data['channel']=trim($_POST['channel']);
// (Need) We just support KER ( Korean Won )
$data['currency']=trim($_POST['currency']);
// Price
$data['money']=trim($_POST['money']);
$wara=new warapay();
$arr=$wara->qrPay($data);
if($arr && is_array($arr)){
//Success get QR code. You can process it.
/*
your code
*/
}
//return
exit(json_encode(array('code'=>0,'data'=>$arr)));
}elseif(!empty($_POST['trade_no'])&& trim($_POST['trade_no'])!=""){
// When your server received payment from WaraPay, you can use this code.
$data['trade_no']=trim($_POST['trade_no']);
$wara=new warapay();
$arr=$wara->queryTrade($data);
if($arr && is_array($arr)){
// Checked this trade no is success. You can process finish billing.
/*
your code
*/
}
//return
exit(json_encode(array('code'=>0,'data'=>$arr)));
}
?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>waraPay example V2.0</title>
<link href="//apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.css" rel="stylesheet">
<script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
<script src="//apps.bdimg.com/libs/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<style>
.tab-pane{
border: 1px solid #ddd;
border-top: 0;
padding: 15px;
}
</style>
<body>
<!-- Fixed navbar -->
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://www.waraPay.com/" target="_blank">WaraPay</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="https://wara-kr.miguyouxi.com/user/" target="_blank">userCenter</a></li>
<li><a href="demoV2.zip" target="_blank">download DEMO code</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="page-header">
<h1><img style="margin-right: 15px;width:150px;" src="waralogo.png" />QR Payment V2.0</h1>
</div>
<div class="row">
<div class="col-lg-6">
<ul id="myTab" class="nav nav-tabs" role="tablist">
<li role="presentation" class="active"><a href="#tab1" id="tab1-tab" role="tab" data-toggle="tab" aria-controls="tab1" aria-expanded="true">Request QR</a></li>
<li role="presentation"><a href="#tab2" role="tab" id="tab2-tab" data-toggle="tab" aria-controls="tab2">Check Trade No</a></li>
</ul>
<div id="myTabContent" class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="tab1" aria-labelledBy="tab1-tab">
<form class="form-horizontal" role="form" action="#" method="POST" id="QRPAY">
<div class="form-group">
<label for="channel" class="col-sm-3 control-label">Payment Method</label>
<div class="col-sm-9">
<select class="form-control m-b valid" name="channel" id="channel" aria-invalid="false">
<option value="alipay">Aliapy</option>
<option value="wechat">WechatPay</option>
<option value="warapay">WaraPay</option>
</select>
</div>
</div>
<div class="form-group">
<label for="out_trade_no" class="col-sm-3 control-label">Set Unique Trade No</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="out_trade_no" name="out_trade_no" placeholder="Set Unique Trade No" required>
<small>Must need to input unique value</small>
</div>
</div>
<div class="form-group">
<label for="currency" class="col-sm-3 control-label">Currency</label>
<div class="col-sm-9">
<select class="form-control m-b valid" name="currency" id="currency" aria-invalid="false">
<?php $currencys=warapay::currency();foreach($currencys as $k=>$v){?>
<option value="<?php echo $k;?>"><?php echo $v;?></option>
<?php }?>
</select>
</div>
</div>
<div class="form-group">
<label for="money" class="col-sm-3 control-label">Price</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="money" name="money" placeholder="Price" required>
<small>Only Integer</small>
</div>
</div>
<div class="form-group">
<div class="text-center">
<button type="button" class="btn btn-danger qrPay" style="min-width:120px">Request</button>
</div>
</div>
</form>
</div>
<div role="tabpanel" class="tab-pane fade in" id="tab2" aria-labelledBy="tab2-tab">
<form class="form-horizontal" role="form" action="#" method="POST" id="QUERY">
<div class="form-group">
<label for="trade_no" class="col-sm-3 control-label">Warapay Trade No</label>
<div class="col-sm-9">
<input type="text" class="form-control" id="trade_no" name="trade_no" placeholder="trade_no" required>
<small>You can write trade no</small>
</div>
</div>
<div class="form-group">
<div class="text-center">
<button type="button" class="btn btn-primary queryTrade" style="min-width:120px">Confirm</button>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="col-lg-6 right">
<div class="panel panel-default viewQr hidden">
<div class="panel-heading title">title</div>
<div class="panel-body">
<p class="text-center img">
<img src="" style="width: 220px;"/>
</p>
<p class="text-center trade_no"></p>
<p class="trade_info">
</p>
</div>
</div>
</div>
</div>
<div id="error" class="alert alert-warning alert-dismissible fade in hidden" role="alert" style="margin-top:15px;">
<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<strong>ERROR:</strong> <p></p>
</div>
<p style="margin-top:40px" class="text-center">WaraPay DEMO WARAPAY.COM </p>
</div>
<script type="text/javascript">
$(function(){
$("body").on("click",".qrPay",function(){
$.post("#",$('#QRPAY').serialize(),function(data){
if(data.code===0){
var item=data.data;
$(".viewQr .title").html("Please you can pay using "+item.channel+" method for "+item.money+" KRW");
$(".viewQr .panel-body img").attr("src",item.qrimg);
$(".viewQr .panel-body .trade_no").html('trade_no:'+item.trade_no);
$("#QUERY #trade_no").val(item.trade_no);
$(".viewQr .img").removeClass("hidden");
$(".viewQr .trade_info").addClass("hidden");
$(".viewQr .trade_no").removeClass("hidden");
$(".viewQr").removeClass("hidden");
$("#error").addClass("hidden");
}else{
$("#error p").html('');
$.each(data,function(k,v){
$("#error p").append('<strong>'+k+':</strong>'+v);
})
$("#error").removeClass("hidden");
}
},"JSON");
}).on("click",".queryTrade",function(){
$.post("#",$('#QUERY').serialize(),function(data){
if(data.code===0){
var item=data.data;
$(".viewQr .title").html("查询结果:");
$(".viewQr .panel-body .trade_no").html('trade_no:'+item.trade_no);
$(".viewQr .trade_info").html('');
$.each(item,function(k,v){
$(".viewQr .trade_info").append('<strong>'+k+':</strong>'+v + '<br/>');
})
$(".viewQr .img").addClass("hidden");
$(".viewQr .trade_info").removeClass("hidden");
$(".viewQr .trade_no").addClass("hidden");
$(".viewQr").removeClass("hidden");
$("#error").addClass("hidden");
}else{
$("#error p").html('');
$.each(data,function(k,v){
$("#error p").append('<strong>'+k+':</strong>'+v);
})
$("#error").removeClass("hidden");
}
},"JSON");
})
})
</script>
</body>
</html>
index.php 에서 사용된 waralogo.png 이미지 파일