Skip to content

Commit 2b3213e

Browse files
authored
remove php version header on sandbox environment (#7)
1 parent ab874f7 commit 2b3213e

12 files changed

+198
-25
lines changed

phpunit.xml.bak

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Contracts/Environment.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
interface Environment
66
{
7+
/**
8+
* @return string
9+
*/
10+
public function name();
11+
712
/**
813
* @return string
914
*/

src/Environment/ProductionEnvironment.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ public function baseUrl()
1313
{
1414
return 'https://api.paypal.com';
1515
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function name()
21+
{
22+
return 'production';
23+
}
1624
}

src/Environment/SandboxEnvironment.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@ public function baseUrl()
1313
{
1414
return 'https://api.sandbox.paypal.com';
1515
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function name()
21+
{
22+
return 'sandbox';
23+
}
1624
}

src/Http/PayPalClient.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,19 @@ public function injectGzipHeaders(Request $request)
101101
*/
102102
public function injectSdkHeaders(Request $request)
103103
{
104-
return $request->withHeader('sdk_name', 'Checkout SDK')
105-
->withHeader('sdk_version', '1.0.0')
106-
->withHeader('sdk_tech_stack', 'PHP '.PHP_VERSION);
104+
$r = $request->withHeader('sdk_name', 'Checkout SDK')
105+
->withHeader('sdk_version', '1.0.0');
106+
107+
/*
108+
* Only inject this header on production
109+
*
110+
* @see https://github.com/phpjuice/paypal-checkout-sdk/issues/6
111+
*/
112+
if ('production' == $this->environment->name()) {
113+
$r = $r->withHeader('sdk_tech_stack', 'PHP '.PHP_VERSION);
114+
}
115+
116+
return $r;
107117
}
108118

109119
/**

tests/Http/AccessTokenRequestTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,55 @@ protected function setUp(): void
2424
$this->environment = new ProductionEnvironment('client_id', 'client_secret');
2525
}
2626

27+
/**
28+
* @test
29+
*/
2730
public function testHasCorrectUri()
2831
{
2932
$request = new AccessTokenRequest($this->environment);
3033
$this->assertEquals('/v1/oauth2/token', $request->getUri());
3134
}
3235

36+
/**
37+
* @test
38+
*/
3339
public function testHasCorrectMethod()
3440
{
3541
$request = new AccessTokenRequest($this->environment);
3642
$this->assertEquals('POST', $request->getMethod());
3743
}
3844

45+
/**
46+
* @test
47+
*/
3948
public function testHasCorrectHeaders()
4049
{
4150
$request = new AccessTokenRequest($this->environment);
4251
$this->assertEquals('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'));
4352
}
4453

54+
/**
55+
* @test
56+
*/
4557
public function testHasBasicAuthHeaders()
4658
{
4759
$request = new AccessTokenRequest($this->environment);
4860
$this->assertEquals('Basic '.$this->environment->basicAuthorizationString(), $request->getHeaderLine('Authorization'));
4961
}
5062

63+
/**
64+
* @test
65+
*/
5166
public function testHasCorrectDataWithGetBody()
5267
{
5368
$request = new AccessTokenRequest($this->environment);
5469
$expected = http_build_query(['grant_type' => 'client_credentials']);
5570
$this->assertEquals($expected, (string) $request->getBody());
5671
}
5772

73+
/**
74+
* @test
75+
*/
5876
public function testExecuteRequest()
5977
{
6078
$mockResponse = json_encode([

tests/Http/AccessTokenTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@
77

88
class AccessTokenTest extends TestCase
99
{
10+
/**
11+
* @test
12+
*/
1013
public function testCreateAccessToken()
1114
{
1215
$accessToken = new AccessToken('A21AAFSO5otrlVigoJUQ1p', 'Bearer', 32400);
1316
$this->assertEquals('A21AAFSO5otrlVigoJUQ1p', $accessToken->getToken());
1417
$this->assertEquals('Bearer', $accessToken->getTokenType());
1518
}
1619

20+
/**
21+
* @test
22+
*/
1723
public function testTokenIsExpired()
1824
{
1925
$accessToken = new AccessToken('A21AAFSO5otrlVigoJUQ1p', 'Bearer', 32400);
@@ -22,6 +28,9 @@ public function testTokenIsExpired()
2228
$this->assertTrue($accessToken->isExpired());
2329
}
2430

31+
/**
32+
* @test
33+
*/
2534
public function testTokenAuthorizationString()
2635
{
2736
$accessToken = new AccessToken('Token', 'Bearer', 32400);

tests/Http/OrderAuthorizeRequestTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,37 @@
1212

1313
class OrderAuthorizeRequestTest extends TestCase
1414
{
15+
/**
16+
* @test
17+
*/
1518
public function testHasCorrectUri()
1619
{
1720
$request = new OrderAuthorizeRequest('1KC5501443316171H');
1821
$this->assertEquals('/v2/checkout/orders/1KC5501443316171H/authorize', $request->getUri());
1922
}
2023

24+
/**
25+
* @test
26+
*/
2127
public function testHasCorrectMethod()
2228
{
2329
$request = new OrderAuthorizeRequest('1KC5501443316171H');
2430
$this->assertEquals('POST', $request->getMethod());
2531
}
2632

33+
/**
34+
* @test
35+
*/
2736
public function testHasCorrectHeaders()
2837
{
2938
$request = new OrderAuthorizeRequest('1KC5501443316171H');
3039
$this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
3140
$this->assertEquals('return=representation', $request->getHeaderLine('Prefer'));
3241
}
3342

43+
/**
44+
* @test
45+
*/
3446
public function testExecuteRequest()
3547
{
3648
$mockResponse = json_encode([

tests/Http/OrderCaptureRequestTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,37 @@
1212

1313
class OrderCaptureRequestTest extends TestCase
1414
{
15+
/**
16+
* @test
17+
*/
1518
public function testHasCorrectUri()
1619
{
1720
$request = new OrderCaptureRequest('1KC5501443316171H');
1821
$this->assertEquals('/v2/checkout/orders/1KC5501443316171H/capture', $request->getUri());
1922
}
2023

24+
/**
25+
* @test
26+
*/
2127
public function testHasCorrectMethod()
2228
{
2329
$request = new OrderCaptureRequest('1KC5501443316171H');
2430
$this->assertEquals('POST', $request->getMethod());
2531
}
2632

33+
/**
34+
* @test
35+
*/
2736
public function testHasCorrectHeaders()
2837
{
2938
$request = new OrderCaptureRequest('1KC5501443316171H');
3039
$this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
3140
$this->assertEquals('return=representation', $request->getHeaderLine('Prefer'));
3241
}
3342

43+
/**
44+
* @test
45+
*/
3446
public function testExecuteRequest()
3547
{
3648
$mockResponse = Utils::jsonEncode([

tests/Http/OrderCreateRequestTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,37 @@
1616

1717
class OrderCreateRequestTest extends TestCase
1818
{
19+
/**
20+
* @test
21+
*/
1922
public function testHasCorrectUri()
2023
{
2124
$request = new OrderCreateRequest();
2225
$this->assertEquals('/v2/checkout/orders', $request->getUri());
2326
}
2427

28+
/**
29+
* @test
30+
*/
2531
public function testHasCorrectMethod()
2632
{
2733
$request = new OrderCreateRequest();
2834
$this->assertEquals('POST', $request->getMethod());
2935
}
3036

37+
/**
38+
* @test
39+
*/
3140
public function testHasCorrectHeaders()
3241
{
3342
$request = new OrderCreateRequest();
3443
$this->assertEquals('application/json', $request->getHeaderLine('Content-Type'));
3544
$this->assertEquals('return=representation', $request->getHeaderLine('Prefer'));
3645
}
3746

47+
/**
48+
* @test
49+
*/
3850
public function testHasCorrectDataWithGetBody()
3951
{
4052
$purchase_unit = new PurchaseUnit('USD', 100.00);
@@ -52,6 +64,9 @@ public function testHasCorrectDataWithGetBody()
5264
$this->assertEquals($order->toArray(), Utils::jsonDecode($request->getBody(), true));
5365
}
5466

67+
/**
68+
* @test
69+
*/
5570
public function testExecuteRequest()
5671
{
5772
$mockResponse = Utils::jsonEncode([

0 commit comments

Comments
 (0)