https://github.com/techtailor/laravel-paytm
A Laravel wrapper for the Paytm Payment Gateway (PG). Now quickly setup and accept UPI, Credit/Debit Card, Net Banking & EMI payments via Paytm PG starting today.
https://github.com/techtailor/laravel-paytm
laravel laravel-paytm payment-gateway payments paytm paytm-payment-gateway paytm-pg
Last synced: 4 months ago
JSON representation
A Laravel wrapper for the Paytm Payment Gateway (PG). Now quickly setup and accept UPI, Credit/Debit Card, Net Banking & EMI payments via Paytm PG starting today.
- Host: GitHub
- URL: https://github.com/techtailor/laravel-paytm
- Owner: TechTailor
- License: mit
- Created: 2022-08-24T16:28:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-08T01:58:59.000Z (almost 3 years ago)
- Last Synced: 2024-06-04T16:34:29.421Z (about 1 year ago)
- Topics: laravel, laravel-paytm, payment-gateway, payments, paytm, paytm-payment-gateway, paytm-pg
- Language: PHP
- Homepage:
- Size: 20.5 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README

[](https://packagist.org/packages/techtailor/laravel-paytm)
[](https://github.com/TechTailor/Laravel-Paytm/issues)
[](license.md)
[](https://packagist.org/packages/techtailor/laravel-paytm)This package provides a simple Laravel wrapper for the Paytm PG (Payment Gateway) to allow you to easily spin up a new laravel app and start accepting UPI, Wallet, Credit/Debit, Net Banking & EMI payments without any hassle. Before getting started, be sure to go through the Paytm [documentation](https://business.paytm.com/docs/js-checkout?ref=jsCheckoutDoc) to have a better understanding.
***Note:** You also need to have a valid Paytm Business Merchant Account to start using the Paytm PG (Payment Gatteway)*
## Installation
You can install the package via composer:
```bash
composer require TechTailor/Laravel-Paytm
```You can publish the config file with:
```bash
php artisan vendor:publish --tag="paytm-config"
```You must publish the assets file using:
```bash
php artisan vendor:publish --tag=paytm-assets
```## Usage
Before you can start using this package, you must familiarize yourself with the payment workflow for the Paytm PG. Read official documentation [here](https://business.paytm.com/docs/js-checkout?ref=jsCheckoutDoc)To give a basic gist, you generate a unique payment token by providing the amount and customer details, then use the txnId and orderId received in the response to initiate the Checkout JS in your front-end.
### Setup Environment
Add the following variables to your .env file, or alternatively, you can publish the config file and update it accordingly.
```php
PAYTM_ENV="testing"
PAYTM_MERCHANT_ID="_YOUR_MERCHANT_ID_FROM_PAYTM_"
PAYTM_MERCHANT_KEY="_YOUR_MERCHANT_KEY_FROM_PAYTM_"
PAYTM_WEBSITE="WEBSTAGING"
PAYTM_CALLBACK_URL="_YOUR_APP_CALLBACK_URL_"
PAYTM_ORDER_ID_PREFIX="PAYTM_ORDERID_"
```
A bit of explainantion -
```php
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.
```### Step # 1 - Generate a Token
```php
// 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);
```
The **$response** will return an array containing:
```php
$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.
```### Step # 2 - Invoking Payment Page & Collecting Payment
You can read detailed documentation for Paytm Checkout JS [here.](https://business.paytm.com/docs/jscheckout-invoke-payment?ref=jsCheckoutdoc)#### Setup Frontend
Start by adding the `@paytmScripts` tag into the `` tag of your page. For ex:```php
Laravel
@paytmScripts```
Next, to initiate the Checkout Payment Page, you have 2 available methods -
##### Method # 1
This method will invoke the payment gateway and upon completion, will redirect the user to the callback url set earlier (or in the config file).
To achieve that, you need to call the `openJsCheckoutPopup(orderId, txnToken, amount)` function and pass it the `orderId`, `txntoken` and the `amount` received in **Step # 1**.
```php
// Somewhere in your page
Pay Now// Before the closing tag
document.getElementById("JsCheckoutPayment").addEventListener("click", function() {
var orderId = "{{ $response['orderId'] }}";
var txnToken = "{{ $response['txnToken'] }}";
var amount = "{{ $response['amount'] }}";
openJsCheckoutPopup(orderId, txnToken, amount);
}
);```
Upon clicking the `Pay Now` button, a pop-up for the Paytm PG will open with all the options to make the payment. Once the payment is complete, you will be redirected to the `callback_url` set in the .env file as `PAYTM_CALLBACK_URL`.##### Method # 2
This method will allow you to handle the response on the same page (and ignore any callback urls set for this transaction). Useful when you want to process transaction without a redirect.
```php
// Somewhere in your page
Pay Now// Before the closing