Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ clover.xml

# Ignore PHPUnit cache file
.phpunit.result.cache

# Ignore PHP-CS-Fixer cache file
.php-cs-fixer.cache
8 changes: 0 additions & 8 deletions lib/PayjpObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ public function __construct($id = null, $opts = null)
// Standard accessor magic methods
public function __set($k, $v)
{
if ($v === "") {
throw new InvalidArgumentException(
'You cannot set \''.$k.'\'to an empty string. '
.'We interpret empty strings as NULL in requests. '
.'You may set obj->'.$k.' = NULL to delete the property'
);
}

if (self::$nestedUpdatableAttributes->includes($k)
&& isset($this->$k) && is_array($v)) {
$this->$k->replaceWith($v);
Expand Down
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ abstract class Util
{
// todo wanna use 'private const' (only PHP >= v7.1.0)
private static $types = array(
'account' => \Payjp\Account::class,
'application_url' => \Payjp\ApplicationUrl::class,
'balance' => \Payjp\Balance::class,
'card' => \Payjp\Card::class,
Expand Down
14 changes: 13 additions & 1 deletion tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AccountTest extends TestCase
{
private function managedAccountResponse($id)
{
return [
$data = [
'accounts_enabled' => [
'merchant',
'customer',
Expand Down Expand Up @@ -80,15 +80,27 @@ private function managedAccountResponse($id)
],
'object' => 'account'
];
return $data;
}

public function testBasicRetrieve()
{
$this->mockRequest('GET', '/v1/accounts', [], $this->managedAccountResponse('acct_ABC'));
$account = Account::retrieve();

$this->assertInstanceOf('Payjp\Account', $account);
$this->assertSame('acct_ABC', $account->id);

$this->assertInstanceOf('Payjp\PayjpObject', $account->customer);
$this->assertSame('acct_cus_38153121efdb7964dd1e147', $account->customer->id);

$this->assertInstanceOf('Payjp\PayjpObject', $account->merchant);
$this->assertSame('acct_mch_002418151ef82e49f6edee1', $account->merchant->id);

$this->assertInstanceOf('Payjp\Collection', $account->customer->cards);
$this->assertTrue(is_array($account->customer->cards->data));
$this->assertCount(1, $account->customer->cards->data);
$this->assertInstanceOf('Payjp\Card', $account->customer->cards->data[0]);
$this->assertSame('car_99abf74cb5527ff68233a8b836dd', $account->customer->cards->data[0]->id);
}
}
4 changes: 4 additions & 0 deletions tests/AuthenticationErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class AuthenticationErrorTest extends TestCase
public function testInvalidCredentials()
{
Payjp::setApiKey('invalid');
$mock = $this->setUpMockRequest();
$mock->expects($this->once())
->method('request')
->willThrowException(new Error\Authentication('Invalid API Key', 401));
try {
Customer::create();
} catch (Error\Authentication $e) {
Expand Down
10 changes: 9 additions & 1 deletion tests/BalanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,16 @@ public function testRetrieve()
$this->assertSame($expectedBalanceResource['statements']['object'], $balance->statements->object);
$this->assertSame($expectedBalanceResource['statements']['url'], $balance->statements->url);

foreach ($balance->statements->data as $statement) {
$expectedStatementsData = $expectedBalanceResource['statements']['data'];
foreach ($balance->statements->data as $index => $statement) {
$this->assertInstanceOf(Statement::class, $statement);
$this->assertSame($expectedStatementsData[$index]['id'], $statement->id);
if (isset($expectedStatementsData[$index]['term']) && $expectedStatementsData[$index]['term'] !== null) {
$this->assertInstanceOf(PayjpObject::class, $statement->term); // Assuming Term becomes PayjpObject
$this->assertSame($expectedStatementsData[$index]['term']['id'], $statement->term->id);
} else {
$this->assertNull($statement->term);
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/CardErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public function testExpiredCard()
'cvc' => '314'
]
];

$mock = $this->setUpMockRequest();
$mock->expects($this->once())
->method('request')
->willThrowException(new Error\Card('Expired card', null, 'expired_card', 402, null, null));
try {
Token::create($params, ['payjp_direct_token_generate' => 'true']);
} catch (Error\Card $e) {
Expand Down
Loading