Skip to content

Commit

Permalink
Merge pull request #300 from TransbankDevelopers/feat/change-param-or…
Browse files Browse the repository at this point in the history
…der-build-methods

feat: change param order build methods
  • Loading branch information
Matiasnickolas authored Oct 1, 2024
2 parents 1afb84f + d0e23ac commit 7d7d4bf
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/PatpassComercio/Inscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,23 +177,23 @@ protected function getBaseUrl(): string
}

/**
* @param string $commerceCode
* @param string $apiKey
* @param string $commerceCode
*
* @return self
*/
public static function buildForIntegration(string $commerceCode, string $apiKey): self
public static function buildForIntegration(string $apiKey, string $commerceCode): self
{
return new self(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION));
}

/**
* @param string $commerceCode
* @param string $apiKey
* @param string $commerceCode
*
* @return self
*/
public static function buildForProduction(string $commerceCode, string $apiKey): self
public static function buildForProduction(string $apiKey, string $commerceCode): self
{
return new self(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION));
}
Expand Down
10 changes: 5 additions & 5 deletions src/Utils/InteractsWithWebpayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ protected function getBaseUrl(): string

/**
* Build an instance configured for integration environment.
* @param string $commerceCode
* @param string $apiKey
* @param string $commerceCode
*
* @return static
*/
public static function buildForIntegration(string $commerceCode, string $apiKey): self
public static function buildForIntegration(string $apiKey, string $commerceCode): self
{
return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_INTEGRATION));
}

/**
* Build an instance configured for integration environment.
* @param string $commerceCode
* Build an instance configured for production environment.
* @param string $apiKey
* @param string $commerceCode
*
* @return static
*/
public static function buildForProduction(string $commerceCode, string $apiKey): self
public static function buildForProduction(string $apiKey, string $commerceCode): self
{
return new static(new Options($apiKey, $commerceCode, Options::ENVIRONMENT_PRODUCTION));
}
Expand Down
7 changes: 4 additions & 3 deletions tests/PatpassComercio/PatpassComercioTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function it_configures_for_integration()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$inscription = Inscription::buildForIntegration($commerceCode, $apiKey);
$inscription = Inscription::buildForIntegration($apiKey, $commerceCode);
$options = $inscription->getOptions();

$this->assertSame($commerceCode, $options->getCommerceCode());
Expand All @@ -49,7 +49,7 @@ public function it_configures_for_production()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$inscription = Inscription::buildForProduction($commerceCode, $apiKey);
$inscription = Inscription::buildForProduction($apiKey, $commerceCode);
$options = $inscription->getOptions();

$this->assertSame($commerceCode, $options->getCommerceCode());
Expand Down Expand Up @@ -159,7 +159,8 @@ public function it_can_set_options()
}

/** @test */
public function it_can_get_base_url() {
public function it_can_get_base_url()
{
$options = new Options('test-api-key', 'test-commerce-code', Options::ENVIRONMENT_INTEGRATION);
$inscription = new Inscription($options);

Expand Down
36 changes: 18 additions & 18 deletions tests/Webpay/OneClick/TransbankOneclickTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ protected function setUp(): void
public function it_creates_an_inscription()
{
$response = MallInscription::buildForIntegration(
Oneclick::INTEGRATION_COMMERCE_CODE,
Oneclick::INTEGRATION_API_KEY
Oneclick::INTEGRATION_API_KEY,
Oneclick::INTEGRATION_COMMERCE_CODE
)->start($this->username, $this->email, $this->responseUrl);

$this->assertInstanceOf(InscriptionStartResponse::class, $response);
Expand All @@ -58,8 +58,8 @@ public function it_fails_creating_an_inscription_with_invalid_email()
$this->expectExceptionMessage('Invalid value for parameter: email');

MallInscription::buildForIntegration(
Oneclick::INTEGRATION_COMMERCE_CODE,
Oneclick::INTEGRATION_API_KEY
Oneclick::INTEGRATION_API_KEY,
Oneclick::INTEGRATION_COMMERCE_CODE
)->start($this->username, 'not_an_email', $this->responseUrl);
}

Expand All @@ -70,8 +70,8 @@ public function it_fails_creating_an_inscription_with_invalid_data()
$this->expectExceptionMessage('username is required');

MallInscription::buildForIntegration(
Oneclick::INTEGRATION_COMMERCE_CODE,
Oneclick::INTEGRATION_API_KEY
Oneclick::INTEGRATION_API_KEY,
Oneclick::INTEGRATION_COMMERCE_CODE
)->start('', $this->email, $this->responseUrl);
}

Expand All @@ -81,14 +81,14 @@ public function it_fails_trying_to_finish_inscription()
$this->createDemoData();

$startResponse = MallInscription::buildForIntegration(
Oneclick::INTEGRATION_COMMERCE_CODE,
Oneclick::INTEGRATION_API_KEY
Oneclick::INTEGRATION_API_KEY,
Oneclick::INTEGRATION_COMMERCE_CODE
)->start($this->username, $this->email, $this->responseUrl);
$this->assertInstanceOf(InscriptionStartResponse::class, $startResponse);
$tokenResponse = $startResponse->getToken();
$response = MallInscription::buildForIntegration(
Oneclick::INTEGRATION_COMMERCE_CODE,
Oneclick::INTEGRATION_API_KEY
Oneclick::INTEGRATION_API_KEY,
Oneclick::INTEGRATION_COMMERCE_CODE
)->finish($tokenResponse);
$this->assertInstanceOf(InscriptionFinishResponse::class, $response);

Expand All @@ -100,8 +100,8 @@ public function it_fails_trying_to_finish_inscription()
public function it_fails_authorizing_a_transaction_with_a_fake_token()
{
$mallTransaction = MallTransaction::buildForIntegration(
Oneclick::INTEGRATION_COMMERCE_CODE,
Oneclick::INTEGRATION_API_KEY
Oneclick::INTEGRATION_API_KEY,
Oneclick::INTEGRATION_COMMERCE_CODE
);
$exception = null;
try {
Expand Down Expand Up @@ -142,8 +142,8 @@ public function it_fails_authorizing_a_transaction_with_no_username()
{
$this->expectException(MallTransactionAuthorizeException::class);
MallTransaction::buildForIntegration(
Oneclick::INTEGRATION_COMMERCE_CODE,
Oneclick::INTEGRATION_API_KEY
Oneclick::INTEGRATION_API_KEY,
Oneclick::INTEGRATION_COMMERCE_CODE
)->authorize('', 'fakeToken', 'buyOrder2132312', [
[
'commerce_code' => Oneclick::INTEGRATION_CHILD_COMMERCE_CODE_1,
Expand All @@ -167,7 +167,7 @@ public function it_configures_inscription_for_integration()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$inscription = MallInscription::buildForIntegration($commerceCode, $apiKey);
$inscription = MallInscription::buildForIntegration($apiKey, $commerceCode);
$inscriptionOptions = $inscription->getOptions();

$this->assertSame($commerceCode, $inscriptionOptions->getCommerceCode());
Expand All @@ -182,7 +182,7 @@ public function it_configures_inscription_for_production()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$inscription = MallInscription::buildForProduction($commerceCode, $apiKey);
$inscription = MallInscription::buildForProduction($apiKey, $commerceCode);
$inscriptionOptions = $inscription->getOptions();

$this->assertSame($commerceCode, $inscriptionOptions->getCommerceCode());
Expand Down Expand Up @@ -213,7 +213,7 @@ public function it_configures_transaction_for_integration()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = MallTransaction::buildForIntegration($commerceCode, $apiKey);
$transaction = MallTransaction::buildForIntegration($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand All @@ -228,7 +228,7 @@ public function it_configures_transaction_for_production()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = MallTransaction::buildForProduction($commerceCode, $apiKey);
$transaction = MallTransaction::buildForProduction($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand Down
4 changes: 2 additions & 2 deletions tests/Webpay/TransaccionCompleta/TransaccionCompletaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function it_configures_for_integration()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = Transaction::buildForIntegration($commerceCode, $apiKey);
$transaction = Transaction::buildForIntegration($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand All @@ -106,7 +106,7 @@ public function it_configures_for_production()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = Transaction::buildForProduction($commerceCode, $apiKey);
$transaction = Transaction::buildForProduction($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand Down
6 changes: 3 additions & 3 deletions tests/Webpay/WebpayPlus/WebpayMallTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function it_configures_for_integration()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = MallTransaction::buildForIntegration($commerceCode, $apiKey);
$transaction = MallTransaction::buildForIntegration($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand All @@ -95,7 +95,7 @@ public function it_configures_for_production()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = MallTransaction::buildForProduction($commerceCode, $apiKey);
$transaction = MallTransaction::buildForProduction($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand Down Expand Up @@ -373,7 +373,7 @@ public function it_can_check_is_rejected_when_details_is_not_approved()
/** @test */
public function it_can_validate_token_input()
{
$transaction = MallTransaction::buildForIntegration('commerceCode', 'apiKey');
$transaction = MallTransaction::buildForIntegration('apiKey', 'commerceCode');

$this->expectException(InvalidArgumentException::class);
$transaction->commit('');
Expand Down
6 changes: 3 additions & 3 deletions tests/Webpay/WebpayPlus/WebpayPlusTransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function it_configures_for_integration()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = Transaction::buildForIntegration($commerceCode, $apiKey);
$transaction = Transaction::buildForIntegration($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand All @@ -96,7 +96,7 @@ public function it_configures_for_production()
$commerceCode = 'testCommerceCode';
$apiKey = 'testApiKey';

$transaction = Transaction::buildForProduction($commerceCode, $apiKey);
$transaction = Transaction::buildForProduction($apiKey, $commerceCode);
$transactionOptions = $transaction->getOptions();

$this->assertSame($commerceCode, $transactionOptions->getCommerceCode());
Expand Down Expand Up @@ -323,7 +323,7 @@ public function it_can_get_data_from_capture()
/** @test */
public function it_can_validate_token_input()
{
$transaction = Transaction::buildForIntegration('commerceCode', 'apiKey');
$transaction = Transaction::buildForIntegration('apiKey', 'commerceCode');

$this->expectException(InvalidArgumentException::class);
$transaction->commit('');
Expand Down

0 comments on commit 7d7d4bf

Please sign in to comment.