Skip to content

Commit

Permalink
Merge pull request #40 from payjp/nonz250/term-balance
Browse files Browse the repository at this point in the history
feat: add term and balance.
  • Loading branch information
nonz250 authored Apr 9, 2024
2 parents 6a48996 + 1962bba commit 10ad21c
Show file tree
Hide file tree
Showing 14 changed files with 763 additions and 488 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.0
1.6.0
28 changes: 28 additions & 0 deletions lib/Balance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Payjp;

class Balance extends ApiResource
{
/**
* @param string $id The ID of the balance to retrieve.
* @param array|string|null $opts
*
* @return Balance
*/
public static function retrieve($id, $opts = null)
{
return self::_retrieve($id, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return array An array of Balances.
*/
public static function all($params = null, $opts = null)
{
return self::_all($params, $opts);
}
}
28 changes: 28 additions & 0 deletions lib/Term.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Payjp;

class Term extends ApiResource
{
/**
* @param string $id The ID of the term to retrieve.
* @param array|string|null $opts
*
* @return Term
*/
public static function retrieve($id, $opts = null)
{
return self::_retrieve($id, $opts);
}

/**
* @param array|null $params
* @param array|string|null $opts
*
* @return array An array of Terms.
*/
public static function all($params = null, $opts = null)
{
return self::_all($params, $opts);
}
}
30 changes: 16 additions & 14 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ abstract class Util
{
// todo wanna use 'private const' (only PHP >= v7.1.0)
private static $types = array(
'application_url' => 'Payjp\\ApplicationUrl',
'card' => 'Payjp\\Card',
'charge' => 'Payjp\\Charge',
'customer' => 'Payjp\\Customer',
'event' => 'Payjp\\Event',
'list' => 'Payjp\\Collection',
'plan' => 'Payjp\\Plan',
'statement' => 'Payjp\\Statement',
'statement_url' => 'Payjp\\StatementUrl',
'subscription' => 'Payjp\\Subscription',
'tenant' => 'Payjp\\Tenant',
'token' => 'Payjp\\Token',
'tenant_transfer' => 'Payjp\\TenantTransfer',
'transfer' => 'Payjp\\Transfer',
'application_url' => \Payjp\ApplicationUrl::class,
'balance' => \Payjp\Balance::class,
'card' => \Payjp\Card::class,
'charge' => \Payjp\Charge::class,
'customer' => \Payjp\Customer::class,
'event' => \Payjp\Event::class,
'list' => \Payjp\Collection::class,
'plan' => \Payjp\Plan::class,
'statement' => \Payjp\Statement::class,
'statement_url' => \Payjp\StatementUrl::class,
'subscription' => \Payjp\Subscription::class,
'tenant' => \Payjp\Tenant::class,
'token' => \Payjp\Token::class,
'tenant_transfer' => \Payjp\TenantTransfer::class,
'term' => \Payjp\Term::class,
'transfer' => \Payjp\Transfer::class,
);

/**
Expand Down
153 changes: 75 additions & 78 deletions tests/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,89 @@ class AccountTest extends TestCase
{
private function managedAccountResponse($id)
{
return array(
'accounts_enabled' => array('merchant', 'customer'),
return [
'accounts_enabled' => [
'merchant',
'customer',
],
'created' => 1432965397,
'customer' => array(
'cards' => array(
'count' => 1,
'data' => array(
array(
'address_city' => '\u8d64\u5742',
'address_line1' => '7-4',
'address_line2' => '203',
'address_state' => '\u6e2f\u533a',
'address_zip' => '1070050',
'address_zip_check' => 'passed',
'brand' => 'Visa',
'country' => self::COUNTRY,
'created' => 1432965397,
'cvc_check' => 'passed',
'exp_month' => 12,
'exp_year' => 2016,
'fingerprint' => 'e1d8225886e3a7211127df751c86787f',
'id' => 'car_99abf74cb5527ff68233a8b836dd',
'last4' => '4242',
'livemode' => true,
'name' => 'Test Hodler',
'object' => 'card'
)
),
'object' => 'list',
'url' => '/v1/accounts/cards'
),
'created' => 1432965397,
'default_card' => null,
'description' => 'user customer',
'email' => null,
'id' => 'acct_cus_38153121efdb7964dd1e147',
'object' => 'customer'
),
'email' => '[email protected]',
'id' => $id,
'merchant' => array(
'bank_enabled' => false,
'brands_accepted' => array(
'Visa',
'American Express',
'MasterCard',
'JCB',
'Diners Club'
),
'business_type' => 'personal',
'charge_type' => null,
'contact_phone' => null,
'country' => 'JP',
'created' => 1432965397,
'currencies_supported' => array(
self::CURRENCY
),
'default_currency' => self::CURRENCY,
'details_submitted' => false,
'id' => 'acct_mch_002418151ef82e49f6edee1',
'livemode_activated_at' => 1432965401,
'livemode_enabled' => true,
'object' => 'merchant',
'product_detail' => null,
'product_name' => null,
'product_type' => null,
'site_published' => false,
'url' => null
),
'object' => 'account'

);
'customer' => [
'cards' => [
'count' => 1,
'data' => [
[
'address_city' => '\u8d64\u5742',
'address_line1' => '7-4',
'address_line2' => '203',
'address_state' => '\u6e2f\u533a',
'address_zip' => '1070050',
'address_zip_check' => 'passed',
'brand' => 'Visa',
'country' => self::COUNTRY,
'created' => 1432965397,
'cvc_check' => 'passed',
'exp_month' => 12,
'exp_year' => 2016,
'fingerprint' => 'e1d8225886e3a7211127df751c86787f',
'id' => 'car_99abf74cb5527ff68233a8b836dd',
'last4' => '4242',
'livemode' => true,
'name' => 'Test Hodler',
'object' => 'card'
]
],
'object' => 'list',
'url' => '/v1/accounts/cards'
],
'created' => 1432965397,
'default_card' => null,
'description' => 'user customer',
'email' => null,
'id' => 'acct_cus_38153121efdb7964dd1e147',
'object' => 'customer'
],
'email' => '[email protected]',
'id' => $id,
'merchant' => [
'bank_enabled' => false,
'brands_accepted' => [
'Visa',
'American Express',
'MasterCard',
'JCB',
'Diners Club'
],
'business_type' => 'personal',
'charge_type' => null,
'contact_phone' => null,
'country' => 'JP',
'created' => 1432965397,
'currencies_supported' => [
self::CURRENCY
],
'default_currency' => self::CURRENCY,
'details_submitted' => false,
'id' => 'acct_mch_002418151ef82e49f6edee1',
'livemode_activated_at' => 1432965401,
'livemode_enabled' => true,
'object' => 'merchant',
'product_detail' => null,
'product_name' => null,
'product_type' => null,
'site_published' => false,
'url' => null
],
'object' => 'account'
];
}

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

$this->assertSame('acct_ABC', $account->id);
$this->assertSame('acct_cus_38153121efdb7964dd1e147', $account->customer->id);
$this->assertSame('acct_mch_002418151ef82e49f6edee1', $account->merchant->id);
}

public function testRetrieve()
{
$account = Account::retrieve();
}
}
Loading

0 comments on commit 10ad21c

Please sign in to comment.