PayUmoney Payment Gateway Integration Steps:-
Pre-requisites:-
- Creating Account on PayUmoney.
- Credentials Required:-
- Merchant Key.
- Salt.
Steps:-
- Create:- table in database : payumoney_setting
- Create:- controller/Payumoney.php
- Create:- views/payumoney/index.php
- Create:- views/payumoney/payment_success.php
- Create:- views/payumoney/payment_failure.php
payumoney_setting
CREATE TABLE `payumoney_setting` (
`id` int(11) NOT NULL,
`mode` varchar(50) NOT NULL,
`merchant_key` varchar(255) NOT NULL,
`merchant_salt` varchar(255) NOT NULL,
`auth_header` varchar(255) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `jk_bd_payumoney_setting` (`id`, `mode`, `merchant_key`, `merchant_salt`, `auth_header`) VALUES
(1, 'sandbox', 'qbh6ArpH', 'SphfouX4Gl', 'VNGRsnGzFhXEnVssXlUvvGuk6fQQkcKMWkvLBg4Vn3k=');
ALTER TABLE `jk_bd_payumoney_setting`
ADD PRIMARY KEY (`id`);
ALTER TABLE `jk_bd_payumoney_setting`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
COMMIT;
Payumoney.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Payumoney extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$data['mode'] = 'sandbox'; //production
$data['credential'] = $this->db->get('payumoney_setting')->row();
$this->load->view('payments/payumoney/index', $data);
}
}
index.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php $this->load->view('common/includes/top_includes'); ?>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
</head>
<?php
//PayUMoney Gateway Details
$MERCHANT_KEY = "YK8HhKBC";
$SALT = "4pHfeSPFRE";
//$PAYU_BASE_URL = "https://sandboxsecure.payu.in"; // For Sandbox Mode
$PAYU_BASE_URL = "https://secure.payu.in"; // For Production Mode
$action = ''; //This is form action which will be decided dynamically
//Creating posted variable which will contain all $_POST data
$posted = array();
if(!empty($_POST)) {
foreach($_POST as $key => $value) {
$posted[$key] = $value;
}
}
$formError = 0;
//Store transaction id in a variable
if(empty($posted['txnid'])) {
// Generate random transaction id
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
} else {
$txnid = $posted['txnid'];
}
$hash = '';
// Hash Sequence
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
//If any of the requried value is empty then set form error to 1
if( empty($posted['key']) || empty($posted['txnid']) || empty($posted['amount']) || empty($posted['firstname']) || empty($posted['email']) || empty($posted['phone']) || empty($posted['productinfo']) || empty($posted['surl']) || empty($posted['furl']) || empty($posted['service_provider'])) {
$formError = 1;
} else {
$hashVarsSeq = explode('|', $hashSequence);
$hash_string = '';
foreach($hashVarsSeq as $hash_var) {
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
$hash_string .= '|';
}
$hash_string .= $SALT;
$hash = strtolower(hash('sha512', $hash_string));
$action = $PAYU_BASE_URL . '/_payment';
}
} elseif(!empty($posted['hash'])) {
$hash = $posted['hash'];
$action = $PAYU_BASE_URL . '/_payment';
}
if(isset($_POST)){
$amount = $_POST['amount'];
} else {
$amount = 0;
}
?>
<script>
var hash = '<?php echo $hash ?>';
var amount = '<?php echo $amount ?>';
function submitPayuForm() {
if(hash == '') {
return;
}
if(amount == '100.00') {
document.getElementById('payuForm').submit();
return;
}
}
</script>
</head>
<body onload="submitPayuForm()" >
<!-- Navigation -->
<?php $this->load->view('common/includes/top_nav'); ?>
<?php if($status == 'success'){ ?>
<div class="bg-success">
<div class="container toast" data-autohide="false">
<div class="toast-header">
<strong class=" mr-auto text-secondary">Payment Successful</strong>
<!--<small class="text-muted">5 mins ago</small>-->
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast">×</button>
</div>
<div class="toast-body text-danger">
<h5 >Your payment is successful.</h5>
</div>
</div>
</div>
<?php } ?>
<?php
if($this->session->has_userdata('is_logged_in')){
$user_id = $this->session->->user_id;
$user = $this->db->where('id', $user_id)->get('user')->row();
} else {
redirect('auth/login', 'refresh');
}
?>
<div class="card-body p-4">
<form class="w3-container" method='POST' action="<?=$action ?>" name="payuForm" id="payuForm">
<input type="hidden" name="key" value="<?php echo $MERCHANT_KEY ?>" />
<input type="hidden" name="hash" value="<?php echo $hash ?>"/>
<input type="hidden" name="txnid" value="<?php echo $txnid ?>" />
<input type="hidden" id="surl" name="surl" value="<?php echo base_url('payumoney/payment_success'); ?>" />
<input type="hidden" id="furl" name="furl" value="<?php echo base_url('payumoney/payment_failure'); ?>" />
<input type="hidden" id="amount" name="amount" value="100.00" />
<input type="hidden" id="service_provider" name="service_provider" value="payu_paisa" />
<input type="hidden" id="pinfo" name="productinfo" value="get_subscription" />
<input type="hidden" id="fname" name="firstname" value="<?php echo $user->full_name; ?>" />
<input type="hidden" id="email" name="email" value="<?php echo $user->email; ?>" />
<input type="hidden" id="mobile" name="phone" value="<?php echo $user->mobile; ?>" />
<input class="btn btn-block btn-light" onClick="e.preventDefault()" tabindex="0" type="submit" name='submit3' value='Purchase Now'>
</form>
</div>
<script src="<?php echo base_url('assets/'); ?>bootstrap/js/bootstrap.bundle.min.js"></script>
<script>
$(document).ready(function(){
$('.toast').toast('show');
});
</script>
</body>
</html>
payment_success.php
<html>
<head>
<title>Payment_successful</title>
<style>
.success-page{
max-width:300px;
display:block;
margin: 0 auto;
text-align: center;
position: relative;
top: 50%;
transform: perspective(1px) translateY(50%)
}
.success-page img{
max-width:62px;
display: block;
margin: 0 auto;
}
.btn-view-orders{
display: block;
border:1px solid #47c7c5;
width:100px;
margin: 0 auto;
margin-top: 45px;
padding: 10px;
color:#fff;
background-color:#47c7c5;
text-decoration: none;
margin-bottom: 20px;
}
h2{
color:#47c7c5;
margin-top: 25px;
}
a{
text-decoration: none;
}
</style>
</head>
<body>
<div class="success-page">
<h2>Payment Successful !</h2>
<p>We are delighted to inform you that we received your payments</p>
<a href="<?php echo base_url('home'); ?>" class="btn-view-orders">Home</a>
<p>Click the button to go to the Home page of BestDivision</p>
</div>
</div>
</body>
</html>
@abcd 1 days ago
Aquí los que apoyamos a Los del limit desde sus inicios..