paypal / PayPal-PHP-Server-SDK

Other
5 stars 1 forks source link

Argument 1 passed to PaypalServerSdkLib\\Authentication\\ClientCredentialsAuthManager::addExpiryTime() must be an instance of PaypalServerSdkLib\\Models\\OAuthToken, array given #17

Open tgilvonas opened 3 days ago

tgilvonas commented 3 days ago

Argument 1 passed to PaypalServerSdkLib\Authentication\ClientCredentialsAuthManager::addExpiryTime() must be an instance of PaypalServerSdkLib\Models\OAuthToken, array given.

I run this code in sandbox mode while I get this error:

$client = PaypalServerSdkClientBuilder::init()
    ->clientCredentialsAuthCredentials(
        ClientCredentialsAuthCredentialsBuilder::init(
            $this->parameterBag->get('PAYPAL_ID'),
            $this->parameterBag->get('PAYPAL_SECRET')
        )
    )
    ->environment(Environment::SANDBOX)
    ->build();

$orderBody = [
    "body" => OrderRequestBuilder::init("CAPTURE", [
        PurchaseUnitRequestBuilder::init(
            AmountWithBreakdownBuilder::init("EUR", $paymentPrice)->build()
        )->build(),
    ])->build(),
];

$apiResponse = $client->getOrdersController()->ordersCreate($orderBody);

PAYPAL_ID and PAYPAL_SECRET from parameter bag are present. PHP version is 7.2

LeonarthusMectus commented 3 days ago

Hey @tgilvonas

What version of the SDK are you using when you see this exception? Can you try adding a loggingConfiguration to your Client Builder similar to the docs here. You shouldn't need to instantiate or add a logger instance yourself, but we do want to avoid masking some header values we're after.

Something like this added to your client builder should work:

->loggingConfiguration(
        LoggingConfigurationBuilder::init()
            ->maskSensitiveHeaders(false)
            ->level(LogLevel::INFO)
            ->requestConfiguration(RequestLoggingConfigurationBuilder::init()->body(true))
            ->responseConfiguration(ResponseLoggingConfigurationBuilder::init()->headers(true))
)

You could play with the LogLevel if you'd like, but INFO should work here. We're looking for a log associated with a request to the v1/oauth2/token endpoint. If you could confirm that call is happening, and grab the debug ID associated with it, that should get us pointed in the right direction.

tgilvonas commented 3 days ago

Dear @LeonarthusMectus , thank you for quick response :) I followed this documentation page: https://github.com/paypal/PayPal-PHP-Server-SDK/blob/0.6.0/doc/logging-configuration-builder.md , debug ID is: "f3414618a73ce"

Could it be the problem with PHP version? Composer requirements are met and package was installed, but there are problems with this old PHP 7.2 version?

LeonarthusMectus commented 3 days ago

The Minimum PHP version is 7.2 so I don't believe that's the cause. Looking at the logs associated with that debug ID, it appears the client_id is not correct, and looks much too short to be the full value. This could mean:

I think the last option is most probable. The API Credentials section of the Dashboard shows only a portion of the client ID by default, and uses an ellipsis (...) to signify it's not the entire value that is shown.

You'll need to click the icon to the right of the client ID value to copy it to your clipboard, or click on the App Name and load the page for that specific app to show the full client ID. Do one of these to copy the entire value into your app, retest, and let us know if that solves the issue.

As an aside, I'm going to look into this on our end as well. Ideally and if possible, I'd think returning the error in some way would be more helpful than throwing a cryptic exception.

tgilvonas commented 3 days ago

Thank you @LeonarthusMectus , now don't waste time - I inadvertently copied the PayPal ID wrong - it was not full (the cause was hurry and not very obvious UI on PayPal panel). Now I think we need to close this issue. Thank you for help! :)