Durgeshsb Payment Integration
Durgeshsb Payment Integration
Step 2:
After generate
Key id rzp_test_HdbQ0mLDRL9PZW
Go to userdash_board.html
<hr>
<h3 class="my-3">Donate Us</h3>
<input id="payment_field" type="text" class="form-control
my-2" placeholder="Enter amount here" />
<div class="container text-center mt-3">
<button onclick="paymentStart()" class="btn btn-success
btn-block">CHECKOUT</button>
</div>
</div>//here we are using Ajax through we are sending request
//code...
//we will use ajax to send requet to server to create order
$.ajax({
url:"/user/create_order", //ab humara data jayega user ke
create_order pe
data:JSON.stringify({amount:amount,info:"order_request"}),
contentType:"application/json",
type:"POST",
dataType:"json",
success:function(response){
//invoked when success
console.log(response);
if(response.status=="created"){
//open payment form
let options ={
key:"rzp_test_HdbQ0mLDRL9PZW",
amount:response.amount,
currency:"INR",
name:"Subhash sb Payment",
description:'Donation',
image:"https://unsplash.com/s/photos/human",
order_id:response.id,
handler:function(response){
console.log(response.razorpay_payment_id);
console.log(response.razorpay_order_id);
console.log(response.razorpay_signature);
console.log("payment successful !!");
//alert("congrates !! Payment successful !!");
swal("Good job!","congrates !! Payment
successful !!","success");
},
prefill:{
name:"",
email:"",
contact:"",
},
notes:{
address:"Rozarpay Corporate Office",
},
theme:{
color:"#3399cc"
},
};
rzp.on("payment failed",function(response){
console.log(response.error.code);
console.log(response.error.description);
console.log(response.error.source);
console.log(response.error.step);
console.log(response.error.reason);
console.log(response.error.metadata.order_id);
console.log(response.error.metadata.payment_id);
});
rzp.open();
}
},
else:function(error){
//invoked when error
console.log(error);
//alert("something went wrong !!");
swal("Failed!","something went wrong !!","error");
}
}
)
};
//add request to controller
}
https://razorpay.com/docs/payments/server-integration/java/payment-gateway/build-integration/
//base.html normal
<script
src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></
script>
<script
src="https://checkout.razorpay.com/v1/checkout.js"></script>
//in same base.html for ajax file before head tag
<script
src="https://code.jquery.com/jquery-3.7.0.min.js"
integrity="sha256-
2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g="
crossorigin="anonymous"></script>