Skip to content

Commit

Permalink
Remove redundant API endpoints for Identity API.
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Sep 12, 2023
1 parent e8e1a79 commit ebb9a55
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 375 deletions.
108 changes: 3 additions & 105 deletions src/Traits/PayPalAPI/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,113 +15,11 @@ trait Identity
*/
public function showProfileInfo()
{
$this->apiEndPoint = 'v1/identity/oauth2/userinfo?schema=paypalv1.1';
$this->apiEndPoint = 'v1/identity/openidconnect/userinfo?schema=openid';

$this->verb = 'get';

return $this->doPayPalRequest();
}

/**
* Create a merchant application.
*
* @param string $client_name
* @param array $redirect_uris
* @param array $contacts
* @param string $payer_id
* @param string $migrated_app
* @param string $application_type
* @param string $logo_url
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/identity/v1/#applications_post
*/
public function createMerchantApplication(string $client_name, array $redirect_uris, array $contacts, string $payer_id, string $migrated_app, string $application_type = 'web', string $logo_url = '')
{
$this->apiEndPoint = 'v1/identity/applications';

$this->options['json'] = array_filter([
'application_type' => $application_type,
'redirect_uris' => $redirect_uris,
'client_name' => $client_name,
'contacts' => $contacts,
'payer_id' => $payer_id,
'migrated_app' => $migrated_app,
'logo_uri' => $logo_url,
]);

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Create a merchant application.
*
* @param array $features
* @param string $account_property
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_post
*/
public function setAccountProperties(array $features, string $account_property = 'BRAINTREE_MERCHANT')
{
$this->apiEndPoint = 'v1/identity/account-settings';

$this->options['json'] = [
'account_property' => $account_property,
'features' => $features,
];
$this->setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Create a merchant application.
*
* @param string $account_property
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/api/identity/v1/#account-settings_deactivate
*/
public function disableAccountProperties(string $account_property = 'BRAINTREE_MERCHANT')
{
$this->apiEndPoint = 'v1/identity/account-settings/deactivate';

$this->options['json'] = [
'account_property' => $account_property,
];

$this->verb = 'post';

return $this->doPayPalRequest();
}

/**
* Get a client token.
*
* @throws \Throwable
*
* @return array|\Psr\Http\Message\StreamInterface|string
*
* @see https://developer.paypal.com/docs/multiparty/checkout/advanced/integrate/#link-sampleclienttokenrequest
*/
public function getClientToken()
{
$this->apiEndPoint = 'v1/identity/generate-token';

$this->verb = 'post';
$this->verb = 'get';

return $this->doPayPalRequest();
}
Expand Down
92 changes: 1 addition & 91 deletions tests/Feature/AdapterFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1176,97 +1176,7 @@ public function it_can_get_user_profile_details()

$response = $this->client->showProfileInfo();

$this->assertArrayHasKey('user_id', $response);
$this->assertArrayHasKey('payer_id', $response);
$this->assertArrayHasKey('emails', $response);
}

/** @test */
public function it_can_create_merchant_applications()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockCreateMerchantApplicationResponse()
)
);

$response = $this->client->createMerchantApplication(
'AGGREGATOR',
[
'https://example.com/callback',
'https://example.com/callback2',
],
[
'[email protected]',
'[email protected]',
],
'WDJJHEBZ4X2LY',
'some-open-id'
);

$this->assertArrayHasKey('client_name', $response);
$this->assertArrayHasKey('contacts', $response);
$this->assertArrayHasKey('redirect_uris', $response);
}

/** @test */
public function it_can_set_account_properties()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client('')
);

$response = $this->client->setAccountProperties($this->mockSetAccountPropertiesParams());

$this->assertEmpty($response);
}

/** @test */
public function it_can_disable_account_properties()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockUpdateOrdersResponse()
)
);

$response = $this->client->disableAccountProperties();

$this->assertEmpty($response);
}

/** @test */
public function it_can_get_client_token()
{
$this->client->setAccessToken([
'access_token' => self::$access_token,
'token_type' => 'Bearer',
]);

$this->client->setClient(
$this->mock_http_client(
$this->mockGetClientTokenResponse()
)
);

$response = $this->client->getClientToken();

$this->assertArrayHasKey('client_token', $response);
$this->assertArrayHasKey('address', $response);
}

/** @test */
Expand Down
57 changes: 4 additions & 53 deletions tests/Mocks/Responses/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,13 @@ trait Identity
private function mockShowProfileInfoResponse(): array
{
return Utils::jsonDecode('{
"user_id": "https://www.paypal.com/webapps/auth/identity/user/mWq6_1sU85v5EG9yHdPxJRrhGHrnMJ-1PQKtX6pcsmA",
"name": "identity test",
"given_name": "identity",
"family_name": "test",
"payer_id": "WDJJHEBZ4X2LY",
"address": {
"street_address": "1 Main St",
"locality": "San Jose",
"street_address": "7917394 Annursnac Hill Road Unit 0C",
"locality": "Ventura",
"region": "CA",
"postal_code": "95131",
"postal_code": "93003",
"country": "US"
},
"verified_account": "true",
"emails": [
{
"value": "[email protected]",
"primary": true
}
]
}', true);
}

private function mockCreateMerchantApplicationResponse(): array
{
return Utils::jsonDecode('{
"client_id": "AeTeCqaPp7JZBfUUb2d21cQ2KqyQGVhonfiUOJu99kgLhFFSrE59ruvhLOT4K3NzQoErgsUH6MY9uRqD",
"client_secret": "cf136dc3c1fc93f31185e5885805d",
"client_id_issued_at": 2893256800,
"client_secret_expires_at": 2893276800,
"redirect_uris": [
"https://example.com/callback",
"https://example.com/callback2"
],
"grant_types": [
"authorization_code",
"refresh_token"
],
"client_name": "AGGREGATOR",
"logo_uri": "https://example.com/logo.png",
"contacts": [
"[email protected]",
"[email protected]"
],
"policy_uri": "https://example.com/policyuri",
"tos_uri": "https://example.com/tosuri",
"scope": "profile email address",
"token_endpoint_auth_method": "client_secret_basic",
"jwks_uri": "https://example.com/my_public_keys.jwks"
}', true);
}

private function mockGetClientTokenResponse(): array
{
return Utils::jsonDecode('{
"client_token": "eyJicmFpbnRyZWUiOnsiYXV0aG9yaXphdGlvbkZpbmdlcnByaW50IjoiYjA0MWE2M2JlMTM4M2NlZGUxZTI3OWFlNDlhMWIyNzZlY2FjOTYzOWU2NjlhMGIzODQyYTdkMTY3NzcwYmY0OHxtZXJjaGFudF9pZD1yd3dua3FnMnhnNTZobTJuJnB1YmxpY19rZXk9czlic3BuaGtxMmYzaDk0NCZjcmVhdGVkX2F0PTIwMTgtMTEtMTRUMTE6MTg6MDAuMTU3WiIsInZlcnNpb24iOiIzLXBheXBhbCJ9LCJwYXlwYWwiOnsiYWNjZXNzVG9rZW4iOiJBMjFBQUhNVExyMmctVDlhSTJacUZHUmlFZ0ZFZGRHTGwxTzRlX0lvdk9ESVg2Q3pSdW5BVy02TzI2MjdiWUJ2cDNjQ0FNWi1lTFBNc2NDWnN0bDUyNHJyUGhUQklJNlBBIn19",
"expires_in": 3600
}
}', true);
}
}
59 changes: 0 additions & 59 deletions tests/Unit/Adapter/IdentityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,63 +27,4 @@ public function it_can_get_user_profile_details()

$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}());
}

/** @test */
public function it_can_create_merchant_applications()
{
$expectedResponse = $this->mockCreateMerchantApplicationResponse();

$expectedMethod = 'createMerchantApplication';

$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);

$mockClient->setApiCredentials($this->getMockCredentials());
$mockClient->getAccessToken();

$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}(
'AGGREGATOR',
[
'https://example.com/callback',
'https://example.com/callback2',
],
[
'[email protected]',
'[email protected]',
],
'WDJJHEBZ4X2LY',
'some-open-id'
));
}

/** @test */
public function it_can_set_account_properties()
{
$expectedResponse = '';

$expectedParams = $this->mockSetAccountPropertiesParams();

$expectedMethod = 'setAccountProperties';

$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);

$mockClient->setApiCredentials($this->getMockCredentials());
$mockClient->getAccessToken();

$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}($expectedParams));
}

/** @test */
public function it_can_disable_account_properties()
{
$expectedResponse = '';

$expectedMethod = 'disableAccountProperties';

$mockClient = $this->mock_client($expectedResponse, $expectedMethod, true);

$mockClient->setApiCredentials($this->getMockCredentials());
$mockClient->getAccessToken();

$this->assertEquals($expectedResponse, $mockClient->{$expectedMethod}());
}
}
Loading

0 comments on commit ebb9a55

Please sign in to comment.