so Recently I am working on one of my clients project and i need to fetch the domain name from the URL. This is a very small task but it is very useful stuff to learn.
In this short article, We will write simple and easy code to get the domain name from URL by using some predefined PHP function.
First we need to parse URL using parse_url(). so we can get the array from parse URL and now we can fetch the specific host from the array using $parse[‘host’].
so in the below example we will find the domain name from a predefined URL which are in our $url variable. so copy the below code and run it on your server so you will found the domain name from a long URL.
Welcome back to shortlearner.com, in this post we will see how to implement Razorpay payment gateway with the help of PHP and CURL.
Razorpay is very popular payment gateway which provides all the clean, fast, secure payments services with hassle free integration.
It allows online business to accept and process payments ,payments modes like including major Credit Cards, Debit Cards, Net-banking, Wallets & UPI. With the easiest integration, completely online onboarding, feature filled checkout and best in class performance, quickly go live with Razorpay and experience the future of payments.
After successful sign up and generate Key ID and Secret Key
Razorpay Payment Gateway features:
Accept All the payment methods like debit card, credit card, netbanking,UPI and wallets.
Razorpay payment gateway is very safe and secure
Easy to integration
Payment gateway kit available on multiple programming language
UPI and Multi Bank EMI options
Before starts to implement the Razorpay Payment Gateway Integration using PHP with cURL, look files structure, we are splits the process in several parts so it will be easy to understand the overall developing process. Step1: Create a file constants.php and define Key ID and Secret Key
Note:please guys never share your secret key to anyone.
Step 2: Create another php file named index.php
in the below index.php code , we are declaring amount , currency , success URL and failure URL into some hidden input tags. so it will automatic redirect to success or failure page according to there response status.
Step 4: Put the below script code in index.php file We will use the chekout.js of Razorpay payment gateway for deduction of payment.
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script type="text/javascript">
jQuery(document).on('click', '#razor-pay-now', function (e) {
var total = (jQuery('form#razorpay-frm-payment').find('input#amount').val() * 100);
var merchant_order_id = jQuery('form#razorpay-frm-payment').find('input#merchant_order_id').val();
var merchant_surl_id = jQuery('form#razorpay-frm-payment').find('input#surl').val();
var merchant_furl_id = jQuery('form#razorpay-frm-payment').find('input#furl').val();
var card_holder_name_id = jQuery('form#razorpay-frm-payment').find('input#billing-name').val();
var merchant_total = total;
var merchant_amount = jQuery('form#razorpay-frm-payment').find('input#amount').val();
var currency_code_id = jQuery('form#razorpay-frm-payment').find('input#currency').val();
var key_id = "<?php echo RAZOR_KEY_ID; ?>";
var store_name = 'shortlearner';
var store_description = 'Payment';
var store_logo = 'img/logo.png';
var email = jQuery('form#razorpay-frm-payment').find('input#billing-email').val();
var phone = jQuery('form#razorpay-frm-payment').find('input#billing-phone').val();
jQuery('.text-danger').remove();
if(card_holder_name_id=="") {
jQuery('input#billing-name').after('<small class="text-danger">Please enter full mame.</small>');
return false;
}
if(email=="") {
jQuery('input#billing-email').after('<small class="text-danger">Please enter valid email.</small>');
return false;
}
if(phone=="") {
jQuery('input#billing-phone').after('<small class="text-danger">Please enter valid phone.</small>');
return false;
}
var razorpay_options = {
key: key_id,
amount: merchant_total,
name: store_name,
description: store_description,
image: store_logo,
netbanking: true,
currency: currency_code_id,
prefill: {
name: card_holder_name_id,
email: email,
contact: phone
},
notes: {
soolegal_order_id: merchant_order_id,
},
handler: function (transaction) {
jQuery.ajax({
url:'callback.php',
type: 'post',
data: {razorpay_payment_id: transaction.razorpay_payment_id, merchant_order_id: merchant_order_id, merchant_surl_id: merchant_surl_id, merchant_furl_id: merchant_furl_id, card_holder_name_id: card_holder_name_id, merchant_total: merchant_total, merchant_amount: merchant_amount, currency_code_id: currency_code_id},
dataType: 'json',
success: function (res) {
if(res.msg){
alert(res.msg);
return false;
}
window.location = res.redirectURL;
}
});
},
"modal": {
"ondismiss": function () {
// code here
}
}
};
// obj
var objrzpv1 = new Razorpay(razorpay_options);
objrzpv1.open();
e.preventDefault();
});
</script>
Step 5: now in the second last step we are creating a success.php file so if transaction status is success than success.php page will show the message of transaction success.
<?php include('templates/header.php'); ?>
<section class="showcase">
<div class="container">
<div class="text-center">
<h1 class="display-3">Thank You!</h1>
<p class="lead">Your payment has been received successfully.</p>
<hr>
<p>
Having trouble? <a href="mailto:info@shortlearner.com">Contact us</a>
</p>
<p class="lead">
<a class="btn btn-primary btn-sm" href="#" role="button">Continue to homepage</a>
</p>
</div>
</div>
</section>
<br><br><br><br><br><br>
<?php include('templates/footer.php');?>
so most of the time we need to Copy Text From One Field To Another using Check Box with JavaScript.
for example if we are creating an e-commerce platform and we want to make it user friendly.
so we are creating a check box which will hep user to copy all the fields of billing address to shipping address.
in the below example there are two buyers , buyer 1 and buyer 2. we take name, email and contact number information from buyer 1 and put it into buyer 2 by clicking on the checkbox
<input type="file" onchange="onFileSelected(event)">
<br>
<textarea id="result" rows="10" cols="50"></textarea>
<script type="text/javascript">
function onFileSelected(event) {
var selectedFile = event.target.files[0];
var reader = new FileReader();
var result = document.getElementById("result");
reader.onload = function(event) {
result.innerHTML = event.target.result;
};
reader.readAsText(selectedFile);
}
</script>
simply just copy the above code and put it on your root directory. hope this post will helps you, if you still facing some bugs or error to than feel free to contact.
thanks for reading the post and please share this code with your developer buddy.
so first of all we should take an overview of our working scenario. in the below code we are created a form with having email, subject,message and attachment fields.
once the form is submitted our script is check that the file’s format is valid or not. if the file format is valid than the attachment is concatenate with our message field and with the help of MIME (Multipurpose Internet Mail Extensions) version and its content type and boundary.
we will send the attachment. once the mail is send successfully our script will display the success message and if the mail isn’t sent than it will display failure message as well.