Skip to content

Commit

Permalink
Merge ab5e27f into ab887b4
Browse files Browse the repository at this point in the history
  • Loading branch information
Rrathinasabapath committed Oct 22, 2020
2 parents ab887b4 + ab5e27f commit 8f1b47d
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Hyperwallet/Hyperwallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,20 @@ public function createPrepaidCard($userToken, PrepaidCard $prepaidCard) {
return new PrepaidCard($body);
}

/**
* Replace a prepaid card
*
* @param string $userToken The user token
* @param PrepaidCard $prepaidCard The prepaid card data
* @return PrepaidCard
*/
public function replacePrepaidCard($userToken, PrepaidCard $prepaidCard) {
if (empty($prepaidCard->getReplacementReason())) {
throw new HyperwalletArgumentException('replacementReason is required!');
}
return $this->createPrepaidCard($userToken, $prepaidCard);
}

/**
* Get a prepaid card
*
Expand Down
48 changes: 48 additions & 0 deletions src/Hyperwallet/Model/PrepaidCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*
* @property string $cardType The prepaid card type
*
* @property String $replacementOf The token of prepaid card to be replaced
* @property String $replacementReason The prepaid card replacement reason
* @property string $cardPackage The prepaid card package
* @property string $cardNumber The prepaid card number
* @property string $cardBrand The prepaid card brand
Expand Down Expand Up @@ -52,6 +54,11 @@ class PrepaidCard extends BaseModel {
const CARD_BRAND_VISA = 'VISA';
const CARD_BRAND_MASTERCARD = 'MASTERCARD';

const REPLACEMENT_REASON_LOST_STOLEN= 'LOST_STOLEN';
const REPLACEMENT_REASON_DAMAGED= 'DAMAGED';
const REPLACEMENT_REASON_COMPROMISED= 'COMPROMISED';
const REPLACEMENT_REASON_EXPIRED= 'EXPIRED';

public static function FILTERS_ARRAY() {
return array('status');
}
Expand Down Expand Up @@ -197,4 +204,45 @@ public function getDateOfExpiry() {
return $this->dateOfExpiry ? new \DateTime($this->dateOfExpiry) : null;
}


/**
* Get the prepaid card token to be replaced
*
* @return string
*/
public function getReplacementOf() {
return $this->replacementOf;
}

/**
* Set the prepaid card token to be replaced
*
* @param string $token
* @return PrepaidCard
*/
public function setReplacementOf($replacementOf) {
$this->replacementOf = $replacementOf;
return $this;
}

/**
* Get the prepaid card's replacement reason
*
* @return string
*/
public function getReplacementReason() {
return $this->replacementReason;
}

/**
* set the prepaid card's replacement reason
*
* @param string $token
* @return PrepaidCard
*/
public function setReplacementReason($replacementReason) {
$this->replacementReason = $replacementReason;
return $this;
}

}
2 changes: 1 addition & 1 deletion src/Hyperwallet/Util/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function __construct($username, $password, $server, $clientOptions = arra
* @throws HyperwalletApiException
*/
public function doPost($partialUrl, array $uriParams, BaseModel $data = null, array $query = array(), array $headers = array()) {
return $this->doRequest('POST', $partialUrl, $uriParams, array(
return $this->doRequest('POST', $partialUrl, $uriParams, array(
'query' => $query,
'body' => $data ? \GuzzleHttp\json_encode($data->getPropertiesForCreate(), JSON_FORCE_OBJECT) : '{}',
'headers' => array_merge($headers, array(
Expand Down
38 changes: 38 additions & 0 deletions tests/Hyperwallet/Tests/HyperwalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,44 @@ public function testCreatePrepaidCard_allParameters() {
\Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => 'test-user-token'), $prepaidCard, array());
}

public function testReplacePrepaidCard_noReplacementReason() {
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);
$prepaidCard = new PrepaidCard();
$prepaidCard->setType(PrepaidCard::TYPE_PREPAID_CARD);
$prepaidCard->setCardPackage("test-card-package");
$prepaidCard->setReplacementOf("test-prepaid-card-token");

try {
$client->replacePrepaidCard('test-user-token', $prepaidCard);
$this->fail('HyperwalletArgumentException expected');
} catch (HyperwalletArgumentException $e) {
$this->assertEquals('replacementReason is required!', $e->getMessage());
}
}

public function testReplacePrepaidCard_allParameters() {
// Setup
$client = new Hyperwallet('test-username', 'test-password');
$apiClientMock = $this->createAndInjectApiClientMock($client);
$prepaidCard = new PrepaidCard();
$prepaidCard->setType(PrepaidCard::TYPE_PREPAID_CARD);
$prepaidCard->setCardPackage("test-card-package");
$prepaidCard->setReplacementOf("test-prepaid-card-token");
$prepaidCard->setReplacementReason(PrepaidCard::REPLACEMENT_REASON_DAMAGED);

\Phake::when($apiClientMock)->doPost('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => 'test-user-token'), $prepaidCard, array())->thenReturn(array('success' => 'true'));

// Run test
$replacedPrepaidCard = $client->replacePrepaidCard('test-user-token', $prepaidCard);
$this->assertNotNull($replacedPrepaidCard);
$this->assertEquals(array('success' => 'true'), $replacedPrepaidCard->getProperties());

// Validate mock
\Phake::verify($apiClientMock)->doPost('/rest/v4/users/{user-token}/prepaid-cards', array('user-token' => 'test-user-token'), $prepaidCard, array());
}

public function testGetPrepaidCard_noUserToken() {
// Setup
$client = new Hyperwallet('test-username', 'test-password');
Expand Down

0 comments on commit 8f1b47d

Please sign in to comment.