Subiendo proyecto completo sin restricciones de git ignore

This commit is contained in:
Jose Sanchez
2023-08-17 11:44:02 -04:00
parent a0d4f5ba3b
commit 20f1c60600
19921 changed files with 2509159 additions and 45 deletions

View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Anand Siddharth
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,321 @@
# Laravel Paytm Wallet
[![Latest Stable Version](https://poser.pugx.org/anandsiddharth/laravel-paytm-wallet/v/stable)](https://packagist.org/packages/anandsiddharth/laravel-paytm-wallet)
[![Total Downloads](https://poser.pugx.org/anandsiddharth/laravel-paytm-wallet/downloads)](https://packagist.org/packages/anandsiddharth/laravel-paytm-wallet)
[![License](https://poser.pugx.org/anandsiddharth/laravel-paytm-wallet/license)](https://packagist.org/packages/anandsiddharth/laravel-paytm-wallet)
[![Join the chat at https://gitter.im/laravel-paytm-wallet/Lobby](https://badges.gitter.im/laravel-paytm-wallet/Lobby.svg)](https://gitter.im/laravel-paytm-wallet/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
**For Laravel 5.0** use version `^1.0.0` <br />
**For Laravel 6.0** use version `^1.0.0` <br />
**For Laravel 7.0** use version `^1.0.0` <br />
**For Laravel 8.0** use version `^2.0.0` <br />
## Introduction
Integrate paytm wallet in your laravel application easily with this package. This package uses official Paytm PHP SDK's.
## License
Laravel Paytm Wallet open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
## Getting Started
To get started add the following package to your `composer.json` file using this command.
composer require anandsiddharth/laravel-paytm-wallet
## Configuring
**Note: For Laravel 5.5 and above auto-discovery takes care of below configuration.**
When composer installs Laravel Paytm Wallet library successfully, register the `Anand\LaravelPaytmWallet\PaytmWalletServiceProvider` in your `config/app.php` configuration file.
```php
'providers' => [
// Other service providers...
Anand\LaravelPaytmWallet\PaytmWalletServiceProvider::class,
],
```
Also, add the `PaytmWallet` facade to the `aliases` array in your `app` configuration file:
```php
'aliases' => [
// Other aliases
'PaytmWallet' => Anand\LaravelPaytmWallet\Facades\PaytmWallet::class,
],
```
#### Add the paytm credentials to the `.env` file
```bash
PAYTM_ENVIRONMENT=local
PAYTM_MERCHANT_ID=YOUR_MERCHANT_ID_HERE
PAYTM_MERCHANT_KEY=YOUR_SECRET_KEY_HERE
PAYTM_MERCHANT_WEBSITE=YOUR_MERCHANT_WEBSITE
PAYTM_CHANNEL=YOUR_CHANNEL_HERE
PAYTM_INDUSTRY_TYPE=YOUR_INDUSTRY_TYPE_HERE
```
#### One more step to go....
On your `config/services.php` add the following configuration
```php
'paytm-wallet' => [
'env' => env('PAYTM_ENVIRONMENT'), // values : (local | production)
'merchant_id' => env('PAYTM_MERCHANT_ID'),
'merchant_key' => env('PAYTM_MERCHANT_KEY'),
'merchant_website' => env('PAYTM_MERCHANT_WEBSITE'),
'channel' => env('PAYTM_CHANNEL'),
'industry_type' => env('PAYTM_INDUSTRY_TYPE'),
],
```
Note : All the credentials mentioned are provided by Paytm after signing up as merchant.
#### Laravel 7 Changes
Our package is comptible with Laravel 7 but same_site setting is changed in default Laravel installation, make sure you change `same_site` to `null` in `config/session.php` or callback won't include cookies and you will be logged out when a payment is completed
```php
<?php
use Illuminate\Support\Str;
return [
/...
'same_site' => null,
];
```
## Usage
### Making a transaction
```php
<?php
namespace App\Http\Controllers;
use PaytmWallet;
class OrderController extends Controller
{
/**
* Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function order()
{
$payment = PaytmWallet::with('receive');
$payment->prepare([
'order' => $order->id,
'user' => $user->id,
'mobile_number' => $user->phonenumber,
'email' => $user->email,
'amount' => $order->amount,
'callback_url' => 'http://example.com/payment/status'
]);
return $payment->receive();
}
/**
* Obtain the payment information.
*
* @return Object
*/
public function paymentCallback()
{
$transaction = PaytmWallet::with('receive');
$response = $transaction->response(); // To get raw response as array
//Check out response parameters sent by paytm here -> http://paywithpaytm.com/developer/paytm_api_doc?target=interpreting-response-sent-by-paytm
if($transaction->isSuccessful()){
//Transaction Successful
}else if($transaction->isFailed()){
//Transaction Failed
}else if($transaction->isOpen()){
//Transaction Open/Processing
}
$transaction->getResponseMessage(); //Get Response Message If Available
//get important parameters via public methods
$transaction->getOrderId(); // Get order id
$transaction->getTransactionId(); // Get transaction id
}
}
```
Make sure the `callback_url` you have mentioned while receiving payment is `post` on your `routes.php` file, Example see below:
```php
Route::post('/payment/status', [App\Http\Controllers\PaytmController::class,'paymentCallback'])->name('status');
```
Important: The `callback_url` must not be csrf protected [Check out here to how to do that](https://laracasts.com/discuss/channels/general-discussion/l5-disable-csrf-middleware-on-certain-routes)
### Get transaction status/information using order id
```php
<?php
namespace App\Http\Controllers;
use PaytmWallet;
class OrderController extends Controller
{
/**
* Obtain the transaction status/information.
*
* @return Object
*/
public function statusCheck(){
$status = PaytmWallet::with('status');
$status->prepare(['order' => $order->id]);
$status->check();
$response = $status->response(); // To get raw response as array
//Check out response parameters sent by paytm here -> http://paywithpaytm.com/developer/paytm_api_doc?target=txn-status-api-description
if($status->isSuccessful()){
//Transaction Successful
}else if($status->isFailed()){
//Transaction Failed
}else if($status->isOpen()){
//Transaction Open/Processing
}
$status->getResponseMessage(); //Get Response Message If Available
//get important parameters via public methods
$status->getOrderId(); // Get order id
$status->getTransactionId(); // Get transaction id
}
}
```
### Initiating Refunds
```php
<?php
namespace App\Http\Controllers;
use PaytmWallet;
class OrderController extends Controller
{
/**
* Initiate refund.
*
* @return Object
*/
public function refund(){
$refund = PaytmWallet::with('refund');
$refund->prepare([
'order' => $order->id,
'reference' => "refund-order-4", // provide refund reference for your future reference (should be unique for each order)
'amount' => 300, // refund amount
'transaction' => $order->transaction_id // provide paytm transaction id referring to this order
]);
$refund->initiate();
$response = $refund->response(); // To get raw response as array
if($refund->isSuccessful()){
//Refund Successful
}else if($refund->isFailed()){
//Refund Failed
}else if($refund->isOpen()){
//Refund Open/Processing
}else if($refund->isPending()){
//Refund Pending
}
}
}
```
### Check Refund Status
```php
<?php
namespace App\Http\Controllers;
use PaytmWallet;
class OrderController extends Controller
{
/**
* Initiate refund.
*
* @return Object
*/
public function refund(){
$refundStatus = PaytmWallet::with('refund_status');
$refundStatus->prepare([
'order' => $order->id,
'reference' => "refund-order-4", // provide reference number (the same which you have entered for initiating refund)
]);
$refundStatus->check();
$response = $refundStatus->response(); // To get raw response as array
if($refundStatus->isSuccessful()){
//Refund Successful
}else if($refundStatus->isFailed()){
//Refund Failed
}else if($refundStatus->isOpen()){
//Refund Open/Processing
}else if($refundStatus->isPending()){
//Refund Pending
}
}
}
```
### Customizing transaction being processed page
Considering the modern app user interfaces, default "transaction being processed page" is too dull which comes with this package. If you would like to modify this, you have the option to do so. Here's how:
You just need to change 1 line in you `OrderController`'s code.
```php
<?php
namespace App\Http\Controllers;
use PaytmWallet;
class OrderController extends Controller
{
/**
* Redirect the user to the Payment Gateway.
*
* @return Response
*/
public function order()
{
$payment = PaytmWallet::with('receive');
$payment->prepare([
'order' => $order->id,
'user' => $user->id,
'mobile_number' => $user->phonenumber,
'email' => $user->email,
'amount' => $order->amount,
'callback_url' => 'http://example.com/payment/status'
]);
return $payment->view('your_custom_view')->receive();
}
```
Here `$payment->receive()` is replaced with `$payment->view('your_custom_view')->receive()`. Replace `your_custom_view` with your view name which resides in your `resources/views/your_custom_view.blade.php`.
And in your view file make sure you have added this line of code before `</body>` (i.e. before closing body tag), which redirects to payment gateway.
`@yield('payment_redirect')`
Here's a sample custom view:
```html
<html>
<head>
</head>
<body>
<h1>Custom payment message</h1>
@yield('payment_redirect')
</body>
</html>
```
That's all folks!
## Support on Beerpay
[![Beerpay](https://beerpay.io/anandsiddharth/laravel-paytm-wallet/badge.svg?style=beer-square)](https://beerpay.io/anandsiddharth/laravel-paytm-wallet) [![Beerpay](https://beerpay.io/anandsiddharth/laravel-paytm-wallet/make-wish.svg?style=flat-square)](https://beerpay.io/anandsiddharth/laravel-paytm-wallet?focus=wish)

View File

@@ -0,0 +1,33 @@
{
"name": "anandsiddharth/laravel-paytm-wallet",
"description": "Integrate paytm wallet easily with this package. This package uses official Paytm PHP SDK's",
"license": "MIT",
"keywords": ["paytm wallet", "laravel"],
"authors": [
{
"name": "Anand Siddharth",
"email": "anandsiddharth21@gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=7.3.0",
"illuminate/support": ">=8.0",
"illuminate/contracts": ">=8.0"
},
"autoload": {
"psr-4": {
"Anand\\LaravelPaytmWallet\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Anand\\LaravelPaytmWallet\\PaytmWalletServiceProvider"
],
"aliases": {
"PaytmWallet": "Anand\\LaravelPaytmWallet\\Facades\\PaytmWallet"
}
}
}
}

View File

@@ -0,0 +1,154 @@
<?php
function encrypt_e_openssl($input, $ky){
$iv = "@@@@&&&&####$$$$";
$data = openssl_encrypt ( $input , "AES-128-CBC" , $ky, 0, $iv );
return $data;
}
function decrypt_e_openssl($crypt, $ky){
$iv = "@@@@&&&&####$$$$";
$data = openssl_decrypt ( $crypt , "AES-128-CBC" , $ky, 0, $iv );
return $data;
}
function generateSalt_e($length) {
$random = "";
srand((double) microtime() * 1000000);
$data = "AbcDE123IJKLMN67QRSTUVWXYZ";
$data .= "aBCdefghijklmn123opq45rs67tuv89wxyz";
$data .= "0FGH45OP89";
for ($i = 0; $i < $length; $i++) {
$random .= substr($data, (rand() % (strlen($data))), 1);
}
return $random;
}
function checkString_e($value) {
$myvalue = ltrim($value);
$myvalue = rtrim($myvalue);
if (in_array($myvalue, ['null', 'NULL'])) {
$myvalue = '';
}
return $myvalue;
}
function getChecksumFromArray($arrayList, $key, $sort=1) {
if ($sort != 0) {
ksort($arrayList);
}
$str = getArray2Str($arrayList);
$salt = generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = encrypt_e_openssl($hashString, $key);
return $checksum;
}
function getChecksumFromString($str, $key) {
$salt = generateSalt_e(4);
$finalString = $str . "|" . $salt;
$hash = hash("sha256", $finalString);
$hashString = $hash . $salt;
$checksum = encrypt_e_openssl($hashString, $key);
return $checksum;
}
function verifychecksum_e($arrayList, $key, $checksumvalue) {
$arrayList = removeCheckSumParam($arrayList);
ksort($arrayList);
$str = getArray2Str($arrayList);
$paytm_hash = decrypt_e_openssl($checksumvalue, $key);
$salt = substr($paytm_hash, -4);
$finalString = $str . "|" . $salt;
$website_hash = hash("sha256", $finalString);
$website_hash .= $salt;
$validFlag = "FALSE";
if ($website_hash == $paytm_hash) {
$validFlag = "TRUE";
} else {
$validFlag = "FALSE";
}
return $validFlag;
}
function verifychecksum_eFromStr($str, $key, $checksumvalue) {
$paytm_hash = decrypt_e_openssl($checksumvalue, $key);
$salt = substr($paytm_hash, -4);
$finalString = $str . "|" . $salt;
$website_hash = hash("sha256", $finalString);
$website_hash .= $salt;
$validFlag = "FALSE";
if ($website_hash == $paytm_hash) {
$validFlag = "TRUE";
} else {
$validFlag = "FALSE";
}
return $validFlag;
}
function getArray2Str($arrayList) {
$paramStr = "";
$flag = 1;
foreach ($arrayList as $key => $value) {
if ($flag) {
$paramStr .= checkString_e($value);
$flag = 0;
} else {
$paramStr .= "|" . checkString_e($value);
}
}
return $paramStr;
}
function redirect2PG($paramList, $key) {
$hashString = getchecksumFromArray($paramList);
$checksum = encrypt_e_openssl($hashString, $key);
}
function removeCheckSumParam($arrayList) {
if (isset($arrayList["CHECKSUMHASH"])) {
unset($arrayList["CHECKSUMHASH"]);
}
return $arrayList;
}
function getTxnStatus($requestParamList) {
return callAPI(PAYTM_STATUS_QUERY_URL, $requestParamList);
}
function initiateTxnRefund($requestParamList) {
$CHECKSUM = getChecksumFromArray($requestParamList,PAYTM_MERCHANT_KEY,0);
$requestParamList["CHECKSUM"] = $CHECKSUM;
return callAPI(PAYTM_REFUND_URL, $requestParamList);
}
function callAPI($apiURL, $requestParamList) {
$jsonResponse = "";
$responseParamList = array();
$JsonData =json_encode($requestParamList);
$postData = 'JsonData='.urlencode($JsonData);
$ch = curl_init($apiURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($postData))
);
$jsonResponse = curl_exec($ch);
$responseParamList = json_decode($jsonResponse,true);
return $responseParamList;
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Anand\LaravelPaytmWallet\Contracts;
interface Factory
{
/**
* Get Paytm Wallet Provider
*
* @param string $driver
* @return \Anand\LaravelPaytmWallet\Contracts\Provider
*/
public function driver($do = null);
}

View File

@@ -0,0 +1,14 @@
<?php
namespace Anand\LaravelPaytmWallet\Contracts;
interface Provider
{
/**
* Return raw response.
*
* @return object
*/
public function response();
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Anand\LaravelPaytmWallet\Facades;
use Illuminate\Support\Facades\Facade;
/**
* @see \Laravel\Socialite\SocialiteManager
*/
class PaytmWallet extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
const STATUS_SUCCESSFUL = 'TXN_SUCCESS';
const STATUS_FAILURE = 'TXN_FAILURE';
const STATUS_OPEN = 'OPEN';
const STATUS_PENDING = 'PENDING';
const RESPONSE_SUCCESSFUL="01";
const RESPONSE_CANCELLED = "141";
const RESPONSE_FAILED = "227";
const RESPONSE_PAGE_CLOSED = "810";
const REPSONSE_REFUND_ALREADY_RAISED = "617";
const RESPONSE_CANCELLED_CUSTOMER = "8102";
const RESPONSE_CANCELLED_CUSTOMER_INSUFFICIENT_BALANCE = "8103";
protected static function getFacadeAccessor()
{
return 'Anand\LaravelPaytmWallet\Contracts\Factory';
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Anand\LaravelPaytmWallet;
use Illuminate\Support\Manager;
use Illuminate\Http\Request;
class PaytmWalletManager extends Manager implements Contracts\Factory{
protected $config;
public function with($driver){
return $this->driver($driver);
}
protected function createReceiveDriver(){
$this->config = $this->container['config']['services.paytm-wallet'];
return $this->buildProvider(
'Anand\LaravelPaytmWallet\Providers\ReceivePaymentProvider',
$this->config
);
}
protected function createStatusDriver(){
$this->config = $this->container['config']['services.paytm-wallet'];
return $this->buildProvider(
'Anand\LaravelPaytmWallet\Providers\StatusCheckProvider',
$this->config
);
}
protected function createBalanceDriver(){
$this->config = $this->container['config']['services.paytm-wallet'];
return $this->buildProvider(
'Anand\LaravelPaytmWallet\Providers\BalanceCheckProvider',
$this->config
);
}
protected function createAppDriver(){
$this->config = $this->container['config']['services.paytm-wallet'];
return $this->buildProvider(
'Anand\LaravelPaytmWallet\Providers\PaytmAppProvider',
$this->config
);
}
protected function createRefundDriver() {
$this->config = $this->container['config']['services.paytm-wallet'];
return $this->buildProvider(
'Anand\LaravelPaytmWallet\Providers\RefundPaymentProvider',
$this->config
);
}
protected function createRefundStatusDriver(){
$this->config = $this->container['config']['services.paytm-wallet'];
return $this->buildProvider(
'Anand\LaravelPaytmWallet\Providers\RefundStatusCheckProvider',
$this->config
);
}
public function getDefaultDriver(){
throw new \Exception('No driver was specified. - Laravel Paytm Wallet');
}
public function buildProvider($provider, $config){
return new $provider(
$this->container['request'],
$config
);
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace Anand\LaravelPaytmWallet;
use Illuminate\Support\ServiceProvider;
class PaytmWalletServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Register bindings in the container.
*
* @return void
*/
public function register()
{
$this->app->singleton('Anand\LaravelPaytmWallet\Contracts\Factory', function ($app) {
// $this->app->singleton('PaytmWallet', function ($app) {
return new PaytmWalletManager($app);
});
}
public function boot(){
$this->loadViewsFrom(__DIR__.'/resources/views', 'paytmwallet');
}
public function provides(){
return ['Anand\LaravelPaytmWallet\Contracts\Factory'];
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Anand\LaravelPaytmWallet\Providers;
use Illuminate\Http\Request;
// require __DIR__.'/../../lib/encdec_paytm.php';
class BalanceCheckProvider extends PaytmWalletProvider{
private $parameters = null;
public function prepare($params = array()){
$defaults = [
'token' => NULL,
];
$_p = array_merge($defaults, $params);
foreach ($_p as $key => $value) {
if ($value == NULL) {
throw new \Exception(' \''.$key.'\' parameter not specified in array passed in prepare() method');
return false;
}
}
$this->parameters = $_p;
return $this;
}
public function check(){
if ($this->parameters == null) {
throw new \Exception("prepare() method not called");
}
return $this->beginTransaction();
}
private function beginTransaction(){
$params = [
'MID' => $this->merchant_id,
'TOKEN' => $this->parameters['token']
];
return $this->api_call($this->paytm_balance_check_url, $params);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Anand\LaravelPaytmWallet\Providers;
use Illuminate\Http\Request;
class PaytmAppProvider extends PaytmWalletProvider{
public function generate(Request $request){
$checksum = getChecksumFromArray($request->all(), $this->merchant_key);
return response()->json([ 'CHECKSUMHASH' => $checksum, 'ORDER_ID' => $request->get('ORDER_ID'), 'payt_STATUS' => '1' ]);
}
public function verify(Request $request, $success = null, $error = null){
$paramList = $request->all();
$return_array = $request->all();
$paytmChecksum = $request->get('CHECKSUMHASH');
$isValidChecksum = verifychecksum_e($paramList, $this->merchant_key, $paytmChecksum);
if ($isValidChecksum) {
if ($success != null && is_callable($success)) {
$success();
}
}else{
if ($error != null && is_callable($error)) {
$error();
}
}
$return_array["IS_CHECKSUM_VALID"] = $isValidChecksum ? "Y" : "N";
unset($return_array["CHECKSUMHASH"]);
$encoded_json = htmlentities(json_encode($return_array));
return view('paytmwallet::app_redirect')->with('json', $encoded_json);
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Anand\LaravelPaytmWallet\Providers;
use Anand\LaravelPaytmWallet\Contracts\Provider as ProviderContract;
use Illuminate\Http\Request;
require __DIR__.'/../../lib/encdec_paytm.php';
class PaytmWalletProvider implements ProviderContract {
protected $request;
protected $response;
protected $paytm_txn_url;
protected $paytm_txn_status_url;
protected $paytm_refund_url;
protected $paytm_refund_status_url;
protected $paytm_balance_check_url;
protected $merchant_key;
protected $merchant_id;
protected $merchant_website;
protected $industry_type;
protected $channel;
public function __construct(Request $request, $config){
$this->request = $request;
if ($config['env'] == 'production') {
$domain = 'securegw.paytm.in';
}else{
$domain = 'securegw-stage.paytm.in';
}
$this->paytm_txn_url = 'https://'.$domain.'/theia/processTransaction';
$this->paytm_txn_status_url = 'https://'.$domain.'/merchant-status/getTxnStatus';
$this->paytm_refund_url = 'https://'.$domain.'/refund/HANDLER_INTERNAL/REFUND';
$this->paytm_refund_status_url = 'https://'.$domain.'/refund/HANDLER_INTERNAL/getRefundStatus';
$this->paytm_balance_check_url = 'https://'.$domain.'/refund/HANDLER_INTERNAL/getRefundStatus';
$this->merchant_key = $config['merchant_key'];
$this->merchant_id = $config['merchant_id'];
$this->merchant_website = $config['merchant_website'];
$this->industry_type = $config['industry_type'];
$this->channel = $config['channel'];
}
public function response(){
$checksum = $this->request->get('CHECKSUMHASH');
if(verifychecksum_e($this->request->post(), $this->merchant_key, $checksum) == "TRUE"){
return $this->response = $this->request->post();
}
throw new \Exception('Invalid checksum');
}
public function getResponseMessage() {
return $this->response()['RESPMSG'];
}
public function api_call($url, $params){
return callAPI($url, $params);
}
public function api_call_new($url, $params){
return callAPI($url, $params);
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace Anand\LaravelPaytmWallet\Providers;
use Anand\LaravelPaytmWallet\Facades\PaytmWallet;
use Anand\LaravelPaytmWallet\Traits\HasTransactionStatus;
use Illuminate\Http\Request;
class ReceivePaymentProvider extends PaytmWalletProvider{
use HasTransactionStatus;
private $parameters = null;
private $view = 'paytmwallet::transact';
public function prepare($params = array()){
$defaults = [
'order' => NULL,
'user' => NULL,
'amount' => NULL,
'callback_url' => NULL,
'email' => NULL,
'mobile_number' => NULL,
];
$_p = array_merge($defaults, $params);
foreach ($_p as $key => $value) {
if ($value == NULL) {
throw new \Exception(' \''.$key.'\' parameter not specified in array passed in prepare() method');
return false;
}
}
$this->parameters = $_p;
return $this;
}
public function receive(){
if ($this->parameters == null) {
throw new \Exception("prepare() method not called");
}
return $this->beginTransaction();
}
public function view($view) {
if($view) {
$this->view = $view;
}
return $this;
}
private function beginTransaction(){
$params = [
'REQUEST_TYPE' => 'DEFAULT',
'MID' => $this->merchant_id,
'ORDER_ID' => $this->parameters['order'],
'CUST_ID' => $this->parameters['user'],
'INDUSTRY_TYPE_ID' => $this->industry_type,
'CHANNEL_ID' => $this->channel,
'TXN_AMOUNT' => $this->parameters['amount'],
'WEBSITE' => $this->merchant_website,
'CALLBACK_URL' => $this->parameters['callback_url'],
'MOBILE_NO' => $this->parameters['mobile_number'],
'EMAIL' => $this->parameters['email'],
];
return view('paytmwallet::form')->with('view', $this->view)->with('params', $params)->with('txn_url', $this->paytm_txn_url)->with('checkSum', getChecksumFromArray($params, $this->merchant_key));
}
public function getOrderId(){
return $this->response()['ORDERID'];
}
public function getTransactionId(){
return $this->response()['TXNID'];
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace Anand\LaravelPaytmWallet\Providers;
use Anand\LaravelPaytmWallet\Facades\PaytmWallet;
use Anand\LaravelPaytmWallet\Traits\HasTransactionStatus;
use Illuminate\Http\Request;
class RefundPaymentProvider extends PaytmWalletProvider{
use HasTransactionStatus;
private $parameters = null;
protected $response;
public function prepare($params = array()){
$defaults = [
'order' => NULL,
'reference' => NULL,
'amount' => NULL,
'transaction' => NULL
];
$_p = array_merge($defaults, $params);
foreach ($_p as $key => $value) {
if ($value == NULL) {
throw new \Exception(' \''.$key.'\' parameter not specified in array passed in prepare() method');
return false;
}
}
$this->parameters = $_p;
return $this;
}
private function beginTransaction(){
$params = array();
$params["MID"] = $this->merchant_id;
$params["ORDERID"] = $this->parameters['order'];
$params["REFID"] = $this->parameters['reference'];
$params["TXNTYPE"] = 'REFUND';
$params["REFUNDAMOUNT"] = $this->parameters['amount'];
$params["TXNID"] = $this->parameters['transaction'];
$chk = getChecksumFromArray($params, $this->merchant_key);
$params['CHECKSUM'] = $chk;
$this->response = $this->api_call_new($this->paytm_refund_url, $params);
return $this;
}
public function initiate(){
if ($this->parameters == null) {
throw new \Exception("prepare() method not called");
}
$this->beginTransaction();
return $this;
}
public function response(){
return $this->response;
}
public function isRefundAlreadyRaised() {
if ($this->isFailed() && $this->response()['RESPCODE'] == PaytmWallet::REPSONSE_REFUND_ALREADY_RAISED) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace Anand\LaravelPaytmWallet\Providers;
use Anand\LaravelPaytmWallet\Traits\HasTransactionStatus;
use Illuminate\Http\Request;
class RefundStatusCheckProvider extends PaytmWalletProvider{
use HasTransactionStatus;
private $parameters = null;
protected $response;
public function prepare($params = array()){
$defaults = [
'order' => NULL,
'reference' => NULL,
];
$_p = array_merge($defaults, $params);
foreach ($_p as $key => $value) {
if ($value == NULL) {
throw new \Exception(' \''.$key.'\' parameter not specified in array passed in prepare() method');
return false;
}
}
$this->parameters = $_p;
return $this;
}
public function check(){
if ($this->parameters == null) {
throw new \Exception("prepare() method not called");
}
return $this->beginTransaction();
}
private function beginTransaction(){
$params = array(
'MID' => $this->merchant_id,
'ORDERID' => $this->parameters['order'],
'REFID' => $this->parameters['reference']
);
$chk = getChecksumFromArray($params, $this->merchant_key);
$params['CHECKSUM'] = $chk;
$this->response = $this->api_call_new($this->paytm_txn_status_url, $params);
return $this;
}
public function response(){
return $this->response;
}
public function getOrderId(){
return $this->response()['ORDERID'];
}
public function getTransactionId(){
return $this->response()['TXNID'];
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace Anand\LaravelPaytmWallet\Providers;
use Anand\LaravelPaytmWallet\Traits\HasTransactionStatus;
use Illuminate\Http\Request;
class StatusCheckProvider extends PaytmWalletProvider{
use HasTransactionStatus;
private $parameters = null;
protected $response;
public function prepare($params = array()){
$defaults = [
'order' => NULL,
];
$_p = array_merge($defaults, $params);
foreach ($_p as $key => $value) {
if ($value == NULL) {
throw new \Exception(' \''.$key.'\' parameter not specified in array passed in prepare() method');
return false;
}
}
$this->parameters = $_p;
return $this;
}
public function check(){
if ($this->parameters == null) {
throw new \Exception("prepare() method not called");
}
return $this->beginTransaction();
}
private function beginTransaction(){
$params = array(
'MID' => $this->merchant_id,
'ORDERID' => $this->parameters['order']
);
$chk = getChecksumFromArray($params, $this->merchant_key);
$params['CHECKSUMHASH'] = $chk;
$this->response = $this->api_call_new($this->paytm_txn_status_url, $params);
return $this;
}
public function response(){
return $this->response;
}
public function getOrderId(){
return $this->response()['ORDERID'];
}
public function getTransactionId(){
return $this->response()['TXNID'];
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Anand\LaravelPaytmWallet\Traits;
use Anand\LaravelPaytmWallet\Facades\PaytmWallet;
trait HasTransactionStatus {
public function isOpen(){
if ($this->response['STATUS'] == PaytmWallet::STATUS_OPEN){
return true;
}
return false;
}
public function isFailed(){
if ($this->response['STATUS'] == PaytmWallet::STATUS_FAILURE) {
return true;
}
return false;
}
public function isSuccessful(){
if($this->response['STATUS'] == PaytmWallet::STATUS_SUCCESSFUL){
return true;
}
return false;
}
public function isPending(){
if($this->response['STATUS'] == PaytmWallet::STATUS_PENDING){
return true;
}
return false;
}
}

View File

@@ -0,0 +1,18 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-I">
<title>Paytm</title>
<script type="text/javascript">
function response(){
return document.getElementById('response').value;
}
</script>
</head>
<body>
Redirect back to the app<br>
<form name="frm" method="post">
<input type="hidden" id="response" name="responseField" value='{{$json}}'>
</form>
</body>
</html>

View File

@@ -0,0 +1,16 @@
@extends($view)
@section('payment_redirect')
<form method="post" action="{{$txn_url}}" name="f1" style="visibility: hidden;">
<table border="1">
<tbody>
@foreach ($params as $key => $value)
<input type="hidden" name="{{$key}}" value="{{$value}}" />
@endforeach
<input type="hidden" name="CHECKSUMHASH" value="{{$checkSum}}">
</tbody>
</table>
<script type="text/javascript">
document.f1.submit();
</script>
</form>
@stop

View File

@@ -0,0 +1,12 @@
<html>
<head>
<title>Merchant Check Out Page</title>
</head>
<body>
<br>
<br>
<center><h1>Your transaction is being processed!!!</h1></center>
<center><h2>Please do not refresh this page...</h2></center>
@yield('payment_redirect')
</body>
</html>