-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from Potelo/charge-exception
Lança exceção quando der erro na cobrança
- Loading branch information
Showing
4 changed files
with
78 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Potelo\MultiPayment\Exceptions; | ||
|
||
class ChargingException extends MultiPaymentException | ||
{ | ||
/** | ||
* @var mixed $chargeResponse The charge response from the gateway | ||
*/ | ||
public $chargeResponse; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,23 +4,21 @@ | |
|
||
use Carbon\Carbon; | ||
use Potelo\MultiPayment\Tests\TestCase; | ||
use Potelo\MultiPayment\Models\Invoice; | ||
use Potelo\MultiPayment\Exceptions\ChargingException; | ||
|
||
class InvoiceBuilderTest extends TestCase | ||
{ | ||
|
||
/** | ||
* Create invoice test. | ||
* | ||
* @dataProvider shouldCreateInvoiceDataProvider | ||
* Create a invoice with mocked data | ||
* | ||
* @param string $gateway | ||
* @param array $data | ||
* | ||
* @return void | ||
* @throws \Potelo\MultiPayment\Exceptions\GatewayException | ||
* @throws \Potelo\MultiPayment\Exceptions\ModelAttributeValidationException | ||
* @return \Potelo\MultiPayment\Models\Invoice | ||
*/ | ||
public function testShouldCreateInvoice(string $gateway, array $data): void | ||
private function createInvoice(string $gateway, array $data): Invoice | ||
{ | ||
$multiPayment = new \Potelo\MultiPayment\MultiPayment($gateway); | ||
$invoiceBuilder = $multiPayment->newInvoice(); | ||
|
@@ -64,7 +62,24 @@ public function testShouldCreateInvoice(string $gateway, array $data): void | |
|
||
); | ||
} | ||
$invoice = $invoiceBuilder->create(); | ||
return $invoiceBuilder->create(); | ||
} | ||
|
||
/** | ||
* Create invoice test. | ||
* | ||
* @dataProvider shouldCreateInvoiceDataProvider | ||
* | ||
* @param string $gateway | ||
* @param array $data | ||
* | ||
* @return void | ||
* @throws \Potelo\MultiPayment\Exceptions\GatewayException | ||
* @throws \Potelo\MultiPayment\Exceptions\ModelAttributeValidationException | ||
*/ | ||
public function testShouldCreateInvoice(string $gateway, array $data): void | ||
{ | ||
$invoice = $this->createInvoice($gateway, $data); | ||
$this->assertInstanceOf(\Potelo\MultiPayment\Models\Invoice::class, $invoice); | ||
$this->assertNotEmpty($invoice->id); | ||
} | ||
|
@@ -139,30 +154,35 @@ public function shouldCreateInvoiceDataProvider(): array | |
]; | ||
} | ||
|
||
public static function customerWithoutAddress(): array | ||
{ | ||
$customer['name'] = 'Fake Customer'; | ||
$customer['email'] = '[email protected]'; | ||
$customer['taxDocument'] = '20176996915'; | ||
$customer['birthDate'] = '1980-01-01'; | ||
$customer['phoneArea'] = '71'; | ||
$customer['phoneNumber'] = '982345678'; | ||
return $customer; | ||
} | ||
|
||
public static function companyWithAddress(): array | ||
/** | ||
* Fail to create invoice test. | ||
* | ||
* @dataProvider shouldNotCreateInvoiceDataProvider | ||
* | ||
* @param string $gateway | ||
* @param array $data | ||
* | ||
* @return void | ||
*/ | ||
public function testShouldNotCreateInvoice(string $gateway, array $data): void | ||
{ | ||
$customer = self::customerWithoutAddress(); | ||
$customer['address'] = self::address(); | ||
return $customer; | ||
$this->expectException(ChargingException::class); | ||
$this->createInvoice($gateway, $data); | ||
} | ||
|
||
public static function companyWithoutAddress(): array | ||
public function shouldNotCreateInvoiceDataProvider(): array | ||
{ | ||
$customer['name'] = 'Fake Company'; | ||
$customer['email'] = '[email protected]'; | ||
$customer['taxDocument'] = '28585583000189'; | ||
return $customer; | ||
return [ | ||
'iugu - credit card - charge fail' => [ | ||
'gateway' => 'iugu', | ||
'data' => [ | ||
'items' => [['description' => 'Teste', 'quantity' => 1, 'price' => 10000,]], | ||
'customer' => self::customerWithAddress(), | ||
'paymentMethod' => 'credit_card', | ||
'creditCard' => array_merge(self::creditCard(), ['number' => '4012888888881881']), | ||
], | ||
], | ||
]; | ||
} | ||
|
||
public static function customerWithAddress(): array | ||
|