Forum arrow_forward_ios Codding

Questions By
Monjoti Mondol
card_giftcard ₹0

question_answer How to integrate RazorPay with my website using PHP?

I want to integrate my website with RazorPay using PHP.

If anyone knows please help.

14-04-2020, Total 1 Ans Best Answered , 571 views


check_circle_outline BEST ANSWER

For Integrating, I also confuse by seeing it's documentation, but after chatting I got the perfect codes about it.

Here is the codes

But you need to install Composer RazorPay PHP before doing that.

For you index.php

<?php $keyId = 'rzp_test_YaWsdfwenh4Lzx'; $keySecret = 'erkaYusfsdweqlCfFZ0M3wQw'; $displayCurrency = 'INR'; //These should be commented out in production // This is for error reporting // Add it to config.php to report any errors error_reporting(E_ALL); ini_set('display_errors', 1); include "vendor/autoload.php"; session_start(); // Create the Razorpay Order use Razorpay\Api\Api; $api = new Api($keyId, $keySecret); // // We create an razorpay order using orders api // Docs: https://docs.razorpay.com/docs/orders // $orderData = [ 'receipt' => 3456, 'amount' => 2000 * 100, // 2000 rupees in paise 'currency' => 'INR', 'payment_capture' => 1 // auto capture ]; $razorpayOrder = $api->order->create($orderData); $razorpayOrderId = $razorpayOrder['id']; $_SESSION['razorpay_order_id'] = $razorpayOrderId; $displayAmount = $amount = $orderData['amount']; if ($displayCurrency == 'INR') { $url = "https://api.fixer.io/latest?symbols=$displayCurrency[&]base=INR"; $exchange = json_decode(file_get_contents($url), true); $displayAmount = $exchange['rates'][$displayCurrency] * $amount / 100; } $data = [ "key" => $keyId, "amount" => $amount, "name" => "DJ Tiesto", "description" => "Tron Legacy", "image" => "https://cdn.razorpay.com/logos/Edr9fWpZCbywmc_medium.jpg", "prefill" => [ "name" => "Daft Punk", "email" => "customer@merchant.com", "contact" => "8011501382", ], "notes" => [ "address" => "Hello World", "merchant_order_id" => "12312321", ], "theme" => [ "color" => "#F37254" ], "order_id" => $razorpayOrderId, ]; if ($displayCurrency == 'INR') { $data['display_currency'] = $displayCurrency; $data['display_amount'] = $displayAmount; } $json = json_encode($data); ?> <DOCTYPE html> <html> <head> <title></title> <meta name="viewport" content="width=device-width"> <style type="text/css"> .razorpay-payment-button{ cursor: pointer; padding: 12px 20px; font-size: 22px; border: 2px solid #ff9800; background-color: #ff9800; color: white; font-weight:bold; width:100%; } .razorpay-payment-button:hover{ background-color: lavender; color: #ff9800; } </style> </head> <body> <form action="success.php" method="POST"> <script src="https://checkout.razorpay.com/v1/checkout.js" data-key="<?php echo $data['key']?>" data-amount="<?php echo $data['amount']?>" data-currency="INR" data-name="<?php echo $data['name']?>" data-image="<?php echo $data['image']?>" data-description="<?php echo $data['description']?>" data-prefill.name="<?php echo $data['prefill']['name']?>" data-prefill.email="<?php echo $data['prefill']['email']?>" data-prefill.contact="<?php echo $data['prefill']['contact']?>" data-notes.shopping_order_id="3456" data-order_id="<?php echo $data['order_id']?>" <?php if ($displayCurrency == 'INR') { ?> data-display_amount="<?php echo $data['display_amount']?>" <?php } ?> <?php if ($displayCurrency == 'INR') { ?> data-display_currency="<?php echo $data['display_currency']?>" <?php } ?> > </script> <-- Any extra fields to be submitted with the form but not sent to Razorpay --> <input type="hidden" name="shopping_order_id" value="3456"> </form> </body> </html>

For your success.php

<?php $keyId = 'rzp_test_YaWprnDNnh4Lzx'; $keySecret = 'erkaYuufT9YwqlCfFZ0M3wQw'; $displayCurrency = 'INR'; //These should be commented out in production // This is for error reporting // Add it to config.php to report any errors error_reporting(E_ALL); ini_set('display_errors', 1); include "vendor/autoload.php"; session_start(); use Razorpay\Api\Api; use Razorpay\Api\Errors\SignatureVerificationError; $success = true; $error = "Payment Failed"; if (empty($_POST['razorpay_payment_id']) === false) { $api = new Api($keyId, $keySecret); try { // Please note that the razorpay order ID must // come from a trusted source (session here, but // could be database or something else) $attributes = array( 'razorpay_order_id' => $_SESSION['razorpay_order_id'], 'razorpay_payment_id' => $_POST['razorpay_payment_id'], 'razorpay_signature' => $_POST['razorpay_signature'] ); $api->utility->verifyPaymentSignature($attributes); } catch(SignatureVerificationError $e) { $success = false; $error = 'Razorpay Error : ' . $e->getMessage(); } } if ($success === true) { $html = "<p>Your payment was successful</p> <p>Payment ID: {$_POST['razorpay_payment_id']}</p>"; } else { $html = "<p>Your payment failed</p> <p>{$error}</p>"; } echo $html; ?>

Monjoti Mondol
14-04-2020

more_horiz Other Answers

Please lock LOGIN to Answer

announcement Recently Asked

question_answer
question_answer
question_answer


announcement Related Ques

question_answer
question_answer
question_answer
question_answer
question_answer
How to get date of every after 30 days using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
How to get the nested Array Data using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
How to properly get Pre Signed URL from s3 Bucket?
Ans(1) ₹0 check_circle_outline
question_answer
How much is the Margin Money of PMEGP Loan fo ST?
Ans(1) ₹0 check_circle_outline
question_answer
I want to register SENDER ID for my SNS SMS, on AWS.
Ans(1) ₹0 check_circle_outline
question_answer
Which is the right time to get EDP Training?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How much Amazon Cloud Hosting charges?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
php count variable values separated with comma
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
error timezone php or set time php timezone
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
What were the documents required for PMEGP Loan?
Ans(1) ₹0 check_circle_outline
question_answer
How to get the present full url using PHP
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
How to transfer data from one website to another?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
How to delete the terminated intences in AWS Amazon?
Ans(2) ₹0 check_circle_outline
question_answer
Which is the best website to learn MongoDB online?
Ans(3) ₹0 check_circle_outline
question_answer
How many countries Twilio can send SMS?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
What is the maximum transaction limits in RazorPay?
Ans(1) ₹0 check_circle_outline
question_answer
PHP SDK - Delete Object not working on s3 - error \
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Linux repeated Keyword problems.. how to solve it?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to create discount percentage using php?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
check if the radio input is checked using javascript
Ans(1) ₹0 check_circle_outline
question_answer
PHP code to get the token of Shiprocket.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
How to use webview on Android studio react native?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
What is SKU in shiprocket? From where I can get it?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to Propose Girls in this 2019?
Ans(2) ₹0 check_circle_outline
question_answer
How to Create Login and Logout system using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to integrate RazorPay with my website using PHP?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
1mb is equal to how much bytes?
Ans(1) ₹0 check_circle_outline
question_answer
How to delete projects from pinPoint on AWS?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
How to enable email functions on php?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
How to do Long poll using PHP and JavaScript?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
How to open a file using Ubuntu Terminal?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
How to send sms using Terminal on AWS SNS?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
How to install PHP?
Ans(0) ₹0
question_answer
question_answer
question_answer
question_answer
How to write ourl url for SEO on href attribute
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
question_answer
What is the response time of PHP $post variable?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
convert numbers into words in php
Ans(2) ₹0 check_circle_outline
question_answer
html css center horizontal list, menu system
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
question_answer
Which is the most played sports in the world?
Ans(2) ₹0 check_circle_outline
question_answer
question_answer
Need PHP functions to convert currencies.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
What is the amount of withdrawn in RazorPay?
Ans(1) ₹0 check_circle_outline
question_answer
Need codes to see the Country using Cloudflare.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
question_answer
Delete s3 object using PHP SDK.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Is RazorPay Really simple and esay to ues?
Ans(1) ₹0 check_circle_outline
question_answer
Multiple database vs single database on mysql?
Ans(1) ₹0 check_circle_outline
question_answer
Need codes to send SMS using AWS SNS in PHP.
Ans(1) ₹0 check_circle_outline
question_answer
.htaccess not working on my site .. what to do?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
Is this PMEGP Loan works Offline also?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
EDP Training Center in Kokrajhar area.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Which type of area is kown as Urban an Rural?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
The test asking
Ans(0) ₹0
question_answer
question_answer
Need ShipRocket support mobile number.
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
Do Aliens really exists?
Ans(3) ₹0 check_circle_outline
question_answer
How pyshic powers work? Is it real or just rumors?
Ans(3) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
Does girls like a man with a beard and mustache
Ans(2) ₹0 check_circle_outline
question_answer
PMEGP Loan Guide Lines.
Ans(1) ₹0 check_circle_outline
question_answer
What is La Liga?
Ans(1) ₹0 check_circle_outline
question_answer
Need official website links for PMEGP Loan.
Ans(1) ₹0 check_circle_outline
question_answer
multiple aws s3 bucket vs one aws s3 bucket?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
Can I create live straming videos using cloudfront?
Ans(1) ₹0 check_circle_outline
question_answer
question_answer
question_answer
question_answer
What is zend2?
Ans(0) ₹0
question_answer
How much tables one Mysql database can have?
Ans(1) ₹0 check_circle_outline
question_answer

WelCome to the World of Digital Expression

Transform your Works into Digital and Makes your life more easier.

123

Total users

123

Active users

5

Active Earners

location_on BTR,Assam,INDIA
(Bodoland)
email [email protected]
call +91 8486866741
rss_feed

Copyright ©2019-20 mritunjoy.com,All Rights Reserved