sverraest / revolut-php

💳 PHP Bindings for the Revolut Business API
https://revolutdev.github.io/business-api/#api-v1-0-introduction
Other
45 stars 17 forks source link

How does one check for the response #5

Closed lstables closed 5 years ago

lstables commented 5 years ago

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?

sverraest commented 5 years ago

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.

lstables commented 5 years ago

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.

sverraest commented 5 years ago

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

lstables commented 5 years ago

Nothing it seems.... :(

lstables commented 5 years ago

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",

sverraest commented 5 years ago

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

lstables commented 5 years ago

Yeah just posting as "000000"

sverraest commented 5 years ago

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.

lstables commented 5 years ago

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

sverraest commented 5 years ago

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

lstables commented 5 years ago

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

Awesome package btw 👍

sverraest commented 5 years ago

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

lstables commented 5 years ago

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.

lstables commented 5 years ago

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