sverraest / revolut-php

💳 PHP Bindings for the Revolut Business API

Home Page:https://revolutdev.github.io/business-api/#api-v1-0-introduction

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does one check for the response

lstables opened this issue · comments

Hi, I using this package with Laravel and all is good, but I need to get the response back from Revolut, so I can save the UUID's they send to out database.

So this is the code I have:

// At the top I have     use RevolutPHP\Client as Revolut;
$pay = new Revolut($this->api_key); 
            $counterparty = $pay->counterparties->create(
                array (
                'company_name' => user()->companies()->first()->name,
                'bank_country' => 'GB',
                'currency' => 'GBP',
                'account_no' => $request->account_no,
                'sort_code' => $request->sort_code,
                "email" => user()->email,
                "phone" => user()->tel,
                'profile_type' => 'business',
                'address' => 
                    array (
                    'street_line1' => user()->companies()->first()->address_line_1,
                    'street_line2' => user()->companies()->first()->address_line_2,
                    'region' => '',
                    'postcode' => user()->companies()->first()->postcode,
                    'city' => user()->companies()->first()->city,
                    'country' => 'GB',
                    ),
                )
            );

Soon as the response is sent back from Revoult I want to be able to grab that data and do what I want with it, how can one achieve this?

Hi, great that you're using this package.
The response itself is parsed automatically as an array.
So your variable $counterparty will be an array that has the following information:

https://revolutdev.github.io/business-api/#add-revolut-counterparty

I would wrap this code in a try / catch block though.

Apologies this is within a try /catch

try {
            $pay = new Revolut($this->api_key); 
            $counterparty = $pay->counterparties->create(
                array (
                'company_name' => user()->companies()->first()->name,
                'bank_country' => 'GB',
                'currency' => 'GBP',
                'account_no' => $request->account_no,
                'sort_code' => $request->sort_code,
                "email" => user()->email,
                "phone" => user()->tel,
                'profile_type' => 'business',
                'address' => 
                    array (
                    'street_line1' => user()->companies()->first()->address_line_1,
                    'street_line2' => user()->companies()->first()->address_line_2,
                    'region' => '',
                    'postcode' => user()->companies()->first()->postcode,
                    'city' => user()->companies()->first()->city,
                    'country' => 'GB',
                    ),
                )
            );
        } catch (Exception $e) {
            \Log::info($e);
            return response()->json(['message' => 'There was something wrong, please try again.', 404]);
        }

So $pay as the array in, but once this is sent to Revolut I want to get their response to I can save the successful creation details.

What do you get when you do print_r($counterparty); after this call?

Nothing it seems.... :(

Seems there's an error either my end or theirs:

POST https://b2b.revolut.com/api/1.0/counterparty` resulted in a `400 Bad Request` response: {"message":"Sort code is in invalid format","code":4002}

Even though sending within the array like so "sort_code" => "$request->sort_code",

The sort_code parameter should be a string like "223344".
Are you including any hyphens maybe? "22-33-44" should be posted as "223344"

Yeah just posting as "000000"

Can you get a full request body / headers which is giving you this error?
Please check that you omit any sensitive data such as API Keys.
Otherwise I suggest to contact Revolut for Business directly.

Yeah API keys everything looks good as I did when I tested it before, so I will contact them directly.

Ok, do update the issue here if you hear back, thanks!

Will do, although they aren't the fastest cats :)

Awesome package btw 👍

Was Revolut able to solve your issue? Anything specific to the package?

Nope, to be honest they were lacking in these areas shall we say. Also it appears they don't do what we wanted it to do, so for now at least we are staying with Stripe.

PS, the package is fine, just Revolut not so...