-
Notifications
You must be signed in to change notification settings - Fork 4
INTEG-427: Implement affiliate seller services #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3f84c7b
implement AffiliateSeller API endpoints
reindert-vetter 10e2052
Make setDeclineReason($declineReason) nullables
reindert-vetter eb61f23
Apply php-cs-fixer changes
reindert-vetter d9171a4
Fix AffiliateSeller mock: use null instead of empty string for declin…
reindert-vetter ceac645
Add seller statistics
reindert-vetter f82e7e2
Add seller payout options
reindert-vetter 1adf320
Add seller payout methods
reindert-vetter 0894bb4
Add seller payout methods
reindert-vetter c150c55
Remove not existing allowEmptyRelations parameter
reindert-vetter 0a06220
Add missing fields to seller profile entity
reindert-vetter c916cdb
Fix sort types to sort the affiliate sellers
reindert-vetter 88dc6f5
Remove payout_methods, it is not a (default) value
reindert-vetter c3ca85c
Apply php-cs-fixer changes
reindert-vetter bf01a23
fix: remove payout methods from affiliate
e6fd65f
fix: update type hinting
91b2186
Some statistics fields are floats
reindert-vetter 822f24e
Apply php-cs-fixer changes
reindert-vetter d759a65
Payment methods without id and dates
reindert-vetter 2114d48
Apply php-cs-fixer changes
reindert-vetter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
181 changes: 181 additions & 0 deletions
181
Tests/Feature/AffiliateSeller/IndexAffiliateSellersTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| <?php | ||
|
|
||
| /** @noinspection PhpUnhandledExceptionInspection */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PlugAndPay\Sdk\Tests\Feature\AffiliateSeller; | ||
|
|
||
| use DateTime; | ||
| use PHPUnit\Framework\TestCase; | ||
| use PlugAndPay\Sdk\Enum\AffiliateSellerIncludes; | ||
| use PlugAndPay\Sdk\Enum\Direction; | ||
| use PlugAndPay\Sdk\Enum\SellerSortType; | ||
| use PlugAndPay\Sdk\Enum\SellerStatus; | ||
| use PlugAndPay\Sdk\Filters\AffiliateSellerFilter; | ||
| use PlugAndPay\Sdk\Service\AffiliateSellerService; | ||
| use PlugAndPay\Sdk\Tests\Feature\AffiliateSeller\Mock\AffiliateSellerIndexMockClient; | ||
|
|
||
| class IndexAffiliateSellersTest extends TestCase | ||
| { | ||
| /** | ||
| * @test | ||
| * @dataProvider relationsProvider | ||
| */ | ||
| public function index_sellers_with_relations(AffiliateSellerIncludes $include, string $includeValue): void | ||
| { | ||
| $client = (new AffiliateSellerIndexMockClient()); | ||
| $service = new AffiliateSellerService($client); | ||
|
|
||
| $sellers = $service->include($include)->get(); | ||
|
|
||
| static::assertSame(1, $sellers[0]->id()); | ||
| static::assertSame("/v2/affiliates/sellers?include=$includeValue", $client->path()); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider for index_sellers_with_relations. | ||
| */ | ||
| public static function relationsProvider(): array | ||
| { | ||
| return [ | ||
| 'address' => [AffiliateSellerIncludes::ADDRESS, 'address'], | ||
| 'contact' => [AffiliateSellerIncludes::CONTACT, 'contact'], | ||
| 'profile' => [AffiliateSellerIncludes::PROFILE, 'profile'], | ||
| 'statistics' => [AffiliateSellerIncludes::STATISTICS, 'statistics'], | ||
| 'payoutOptions' => [AffiliateSellerIncludes::PAYOUT_OPTIONS, 'payout_options'], | ||
| 'payoutMethods' => [AffiliateSellerIncludes::PAYOUT_METHODS, 'payout_methods'], | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider sellerFilterDataProvider | ||
| * @test | ||
| */ | ||
| public function index_sellers_with_filter(string $method, mixed $value, string $queryKey, string $queryValue): void | ||
| { | ||
| $client = (new AffiliateSellerIndexMockClient()); | ||
| $service = new AffiliateSellerService($client); | ||
|
|
||
| $filter = (new AffiliateSellerFilter())->$method($value); | ||
| $service->get($filter); | ||
|
|
||
| static::assertSame("/v2/affiliates/sellers?$queryKey=$queryValue", $client->path()); | ||
| } | ||
|
|
||
| /** | ||
| * @test | ||
| */ | ||
| public function index_sellers_with_null_decline_reason(): void | ||
| { | ||
| $client = (new AffiliateSellerIndexMockClient([ | ||
| [ | ||
| 'id' => 1, | ||
| 'name' => 'John Doe', | ||
| 'email' => 'john@example.com', | ||
| 'decline_reason' => null, | ||
| 'profile_id' => 1, | ||
| 'status' => 'accepted', | ||
| 'payout_methods' => null, | ||
| ], | ||
| ])); | ||
| $service = new AffiliateSellerService($client); | ||
| $sellers = $service->get(); | ||
|
|
||
| static::assertSame(1, $sellers[0]->id()); | ||
| static::assertNull($sellers[0]->declineReason()); | ||
| } | ||
|
|
||
| /** | ||
| * Data provider for index_sellers_with_filter. | ||
| */ | ||
| public static function sellerFilterDataProvider(): array | ||
| { | ||
| return [ | ||
| [ | ||
| 'method' => 'limit', | ||
| 'value' => 10, | ||
| 'queryKey' => 'limit', | ||
| 'queryValue' => '10', | ||
| ], | ||
| [ | ||
| 'method' => 'sort', | ||
| 'value' => SellerSortType::NAME, | ||
| 'queryKey' => 'sort', | ||
| 'queryValue' => 'name', | ||
| ], | ||
| [ | ||
| 'method' => 'sort', | ||
| 'value' => SellerSortType::COMMISSION, | ||
| 'queryKey' => 'sort', | ||
| 'queryValue' => 'commission', | ||
| ], | ||
| [ | ||
| 'method' => 'sort', | ||
| 'value' => SellerSortType::LOCKED_REVENUE, | ||
| 'queryKey' => 'sort', | ||
| 'queryValue' => 'locked_revenue', | ||
| ], | ||
| [ | ||
| 'method' => 'sort', | ||
| 'value' => SellerSortType::PAID_REVENUE, | ||
| 'queryKey' => 'sort', | ||
| 'queryValue' => 'paid_revenue', | ||
| ], | ||
| [ | ||
| 'method' => 'sort', | ||
| 'value' => SellerSortType::PENDING_REVENUE, | ||
| 'queryKey' => 'sort', | ||
| 'queryValue' => 'pending_revenue', | ||
| ], | ||
| [ | ||
| 'method' => 'sort', | ||
| 'value' => SellerSortType::SALES, | ||
| 'queryKey' => 'sort', | ||
| 'queryValue' => 'sales', | ||
| ], | ||
| [ | ||
| 'method' => 'sort', | ||
| 'value' => SellerSortType::TOTAL_REVENUE, | ||
| 'queryKey' => 'sort', | ||
| 'queryValue' => 'total_revenue', | ||
| ], | ||
| [ | ||
| 'method' => 'direction', | ||
| 'value' => Direction::DESC, | ||
| 'queryKey' => 'direction', | ||
| 'queryValue' => 'desc', | ||
| ], | ||
| [ | ||
| 'method' => 'query', | ||
| 'value' => 'John', | ||
| 'queryKey' => 'q', | ||
| 'queryValue' => 'John', | ||
| ], | ||
| [ | ||
| 'method' => 'status', | ||
| 'value' => SellerStatus::ACCEPTED, | ||
| 'queryKey' => 'status', | ||
| 'queryValue' => 'accepted', | ||
| ], | ||
| [ | ||
| 'method' => 'eligibleForPayout', | ||
| 'value' => true, | ||
| 'queryKey' => 'eligible_for_payout', | ||
| 'queryValue' => '1', | ||
| ], | ||
| [ | ||
| 'method' => 'since', | ||
| 'value' => new DateTime('2023-01-01'), | ||
| 'queryKey' => 'since', | ||
| 'queryValue' => '2023-01-01', | ||
| ], | ||
| [ | ||
| 'method' => 'until', | ||
| 'value' => new DateTime('2023-12-31'), | ||
| 'queryKey' => 'until', | ||
| 'queryValue' => '2023-12-31', | ||
| ], | ||
| ]; | ||
| } | ||
| } | ||
33 changes: 33 additions & 0 deletions
33
Tests/Feature/AffiliateSeller/Mock/AffiliateSellerIndexMockClient.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PlugAndPay\Sdk\Tests\Feature\AffiliateSeller\Mock; | ||
|
|
||
| use PlugAndPay\Sdk\Entity\Response; | ||
| use PlugAndPay\Sdk\Tests\Feature\ClientMock; | ||
|
|
||
| class AffiliateSellerIndexMockClient extends ClientMock | ||
| { | ||
| private string $path; | ||
|
|
||
| /** @noinspection PhpMissingParentConstructorInspection */ | ||
| public function __construct(array $data = [[]]) | ||
| { | ||
| foreach ($data as $sellerData) { | ||
| $this->responseBody[] = $sellerData + AffiliateSellerShowMockClient::BASIC_SELLER; | ||
| } | ||
| } | ||
|
|
||
| public function get(string $path): Response | ||
| { | ||
| $this->path = $path; | ||
|
|
||
| return new Response(Response::HTTP_OK, ['data' => $this->responseBody]); | ||
| } | ||
|
|
||
| public function path(): string | ||
| { | ||
| return $this->path; | ||
| } | ||
| } |
149 changes: 149 additions & 0 deletions
149
Tests/Feature/AffiliateSeller/Mock/AffiliateSellerShowMockClient.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace PlugAndPay\Sdk\Tests\Feature\AffiliateSeller\Mock; | ||
|
|
||
| use JsonException; | ||
| use PlugAndPay\Sdk\Entity\Response; | ||
| use PlugAndPay\Sdk\Exception\ExceptionFactory; | ||
| use PlugAndPay\Sdk\Exception\NotFoundException; | ||
| use PlugAndPay\Sdk\Exception\ValidationException; | ||
| use PlugAndPay\Sdk\Tests\Feature\ClientMock; | ||
|
|
||
| class AffiliateSellerShowMockClient extends ClientMock | ||
| { | ||
| public const BASIC_SELLER = [ | ||
| 'id' => 1, | ||
| 'name' => 'John Doe', | ||
| 'email' => 'john@example.com', | ||
| 'decline_reason' => '', | ||
|
reindert-vetter marked this conversation as resolved.
|
||
| 'profile_id' => 1, | ||
| 'status' => 'accepted', | ||
| ]; | ||
| protected string $path; | ||
|
|
||
| /** @noinspection PhpMissingParentConstructorInspection */ | ||
| public function __construct(array $data = []) | ||
| { | ||
| $this->responseBody = ['data' => $data + self::BASIC_SELLER]; | ||
| } | ||
|
|
||
| public function address(array $data = []): self | ||
| { | ||
| $this->responseBody['data']['address'] = $data + [ | ||
| 'city' => 'New York', | ||
| 'country' => 'US', | ||
| 'street' => 'Main St', | ||
| 'housenumber' => '123', | ||
| 'zipcode' => '10001', | ||
| ]; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function contact(array $data = []): self | ||
| { | ||
| $this->responseBody['data']['contact'] = $data + [ | ||
| 'company' => 'ACME Corp', | ||
| 'email' => 'john@example.com', | ||
| 'firstname' => 'John', | ||
| 'lastname' => 'Doe', | ||
| 'telephone' => '+1234567890', | ||
| 'website' => 'https://example.com', | ||
| 'vat_id_number' => 'US123456789', | ||
| 'tax_exempt' => 'none', | ||
| ]; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @throws NotFoundException | ||
| * @throws ValidationException | ||
| * @throws JsonException | ||
| */ | ||
| public function get(string $path): Response | ||
| { | ||
| $this->path = $path; | ||
| $response = new Response(Response::HTTP_OK, $this->responseBody); | ||
|
|
||
| $exception = ExceptionFactory::create($response->status(), json_encode($response->body(), JSON_THROW_ON_ERROR)); | ||
| if ($exception) { | ||
| throw $exception; | ||
| } | ||
|
|
||
| return $response; | ||
| } | ||
|
|
||
| public function path(): string | ||
| { | ||
| return $this->path; | ||
| } | ||
|
|
||
| public function profile(array $data = []): self | ||
| { | ||
| $this->responseBody['data']['profile'] = $data + [ | ||
| 'id' => 14, | ||
| 'default_recurring' => false, | ||
| 'default_type' => 'percentage', | ||
| 'default_value' => '50.00', | ||
| 'default_form_value' => '2.50', | ||
| 'label' => '', | ||
| 'session_lifetime' => 120, | ||
| 'tenant_id' => 3, | ||
| ]; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function statistics(array $data = []): self | ||
| { | ||
| $this->responseBody['data']['statistics'] = $data + [ | ||
| 'clicks' => null, | ||
| 'commission' => 0, | ||
| 'locked' => 0, | ||
| 'orders' => 0, | ||
| 'paidout' => 0, | ||
| 'pending' => 0, | ||
| 'recurring' => 0, | ||
| 'sales' => 0, | ||
| 'value' => 0, | ||
| ]; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function payoutOptions(array $data = []): self | ||
| { | ||
| $this->responseBody['data']['payout_options'] = $data + [ | ||
| 'method' => 'paypal', | ||
| 'settings' => [ | ||
| 'email' => 'oramcharan@example.com', | ||
| 'phone' => '+3177 4223366', | ||
| 'paypal_me_link' => 'https://paypal.me/lopes.jennifer', | ||
| ], | ||
| ]; | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| public function payoutMethods(?array $data = null): self | ||
| { | ||
| if ($data === null) { | ||
| $data = [ | ||
| [ | ||
| 'method' => 'bank_transfer', | ||
| 'settings' => [ | ||
| 'iban' => 'NL91ABNA0417164300', | ||
| 'bic' => 'ABNANL2A', | ||
| ], | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| $this->responseBody['data']['payout_methods'] = $data; | ||
|
|
||
| return $this; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.