SettlementBatchSummaryTest.php
3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Test\Integration;
require_once dirname(__DIR__) . '/Setup.php';
use DateTime;
use Test;
use Test\Setup;
use Braintree;
class SettlementBatchSummaryTest extends Setup
{
public function isMasterCard($record)
{
return $record['cardType'] == Braintree\CreditCard::MASTER_CARD;
}
public function testGenerate_returnsAnEmptyCollectionWhenThereIsNoData()
{
$result = Braintree\SettlementBatchSummary::generate('2000-01-01');
$this->assertTrue($result->success);
$this->assertEquals(0, count($result->settlementBatchSummary->records));
}
public function testGatewayGenerate_returnsAnEmptyCollectionWhenThereIsNoData()
{
$gateway = new Braintree\Gateway([
'environment' => 'development',
'merchantId' => 'integration_merchant_id',
'publicKey' => 'integration_public_key',
'privateKey' => 'integration_private_key'
]);
$result = $gateway->settlementBatchSummary()->generate('2000-01-01');
$this->assertTrue($result->success);
$this->assertEquals(0, count($result->settlementBatchSummary->records));
}
public function testGenerate_returnsAnErrorIfTheDateCanNotBeParsed()
{
$result = Braintree\SettlementBatchSummary::generate('OMG NOT A DATE');
$this->assertFalse($result->success);
$errors = $result->errors->forKey('settlementBatchSummary')->onAttribute('settlementDate');
$this->assertEquals(Braintree\Error\Codes::SETTLEMENT_BATCH_SUMMARY_SETTLEMENT_DATE_IS_INVALID, $errors[0]->code);
}
public function testGenerate_returnsTransactionsSettledOnAGivenDay()
{
$transaction = Braintree\Transaction::saleNoValidate([
'amount' => '100.00',
'creditCard' => [
'number' => '5105105105105100',
'expirationDate' => '05/12'
],
'options' => ['submitForSettlement' => true]
]);
Braintree\Test\Transaction::settle($transaction->id);
$today = new Datetime;
$result = Braintree\SettlementBatchSummary::generate(Test\Helper::nowInEastern());
$this->assertTrue($result->success);
$masterCardRecords = array_filter($result->settlementBatchSummary->records, 'self::isMasterCard');
$masterCardKeys = array_keys($masterCardRecords);
$masterCardIndex = $masterCardKeys[0];
$this->assertTrue(count($masterCardRecords) > 0);
$this->assertEquals(Braintree\CreditCard::MASTER_CARD, $masterCardRecords[$masterCardIndex]['cardType']);
}
public function testGenerate_canBeGroupedByACustomField()
{
$transaction = Braintree\Transaction::saleNoValidate([
'amount' => '100.00',
'creditCard' => [
'number' => '5105105105105100',
'expirationDate' => '05/12'
],
'customFields' => [
'store_me' => 'custom value'
],
'options' => ['submitForSettlement' => true]
]);
Braintree\Test\Transaction::settle($transaction->id);
$today = new Datetime;
$result = Braintree\SettlementBatchSummary::generate(Test\Helper::nowInEastern(), 'store_me');
$this->assertTrue($result->success);
$this->assertTrue(count($result->settlementBatchSummary->records) > 0);
$this->assertArrayHasKey('store_me', $result->settlementBatchSummary->records[0]);
}
}