1. Go to this page and download the library: Download techtailor/laravel-paytm library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
PAYTM_ENV - Your payments environment. Can be set to "testing" or "production".
PAYTM_MERCHANT_ID - Your Unique Merchant ID from Paytm. Use the test id and key when in the testing environment.
PAYTM_MERCHANT_KEY - Your Unique Merchant Key from Paytm .Keep it safe.
PAYTM_WEBSITE - Set it to "WEBSTAGING" for testing environment or to "DEFAULT" when in the production environment. You can also use a custom one after setting it up in your Paytm Bussiness Dashboard.
PAYTM_CALLBACK_URL - The url to redirect to after payment is completed. Ex: https://yoursite.com/callback/paytm
PAYTM_ORDER_ID_PREFIX - Your custom prefix for the order id. Can be anything.
// Import facade at the top
use TechTailor\Paytm\Facades\Paytm;
$amount = '1.0'; // Amount to charge the customer. Can be an integer or a float value upto 2 decimals.
$customer = array(
'custId' => $custId, // MANDATORY - A unique identifier generated by your system.
'mobile' => $mobile, // OPTIONAL - Required in case of EMI Payment Option is selected.
'email' => $email, // OPTIONAL
'firstName' => $firstName, // OPTIONAL
'lastName' => $lastName // OPTIONAL
);
// This is an optional url which you can pass to customize the callback url per transaction.
// If null is provided, the app will use the callback url set in the config/paytm.php file.
$callback = 'https://yourwebsite.com/callback/new';
// Call the getTransactionToken function.
$response = Paytm::getTransactionToken($amount, $customer, $callback);
$response['success'] => true, // true or false
$response['orderId'] => $orderId, // unique order_id generated for this txn
$response['txnToken'] => $token, // unique transaction token. Only if 'success' => true
$response['amount'] => $amount, // amount to be paid
$response['message'] => 'Success', // a response message according to the result. Ex: Success, System error, Failed, etc.
// Somewhere in your page
<button type="button" id="JsCheckoutPayment" name="submit" class="btn btn-primary">Pay Now</button>
// Before the closing </body> tag
<script type="application/javascript">
document.getElementById("JsCheckoutPayment").addEventListener("click", function() {
var orderId = "{{ $response['orderId'] }}";
var txnToken = "{{ $response['txnToken'] }}";
var amount = "{{ $response['amount'] }}";
openJsCheckoutPopup(orderId, txnToken, amount);
}
);
</script>
// Somewhere in your page
<button type="button" id="JsCheckoutPayment" name="submit" class="btn btn-primary">Pay Now</button>
// Before the closing </body> tag
<script type="application/javascript">
document.getElementById("JsCheckoutPayment").addEventListener("click", function() {
var orderId = "{{ $response['orderId'] }}";
var txnToken = "{{ $response['txnToken'] }}";
var amount = "{{ $response['amount'] }}";
// Pass an additional "false" attribute which marks redirect as false.
openJsCheckoutPopup(orderId, txnToken, amount, false);
}
);
// To be executed upon completion of the payment (only if false is passed above).
function paymentCompleted(paymentStatus) {
window.Paytm.CheckoutJS.close(); // Close the Paytm PG Pop-up.
console.log(paymentStatus); // Log or use the payment status/details returned.
}
</script>
$response['success'] => true, // true or false
$response['orderId'] => $orderId, // unique order_id generated for this txn
$response['txnToken'] => $token, // unique transaction token. Only if 'success' => true
$response['amount'] => $amount, // amount to be paid
$response['message'] => '', // a response message according to the result.