braintree / braintree_php

Braintree PHP library
https://developer.paypal.com/braintree/docs/start/overview
MIT License
546 stars 224 forks source link

Feature Request: Custom HTTP client #281

Closed patrickkusebauch closed 4 years ago

patrickkusebauch commented 4 years ago

General information

Issue description

Setup

Currently, we are forced into using the included HTTP client implementation. Example from SubscriptionGateway class

class SubscriptionGateway
{
    private $_gateway;
    private $_config;
    private $_http;

    public function __construct($gateway)
    {
        $this->_gateway = $gateway;
        $this->_config = $gateway->config;
        $this->_config->assertHasAccessTokenOrKeys();
        $this->_http = new Http($gateway->config);
    }
}

This HTTP class cannot be switched, since it is created directly in the class and not passed as a dependency.

This HTTP class, in turn, creates CurlRequest class that is again hardcoded and cannot be swapped by any means:

class Http
{
    public function _doUrlRequest($httpVerb, $url, $requestBody = null, $file = null, $customHeaders = null)
    {
        $curlRequest = new CurlRequest($url);
        return Curl::makeRequest($httpVerb, $url, $this->_config, $curlRequest, $requestBody, $file, $customHeaders, $this->_useClientCredentials);
    }
}

This CurlRequest class calls curl_* methods directly and therefore there is no way to alter/add any further code.

Why change?

Because right now there is no possibility for any type of logging, analytics, and metrics for the requests. I cannot track any information about the CURL requests themselves, at best, I can wrap the library code itself, but that gives me only very little information in contrast to what curl_getinfo can give you about the request.

hollabaq86 commented 4 years ago

👋 @patrickkusebauch thanks for reaching out. We've talked this over internally, and we're going to pass on this request - it introduces a support burden that we're not willing to take on, plus folks can continue to use responses as they are for logging/analytics of requests.

This said, you're 💯 welcome to fork our repo and make the changes you need.

AidasK commented 2 years ago

Hello @patrickkusebauch, have you found a solution to overcome this?

AidasK commented 2 years ago

Same issue: https://github.com/braintree/braintree_php/issues/141

Looks like reasons not to implement this are no longer valid for this day.

mcsocha commented 1 year ago

My team has a need for a custom HTTP client. Wondering if anyone can reconsider?