Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose if using sandbox #12

Merged
merged 2 commits into from
May 22, 2021
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
1 change: 1 addition & 0 deletions src/Facades/MercadoPago.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* @method static \Puntodev\MercadoPago\MercadoPagoApi defaultClient()
* @method static \Puntodev\MercadoPago\MercadoPagoApi withCredentials(string $clientId, string $clientSecret)
* @method static bool usingSandbox()
*
* @see \Puntodev\MercadoPago\MercadoPago
*/
Expand Down
6 changes: 4 additions & 2 deletions src/MercadoPago.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function defaultClient(): MercadoPagoApi
return new MercadoPagoApi(
$clientId,
$clientSecret,
$this->useSandbox
);
}

Expand All @@ -30,7 +29,10 @@ public function withCredentials(string $clientId, string $clientSecret): Mercado
return new MercadoPagoApi(
$clientId,
$clientSecret,
$this->useSandbox
);
}

public function usingSandbox(): bool {
return $this->useSandbox;
}
}
7 changes: 1 addition & 6 deletions src/MercadoPagoApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,16 @@ class MercadoPagoApi
/** @var string */
private string $host;

/** @var bool */
private bool $useSandbox;

/**
* MercadoPagoApi constructor.
* @param string $apiClientKey
* @param string $apiClientSecret
* @param bool $useSandbox
*/
public function __construct(string $apiClientKey, string $apiClientSecret, bool $useSandbox)
public function __construct(string $apiClientKey, string $apiClientSecret)
{
$this->apiClientKey = $apiClientKey;
$this->apiClientSecret = $apiClientSecret;
$this->host = 'api.mercadopago.com';
$this->useSandbox = $useSandbox;
}

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/MercadoPagoApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Exception;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Log;
use Puntodev\MercadoPago\MercadoPagoApi;
use Puntodev\MercadoPago\PaymentPreferenceBuilder;

Expand All @@ -21,15 +20,13 @@ public function setUp(): void
$this->mercadoPagoApi = new MercadoPagoApi(
config('mercadopago.client_id'),
config('mercadopago.client_secret'),
config('mercadopago.use_sandbox')
);
}

protected function getEnvironmentSetUp($app)
{
$app['config']->set('mercadopago.client_id', env('MERCADOPAGO_API_CLIENT_ID'));
$app['config']->set('mercadopago.client_secret', env('MERCADOPAGO_API_CLIENT_SECRET'));
$app['config']->set('mercadopago.use_sandbox', env('SANDBOX_GATEWAYS'));
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/MercadoPagoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,15 @@ public function with_credentials()

$this->assertInstanceOf(MercadoPagoApi::class, $client);
}

/** @test */
public function using_sandbox()
{
/** @var MercadoPago $mercadoPago */
$mercadoPago = $this->app->make('mercadopago');

$usingSandbox = $mercadoPago->usingSandbox();

$this->assertTrue($usingSandbox);
}
}