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

Problem with access to the account

octapudus opened this issue · comments

Hey i set everything as you described, i think.

///php code

require "vendor/autoload.php";

$authProvider = new \RevolutPHP\Auth\Provider([
'clientId' => 'BLABLABLAmyid', // As shown when uploading your key
'privateKey' => 'blablabla/pathto my private key/privatekey.pem',
'redirectUri' => 'web link that i indicated into public key', // The URL to redirect the user to after the authorisation step
'isSandbox' => true
]);

$url = $authProvider->getAuthorizationUrl();

$accessToken = $authProvider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);

but still it's giving this error:
i will hide my path to the privacy reasons with "myDirectoryToSourceCOde*"

Fatal error: Uncaught BadMethodCallException: Required parameter not passed: "code" in myDirectoryToSourceCOdevendor/league/oauth2-client/src/Tool/RequiredParameterTrait.php:35 Stack trace: #0 myDirectoryToSourceCOdevendor/league/oauth2-client/src/Tool/RequiredParameterTrait.php(53): League\OAuth2\Client\Grant\AbstractGrant->checkRequiredParameter('code', Array) #1 myDirectoryToSourceCOdevendor/league/oauth2-client/src/Grant/AbstractGrant.php(76): League\OAuth2\Client\Grant\AbstractGrant->checkRequiredParameters(Array, Array) #2 myDirectoryToSourceCOdevendor/league/oauth2-client/src/Provider/AbstractProvider.php(535): League\OAuth2\Client\Grant\AbstractGrant->prepareRequestParameters(Array, Array) #3 myDirectoryToSourceCOdevendor/vdbelt/oauth2-revolut/src/Provider/Revolut.php(144): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\AuthorizationCode), Array) #4 /v in myDirectoryToSourceCOdevendor/league/oauth2-client/src/Tool/RequiredParameterTrait.php on line 35

Hi,

You try to pass the Revolut code without authenticate your Revolut access.
In your code, you get the Authorization Url. You should use it to redirect the visitor to the Revolut Authorization form.

Hope this could help.

require "vendor/autoload.php";
$authProvider = new \RevolutPHP\Auth\Provider([
'clientId' => 'BLABLABLAmyid', // As shown when uploading your key
'privateKey' => 'blablabla/pathto my private key/privatekey.pem',
'redirectUri' => 'web link that i indicated into public key', // The URL to redirect the user to after the authorisation step
'isSandbox' => true
]);

Here is the most important thing

if($_GET["code"]=='') {
$url = $authProvider->getAuthorizationUrl();
header("location:".$url); // This header will redirect the user if you didn't get Revolut code through GET.
}

$accessToken = $authProvider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);

Not exacly.
Because i did all step by step indication..

Can you make the step by step instrusction? Beetween installing software and setting things into revolut business account?
Because nlw its not too much clean. And you are the only one person with this kind of libraries.

Thank you

Hi, you should follow instructions described and test my solution.

Regards

Please permit me to show the problem by telegram.
Please contact. Thank you

I don't use telegram sorry, but i can support you here.

Ok sorry it was only for real time problem solving.

By the way.
I created the certificates. I created the key inside business account.

I get all the staff as you described. But it still get that error and i don't understand where is the problem.

Are you sure that there wasn'ylt any change into revolut rules about part of key management that could give me some kind of errors?

Because i saw they implemented a new staff like json web token.
Is it implemented in your library?

I am discovering the library actually.
What i can say is that your error is due to this line :

$accessToken = $authProvider->getAccessToken('authorization_code', ['code' => $_GET['code']

That's simple. Your variable is not set if you don't have ?code=xxxxxxxxxxxxxx in your URL.

If you want my code working, you have to set the REQUEST URI in your Revolut account to be the same as your php webpage. I don't know exactly if it is a good practice, as i am discovering the library.

In my account, my request URI is https://mywebsite.com/revolut/oauth.php
The code i give you is located to this page. That should work if you do the same, but i encounter an issue reloading this webpage with the code passed in URL (i opened a ticket).

I'm sure a developper could help us regarding this problem.

Uhm.
I send it to not exactly a file. But direction which send me to the index.php
But maybe that is the problem

I go to sleep now. Please check this chat in the next days. I will create a dedicated file like whatever.php

And will see

Please try this code, it should output an URL.
Copy this URL in your browser. Or tell me if you get any error.

require "vendor/autoload.php";
$authProvider = new \RevolutPHP\Auth\Provider([
'clientId' => 'BLABLABLAmyid', // As shown when uploading your key
'privateKey' => 'blablabla/pathto my private key/privatekey.pem',
'redirectUri' => 'web link that i indicated into public key', // The URL to redirect the user to after the authorisation step
'isSandbox' => true
]);
echo $url = $authProvider->getAuthorizationUrl();

Ok i try it now

You may access Revolut Authentification webpage. Connect to your account, and input your sms code. In case of success, you may be redirected to your request URI set in your Revolut Business account.

If you get an error, just copy the last line of your apache or nginx apache log here.

on running that code i have a blank page:

let me show you, i just gonna change my domain due to the privacy reasons:
only domain will be changed (and also some characters of key)

this is the link after sms. (as you see i sent it to direction "amministrazione" so to index of that direction.
https://mydomain.com/amministrazione/?code=oa_prod_qbFSGdBw6ZD9pTStDHpLO4lMq4Zn8YJn_gnUW5M3SSQ&state=

than i run into https://mydomain.com/payments/ this code

require "vendor/autoload.php";

$authProvider = new \RevolutPHP\Auth\Provider([
'clientId' => 'kX0mpaJdri-IB6zhtUGHNJFZeV6rWtWEw1DY6FacRQM', // As shown when uploading your key
'privateKey' => 'file:///var/www/www-root/data/www/mydomanin.com/payments/test/privatekey.pem',
'redirectUri' => 'https://mydomanin.com/amministrazione/', // The URL to redirect the user to after the authorisation step
'isSandbox' => false
]);
$url = $authProvider->getAuthorizationUrl();

and nothing happn

yeah sure, i put random digits of the same lenght, it's not mine client id :)

but the way now i see, there is the link. (again with random digits that i will put)
so answer is
https://business.revolut.com/app-confirm?state=74d5560826a85a966153893fa2c95c03&scope=READ&response_type=code&approval_prompt=auto&redirect_uri=https%3A%2F%2Fmydomanin.com%2Famministrazione%2F&client_id=kX0mpaJdri-IB6zhtUGHNJFZeas5rWtWEw1DYa3w65QM

now im trying to take the access token which i need in order to access to my account.

than the errors starts:

$accessToken = $authProvider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);

tice: Undefined index: code in /var/www/www-root/data/www/mydomain.com/payments/index.php on line 53

Fatal error: Uncaught BadMethodCallException: Required parameter not passed: "code" in /var/www/www-root/data/www/mydomain.com/payments/vendor/league/oauth2-client/src/Tool/RequiredParameterTrait.php:35 Stack trace: #0 /var/www/www-root/data/www/mydomain.com/payments/vendor/league/oauth2-client/src/Tool/RequiredParameterTrait.php(53): League\OAuth2\Client\Grant\AbstractGrant->checkRequiredParameter('code', Array) #1 /var/www/www-root/data/www/mydomain.com/payments/vendor/league/oauth2-client/src/Grant/AbstractGrant.php(76): League\OAuth2\Client\Grant\AbstractGrant->checkRequiredParameters(Array, Array) #2 /var/www/www-root/data/www/mydomain.com/payments/vendor/league/oauth2-client/src/Provider/AbstractProvider.php(535): League\OAuth2\Client\Grant\AbstractGrant->prepareRequestParameters(Array, Array) #3 /var/www/www-root/data/www/mydomain.com/payments/vendor/vdbelt/oauth2-revolut/src/Provider/Revolut.php(144): League\OAuth2\Client\Provider\AbstractProvider->getAccessToken(Object(League\OAuth2\Client\Grant\AuthorizationCode), Array) #4 /v in /var/www/www-root/data/www/mydomain.com/payments/vendor/league/oauth2-client/src/Tool/RequiredParameterTrait.php on line 35

can you just share your code please? @Cyrilouletouriste