Skip to content
This repository has been archived by the owner on Aug 13, 2020. It is now read-only.

Commit

Permalink
Merge pull request #62 from laravel/cleanup
Browse files Browse the repository at this point in the history
[3.0] Cleanup
  • Loading branch information
taylorotwell authored Dec 12, 2018
2 parents 4ea96c4 + 44e29e4 commit 7b67c14
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 141 deletions.
4 changes: 0 additions & 4 deletions .env.example

This file was deleted.

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/vendor
/.env
composer.phar
composer.lock
.DS_Store
Expand Down
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
language: php

php:
- 7.0
- 7.1
- 7.2
- 7.3

sudo: false

install: travis_retry composer install --no-interaction --prefer-source
before_install:
- phpenv config-rm xdebug.ini || true

script: vendor/bin/phpunit --verbose
install: travis_retry composer install --no-interaction --prefer-dist --no-suggest

matrix:
allow_failures:
- php: 7.1
script: vendor/bin/phpunit --verbose
23 changes: 9 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
}
],
"require": {
"php": ">=7.0",
"braintree/braintree_php": "~3.0",
"php": "^7.1.3",
"braintree/braintree_php": "~3.38",
"dompdf/dompdf": "^0.8.0",
"illuminate/database": "~5.3",
"illuminate/support": "~5.3",
"illuminate/database": "~5.7",
"illuminate/support": "~5.7",
"nesbot/carbon": "~1.0",
"symfony/http-kernel": "~3.0|~4.0"
},
"require-dev": {
"illuminate/http": "~5.3",
"illuminate/routing": "~5.3",
"illuminate/view": "~5.3",
"ext-json": "*",
"illuminate/http": "~5.7",
"illuminate/routing": "~5.7",
"illuminate/view": "~5.7",
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~6.0",
"vlucas/phpdotenv": "~2.0"
"phpunit/phpunit": "~7.0"
},
"autoload": {
"psr-4": {
Expand All @@ -46,11 +46,6 @@
]
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
]
},
"config": {
"sort-packages": true
},
Expand Down
7 changes: 6 additions & 1 deletion phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="BRAINTREE_MERCHANT_ID" value=""/>
<env name="BRAINTREE_PUBLIC_KEY" value=""/>
<env name="BRAINTREE_PRIVATE_KEY" value=""/>
<env name="BRAINTREE_MODEL" value="Laravel\Cashier\Tests\User"/>
</php>
</phpunit>
6 changes: 4 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ You will need to set the following details locally and on your Braintree account

### Local

#### .env
#### Environment Variables

BRAINTREE_MERCHANT_ID=
BRAINTREE_PUBLIC_KEY=
BRAINTREE_PRIVATE_KEY=
BRAINTREE_MODEL=User
BRAINTREE_MODEL=Laravel\Cashier\Tests\User

You can set these variables in the `phpunit.xml.dist` file.

### Braintree

Expand Down
45 changes: 25 additions & 20 deletions src/Billable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Exception;
use Carbon\Carbon;
use Braintree\Customer;
use Illuminate\Support\Arr;
use Braintree\PaymentMethod;
use Braintree\PayPalAccount;
use InvalidArgumentException;
use Braintree\Result\Successful;
use Braintree\TransactionSearch;
use Illuminate\Support\Collection;
use Braintree\Customer as BraintreeCustomer;
Expand All @@ -22,13 +24,11 @@ trait Billable
*
* @param int $amount
* @param array $options
* @return array
* @return \Braintree\Result\Successful
* @throws \Exception
*/
public function charge($amount, array $options = [])
public function charge($amount, array $options = []): Successful
{
$customer = $this->asBraintreeCustomer();

$response = BraintreeTransaction::sale(array_merge([
'amount' => number_format($amount * (1 + ($this->taxPercentage() / 100)), 2, '.', ''),
'paymentMethodToken' => $this->paymentMethod()->token,
Expand All @@ -51,9 +51,10 @@ public function charge($amount, array $options = [])
* @param string $description
* @param int $amount
* @param array $options
* @return array
* @return \Braintree\Result\Successful
* @throws \Exception
*/
public function tab($description, $amount, array $options = [])
public function tab($description, $amount, array $options = []): Successful
{
return $this->charge($amount, array_merge($options, [
'customFields' => [
Expand All @@ -68,9 +69,10 @@ public function tab($description, $amount, array $options = [])
* @param string $description
* @param int $amount
* @param array $options
* @return array
* @return \Braintree\Result\Successful
* @throws \Exception
*/
public function invoiceFor($description, $amount, array $options = [])
public function invoiceFor($description, $amount, array $options = []): Successful
{
return $this->tab($description, $amount, $options);
}
Expand All @@ -82,7 +84,7 @@ public function invoiceFor($description, $amount, array $options = [])
* @param string $plan
* @return \Laravel\Cashier\SubscriptionBuilder
*/
public function newSubscription($subscription, $plan)
public function newSubscription($subscription, $plan): SubscriptionBuilder
{
return new SubscriptionBuilder($this, $subscription, $plan);
}
Expand Down Expand Up @@ -153,16 +155,15 @@ public function subscription($subscription = 'default')
{
return $this->subscriptions->sortByDesc(function ($value) {
return $value->created_at->getTimestamp();
})
->first(function ($value) use ($subscription) {
})->first(function ($value) use ($subscription) {
return $value->name === $subscription;
});
}

/**
* Get all of the subscriptions for the model.
*
* @return \Illuminate\Database\Eloquent\Collection
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function subscriptions()
{
Expand Down Expand Up @@ -196,7 +197,7 @@ public function findInvoice($id)
* @param string $id
* @return \Laravel\Cashier\Invoice
*/
public function findInvoiceOrFail($id)
public function findInvoiceOrFail($id): Invoice
{
$invoice = $this->findInvoice($id);

Expand All @@ -212,12 +213,12 @@ public function findInvoiceOrFail($id)
*
* @param string $id
* @param array $data
* @param string $storagePath
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Throwable
*/
public function downloadInvoice($id, array $data, $storagePath = null)
public function downloadInvoice($id, array $data)
{
return $this->findInvoiceOrFail($id)->download($data, $storagePath);
return $this->findInvoiceOrFail($id)->download($data);
}

/**
Expand All @@ -226,8 +227,9 @@ public function downloadInvoice($id, array $data, $storagePath = null)
* @param bool $includePending
* @param array $parameters
* @return \Illuminate\Support\Collection
* @throws \Braintree\Exception\NotFound
*/
public function invoices($includePending = false, $parameters = [])
public function invoices($includePending = false, $parameters = []): Collection
{
$invoices = [];

Expand Down Expand Up @@ -262,8 +264,9 @@ public function invoices($includePending = false, $parameters = [])
*
* @param array $parameters
* @return \Illuminate\Support\Collection
* @throws \Braintree\Exception\NotFound
*/
public function invoicesIncludingPending(array $parameters = [])
public function invoicesIncludingPending(array $parameters = []): Collection
{
return $this->invoices(true, $parameters);
}
Expand Down Expand Up @@ -349,6 +352,7 @@ public function applyCoupon($coupon, $subscription = 'default', $removeOthers =
* Get the default payment method for the customer.
*
* @return array
* @throws \Braintree\Exception\NotFound
*/
public function paymentMethod()
{
Expand Down Expand Up @@ -406,7 +410,7 @@ public function onPlan($plan)
* @return \Braintree\Customer
* @throws \Exception
*/
public function createAsBraintreeCustomer($token, array $options = [])
public function createAsBraintreeCustomer($token, array $options = []): Customer
{
$response = BraintreeCustomer::create(
array_replace_recursive([
Expand Down Expand Up @@ -456,8 +460,9 @@ public function taxPercentage()
* Get the Braintree customer for the model.
*
* @return \Braintree\Customer
* @throws \Braintree\Exception\NotFound
*/
public function asBraintreeCustomer()
public function asBraintreeCustomer(): Customer
{
return BraintreeCustomer::find($this->braintree_id);
}
Expand Down
3 changes: 2 additions & 1 deletion src/BraintreeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Cashier;

use Exception;
use Braintree\Plan;
use Braintree\Plan as BraintreePlan;

class BraintreeService
Expand All @@ -14,7 +15,7 @@ class BraintreeService
* @return \Braintree\Plan
* @throws \Exception
*/
public static function findPlan($id)
public static function findPlan($id): Plan
{
$plans = BraintreePlan::all();

Expand Down
1 change: 1 addition & 0 deletions src/Cashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Cashier
* @param string $currency
* @param string|null $symbol
* @return void
* @throws \Exception
*/
public static function useCurrency($currency, $symbol = null)
{
Expand Down
10 changes: 0 additions & 10 deletions src/CashierServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,4 @@ public function boot()
__DIR__.'/../resources/views' => base_path('resources/views/vendor/cashier'),
]);
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
//
}
}
16 changes: 8 additions & 8 deletions src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ protected function parseBraintreeNotification($request)
* Handle a subscription cancellation notification from Braintree.
*
* @param \Braintree\WebhookNotification $webhook
* @return \Illuminate\Http\Response
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function handleSubscriptionCanceled($webhook)
protected function handleSubscriptionCanceled($webhook): Response
{
return $this->cancelSubscription($webhook->subscription->id);
}
Expand All @@ -60,9 +60,9 @@ protected function handleSubscriptionCanceled($webhook)
* Handle a subscription expiration notification from Braintree.
*
* @param \Braintree\WebhookNotification $webhook
* @return \Illuminate\Http\Response
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function handleSubscriptionExpired($webhook)
protected function handleSubscriptionExpired($webhook): Response
{
return $this->cancelSubscription($webhook->subscription->id);
}
Expand All @@ -71,9 +71,9 @@ protected function handleSubscriptionExpired($webhook)
* Handle a subscription cancellation notification from Braintree.
*
* @param string $subscriptionId
* @return \Illuminate\Http\Response
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function cancelSubscription($subscriptionId)
protected function cancelSubscription($subscriptionId): Response
{
$subscription = $this->getSubscriptionById($subscriptionId);

Expand All @@ -90,7 +90,7 @@ protected function cancelSubscription($subscriptionId)
* @param string $subscriptionId
* @return \Laravel\Cashier\Subscription
*/
protected function getSubscriptionById($subscriptionId)
protected function getSubscriptionById($subscriptionId): Subscription
{
return Subscription::where('braintree_id', $subscriptionId)->first();
}
Expand All @@ -101,7 +101,7 @@ protected function getSubscriptionById($subscriptionId)
* @param array $parameters
* @return \Symfony\Component\HttpFoundation\Response
*/
public function missingMethod($parameters = [])
public function missingMethod(array $parameters = []): Response
{
return new Response;
}
Expand Down
Loading

0 comments on commit 7b67c14

Please sign in to comment.