未收到通知回调

时间:2018-04-26 12:09:38

标签: php laravel api payment-gateway payment-processing

我正在使用这个laravel包“https://github.com/kanazaca/easypay”来使用Easypay API创建MB引用。

我有这个方法来创建引用:

public function generateReference()
{

    $amount = Session::get('total');

    $payment_info = [
        't_value' => $amount,
        'o_obs' => '',
        't_key' => 1
    ];

    $easypay = new EasyPay($payment_info);

    $reference = $easypay->createReference();

    Session::put('entity', $reference['ep_entity']);
    Session::put('reference', $reference['ep_reference']);
    Session::put('value', $reference['ep_value']);

}

这个代码工作正常我得到了一些可以用MB或信用卡支付的参考代码。

然后,当付款时,easypay将调用“通知URL”。 我们应该在“URL配置”下配置easypay的后台。  因为当easypay服务收到付款时,他们会调用我们提供的URL。所以我在easypay的后台定义了一个url并在项目中创建了一个路由:

Route::get('/easypay/notification-callback', [
    'uses' => 'PaymentController@receiveNotifications',
    'as'   =>'mb.notifications'
]);

在api后台有一个模拟付款的按钮,点击此按钮后没有任何反应,如果我手动访问“http://....ngrok.io/easypay/notification-callback”,它会显示一个空数组:

[]

但是在文档(https://docs.easypay.pt/workflow/payment-notification)中说当Easypay调用此端点时,它会附带一些参数:“ep_cin”,“ep_user”和“ep_doc”,这些参数在此过程中是必需的。所以它不应该出现一个空数组。

你知道这可能是什么问题吗?我是一个初学者的API,所以我不知道问题是什么。

PaymentController receiveNotifications()方法:

 public function receiveNotifications(Request $request)
    {
        dd($request->all());

         //$easypay = new EasyPay($payment_info);

        //$xml = $easypay->processPaymentInfo();

        //return \Response::make($xml, '200')->header('Content-Type', 'text/xml'); //must return in text/xml for easypay
    }

带日志的receiveNotifications()方法:

public function receiveNotifications(Request $request)
    {

        //dd($request->all());
        Log::info('Showing info: ' .var_export($request->all(),true));

        $payment_info = [
            'ep_cin' => $request->ep_cin,
            'ep_user' => $request->ep_user,
            'ep_doc'  => $request->ep_doc
        ];

        Log::info('Showing info: ' .var_export($payment_info,true));

        //dd($payment_info);

        $easypay = new EasyPay($payment_info);

        $xml = $easypay->processPaymentInfo();

        return \Response::make($xml, '200')->header('Content-Type', 'text/xml'); //must return in text/xml for easypay
    }

1 个答案:

答案 0 :(得分:0)

会话保存在访问启动付款的网站的用户的会话文件中。

如果您在那里做任何事情,receiveNotifications将从属于支付网关服务器的会话文件中调用数据。数据不匹配,因为两者之间并不了解。

此外,您的请求处理中可能没有Session::save()将会话数据写入文件。

将引用存储在数据库中。创建一个用于存储此数据的模型,以便您可以在该模型中查询正确的参考ID以验证/执行操作。

当请求从支付网关返回时,使用变量ep_cin,ep_user和ep_doc从模型中获取数据。

当您使用GET请求手动请求所请求的数据时,该请求不会发送上述数据。

付款服务提供商提出的请求将获得DD的结果但是没有记录,所以没有任何反应。

Log your data用于远程api触发的请求,看看会发生什么。