Skip to content

Commit

Permalink
Use tracking id from env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Aug 31, 2020
1 parent 6b95950 commit 7e3d4e1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
14 changes: 7 additions & 7 deletions spec/Client/PayPalClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class PayPalClientSpec extends ObjectBehavior
{
function let(ClientInterface $client, LoggerInterface $logger): void
{
$this->beConstructedWith($client, $logger, 'https://test-api.paypal.com/');
$this->beConstructedWith($client, $logger, 'https://test-api.paypal.com/', 'TRACKING-ID');
}

function it_implements_pay_pal_client_interface(): void
Expand All @@ -46,7 +46,7 @@ function it_calls_get_request_on_paypal_api(
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code',
'PayPal-Partner-Attribution-Id' => 'TRACKING-ID',
],
]
)->willReturn($response);
Expand All @@ -72,7 +72,7 @@ function it_logs_debug_id_from_failed_get_request(
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code',
'PayPal-Partner-Attribution-Id' => 'TRACKING-ID',
],
]
)->willThrow($exception->getWrappedObject());
Expand Down Expand Up @@ -103,7 +103,7 @@ function it_calls_post_request_on_paypal_api(
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code',
'PayPal-Partner-Attribution-Id' => 'TRACKING-ID',
],
'json' => ['parameter' => 'value', 'another_parameter' => 'another_value'],
]
Expand Down Expand Up @@ -133,7 +133,7 @@ function it_logs_debug_id_from_failed_post_request(
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code',
'PayPal-Partner-Attribution-Id' => 'TRACKING-ID',
],
'json' => ['parameter' => 'value', 'another_parameter' => 'another_value'],
]
Expand Down Expand Up @@ -168,7 +168,7 @@ function it_calls_patch_request_on_paypal_api(
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code',
'PayPal-Partner-Attribution-Id' => 'TRACKING-ID',
],
'json' => ['parameter' => 'value', 'another_parameter' => 'another_value'],
]
Expand Down Expand Up @@ -198,7 +198,7 @@ function it_logs_debug_id_from_failed_patch_request(
'Authorization' => 'Bearer TOKEN',
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code',
'PayPal-Partner-Attribution-Id' => 'TRACKING-ID',
],
'json' => ['parameter' => 'value', 'another_parameter' => 'another_value'],
]
Expand Down
8 changes: 6 additions & 2 deletions src/Client/PayPalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ final class PayPalClient implements PayPalClientInterface
/** @var string */
private $baseUrl;

public function __construct(ClientInterface $client, LoggerInterface $logger, string $baseUrl)
/** @var string */
private $trackingId;

public function __construct(ClientInterface $client, LoggerInterface $logger, string $baseUrl, string $trackingId)
{
$this->client = $client;
$this->logger = $logger;
$this->baseUrl = $baseUrl;
$this->trackingId = $trackingId;
}

public function get(string $url, string $token): array
Expand All @@ -58,7 +62,7 @@ private function request(string $method, string $url, string $token, array $data
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code',
'PayPal-Partner-Attribution-Id' => $this->trackingId,
],
];

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<argument type="service" id="sylius.http_client" />
<argument type="service" id="logger" />
<argument>%env(resolve:PAYPAL_API_BASE_URL)%</argument>
<argument>%env(resolve:PAYPAL_TRACKING_ID)%</argument>
</service>

<service
Expand Down

0 comments on commit 7e3d4e1

Please sign in to comment.