buckaroo-it / BuckarooWrapper_Laravel

This repository contains the Buckaroo Laravel Wrapper
1 stars 1 forks source link

Implementation Issue with in3 Payment Using Laravel Wrapper #6

Closed AlexVanSteenhoven closed 3 months ago

AlexVanSteenhoven commented 4 months ago

Description

We are currently in the process of integrating in3 payments into our application to meet a client's requirements. Despite following the official documentation for the Laravel wrapper, we are encountering issues that prevent successful payment processing. Notably, the lack of autocompletion is adding complexity to the implementation process.

Issue details

Environment:

Code snippet from our application

Error messages

<?php
Buckaroo\Transaction\Response\TransactionResponse { // app/Http/Controllers/OrderController.php:96
  data: [
    "Key" => "0891B529AB9F4276B93AD36D07C805D8",
    "Status" => [,
      "Code" => [,
        "Code" => 491,
        "Description" => "Validation failure",
      ],
      "SubCode" => null,
      "DateTime" => "2024-03-05T12:03:26",
    ],
    "RequiredAction" => null,
    "Services" => null,
    "CustomParameters" => null,
    "AdditionalParameters" => null,
    "RequestErrors" => [,
      "ChannelErrors" => [],
      "ServiceErrors" => [],
      "ActionErrors" => [],
      "ParameterErrors" => [,
        0 => [,
          "Service" => null,
          "Action" => "Pay",
          "Name" => "amount",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "amount should be provided for the action.",
        ],
        1 => [,
          "Service" => null,
          "Action" => "Pay",
          "Name" => "invoicenumber",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "invoicenumber should be provided for the action.",
        ],
        2 => [,
          "Service" => "In3",
          "Action" => "Pay",
          "Name" => "Email",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "Parameter 'Email' missing",
        ],
        3 => [,
          "Service" => "In3",
          "Action" => "Pay",
          "Name" => "Category",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "Parameter 'Category' missing",
        ],
        4 => [,
          "Service" => "In3",
          "Action" => "Pay",
          "Name" => "Quantity",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "Parameter 'Quantity' missing",
        ],
        5 =>[,
          "Service" => "In3",
          "Action" => "Pay",
          "Name" => "Phone",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "Parameter 'Phone' missing",
        ],
        6 =>  [,
          "Service" => "In3",
          "Action" => "Pay",
          "Name" => "StreetNumber",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "Parameter 'StreetNumber' missing",
        ],
        7 => [,
          "Service" => "In3",
          "Action" => "Pay",
          "Name" => "GrossUnitPrice",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "Parameter 'GrossUnitPrice' missing",
        ],
        8 => [,
          "Service" => "In3",
          "Action" => "Pay",
          "Name" => "Street",
          "Error" => "ParameterMissing",
          "ErrorMessage" => "Parameter 'Street' missing",
        ],
        9 => [▶],
        10 => [▶],
        11 => [▶],
        12 => [▶],
        13 => [▶],
        14 => [▶],
        15 => [▶],
        16 => [▶],
        17 => [▶],
        18 => [▶],
        19 => [▶],
]

Expected behaviour

A response from the api with data about the new payment made

ShuCh3n commented 4 months ago

Dear @AlexVanSteenhoven,

You're using the wrong payload. Please see https://github.com/buckaroo-it/BuckarooSDK_PHP/blob/master/example/transactions/in3.php for the correct payload.

In addition, please check our documentation https://docs.buckaroo.io/v1/docs/en/php-sdk regarding our PHP SDK.

AlexVanSteenhoven commented 4 months ago

Dear @ShuCh3n,

Thanks for providing the correct payload.

Now it will work but now in the BuckarooController.php I get the following error: Call to undefined method Buckaroo\Laravel\BuckarooManager::client()

Looking in the BuckarooManager there is indeed no client, when I replaced it with Buckaroo::api() it works. After this there is no transaction so the ->update([...]) method throws an error. Does this has to be an update statement or should it be create?

public function return(Request $request)
    {
        $bodyIsValid = Buckaroo::client()->validateBody((!empty($_POST))? $_POST : $request->getContent(),  $request->header('Authorization') ?? '', route('buckaroo.return')); // <-- Here

        if($bodyIsValid)
        {
            try{
                $transaction_id = $request->get('BRQ_TRANSACTIONS') ?? $request->get('brq_transactions');
                $transaction = BuckarooTransaction::firstWhere('brq_transactions', $transaction_id);
                $transaction->update([
                    'brq_statuscode'                => $request->get('BRQ_STATUSCODE') ?? $request->get('brq_statuscode'),
                    'brq_statuscode_detail'         => $request->get('BRQ_STATUSCODE_DETAIL') ?? $request->get('brq_statuscode_detail'),
                    'brq_statusmessage'             => $request->get('BRQ_STATUSMESSAGE') ?? $request->get('brq_statusmessage')
                ]);
            }catch(QueryException $e){}

            return 'Success';
        }

        return 'Body is not valid';
    }
ShuCh3n commented 4 months ago

Have you created the transaction in the first place?

$transaction = BuckarooTransaction::where('brq_transactions', $transaction_id)->firstOrFail();

You'll probably get a 404 or a model not found

AlexVanSteenhoven commented 4 months ago

No I did not, I was expecting that a transaction already was created.

So where and when do I need to create the transaction? This is a bit unclear for me

ShuCh3n commented 4 months ago

Right after you execute the transaction you will get a transaction key from the response.

$response = Buckaroo::api()->method('in3')->pay($payload);

dd($response); //You'll find the transaction key over here

Store this transaction key in the database for further reference.

AlexVanSteenhoven commented 4 months ago

All right it works now!

The only weird thing is that after the transaction is successfully made, the user is automatically signed out. Could the Wrapper / API cause this or not because this is the only option where this happens.

ShuCh3n commented 4 months ago

Dear @AlexVanSteenhoven

We don't touch any parts that are related to the sessions. Please check the middleware whether you have initialized the session. But that has nothing to do with our Buckaroo Laravel Wrapper.

If you contact me directly I would be more the happy to help you. If all the issues that you were facing are resolved, please close this issue ticket.

Thank you!

AlexVanSteenhoven commented 3 months ago

I see I did not close the issue, my issue is gone and every thing works now.

Closing this issue now. Thanks for all of the help!