Search code examples
phplaravelapipayment-gatewaypayment-processing

Notification callback is not being received


Im using this laravel package "https://github.com/kanazaca/easypay" to create a MB reference using the Easypay API.

I have this method to create the reference:

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']);

}

And it works fine with this code I get some reference codes which can be payed using MB or credit-card.

Then, when a payment is made, easypay will call a "Notification URL". that we should configure on easypay's backoffice under "URL Configurations". Because when the easypay service receives the payment they will call the URL that we provided. So I defined a url in the easypay´s backoffice and created a route in the project:

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

In the api backoffice there is a button that simulates a payment, after this button is clicked nothing happens and if I manually access "http://....ngrok.io/easypay/notification-callback" it appears an empty array:

[]

But in the documentation (https://docs.easypay.pt/workflow/payment-notification) says that when Easypay calls this endpoint, it comes with a few parameters: "ep_cin", "ep_user" and "ep_doc" that will be necessary in the process. So it should not appear an empty array.

Do you know what can be the issue? Im a beginner uing API´s so Im not understnading what the issue can be.

PaymentController receiveNotifications() method:

 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() method with log:

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
    }

Solution

  • The session is saved in the session file of the user that visits your website that initiates the payment.

    The receiveNotifications would call data from the session file that belongs to the payment gateway server if you were doing anything there. The data isn't matched because the two don't know about each other.

    Also, you might not have a Session::save() somewhere in your request handling which writes the session data to file.

    Store the reference in a database. Create a model for storing this data, so you can then query that model for the correct reference ID to verify/do stuff.

    When the request comes back from the payment gateway use the variables ep_cin, ep_user and ep_doc to get the data from the model.

    When you manually request that data you are requesting it with a GET request, which doesn't send the above data along.

    The request made by the payment provider will get the result of the DD but that's logged nowhere, so nothing happens.

    Log your data for requests triggered by remote api's to see what happens.