Skip to content

Commit

Permalink
Add sandbox mode and Shipping class (ptondereau#4)
Browse files Browse the repository at this point in the history
* Add sandbox parameter

* Add sandbox parameter to constructors

* Add Shipping service

* Update readme

* Fix code style notices

* Fix indentation according to CI reqs

Despite it looks weird now

* Stupid CI :)

* Fix review notes
  • Loading branch information
ivan-mosiev-altexsoft authored and ptondereau committed Jan 6, 2017
1 parent d8e2a59 commit 4d03046
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 7 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ You can register the all or some Ups facade in the `aliases` key of your `config
* `'UPSTimeInTransit' => 'Ptondereau\LaravelUpsApi\Facades\UpsTimeInTransit'`
* `'UPSTracking' => 'Ptondereau\LaravelUpsApi\Facades\UpsTracking'`
* `'UPSTradeability' => 'Ptondereau\LaravelUpsApi\Facades\UpsTradeability'`
* `'UPSShipping' => 'Ptondereau\LaravelUpsApi\Facades\UpsShipping'`



## Configuration
Expand All @@ -67,6 +69,7 @@ You also need to add env variables into your .env with your credentials:
UPS_ACCESS_KEY=key
UPS_USER_ID=userId
UPS_PASSWORD=password
UPS_SANDBOX=true
```

## Usage
Expand Down
1 change: 1 addition & 0 deletions config/ups.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
'access_key' => env('UPS_ACCESS_KEY', 'test'),
'user_id' => env('UPS_USER_ID', 'test'),
'password' => env('UPS_PASSWORD', 'test'),
'sandbox' => env('UPS_SANDBOX', true),
];
23 changes: 23 additions & 0 deletions src/Facades/UpsShipping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Ptondereau\LaravelUpsApi\Facades;

use Illuminate\Support\Facades\Facade;

/**
* This is the Tradeability facade class.
*
* @author Pierre Tondereau <[email protected]>
*/
class UpsShipping extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'ups.shipping';
}
}
71 changes: 64 additions & 7 deletions src/UpsApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Ups\TimeInTransit;
use Ups\Tracking;
use Ups\Tradeability;
use Ups\Shipping;

/**
* This is the Ups Api service provider class.
Expand Down Expand Up @@ -45,6 +46,7 @@ public function register()
$this->registerTimeInTransit();
$this->registerLocator();
$this->registerTradeability();
$this->registerShipping();
}

/**
Expand Down Expand Up @@ -73,7 +75,12 @@ protected function registerAddressValidation()
$this->app->singleton('ups.address-validation', function (Container $app) {
$config = $app->config->get('ups');

return new AddressValidation($config['access_key'], $config['user_id'], $config['password']);
return new AddressValidation(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

Expand All @@ -87,7 +94,12 @@ protected function registerQuantumView()
$this->app->singleton('ups.quantum-view', function (Container $app) {
$config = $app->config->get('ups');

return new QuantumView($config['access_key'], $config['user_id'], $config['password']);
return new QuantumView(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

Expand All @@ -101,7 +113,12 @@ protected function registerTracking()
$this->app->singleton('ups.tracking', function (Container $app) {
$config = $app->config->get('ups');

return new Tracking($config['access_key'], $config['user_id'], $config['password']);
return new Tracking(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

Expand All @@ -115,7 +132,12 @@ protected function registerRate()
$this->app->singleton('ups.rate', function (Container $app) {
$config = $app->config->get('ups');

return new Rate($config['access_key'], $config['user_id'], $config['password']);
return new Rate(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

Expand All @@ -129,7 +151,12 @@ protected function registerTimeInTransit()
$this->app->singleton('ups.time-in-transit', function (Container $app) {
$config = $app->config->get('ups');

return new TimeInTransit($config['access_key'], $config['user_id'], $config['password']);
return new TimeInTransit(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

Expand All @@ -143,7 +170,12 @@ protected function registerLocator()
$this->app->singleton('ups.locator', function (Container $app) {
$config = $app->config->get('ups');

return new Locator($config['access_key'], $config['user_id'], $config['password']);
return new Locator(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

Expand All @@ -157,7 +189,31 @@ protected function registerTradeability()
$this->app->singleton('ups.tradeability', function (Container $app) {
$config = $app->config->get('ups');

return new Tradeability($config['access_key'], $config['user_id'], $config['password']);
return new Tradeability(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

/**
* Register the Tradeability class.
*
* @return void
*/
protected function registerShipping()
{
$this->app->singleton('ups.shipping', function (Container $app) {
$config = $app->config->get('ups');

return new Shipping(
$config['access_key'],
$config['user_id'],
$config['password'],
$config['sandbox']
);
});
}

Expand All @@ -176,6 +232,7 @@ public function provides()
'ups.time-in-transit',
'ups.locator',
'ups.tradeability',
'ups.shipping',
];
}
}
5 changes: 5 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ public function testPasswordConfig()
{
$this->assertEquals(Config::get('ups.password'), 'test');
}

public function testSandboxConfig()
{
$this->assertTrue(Config::get('ups.sandbox'));
}
}
48 changes: 48 additions & 0 deletions tests/Facades/UpsShippingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Ptondereau\Tests\LaravelUpsApi\Facades;

use GrahamCampbell\TestBenchCore\FacadeTrait;
use Ptondereau\LaravelUpsApi\Facades\UpsShipping;
use Ptondereau\Tests\LaravelUpsApi\TestCase;
use Ups\Shipping;

/**
* This is the UpsTradeabilityTest facade test class.
*
* @author Pierre Tondereau <[email protected]>
*/
class UpsShippingTest extends TestCase
{
use FacadeTrait;

/**
* Get the facade accessor.
*
* @return string
*/
protected function getFacadeAccessor()
{
return 'ups.shipping';
}

/**
* Get the facade class.
*
* @return string
*/
protected function getFacadeClass()
{
return UpsShipping::class;
}

/**
* Get the facade root.
*
* @return string
*/
protected function getFacadeRoot()
{
return Shipping::class;
}
}
6 changes: 6 additions & 0 deletions tests/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Ups\TimeInTransit;
use Ups\Tracking;
use Ups\Tradeability;
use Ups\Shipping;

/**
* This is the service provider test class.
Expand Down Expand Up @@ -54,4 +55,9 @@ public function testTradeabilityIsInjectable()
{
$this->assertIsInjectable(Tradeability::class);
}

public function testShippingIsInjectable()
{
$this->assertIsInjectable(Shipping::class);
}
}

0 comments on commit 4d03046

Please sign in to comment.