-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreditCardPaymentTest.php
124 lines (96 loc) · 5.69 KB
/
CreditCardPaymentTest.php
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
declare( strict_types = 1 );
namespace WMDE\Fundraising\PaymentContext\Tests\Unit\Domain\Model;
use PHPUnit\Framework\TestCase;
use WMDE\Euro\Euro;
use WMDE\Fundraising\PaymentContext\Domain\Model\CreditCardPayment;
use WMDE\Fundraising\PaymentContext\Domain\Model\LegacyPaymentStatus;
use WMDE\Fundraising\PaymentContext\Domain\Model\PaymentInterval;
use WMDE\Fundraising\PaymentContext\Tests\Data\CreditCardPaymentBookingData;
use WMDE\Fundraising\PaymentContext\Tests\Fixtures\DummyPaymentIdRepository;
/**
* @covers \WMDE\Fundraising\PaymentContext\Domain\Model\CreditCardPayment
*/
class CreditCardPaymentTest extends TestCase {
private const OTHER_TRANSACTION_ID = '3388998877';
public function testNewCreditCardPaymentsAreNotBooked(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$this->assertTrue( $creditCardPayment->canBeBooked( [] ) );
}
public function testCompletePaymentWithOutTransactionIdFails(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$this->expectException( \InvalidArgumentException::class );
$creditCardPayment->bookPayment( [], new DummyPaymentIdRepository() );
}
public function testCompletePaymentWithEmptyTransactionDataFails(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$this->expectException( \InvalidArgumentException::class );
$creditCardPayment->bookPayment( [ 'transactionId' => '' ], new DummyPaymentIdRepository() );
}
public function testPaymentCannotBeBookedMultipleTimes(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$creditCardPayment->bookPayment( CreditCardPaymentBookingData::newValidBookingData(), new DummyPaymentIdRepository() );
$this->expectException( \DomainException::class );
$creditCardPayment->bookPayment(
[
...CreditCardPaymentBookingData::newValidBookingData(),
'transactionId' => self::OTHER_TRANSACTION_ID
],
new DummyPaymentIdRepository()
);
}
public function testBookPaymentWithValidTransactionMarksItBooked(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$creditCardPayment->bookPayment( CreditCardPaymentBookingData::newValidBookingData(), new DummyPaymentIdRepository() );
$this->assertFalse( $creditCardPayment->canBeBooked( CreditCardPaymentBookingData::newValidBookingData() ) );
// Credit cards get their valuation date from current time instead of transaction data
$this->assertNotNull( $creditCardPayment->getValuationDate() );
$this->assertEqualsWithDelta( time(), $creditCardPayment->getValuationDate()->getTimestamp(), 5 );
}
public function testGivenBookedPayment_paymentLegacyDataIsNonEmptyArray(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$creditCardPayment->bookPayment( CreditCardPaymentBookingData::newValidBookingData(), new DummyPaymentIdRepository() );
$legacyData = $creditCardPayment->getLegacyData();
$this->assertNotEmpty( $legacyData->paymentSpecificValues );
// spot-check some values to see if we have the right field names
$this->assertSame( '1337', $legacyData->paymentSpecificValues['mcp_amount'] );
$this->assertSame( 'customer.prefix-ID2tbnag4a9u', $legacyData->paymentSpecificValues['ext_payment_id'] );
$this->assertSame( 'e20fb9d5281c1bca1901c19f6e46213191bb4c17', $legacyData->paymentSpecificValues['ext_payment_account'] );
$this->assertNotEmpty( $legacyData->paymentSpecificValues['ext_payment_timestamp'] );
}
public function testGivenNewPayment_paymentLegacyDataIsEmptyArray(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$this->assertSame( [], $creditCardPayment->getLegacyData()->paymentSpecificValues );
}
public function testStatusInLegacyDataChangesWithBookedStatus(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$bookedCreditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$bookedCreditCardPayment->bookPayment( CreditCardPaymentBookingData::newValidBookingData(), new DummyPaymentIdRepository() );
$this->assertSame( LegacyPaymentStatus::EXTERNAL_INCOMPLETE->value, $creditCardPayment->getLegacyData()->paymentStatus );
$this->assertSame( LegacyPaymentStatus::EXTERNAL_BOOKED->value, $bookedCreditCardPayment->getLegacyData()->paymentStatus );
}
public function testGetDisplayDataReturnsAllFieldsToDisplayForBookedPayment(): void {
$creditCardPayment = new CreditCardPayment( 1, Euro::newFromInt( 1000 ), PaymentInterval::Monthly );
$creditCardPayment->bookPayment( CreditCardPaymentBookingData::newValidBookingData(), new DummyPaymentIdRepository() );
$expectedValues = [
'amount' => 100000,
'interval' => 1,
'paymentType' => 'MCP',
'ext_payment_id' => 'customer.prefix-ID2tbnag4a9u',
'mcp_amount' => '1337',
'ext_payment_account' => 'e20fb9d5281c1bca1901c19f6e46213191bb4c17',
'mcp_sessionid' => 'CC13064b2620f4028b7d340e3449676213336a4d',
'mcp_auth' => 'd1d6fae40cf96af52477a9e521558ab7',
'mcp_title' => 'Your generous donation',
'mcp_country' => 'DE',
'mcp_currency' => 'EUR',
'mcp_cc_expiry_date' => '',
'ext_payment_status' => 'processed'
];
$actualDisplayData = $creditCardPayment->getDisplayValues();
$this->assertNotNull( $creditCardPayment->getValuationDate() );
$this->assertFalse( $creditCardPayment->canBeBooked( [] ) );
unset( $actualDisplayData['ext_payment_timestamp'] );
$this->assertEquals( $expectedValues, $actualDisplayData );
}
}