forked from sostenesgomes/pagarme-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the `reference_key` attribute `AbstractTransactions`. That will be usefull because this attribute avoid transactions duplication accidentally. This attribute should have an unique value and has 20 caracters at least.
- Loading branch information
Showing
5 changed files
with
188 additions
and
31 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
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 |
---|---|---|
|
@@ -11,6 +11,8 @@ | |
|
||
class BoletoTransactionCreateTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use FakeReferenceKey; | ||
|
||
const PATH = 'transactions'; | ||
|
||
const CARD_ID = 1; | ||
|
@@ -20,9 +22,9 @@ public function boletoOptions() | |
$customer = $this->getCustomerMock(); | ||
|
||
return [ | ||
[null], | ||
[date('Y-m-d', strtotime("tomorrow"))], | ||
[date('Y-m-d', strtotime("+15 days"))] | ||
[null, null], | ||
[date('Y-m-d', strtotime("tomorrow")), $this->getFakeReferenceKey()], | ||
[date('Y-m-d', strtotime("+15 days")), null] | ||
]; | ||
} | ||
|
||
|
@@ -63,7 +65,55 @@ public function mustPayloadBeCorrect($expirationDate) | |
'metadata' => null, | ||
'async' => null, | ||
'boleto_instructions' => null, | ||
'soft_descriptor' => null | ||
'soft_descriptor' => null, | ||
'reference_key' => null | ||
], | ||
$transactionCreate->getPayload() | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider boletoOptions | ||
*/ | ||
public function mustContainsTheRightReferenceKey( | ||
$expirationDate, | ||
$referenceKey | ||
) | ||
{ | ||
$transaction = $this->createTransaction($expirationDate); | ||
$transactionCreate = new BoletoTransactionCreate($transaction); | ||
|
||
$this->assertEquals( | ||
[ | ||
'amount' => 1337, | ||
'payment_method' => 'boleto', | ||
'postback_url' => 'example.com/postback', | ||
'boleto_expiration_date' => $expirationDate, | ||
'customer' => [ | ||
'name' => 'Eduardo Nascimento', | ||
'born_at' => '15071991', | ||
'document_number' => '10586649727', | ||
'email' => '[email protected]', | ||
'sex' => 'M', | ||
'address' => [ | ||
'street' => 'rua teste', | ||
'street_number' => 42, | ||
'neighborhood' => 'centro', | ||
'zipcode' => '01227200', | ||
'complementary' => null | ||
], | ||
'phone' => [ | ||
'ddi' => 55, | ||
'ddd' => 15, | ||
'number' => 987523421 | ||
] | ||
], | ||
'metadata' => null, | ||
'async' => null, | ||
'boleto_instructions' => null, | ||
'soft_descriptor' => null, | ||
'reference_key' => null | ||
], | ||
$transactionCreate->getPayload() | ||
); | ||
|
@@ -98,7 +148,8 @@ public function mustPayloadContainSplitRule() | |
'postback_url' => 'example.com/postback', | ||
'customer' => $customerMock, | ||
'boleto_expiration_date' => $expirationDate, | ||
'split_rules' => $rules | ||
'split_rules' => $rules, | ||
'referenceKey' => null | ||
] | ||
); | ||
|
||
|
@@ -151,7 +202,8 @@ public function mustPayloadContainSplitRule() | |
'metadata' => null, | ||
'async' => null, | ||
'boleto_instructions' => null, | ||
'soft_descriptor' => null | ||
'soft_descriptor' => null, | ||
'reference_key' => null | ||
], | ||
$transactionCreate->getPayload() | ||
); | ||
|
@@ -185,16 +237,20 @@ public function mustMethodBeCorrect() | |
$this->assertEquals(RequestInterface::HTTP_POST, $transactionCreate->getMethod()); | ||
} | ||
|
||
private function createTransaction($expirationDate) | ||
private function createTransaction( | ||
$expirationDate, | ||
$referenceKey = null | ||
) | ||
{ | ||
$customerMock = $this->getCustomerMock(); | ||
|
||
$transaction = new BoletoTransaction( | ||
[ | ||
'amount' => 1337, | ||
'postback_url' => 'example.com/postback', | ||
'postback_url' => 'example.com/postback', | ||
'customer' => $customerMock, | ||
'boleto_expiration_date' => $expirationDate | ||
'boleto_expiration_date' => $expirationDate, | ||
'reference_key' => $referenceKey | ||
] | ||
); | ||
|
||
|
@@ -244,7 +300,8 @@ public function mustPayloadContainSoftDescriptor() | |
'amount' => 1338, | ||
'postback_url' => 'example.com/postback', | ||
'customer' => $customerMock, | ||
'soft_descriptor' => "Minha loja" | ||
'soft_descriptor' => "Minha loja", | ||
'referenceKey' => null | ||
] | ||
); | ||
|
||
|
@@ -280,7 +337,8 @@ public function mustPayloadContainSoftDescriptor() | |
'metadata' => null, | ||
'async' => null, | ||
'boleto_instructions' => null, | ||
'soft_descriptor' => 'Minha loja' | ||
'soft_descriptor' => 'Minha loja', | ||
'reference_key' => null | ||
], | ||
$transactionCreate->getPayload() | ||
); | ||
|
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
Oops, something went wrong.