Skip to content
This repository was archived by the owner on Jul 25, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendor
.idea
nbproject

composer.lock
96 changes: 96 additions & 0 deletions src/Cleeng/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,102 @@ public function getCustomer()
return $this->api('getCustomer', array('customerToken' => $this->getCustomerToken()), $userInfo);
}

/**
* Customer API: requestPasswordReset
*
* @throws Cleeng_Exception_RuntimeException
*/
public function requestPasswordReset($email, $resetUrl = '')
{
if (!$this->getPublisherToken()) {
throw new Cleeng_Exception_RuntimeException("Cannot call " . __FUNCTION__ . ": setPublisherToken must be used first.");
}

$this->api(
'requestPasswordReset',
array(
'publisherToken' => $this->getPublisherToken(),
'customerEmail' => $email,
'resetUrl' => $resetUrl
)
);
}

/**
* Customer API: registerCustomer
*
* @throws Cleeng_Exception_RuntimeException
*/
public function registerCustomer($email, $locale, $country, $currency, $password = "", $facebookId = "")
{
if (!$this->getPublisherToken()) {
throw new Cleeng_Exception_RuntimeException("Cannot call " . __FUNCTION__ . ": setPublisherToken must be used first.");
}

$customerToken = new Cleeng_Entity_CustomerToken();
return $this->api(
'registerCustomer',
array(
'publisherToken' => $this->getPublisherToken(),
'customerData' => array(
'email' => $email,
'locale' => $locale,
'country' => $country,
'currency' => $currency,
'password' => $password,
'facebookId' => $facebookId,
)
),
$customerToken
);
}

/**
* Customer API: generateCustomerTokenFromPassword
*
* @throws Cleeng_Exception_RuntimeException
*/
public function generateCustomerTokenFromPassword($email, $password)
{
if (!$this->getPublisherToken()) {
throw new Cleeng_Exception_RuntimeException("Cannot call " . __FUNCTION__ . ": setPublisherToken must be used first.");
}

$customerToken = new Cleeng_Entity_CustomerToken();
return $this->api(
'generateCustomerTokenFromPassword',
array(
'publisherToken' => $this->getPublisherToken(),
'customerEmail' => $email,
'password' => $password,
),
$customerToken
);
}

/**
* Customer API: getPrice
*
* @throws Cleeng_Exception_RuntimeException
*/
public function getPrice($offerId, $ipAddress)
{
if (!$this->getPublisherToken()) {
throw new Cleeng_Exception_RuntimeException("Cannot call " . __FUNCTION__ . ": setPublisherToken must be used first.");
}

$price = new Cleeng_Entity_Base();
return $this->api(
'getPrice',
array(
'publisherToken' => $this->getPublisherToken(),
'offerId' => $offerId,
'ipAddress' => $ipAddress,
),
$price
);
}

/**
* Customer API: getCustomerEmail
*
Expand Down
15 changes: 14 additions & 1 deletion tests/Cleeng/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ public function testGetCustomer()
$this->assertEquals('BE', $entity->country);
}

public function testRequestPasswordReset()
{
$transport = $this->getMock('Cleeng_Transport_AbstractTransport', array('call'));
$transport->expects($this->once())->method('call')
->will($this->returnValue('[{"result": {"success": true}, "id": "1", "error": null, "jsonrpc": "2.0"}]'));

$api = new Cleeng_Api();
$api->setTransport($transport);
$response = $api->requestPasswordReset('johndoe@domain.com', 'http://www.domain.com');

$this->assertEquals(null, $response);
}

public function testPrepareRemoteAuth()
{
$transport = $this->getMock('Cleeng_Transport_AbstractTransport', array('call'));
Expand Down Expand Up @@ -324,7 +337,7 @@ public function testUpdateAssociate()
$this->assertEquals('en_US', $entity->locale);
$this->assertEquals('US', $entity->country);
}

public function testListTransactions()
{
$transport = $this->getMock('Cleeng_Transport_AbstractTransport', array('call'));
Expand Down