Skip to content

Commit

Permalink
Expose if using sandbox (#12)
Browse files Browse the repository at this point in the history
* Expose whether using sandbox or not

* The actual mercado pago api doesn't have the concept of sandbox except for the client choosing either of the returned endpoints
  • Loading branch information
marianogoldman authored May 22, 2021
1 parent 592c3de commit 1ce9ef1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
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);
}
}

0 comments on commit 1ce9ef1

Please sign in to comment.