From c2934ab64dc6cf0cc251c56b65ae9727e08c30a2 Mon Sep 17 00:00:00 2001 From: SirDomin Date: Mon, 31 Aug 2020 07:23:22 +0200 Subject: [PATCH] fixed where partner attribution id was hardcoded --- spec/Api/CompleteOrderApiSpec.php | 4 ++-- spec/Api/CreateOrderApiSpec.php | 2 +- spec/Api/OrderDetailsApiSpec.php | 4 ++-- spec/Api/RefundPaymentApiSpec.php | 4 ++-- src/Api/CompleteOrderApi.php | 8 ++++++-- src/Api/CreateOrderApi.php | 8 ++++++-- src/Api/OrderDetailsApi.php | 8 ++++++-- src/Api/RefundPaymentApi.php | 8 ++++++-- src/Resources/config/services/api.xml | 4 ++++ 9 files changed, 35 insertions(+), 15 deletions(-) diff --git a/spec/Api/CompleteOrderApiSpec.php b/spec/Api/CompleteOrderApiSpec.php index 1249ead7..f5fd6610 100644 --- a/spec/Api/CompleteOrderApiSpec.php +++ b/spec/Api/CompleteOrderApiSpec.php @@ -25,7 +25,7 @@ final class CompleteOrderApiSpec extends ObjectBehavior { function let(Client $client): void { - $this->beConstructedWith($client, 'https://api.test-paypal.com/'); + $this->beConstructedWith($client, 'https://api.test-paypal.com/', 'PARTNER_ATTRIBUTION_ID'); } function it_implements_complete_order_api_interface(): void @@ -51,7 +51,7 @@ function it_completes_pay_pal_order_with_given_id( 'headers' => [ 'Authorization' => 'Bearer TOKEN', 'Prefer' => 'return=representation', - 'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code', + 'PayPal-Partner-Attribution-Id' => 'PARTNER_ATTRIBUTION_ID', 'Content-Type' => 'application/json', ], ] diff --git a/spec/Api/CreateOrderApiSpec.php b/spec/Api/CreateOrderApiSpec.php index 57992226..3c2b1304 100644 --- a/spec/Api/CreateOrderApiSpec.php +++ b/spec/Api/CreateOrderApiSpec.php @@ -29,7 +29,7 @@ final class CreateOrderApiSpec extends ObjectBehavior { function let(Client $client): void { - $this->beConstructedWith($client, 'https://api.test-paypal.com/'); + $this->beConstructedWith($client, 'https://api.test-paypal.com/', 'PARTNER_ATTRIBUTION_ID'); } function it_implements_create_order_api_interface(): void diff --git a/spec/Api/OrderDetailsApiSpec.php b/spec/Api/OrderDetailsApiSpec.php index 780657de..be3d2f8f 100644 --- a/spec/Api/OrderDetailsApiSpec.php +++ b/spec/Api/OrderDetailsApiSpec.php @@ -24,7 +24,7 @@ final class OrderDetailsApiSpec extends ObjectBehavior { function let(Client $client): void { - $this->beConstructedWith($client, 'https://api.test-paypal.com/'); + $this->beConstructedWith($client, 'https://api.test-paypal.com/', 'PARTNER_ATTRIBUTION_ID'); } function it_implements_pay_pal_order_details_provider_interface(): void @@ -46,7 +46,7 @@ function it_provides_details_about_pay_pal_order( 'Authorization' => 'Bearer TOKEN', 'Content-Type' => 'application/json', 'Accept' => 'application/json', - 'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code', + 'PayPal-Partner-Attribution-Id' => 'PARTNER_ATTRIBUTION_ID', ], ] )->willReturn($detailsResponse); diff --git a/spec/Api/RefundPaymentApiSpec.php b/spec/Api/RefundPaymentApiSpec.php index 2135d1af..1b2ac4d3 100644 --- a/spec/Api/RefundPaymentApiSpec.php +++ b/spec/Api/RefundPaymentApiSpec.php @@ -26,7 +26,7 @@ final class RefundPaymentApiSpec extends ObjectBehavior { function let(Client $client): void { - $this->beConstructedWith($client, 'https://api.test-paypal.com/'); + $this->beConstructedWith($client, 'https://api.test-paypal.com/', 'PARTNER_ATTRIBUTION_ID'); } function it_implements_refund_order_api_interface(): void @@ -51,7 +51,7 @@ function it_refunds_pay_pal_payment_with_given_id( Argument::that(function (array $options): bool { return $options['headers']['Authorization'] === 'Bearer TOKEN' && - $options['headers']['PayPal-Partner-Attribution-Id'] === 'sylius-ppcp4p-bn-code' && + $options['headers']['PayPal-Partner-Attribution-Id'] === 'PARTNER_ATTRIBUTION_ID' && $options['headers']['Content-Type'] === 'application/json' && is_string($options['headers']['PayPal-Request-Id']) ; diff --git a/src/Api/CompleteOrderApi.php b/src/Api/CompleteOrderApi.php index dedac6e6..a9124134 100644 --- a/src/Api/CompleteOrderApi.php +++ b/src/Api/CompleteOrderApi.php @@ -23,10 +23,14 @@ final class CompleteOrderApi implements CompleteOrderApiInterface /** @var string */ private $baseUrl; - public function __construct(Client $client, string $baseUrl) + /** @var string */ + private $partnerAttributionId; + + public function __construct(Client $client, string $baseUrl, string $partnerAttributionId) { $this->client = $client; $this->baseUrl = $baseUrl; + $this->partnerAttributionId = $partnerAttributionId; } public function complete(string $token, string $orderId): array @@ -38,7 +42,7 @@ public function complete(string $token, string $orderId): array 'headers' => [ 'Authorization' => 'Bearer ' . $token, 'Prefer' => 'return=representation', - 'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code', + 'PayPal-Partner-Attribution-Id' => $this->partnerAttributionId, 'Content-Type' => 'application/json', ], ] diff --git a/src/Api/CreateOrderApi.php b/src/Api/CreateOrderApi.php index 5559ed64..316aad3b 100644 --- a/src/Api/CreateOrderApi.php +++ b/src/Api/CreateOrderApi.php @@ -28,10 +28,14 @@ final class CreateOrderApi implements CreateOrderApiInterface /** @var string */ private $baseUrl; - public function __construct(Client $client, string $baseUrl) + /** @var string */ + private $partnerAttributionId; + + public function __construct(Client $client, string $baseUrl, string $partnerAttributionId) { $this->client = $client; $this->baseUrl = $baseUrl; + $this->partnerAttributionId = $partnerAttributionId; } public function create(string $token, PaymentInterface $payment): array @@ -97,7 +101,7 @@ public function create(string $token, PaymentInterface $payment): array 'Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json', - 'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code', + 'PayPal-Partner-Attribution-Id' => $this->partnerAttributionId, ], 'json' => $data, ] diff --git a/src/Api/OrderDetailsApi.php b/src/Api/OrderDetailsApi.php index 18fe1d19..23a1b029 100644 --- a/src/Api/OrderDetailsApi.php +++ b/src/Api/OrderDetailsApi.php @@ -14,10 +14,14 @@ final class OrderDetailsApi implements OrderDetailsApiInterface /** @var string */ private $baseUrl; - public function __construct(Client $client, string $baseUrl) + /** @var string */ + private $partnerAttributionId; + + public function __construct(Client $client, string $baseUrl, string $partnerAttributionId) { $this->client = $client; $this->baseUrl = $baseUrl; + $this->partnerAttributionId = $partnerAttributionId; } public function get(string $token, string $orderId): array @@ -29,7 +33,7 @@ public function get(string $token, string $orderId): array 'Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json', 'Accept' => 'application/json', - 'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code', + 'PayPal-Partner-Attribution-Id' => $this->partnerAttributionId, ], ] ); diff --git a/src/Api/RefundPaymentApi.php b/src/Api/RefundPaymentApi.php index a63d85c6..018b8dbb 100644 --- a/src/Api/RefundPaymentApi.php +++ b/src/Api/RefundPaymentApi.php @@ -24,10 +24,14 @@ final class RefundPaymentApi implements RefundPaymentApiInterface /** @var string */ private $baseUrl; - public function __construct(Client $client, string $baseUrl) + /** @var string */ + private $partnerAttributionId; + + public function __construct(Client $client, string $baseUrl, string $partnerAttributionId) { $this->client = $client; $this->baseUrl = $baseUrl; + $this->partnerAttributionId = $partnerAttributionId; } public function refund(string $token, string $paymentId): array @@ -38,7 +42,7 @@ public function refund(string $token, string $paymentId): array [ 'headers' => [ 'Authorization' => 'Bearer ' . $token, - 'PayPal-Partner-Attribution-Id' => 'sylius-ppcp4p-bn-code', + 'PayPal-Partner-Attribution-Id' => $this->partnerAttributionId, 'Content-Type' => 'application/json', 'PayPal-Request-Id' => Uuid::uuid4()->toString(), ], diff --git a/src/Resources/config/services/api.xml b/src/Resources/config/services/api.xml index a8a52f93..78c8a7f0 100644 --- a/src/Resources/config/services/api.xml +++ b/src/Resources/config/services/api.xml @@ -16,6 +16,7 @@ > %env(resolve:PAYPAL_API_BASE_URL)% + %env(resolve:PAYPAL_TRACKING_ID)% %env(resolve:PAYPAL_API_BASE_URL)% + %env(resolve:PAYPAL_TRACKING_ID)%) %env(resolve:PAYPAL_API_BASE_URL)% + %env(resolve:PAYPAL_TRACKING_ID)% %env(resolve:PAYPAL_API_BASE_URL)% + %env(resolve:PAYPAL_TRACKING_ID)%