Skip to content

Conversation

@olivierbellone
Copy link
Contributor

@olivierbellone olivierbellone commented Sep 13, 2016

r? @brandur
cc @stripe/api-libraries

This PR adds a setAppInfo method to the static Stripe class. The method takes three parameters:

  • $appName (mandatory): the application's name
  • $appVersion (optional): the application's version
  • $appUrl (optional): the URL for the application's site

The method is meant to be used by plugin developers. After the method has been called, the headers sent with every request will be modified like this:

  • User-Agent will have the additional information appended at the end, e.g. Stripe/v1 PhpBindings/3.21.0 would become Stripe/v1 PhpBindings/3.21.0 MyAwesomeApp/1.2.34 (https://myawesomeapp.example)
  • X-Stripe-Client-User-Agent will have an additional application key with the same string that's appended to User-Agent, e.g. MyAwesomeApp/1.2.34 (https://myawesomeapp.example)

For more context about the motivation behind this PR, see the DX-120 issue internally.

);
if ($appInfo !== null) {
$uaString .= ' ' . $appInfo;
$ua['application'] = $appInfo;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to do nested values in here - i.e., leave the 'object' as an object? It might be easier to grok [0] for analytics etc. if it didn't require parsing the string.

[0] This might actually be the first time I've typed grok on the internet.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point. It definitely should be possible, I'll give it a try!

'User-Agent' => 'Stripe/v1 PhpBindings/' . Stripe::VERSION,
'Authorization' => 'Bearer ' . $myApiKey,
);
$defaultHeaders = $this->_defaultHeaders($myApiKey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Way cleaner here now.

@brandur
Copy link
Contributor

brandur commented Sep 13, 2016

@olivierbellone Awesome! Thanks again for picking this up and running with it; it should be hugely helpful in tracking down future compatibility problems.

LGTM.

@stripe-ci stripe-ci assigned olivierbellone and unassigned brandur Sep 13, 2016
@brandur brandur merged commit a36c643 into master Sep 13, 2016
@brandur brandur deleted the ob-user-agent-app branch September 13, 2016 18:13
@brandur
Copy link
Contributor

brandur commented Sep 13, 2016

Released as 3.22.0.

@snez
Copy link

snez commented Nov 11, 2016

Hey guys, could we please get a port of this for the older 1.x libraries? If a 1.19.0 is under consideration, could you please throw in 3D Secure as well based on snez/stripe-php@15df5eb

Thanks!

@brandur
Copy link
Contributor

brandur commented Nov 11, 2016

@snez Sorry for the answer that's sure to be disappointing, but 1.x is not maintained and we don't backport changes to it. Is there anything that we can do to help you upgrade? Being on such an ancient release is going to cause other trouble in the long run like not getting other more minor bug fixes, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants