Skip to content

Commit

Permalink
Docblock comments for most files. Listeners still need to be done.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhartman committed Nov 17, 2019
1 parent 944dbef commit dddff35
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 84 deletions.
3 changes: 0 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
}
},
"extra": {
"branch-alias": {
"dev-master": "8.0-dev"
},
"laravel": {
"providers": [
"TwentyTwoDigital\\CashierFastspring\\CashierServiceProvider"
Expand Down
63 changes: 38 additions & 25 deletions src/Billable.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
<?php

/**
* This file implements Billable.
*
* @author Bilal Gultekin <bilal@gultekin.me>
* @author Justin Hartman <justin@22digital.co.za>
* @copyright 2019 22 Digital
* @license MIT
* @since v0.1
*/
namespace TwentyTwoDigital\CashierFastspring;

use TwentyTwoDigital\CashierFastspring\Exceptions\NotImplementedException;
use TwentyTwoDigital\CashierFastspring\Fastspring\Fastspring;
use Exception;

/**
* Billable trait.
*
* {@inheritDoc}
*/
trait Billable
{
/**
* Make a "one off" charge on the customer for the given amount.
*
* @param int $amount
* @param array $options
* @param int $amount The amount to charge
* @param array $options Array of options
*
* @throws \InvalidArgumentException
* @throws Exceptions\NotImplementedException
* @throws \TwentyTwoDigital\CashierFastspring\Exceptions\NotImplementedException
*/
public function charge($amount, array $options = [])
{
Expand All @@ -25,11 +37,10 @@ public function charge($amount, array $options = [])
/**
* Refund a customer for a charge.
*
* @param string $charge
* @param array $options
* @param string $charge The amount to refund
* @param array $options Array of options
*
* @throws \InvalidArgumentException
* @throws Exceptions\NotImplementedException
* @throws \TwentyTwoDigital\CashierFastspring\Exceptions\NotImplementedException
*/
public function refund($charge, array $options = [])
{
Expand All @@ -39,8 +50,8 @@ public function refund($charge, array $options = [])
/**
* Begin creating a new subscription.
*
* @param string $subscription
* @param string $plan
* @param string $subscription Subscription name
* @param string $plan The plan name
*
* @return \TwentyTwoDigital\CashierFastspring\SubscriptionBuilder
*/
Expand All @@ -52,8 +63,8 @@ public function newSubscription($subscription, $plan)
/**
* Determine if the subscription is on trial.
*
* @param string $subscription
* @param string|null $plan
* @param string $subscription Subscription name
* @param string|null $plan Plan name
*
* @return bool
*/
Expand All @@ -72,8 +83,8 @@ public function onTrial($subscription = 'default', $plan = null)
/**
* Determine if the model has a given subscription.
*
* @param string $subscription
* @param string|null $plan
* @param string $subscription Subscription name
* @param string|null $plan Plan name
*
* @return bool
*/
Expand Down Expand Up @@ -131,8 +142,8 @@ public function invoices()
/**
* Determine if the model is actively subscribed to one of the given plans.
*
* @param array|string $plans
* @param string $subscription
* @param string|null $plans Plan name
* @param string $subscription Subscription name
*
* @return bool
*/
Expand All @@ -156,7 +167,7 @@ public function subscribedToPlan($plans, $subscription = 'default')
/**
* Determine if the entity is on the given plan.
*
* @param string $plan
* @param string $plan Plan name
*
* @return bool
*/
Expand All @@ -180,7 +191,7 @@ public function hasFastspringId()
/**
* Generate authenticated url of fastspring account management panel.
*
* @return bool
* @return \TwentyTwoDigital\CashierFastspring\Fastspring\Fastspring
*/
public function accountManagementURI()
{
Expand All @@ -192,9 +203,9 @@ public function accountManagementURI()
/**
* Create a Fastspring customer for the given user model.
*
* @param array $options
* @param array $options Options array of customer information
*
* @return object
* @return \TwentyTwoDigital\CashierFastspring\Fastspring\Fastspring
*/
public function createAsFastspringCustomer(array $options = [])
{
Expand Down Expand Up @@ -223,16 +234,16 @@ public function createAsFastspringCustomer(array $options = [])
}

/**
* Update the related account on the Fastspring-side the given user model.
* Update the related account on Fastspring, given user-model.
*
* @param array $options
* @param array $options array of customer information
*
* @throws Exception No valid Fastspring ID
*
* @return object
*/
public function updateAsFastspringCustomer(array $options = [])
{
// check the fastspring_id first
// if there is non, no need to try
if (!$this->hasFastspringId()) {
throw new Exception('User has no fastspring_id');
}
Expand All @@ -258,6 +269,8 @@ public function updateAsFastspringCustomer(array $options = [])
/**
* Get the Fastspring customer for the model.
*
* @throws Exception No valid Fastspring ID
*
* @return object
*/
public function asFastspringCustomer()
Expand Down
13 changes: 12 additions & 1 deletion src/CashierServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<?php

/**
* This file implements Laravel Cashier Service Provider.
*
* @author Justin Hartman <justin@22digital.co.za>
* @copyright 2019 22 Digital
* @since v0.1
*/
namespace TwentyTwoDigital\CashierFastspring;

use Illuminate\Support\ServiceProvider;

/**
* This class describes the Laravel Cashier Service Provider.
*
* {@inheritDoc}
*/
class CashierServiceProvider extends ServiceProvider
{
/**
Expand Down
9 changes: 8 additions & 1 deletion src/Exceptions/NotImplementedException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<?php

/**
* This file implements Not Implemented Exception.
*
* @author Justin Hartman <justin@22digital.co.za>
* @copyright 2019 22 Digital
* @since v0.1
*/
namespace TwentyTwoDigital\CashierFastspring\Exceptions;

use BadMethodCallException;

class NotImplementedException extends BadMethodCallException
{
//
}
50 changes: 27 additions & 23 deletions src/Fastspring/ApiClient.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
<?php

namespace TwentyTwoDigital\CashierFastspring\Fastspring;

use GuzzleHttp\Client;

/**
* ApiClient is a simple class for sending requests to FastSpring API.
*
* This class aims to handle some APIs of Fastspring if you think to develop
* and add some other features please consider not doing it with one class.
* This class aims to handle some APIs of Fastspring if you think to develop and
* add some other features please consider not doing it with one class.
*
* Note: This class does not cover whole FastSpring API, it covers just a couple of things
* in FastSpring API like accounts and sessions.
* Note: This class does not cover whole FastSpring API, it covers just a couple
* of things in FastSpring API like accounts and sessions.
*
* Example usage:
* ```php
* $fastspring = new ApiClient();
* $accounts = $fastspring->getAccounts();
* ```
*
* @author Bilal Gultekin <bilal@gultekin.me>
*
* @version 0.1
* @author Bilal Gultekin <bilal@gultekin.me>
* @version v0.1:
* @copyright 2019 22 Digital
* @license MIT
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api
*/
namespace TwentyTwoDigital\CashierFastspring\Fastspring;

use GuzzleHttp\Client;

/**
* This class describes an api client.
*
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api
* {@inheritDoc}
*/
class ApiClient
{
Expand Down Expand Up @@ -66,8 +70,8 @@ class ApiClient
/**
* Create a new Fastspring API interface instance.
*
* @param string $username
* @param string $password
* @param string $username Fastspring API username
* @param string $password Fastspring API password
*
* @return void
*/
Expand All @@ -84,7 +88,7 @@ public function __construct($username = null, $password = null)
/**
* Send a request to Fastspring API with given parameters.
*
* @param string $method Method of HTTP request like PUT, GET, POST etc.
* @param string $method Method of HTTP request like PUT, GET, POST
* @param string $path Path of API
* @param string $query Query parameters
* @param string $formParameters Form parameters
Expand Down Expand Up @@ -170,14 +174,12 @@ protected function handleResponse($response)
return json_decode($message);
}

// API methods

/**
* Create account.
*
* @param array $account Account details
*
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api/accounts Account details
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api/accounts Account details
*
* @return object Response of fastspring
*/
Expand All @@ -192,7 +194,7 @@ public function createAccount($account)
* @param string $fastspringId Fastspring ID of related account
* @param array $account Account details
*
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api/accounts Account details
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api/accounts Account details
*
* @return object Response of fastspring
*/
Expand Down Expand Up @@ -231,7 +233,7 @@ public function getAccount($accountId, $parameters = [])
*
* @param array $session Sessions details
*
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api/sessions Session details
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api/sessions Session details
*
* @return object Response of fastspring
*/
Expand Down Expand Up @@ -289,7 +291,8 @@ public function getSubscriptionsEntries($subscriptionIds)
/**
* Update subscriptions.
*
* @param array $subscriptions Data of all subscriptions wanted to be updated (should include subscription => $id)
* @param array $subscriptions Data of all subscriptions wanted to be
* updated (should include subscription => $id)
*
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api/subscriptions#id-/subscriptions-Updateexistingsubscriptioninstances
*
Expand All @@ -306,7 +309,8 @@ public function updateSubscriptions($subscriptions)
* Cancel subscription.
*
* @param string|int $subscriptionId ID of the subscription
* @param array $parameters Query Parameters for example to delete immediately pass ['billingPeriod' => 0]
* @param array $parameters Query Parameters for example to delete
* immediately pass ['billingPeriod' => 0]
*
* @return object Response of fastspring
*/
Expand Down
33 changes: 22 additions & 11 deletions src/Fastspring/Fastspring.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
<?php

/**
* This class helps to reach the Fastspring class with Laravel config and static
* methods.
*
* @author Bilal Gultekin <bilal@gultekin.me>
* @version 0.1:
* @copyright 2019 22 Digital
* @license MIT
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api
*/
namespace TwentyTwoDigital\CashierFastspring\Fastspring;

/**
* This class helps to reach Fastspring class with laravel config and static methods.
*
* @author Bilal Gultekin <bilal@gultekin.me>
* This class describes the Fastspring implementation.
*
* @version 0.1
*
* @see https://docs.fastspring.com/integrating-with-fastspring/fastspring-api
* {@inheritDoc}
*/
class Fastspring
{
Expand All @@ -21,13 +26,19 @@ class Fastspring
public static $instance;

/**
* It is not useful to construct this Fastspring class everytime.
* This helps to construct this class with the current config.
* Static method.
*
* It is not useful to construct this Fastspring class everytime. This helps
* to construct this class with the current config. if there is not any
* constructed instance then construct and save it to self::$instance
*
* @param string $method The method
* @param array $parameters The parameters for username and password
*
* @return self
*/
public static function __callStatic($method, $parameters)
{
// if there is not any constructed instance
// construct and save it to self::$instance
if (!self::$instance) {
$username = (getenv('FASTSPRING_USERNAME') ?: config('services.fastspring.username'));
$password = (getenv('FASTSPRING_PASSWORD') ?: config('services.fastspring.password'));
Expand Down
Loading

0 comments on commit dddff35

Please sign in to comment.