Skip to content

Commit

Permalink
Initial stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel HUEZ authored and Manuel HUEZ committed Nov 17, 2016
1 parent 3d7f1d7 commit 7f68d6e
Show file tree
Hide file tree
Showing 32 changed files with 1,707 additions and 1,547 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The package's installation is done using composer. Simply add these lines to you
``` json
{
"require": {
"ProcessOut/ProcessOut-php": "^4.5.1"
"ProcessOut/ProcessOut-php": "^5.0.0"
}
}
```
Expand All @@ -29,4 +29,4 @@ And run the composer update command to install/update the package.

``` sh
composer update
```
```
12 changes: 5 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{
"name": "ProcessOut/ProcessOut-php",
"name": "processout/processout-php",
"description": "ProcessOut API bindings.",
"keywords": [
"ProcessOut",
"processout",
"api",
"bindings"
],
"homepage": "https://processout.com",
"homepage": "https://www.processout.com",
"license": "MIT",
"authors": [
{
"name": "ProcessOut",
"homepage": "https://processout.com"
"homepage": "https://www.processout.com"
}
],
"require": {
"php": ">=5.4",
"ext-curl": "*",
"ext-mbstring": "*",

"anlutro/curl": "1.4"
"ext-mbstring": "*"
},
"autoload": {
"psr-4": {
Expand Down
34 changes: 34 additions & 0 deletions init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

include_once(dirname(__FILE__) . "/src/ProcessOut.php");

include_once(dirname(__FILE__) . "/src/Exceptions/AuthenticationException.php");
include_once(dirname(__FILE__) . "/src/Exceptions/GenericException.php");
include_once(dirname(__FILE__) . "/src/Exceptions/InternalException.php");
include_once(dirname(__FILE__) . "/src/Exceptions/NotFoundException.php");
include_once(dirname(__FILE__) . "/src/Exceptions/ValidationException.php");

include_once(dirname(__FILE__) . "/src/Networking/Request.php");
include_once(dirname(__FILE__) . "/src/Networking/Response.php");

include_once(dirname(__FILE__) . "/src/Activity.php");
include_once(dirname(__FILE__) . "/src/AuthorizationRequest.php");
include_once(dirname(__FILE__) . "/src/Card.php");
include_once(dirname(__FILE__) . "/src/Coupon.php");
include_once(dirname(__FILE__) . "/src/Customer.php");
include_once(dirname(__FILE__) . "/src/Token.php");
include_once(dirname(__FILE__) . "/src/Discount.php");
include_once(dirname(__FILE__) . "/src/Event.php");
include_once(dirname(__FILE__) . "/src/Gateway.php");
include_once(dirname(__FILE__) . "/src/GatewayConfiguration.php");
include_once(dirname(__FILE__) . "/src/Invoice.php");
include_once(dirname(__FILE__) . "/src/CustomerAction.php");
include_once(dirname(__FILE__) . "/src/Plan.php");
include_once(dirname(__FILE__) . "/src/Product.php");
include_once(dirname(__FILE__) . "/src/Project.php");
include_once(dirname(__FILE__) . "/src/Refund.php");
include_once(dirname(__FILE__) . "/src/Subscription.php");
include_once(dirname(__FILE__) . "/src/Transaction.php");
include_once(dirname(__FILE__) . "/src/Webhook.php");

include_once(dirname(__FILE__) . "/src/GatewayRequest.php");
34 changes: 34 additions & 0 deletions spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

include 'init.php';

$client = new \ProcessOut\ProcessOut('proj_gAO1Uu0ysZJvDuUpOGPkUBeE3pGalk3x',
'key_fBjPvkgT8gyKc1SUpy0PfjL7UgsRmUug');

// Create and fetch a new invoice
$invoice = $client->newInvoice(array(
'name' => 'Test invoice',
'amount' => '9.99',
'currency' => 'USD'
))->create();

assert(!empty($invoice->getId()), 'The invoice ID should not be empty');

$fetched = $client->newInvoice()->find($invoice->getId());
assert(!empty($fetched->getId()), 'The fetched invoice ID should not be empty');
assert($invoice->getId() == $fetched->getId(), 'The invoices ID should be equal');

// Fetch the customers
$customers = $client->newCustomer()->all();

// Create a subscription for a customer
$customer = $client->newCustomer()->create();
assert(!empty($customer->getId()), 'The created customer ID should not be empty');

$subscription = $client->newSubscription(array(
'amount' => '9.99',
'currency' => 'USD',
'interval' => '1d',
'name' => 'great subscription'
))->create($customer->getId());
assert(!empty($subscription->getId()), 'The created subscription ID should not be empty');
81 changes: 36 additions & 45 deletions src/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
namespace ProcessOut;

use ProcessOut\ProcessOut;
use ProcessOut\Networking\Response;
use ProcessOut\Networking\RequestProcessoutPrivate;

use ProcessOut\Networking\Request;

class Activity
{

/**
* ProcessOut's instance
* ProcessOut's client
* @var ProcessOut\ProcessOut
*/
protected $instance;
protected $client;

/**
* ID of the activity
Expand Down Expand Up @@ -56,18 +54,16 @@ class Activity

/**
* Activity constructor
* @param ProcessOut\ProcessOut|null $processOut
* @param ProcessOut\ProcessOut $client
* @param array|null $prefill
*/
public function __construct(ProcessOut $processOut = null)
public function __construct(ProcessOut $client, $prefill = array())
{
if(is_null($processOut))
{
$processOut = ProcessOut::getDefault();
}

$this->instance = $processOut;
$this->client = $client;



$this->fillWithData($prefill);
}


Expand Down Expand Up @@ -115,7 +111,7 @@ public function setProject($value)
$this->project = $value;
else
{
$obj = new Project($this->instance);
$obj = new Project($this->client);
$obj->fillWithData($value);
$this->project = $obj;
}
Expand Down Expand Up @@ -218,43 +214,43 @@ public function setCreatedAt($value)
*/
public function fillWithData($data)
{
if(! empty($data["id"]))
$this->setId($data["id"]);
if(! empty($data['id']))
$this->setId($data['id']);

if(! empty($data["project"]))
$this->setProject($data["project"]);
if(! empty($data['project']))
$this->setProject($data['project']);

if(! empty($data["title"]))
$this->setTitle($data["title"]);
if(! empty($data['title']))
$this->setTitle($data['title']);

if(! empty($data["content"]))
$this->setContent($data["content"]);
if(! empty($data['content']))
$this->setContent($data['content']);

if(! empty($data["level"]))
$this->setLevel($data["level"]);
if(! empty($data['level']))
$this->setLevel($data['level']);

if(! empty($data["created_at"]))
$this->setCreatedAt($data["created_at"]);
if(! empty($data['created_at']))
$this->setCreatedAt($data['created_at']);

return $this;
}


/**
* Get all the project activities.
* @param array $options
* @return array
*/
public static function all($options = array())
public function all($options = array())
{
$cur = new Activity();
$request = new RequestProcessoutPrivate($cur->instance);
$request = new Request($this->client);
$path = "/activities";

$data = array(

);

$response = new Response($request->get($path, $data, $options));
$response = $request->get($path, $data, $options);
$returnValues = array();


Expand All @@ -263,45 +259,40 @@ public static function all($options = array())
$body = $response->getBody();
foreach($body['activities'] as $v)
{
$tmp = new Activity($cur->instance);
$tmp = new Activity($this->client);
$tmp->fillWithData($v);
$a[] = $tmp;
}

$returnValues["Activities"] = $a;

return array_values($returnValues)[0];
$returnValues['Activities'] = $a;

return array_values($returnValues)[0];
}

/**
* Find a specific activity and fetch its data.
* @param string $activityId
* @param array $options
* @return $this
*/
public static function find($activityId, $options = array())
public function find($activityId, $options = array())
{
$cur = new Activity();
$request = new RequestProcessoutPrivate($cur->instance);
$request = new Request($this->client);
$path = "/activities/" . urlencode($activityId) . "";

$data = array(

);

$response = new Response($request->get($path, $data, $options));
$response = $request->get($path, $data, $options);
$returnValues = array();


// Handling for field activity
$body = $response->getBody();
$body = $body['activity'];

$returnValues["find"] = $cur->fillWithData($body);
return array_values($returnValues)[0];
$body = $body['activity'];
$returnValues['find'] = $this->fillWithData($body);

return array_values($returnValues)[0];
}


}
Loading

0 comments on commit 7f68d6e

Please sign in to comment.