【问题标题】:Session automatically gets destroyed on payment gateway call back in Laravel会话在 Laravel 中的支付网关回调时自动销毁
【发布时间】:2020-07-31 22:57:33
【问题描述】:

我正在尝试将 CCavenue.com 支付网关集成到我的 Laravel 7 项目中。我面临的唯一问题是回调 url,在从支付网关获取发布数据后,活动会话会自动销毁。我还在中间件中添加了 CSRF 异常。

PayController(生成付款请求和 URL)

<?php

namespace App\Http\Controllers\user;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class PayController extends Controller

{

public function __construct()
{
    $this->middleware('auth:web');
}


public function index()
{

    return view('user.addmoney');
}


public function addmoney(Request $request)
{
    $validatedData = $request->validate([
        'Amount' => 'required|numeric',
    ]);

    $Amount = $validatedData['Amount'];

    $working_key = '5dfsdfsdf3323423'; //Shared by CCAVENUES
    $access_code = 'asdasdas234234'; //Shared by CCAVENUES

    echo $merchant_data = 'merchant_id=555&order_id=123654789&amount=' . $Amount . '&currency=AED&redirect_url=http://localhost:8000/addmoneyresponse&cancel_url=http://localhost:8000/addmoneyresponse&language=EN&billing_name=Charli&billing_address=Room no 1101, near Railway station Ambad&billing_city=Indore&billing_country=India&billing_tel=9595226054&billing_email=atul.kadam@avenues.info&promo_code=&customer_identifier=&integration_type=iframe_normal&';
    $encrypted_data =  $this->encrypt($merchant_data, $working_key); // Method for encrypting the data.


    echo "<br>";

    $production_url = 'https://secure.ccavenue.ae/transaction/transaction.do?command=initiateTransaction&encRequest=' . $encrypted_data . '&access_code=' . $access_code;

    return redirect()->away($production_url);


    //return view('user.addmoneyrequest', compact('production_url'));


}






function encrypt($plainText, $key)
{
    $key = $this->hextobin(md5($key));
    $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
    $openMode = openssl_encrypt($plainText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);
    $encryptedText = bin2hex($openMode);
    return $encryptedText;
}

function decrypt($encryptedText, $key)
{
    $key = $this->hextobin(md5($key));
    $initVector = pack("C*", 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
    $encryptedText = $this->hextobin($encryptedText);
    $decryptedText = openssl_decrypt($encryptedText, 'AES-128-CBC', $key, OPENSSL_RAW_DATA, $initVector);
    return $decryptedText;
}
//*********** Padding Function *********************

function pkcs5_pad($plainText, $blockSize)
{
    $pad = $blockSize - (strlen($plainText) % $blockSize);
    return $plainText . str_repeat(chr($pad), $pad);
}

//********** Hexadecimal to Binary function for php 4.0 version ********

function hextobin($hexString)
{
    $length = strlen($hexString);
    $binString = "";
    $count = 0;
    while ($count < $length) {
        $subString = substr($hexString, $count, 2);
        $packedString = pack("H*", $subString);
        if ($count == 0) {
            $binString = $packedString;
        } else {
            $binString .= $packedString;
        }

        $count += 2;
    }
    return $binString;
    }
}

PayResponseController(流程回调)

<?php

namespace App\Http\Controllers\user;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;


class PayResponseController extends Controller
{


    public function addmoneyresponse(Request $request)
    {


        return $request->all();

        //return view('user.dashboard');



    }
}

【问题讨论】:

  • 注意您应该避免在诸如 stackoverflow 之类的论坛上发布敏感信息和密码。用其他东西替换它们并提到它们是所需的代码
  • 是的,这些只是沙盒密码,所以完全没问题

标签: php laravel payment-gateway laravel-7 ccavenue


【解决方案1】:

我遇到了类似的问题,解决方案是让登录按钮记住我设置为 true。记住我的令牌仅在用户注销后才会更改。

【讨论】:

    【解决方案2】:

    Laravel 7 中有一个名为 same_site 的选项在您的 config/session.php 设置中已在默认 Laravel 安装中更改,请确保将 same_site 更改为 null 否则回调不会包含 cookie,您将在付款完成后退出。所以在你的config/session.php更新里面

    return [
      ...
      ...
      'same_site' => null,
      ...
      ...
    ];
    

    更新:一些支付网关导致了同样的问题,所以即使在将 same_site 设置为 null 后,问题也没有解决,所以另一个解决方案可以是

    'secure' => env('SESSION_SECURE_COOKIE', null) 
    

    将此“安全”选项设置为 false 而不是 null

    'secure' => env('SESSION_SECURE_COOKIE', false)
    

    【讨论】:

      【解决方案3】:

      我遇到了这个问题,我为回调添加了一个 API 路由并在其中返回一个视图:

      routes 文件夹中,api.php 文件:

      Route::post('/callback','callbackController@callback');
      

      内部controller

      public function callback(Request $request) {
      
      // some code here 
      
      return view('callback');
      }
      

      并将此设置为回调:

      http://yourdomain.com/api/callback
      

      【讨论】:

        【解决方案4】:

        在 session.php 中使用 'samesite' => null 而不是 'samesite' => 'lax'

        【讨论】:

          猜你喜欢
          • 2015-11-26
          • 2012-02-15
          • 2015-03-20
          • 2019-10-19
          • 2022-08-20
          • 1970-01-01
          • 1970-01-01
          • 2016-03-21
          • 2014-10-23
          相关资源
          最近更新 更多