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
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

# PHP PSR-2 Coding Standards
# http://www.php-fig.org/psr/psr-2/

root = true

[*.php]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
indent_size = 4
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ require_once("/path/to/Finix/Bootstrap.php");

```php
require(__DIR__ . '/src/Finix/Settings.php');
Finix\Settings::configure('http://b.papi.staging.finix.io', '$USERNAME', '$PASSWORD');
Finix\Settings::configure('https://api-staging.finix.io/', '$USERNAME', '$PASSWORD');
require(__DIR__ . '/src/Finix/Bootstrap.php');
\Finix\Bootstrap::init();
```
Expand Down
14 changes: 6 additions & 8 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
<?php

require(__DIR__ . '/src/Finix/Settings.php');
require(__DIR__ . '/tests/Finix/SampleData.php');
require(__DIR__ . '/tests/Finix/Fixtures.php');
require(__DIR__ . '/src/Finix/Bootstrap.php');

use \Finix\Tests\SampleData;
use \Finix\Tests\Fixtures;
use \Finix\Settings;
use \Finix\Bootstrap;

Settings::configure(
SampleData::$apiUrl,
SampleData::$username,
SampleData::$password
);
Settings::configure([
"root_url" => Fixtures::$apiUrl
]);

Bootstrap::init();
Bootstrap::init();
3 changes: 2 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ dependencies:
test:
override:
- mkdir -p $CIRCLE_TEST_REPORTS/phpunit
- ./vendor/bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
- ./vendor/bin/phpunit --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml:
timeout: 1200
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "finix/processing-php",
"version": "1.0.1",
"version": "1.0.2",
"description": "A PHP HTTP Client conforming to the HAL hypermedia type for the Finix processing API",
"license": "Apache2",
"authors": [
Expand Down
4 changes: 3 additions & 1 deletion src/Finix/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ private static function _autoload($base, $classname)
*/
private static function initializeResources()
{
if (self::$initialized)
if (self::$initialized) {
return;
}

Resource::init();

Resources\User::init();
Resources\Application::init();
Resources\Identity::init();
Resources\Processor::init();
Expand Down
4 changes: 3 additions & 1 deletion src/Finix/Http/Auth/BasicAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Finix\Http\Auth;

use Finix\Http;
use Finix\Settings;
use Finix\Http\AbstractClient;
use GuzzleHttp\Message\RequestInterface;

Expand Down Expand Up @@ -86,7 +87,8 @@ private function isRequestAuthorized(RequestInterface $httpRequest)
*/
private function getCredentials()
{
$basic = base64_encode($this->user_id . ':' . $this->password);
$basic = base64_encode(Settings::$username . ':' . Settings::$password);
// $basic = base64_encode($this->user_id . ':' . $this->password);
return $basic;
}
}
65 changes: 45 additions & 20 deletions src/Finix/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Finix\Http\Auth\BasicAuthentication;
use Finix\Http\JsonBody;
use Finix\Http\Request;
use Finix\Resources\Verification;
use Finix\Utils\ArrayProxy;
use \stdClass;

Expand All @@ -15,7 +16,8 @@ abstract class Resource
protected $state;

protected static $href;
protected static $client;
protected $client;
// protected static $client;
protected static $registry;

/**
Expand All @@ -24,10 +26,10 @@ abstract class Resource
*/
public static function getHrefSpec($resource = null)
{
if(is_null($resource)){
if (is_null($resource)) {
$resource = get_called_class();
}
if(!is_string($resource)) {
if (!is_string($resource)) {
$resource = get_class($resource);
}
return self::getRegistry()->getHrefSpecForResource($resource);
Expand All @@ -36,9 +38,9 @@ public static function getHrefSpec($resource = null)
/**
* @return Hal\Client
*/
public static function getClient()
public function getClient()
{
return self::$client;
return $this->client;
}

/**
Expand All @@ -51,23 +53,33 @@ public static function getRegistry()

public static function init()
{
self::$client = new Hal\Client(
Settings::$url_root,
'/',
null,
new BasicAuthentication(Settings::$username, Settings::$password));
self::$registry = new Registry();
}

public function __construct(array $state = null, array $links = null)
{
$this->client = self::createClient();
$this->setResource(new Hal\Resource($state, $links));
}

private static function createClient()
{
if (Settings::$username == null || Settings::$password == null) {
$client = new Hal\Client(Settings::$url_root, '/');
}
else {
$client = new Hal\Client(
Settings::$url_root,
'/',
null,
new BasicAuthentication(Settings::$username, Settings::$password));
}
return $client;
}

public function __get($name)
{
if($this->state->has_key($name))
{
if ($this->state->has_key($name)) {
return $this->state[$name];
}

Expand All @@ -92,8 +104,8 @@ public function __set($name, $value)
public function __isset($name)
{
if (array_key_exists($name, $this->resource->getAllLinks()) ||
array_key_exists($name, $this->resource->getState()))
{
array_key_exists($name, $this->resource->getState())
) {
return true;
}

Expand All @@ -111,11 +123,21 @@ public function __isset($name)
public static function retrieve($id)
{
$uri = self::getHrefSpec()->collection_uri . '/' . $id;
$resource = self::getClient()->sendRequest(new Request($uri));
$resource = self::createClient()->sendRequest(new Request($uri));
$class = get_called_class();
return new $class($resource->getState(), $resource->getAllLinks());
}

public function refresh() {
$request = new Request(
$this->resource->getLink("self")->getHref(),
'GET'
);
$resource = $this->getClient()->sendRequest($request);
$this->setResource($resource);
return $this;
}

/**
* @return \Finix\Resource
* @throws Hal\Exception\HalClientErrorException
Expand All @@ -128,12 +150,11 @@ public static function retrieve($id)
public function save()
{
if (empty($this->state["tags"])) {
$this->state["tags"] = new stdClass();
$this->state["tags"] = new stdClass();
}

$payload = new JsonBody(iterator_to_array($this->state));
if($this->isUpdate())
{
if ($this->isUpdate()) {
$request = new Request(
$this->resource->getLink("self")->getHref(),
'PUT',
Expand Down Expand Up @@ -199,5 +220,9 @@ private function setResource($resource)
$this->state = new ArrayProxy($resource->getState());
}


}
public function verifyOn(Verification $verification)
{
$verifyLink = $this->resource->getLink("verifications")->getHref();
return $verification->create($verifyLink);
}
}
11 changes: 10 additions & 1 deletion src/Finix/Resources/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,13 @@ public static function init()
self::getRegistry()->add(get_called_class(), new HrefSpec('applications', 'id', '/'));
}

}
public function createPartnerUser(User $user)
{
return $user->create($this->resource->getLink("users")->getHref());
}

public function createProcessor(Processor $processor)
{
return $processor->create($this->resource->getLink("processors")->getHref());
}
}
14 changes: 13 additions & 1 deletion src/Finix/Resources/Authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,16 @@ public static function init()
self::getRegistry()->add(get_called_class(), new HrefSpec('authorizations', 'id', '/'));
}

}
public function capture($amount, $fee = 0)
{
$this->state["capture_amount"] = $amount;
$this->state["fee"] = $fee;
return $this->save();
}

public function void($voidMe)
{
$this->state["void_me"] = $voidMe;
return $this->save();
}
}
13 changes: 13 additions & 0 deletions src/Finix/Resources/BankAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Finix\Resources;


class BankAccount extends PaymentInstrument
{
public function __construct(array $state = [], array $links = null)
{
$state["type"] = "BANK_ACCOUNT";
parent::__construct($state, $links);
}
}
46 changes: 13 additions & 33 deletions src/Finix/Resources/Identity.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,25 @@ public static function init()
self::getRegistry()->add(get_called_class(), new HrefSpec('identities', 'id', '/'));
}

/**
* @param string $processor the processor to underwrite the merchant on
* @return \Finix\Resources\Merchant
* @throws \Finix\Hal\Exception\LinkNotUniqueException
* @throws \Finix\Hal\Exception\RelNotFoundException
*/
public function provisionMerchantOn(array $args)
public function provisionMerchantOn(Merchant $merchant)
{
$merchant = new Merchant(["processor"=>$args['processor']]);
return $merchant->create($this->resource->getLink("underwriting")->getHref());
return $merchant->create($this->resource->getLink("merchants")->getHref());
}

public function createSettlement(Settlement $settlement)
{
return $settlement->create($this->resource->getLink("settlements")->getHref());
}

/**
* @param string $processor the processor to settle the funds out to
* @param string $currency the currency for the settlment
* @return \Finix\Resources\Settlement
* @throws \Finix\Hal\Exception\LinkNotUniqueException
* @throws \Finix\Hal\Exception\RelNotFoundException
*/
public function createSettlement(array $args)
public function createPaymentCard(PaymentCard $card)
{
// TODO passing identity field by default bc it's redudant, users shouldn't need to pass this. remove once bug is fixed
$settlement = new Settlement(["processor"=>$args['processor'], "currency"=>$args['currency'], "identity"=>$this->resource->getState()["id"]]);
// TODO shouldn't this link should not be construcuted, update when identity resource is fixed
return $settlement->create($this->resource->getLink("self")->getHref() . "/settlements");
$card->state["identity"] = $this->id;
return $card->create($this->resource->getLink("payment_instruments")->getHref());
}

/**
* @param string $processor the processor to settle the funds out to
* @param string $currency the currency for the settlment
* @return \Finix\Resources\Settlement
* @throws \Finix\Hal\Exception\LinkNotUniqueException
* @throws \Finix\Hal\Exception\RelNotFoundException
*/
public function verifyOn(array $args)
public function createBankAccount(BankAccount $bankAccount)
{
$verification = new Verification(["processor"=>$args['processor']]);
// TODO shouldn't this link should not be construcuted, update when identity resource is fixed
return $verification->create($this->resource->getLink("verifications")->getHref());
$bankAccount->state["identity"] = $this->id;
return $bankAccount->create($this->resource->getLink("payment_instruments")->getHref());
}
}
}
8 changes: 3 additions & 5 deletions src/Finix/Resources/Merchant.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

class Merchant extends Resource
{

public static function init()
{
self::getRegistry()->add(
get_called_class(),
new HrefSpec('merchants', 'id', '/'));
self::getRegistry()->add(get_called_class(), new HrefSpec('merchants', 'id', '/'));
}

}
}
14 changes: 14 additions & 0 deletions src/Finix/Resources/PaymentCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Finix\Resources;


class PaymentCard extends PaymentInstrument
{

public function __construct(array $state = [], array $links = null)
{
$state["type"] = "PAYMENT_CARD";
parent::__construct($state, $links);
}
}
Loading