-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from brandedcrate/add_vaults_suppoert
refs #3 add vaults support
- Loading branch information
Showing
7 changed files
with
247 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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,59 @@ | ||
<?php namespace BrandedCrate\PayJunction; | ||
|
||
class CustomerVaultClient extends Client | ||
{ | ||
/** | ||
* create a new customer vault | ||
* @param $customerId | ||
* @param $params | ||
* @return array|mixed | ||
*/ | ||
public function create($customerId, $params) | ||
{ | ||
return $this->post("/customers/$customerId/vaults", $params); | ||
} | ||
|
||
/** | ||
* read a customer vault | ||
* @param $customerid | ||
* @param $id | ||
* @return array|mixed | ||
*/ | ||
public function read($customerId, $id) | ||
{ | ||
return $this->get("/customers/$customerId/vaults/$id"); | ||
} | ||
|
||
/** | ||
* index all customer vaults | ||
* @param $customerid | ||
* @return array|mixed | ||
*/ | ||
public function index($customerId) | ||
{ | ||
return $this->get("/customers/$customerId/vaults"); | ||
} | ||
|
||
/** | ||
* update existing customer vault | ||
* @param $customerId | ||
* @param $id | ||
* @param null $params | ||
* @return array|mixed | ||
*/ | ||
public function update($customerId, $id, $params = null) | ||
{ | ||
return $this->put("/customers/$customerId/vaults/$id", $params); | ||
} | ||
|
||
/** | ||
* delete a customer vault | ||
* @param $customerId | ||
* @param $id | ||
* @return array|mixed | ||
*/ | ||
public function delete($customerId, $id) | ||
{ | ||
return $this->del("/customers/$customerId/vaults/$id"); | ||
} | ||
} |
This file contains 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
This file contains 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,134 @@ | ||
<?php | ||
|
||
namespace BrandedCrate\PayJunction\Test\Integration; | ||
|
||
use BrandedCrate\PayJunction; | ||
|
||
class CustomerVaultTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Runs once before all tests are started | ||
*/ | ||
public function setUp() | ||
{ | ||
$options = array( | ||
'username' => 'pj-ql-01', | ||
'password' => 'pj-ql-01p', | ||
'appkey' => '2489d40d-a74f-474f-9e8e-7b39507f3101', | ||
'endpoint' => 'test' | ||
); | ||
|
||
$this->client = new PayJunction\Client($options); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function createCustomer() | ||
{ | ||
return $this->client->customer()->create(array( | ||
'email' => '[email protected]', | ||
'firstName' => 'Joe', | ||
'lastName' => 'Schmoe', | ||
)); | ||
} | ||
|
||
public function createCustomerVaultMc($customer) | ||
{ | ||
return $this->client->customerVault() | ||
->create($customer->customerId, array( | ||
'cardNumber' => '5105105105105100', | ||
'cardExpMonth' => '9', | ||
'cardExpYear' => '24', | ||
'address' => '1600 Pennsylvania Ave NW', | ||
'city' => 'Washington', | ||
'state' => 'DC', | ||
'zip' => 20500 | ||
)); | ||
} | ||
|
||
public function createCustomerVaultVisa($customer) | ||
{ | ||
return $this->client->customerVault() | ||
->create($customer->customerId, array( | ||
'cardNumber' => '4242424242424242', | ||
'cardExpMonth' => '2', | ||
'cardExpYear' => '25' | ||
)); | ||
} | ||
|
||
public function createCustomerVaultAch($customer) | ||
{ | ||
return $this->client->customerVault() | ||
->create($customer->customerId, array( | ||
'achRoutingNumber' => '104000016', | ||
'achAccountNumber' => '123456789', | ||
'achAccountType' => 'CHECKING', | ||
'achType' => 'CCD' | ||
)); | ||
} | ||
|
||
public function testCreateCustomerVault() | ||
{ | ||
$customer = $this->createCustomer(); | ||
$vault = $this->createCustomerVaultMc($customer); | ||
|
||
$type = gettype($vault->vaultId); | ||
$this->assertTrue( | ||
is_integer($vault->vaultId), | ||
"Got a $type instead of an integer. A vault was not created" | ||
); | ||
} | ||
|
||
public function testReadCustomerVault() | ||
{ | ||
$customer = $this->createCustomer(); | ||
$vaultId = $this->createCustomerVaultMc($customer)->vaultId; | ||
|
||
$vault = $this->client->customerVault() | ||
->read($customer->customerId, $vaultId); | ||
|
||
$this->assertEquals($vault->lastFour, 5100, 'Credit card is not in vault'); | ||
} | ||
|
||
public function testIndexCustomerVault() | ||
{ | ||
$customer = $this->createCustomer(); | ||
$vault1Id = $this->createCustomerVaultMc($customer)->vaultId; | ||
$vault2Id = $this->createCustomerVaultVisa($customer)->vaultId; | ||
|
||
$vaults = $this->client->customerVault() | ||
->index($customer->customerId); | ||
|
||
$vaultIdsInIndex = array( | ||
$vaults->results[0]->vaultId, | ||
$vaults->results[1]->vaultId, | ||
); | ||
|
||
$this->assertEquals(in_array($vault1Id, $vaultIdsInIndex), true, 'Missing vault 1'); | ||
$this->assertEquals(in_array($vault2Id, $vaultIdsInIndex), true, 'Missing vault 2'); | ||
} | ||
|
||
public function testUpdateCustomerVault() | ||
{ | ||
$customer = $this->createCustomer(); | ||
$vaultId = $this->createCustomerVaultAch($customer)->vaultId; | ||
|
||
$vault = $this->client->customerVault() | ||
->update($customer->customerId, $vaultId, array( | ||
'address' => 'somenewaddress' | ||
)); | ||
|
||
$this->assertEquals($vault->address->address, 'somenewaddress', 'Address unchanged'); | ||
} | ||
|
||
public function testDeleteCustomerVault() | ||
{ | ||
$customer = $this->createCustomer(); | ||
$vaultId = $this->createCustomerVaultAch($customer)->vaultId; | ||
|
||
$response = $this->client->customerVault() | ||
->delete($customer->customerId, $vaultId); | ||
|
||
$this->assertEquals($response, true, 'Vault not deleted'); | ||
} | ||
} |
This file contains 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
This file contains 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