Skip to content

Commit

Permalink
Merge pull request #24 from TransbankDevelopers/chore/improve-transac…
Browse files Browse the repository at this point in the history
…tion-create-params-order

Change Transaction::create params order and upgrade readme file
  • Loading branch information
goncafa authored Aug 24, 2018
2 parents d3c5f7d + 75b2e5f commit 86165af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use Transbank\Onepay\Options;
$options = new Options('otro-api-key', 'otro-shared-secret');

# Al crear transacción
$transaction = Transaction::create($carro, $options, $channel);
$transaction = Transaction::create($carro, ChannelEnum::WEB(), $options);

# Al confirmar transacción
$commitTransaction = Transaction::commit($occ, $externalUniqueNumber, $options)
Expand Down Expand Up @@ -129,7 +129,7 @@ $segundoCarro = ShoppingCart::fromJSON($losObjetos);

Teniendo un carro, se puede crear una `Transaction`
```php
$transaction = Transaction::create($carro, null, ChannelEnum::WEB());
$transaction = Transaction::create($carro, ChannelEnum::WEB());

# Retorna un objeto TransactionCreateResponse con getters (getNombreAtributo) y setters(setNombreAtributo) para:

Expand Down Expand Up @@ -163,7 +163,7 @@ json_encode($transaction);
En caso de que falle el `create` de una `Transaction` se devuelve un objeto de tipo `TransactionCreateException`, donde
la propiedad `message`contiene la razón del fallo.

El tercer parámetro en el ejemplo corresponde al `$channel` y puede ser puede ser `ChannelEnum::WEB()`,
El segundo parámetro en el ejemplo corresponde al `$channel` y puede ser `ChannelEnum::WEB()`,
`ChannelEnum::MOBILE()` o `ChannelEnum::APP()` dependiendo si quien está realizando el pago está usando un browser en
versión Desktop, Móvil o está utilizando alguna aplicación móvil nativa.

Expand Down
7 changes: 6 additions & 1 deletion lib/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ private static function getHttpClient()
* @throws TransactionCreateException
* @throws \Exception
*/
public static function create($shoppingCart, $options = null, $channel = null)
public static function create($shoppingCart, $channel = null, $options = null)
{
if ($channel instanceof Options) {
$options = $channel;
$channel = null;
}

if (null != $channel && $channel == ChannelEnum::APP() && null == OnepayBase::getAppScheme())
throw new TransactionCreateException('You need to set an appScheme if you want to use the APP channel');

Expand Down
10 changes: 5 additions & 5 deletions tests/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function testTransactionCreationWorksWithOptions()
$this->assertEquals('Zapatos', $firstItem->getDescription());
$this->assertEquals('Pantalon', $secondItem->getDescription());

$response = Transaction::create($shoppingCart);
$response = Transaction::create($shoppingCart, $options);

$this->assertEquals($response instanceof TransactionCreateResponse, true);
$this->assertEquals($response->getResponseCode(), "OK");
Expand Down Expand Up @@ -363,7 +363,7 @@ public function testTransactionFailsWhenChannelMobileAndCallbackUrlNull() {
// This should raise a TransactionCreateException
try {
$this->setExpectedException(TransactionCreateException::class, 'You need to set a valid callback if you want to use the MOBILE channel');
$response = Transaction::create($shoppingCart, null, ChannelEnum::MOBILE());
$response = Transaction::create($shoppingCart, ChannelEnum::MOBILE());
}
finally {
// Reset the HttpClient static property to its original state
Expand All @@ -387,7 +387,7 @@ public function testTransactionWhenChannelMobileAndCallbackUrlNotNull() {
$this->assertEquals('Zapatos', $firstItem->getDescription());
$this->assertEquals('Pantalon', $secondItem->getDescription());

$response = Transaction::create($shoppingCart, null, ChannelEnum::MOBILE());
$response = Transaction::create($shoppingCart, ChannelEnum::MOBILE());

$this->assertEquals($response instanceof TransactionCreateResponse, true);
$this->assertEquals($response->getResponseCode(), "OK");
Expand All @@ -414,7 +414,7 @@ public function testTransactionFailsWhenChannelAPPAndAppSchemeNull() {
// This should raise a TransactionCreateException
try {
$this->setExpectedException(TransactionCreateException::class, 'You need to set an appScheme if you want to use the APP channel');
$response = Transaction::create($shoppingCart, null, ChannelEnum::APP());
$response = Transaction::create($shoppingCart, ChannelEnum::APP());
}
finally {
// Reset the HttpClient static property to its original state
Expand All @@ -437,7 +437,7 @@ public function testTransactionWhenChannelAPPAndAppSchemeNotNull() {
$this->assertEquals('Zapatos', $firstItem->getDescription());
$this->assertEquals('Pantalon', $secondItem->getDescription());

$response = Transaction::create($shoppingCart, null, ChannelEnum::APP());
$response = Transaction::create($shoppingCart, ChannelEnum::APP());

$this->assertEquals($response instanceof TransactionCreateResponse, true);
$this->assertEquals($response->getResponseCode(), "OK");
Expand Down

0 comments on commit 86165af

Please sign in to comment.