Skip to content

Commit

Permalink
Add unlink account endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Radt committed Mar 1, 2018
1 parent 4dfe46a commit 47c58c6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Service/FacebookMessengerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,32 @@ public function getPsid($linkingToken)
return json_decode($this->curlService->get($url, $params), true);
}

/**
* Account Unlink
*
* @param string|int $psid
*
* @return mixed
*
* @throws FacebookMessengerException
*/
public function unlinkAccount($psid)
{
$this->checkAccessToken();

$params = [
'access_token' => $this->accessToken,
];

$content = $this->serializer->serialize([
'psid' => $psid,
], 'json');

$url = self::FB_API_URL.'/me/unlink_accounts?'.http_build_query($params);

return json_decode($this->curlService->post($url, $content), true);
}

/**
* Handle a verification token request, check against the given verificationToken.
* Throw an exception when the token is invalid, or return null when the request isn't a verification request.
Expand Down
24 changes: 24 additions & 0 deletions Tests/Service/FacebookMessengerServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,30 @@ public function testGetPsid()
self::assertEquals(2, $result['recipient']);
}

/**
* Test unlink an account
*
* @throws \PouleR\FacebookMessengerBundle\Exception\FacebookMessengerException
*/
public function testUnlinkAccount()
{
$curlService = $this->createMock(CurlService::class);
$curlService->expects(self::once())
->method('post')
->with(
'https://graph.facebook.com/v2.6/me/unlink_accounts?access_token=token',
'{"psid":"PSID"}'
)
->willReturn('{"result": "unlink account success"}');

$service = new FacebookMessengerService($curlService);
$service->setAccessToken('token');

$result = $service->unlinkAccount('PSID');

self::assertEquals('unlink account success', $result['result']);
}

/**
* Test if null is returned when there is no hub_mode set in the request
*/
Expand Down

0 comments on commit 47c58c6

Please sign in to comment.