-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreditCardPayment.php
76 lines (60 loc) · 2.07 KB
/
CreditCardPayment.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
<?php
declare( strict_types = 1 );
namespace WMDE\Fundraising\PaymentContext\Domain\Model;
use DateTimeImmutable;
use DomainException;
use WMDE\Euro\Euro;
use WMDE\Fundraising\PaymentContext\Domain\Model\BookingDataTransformers\CreditCardBookingTransformer;
use WMDE\Fundraising\PaymentContext\Domain\Repositories\PaymentIDRepository;
/**
* @license GPL-2.0-or-later
* @author Kai Nissen < kai.nissen@wikimedia.de >
*/
class CreditCardPayment extends Payment implements BookablePayment {
use LegacyBookingStatusTrait;
private const PAYMENT_METHOD = 'MCP';
/**
* @var array<string,string>
*/
protected array $bookingData;
protected ?DateTimeImmutable $valuationDate = null;
public function __construct( int $id, Euro $amount, PaymentInterval $interval ) {
parent::__construct( $id, $amount, $interval, self::PAYMENT_METHOD );
$this->bookingData = [];
}
public function getValuationDate(): ?DateTimeImmutable {
return $this->valuationDate;
}
public function isBooked(): bool {
return $this->valuationDate !== null && !empty( $this->bookingData );
}
public function canBeBooked( array $transactionData ): bool {
return $this->valuationDate === null && empty( $this->bookingData );
}
public function bookPayment( array $transactionData, PaymentIDRepository $idGenerator ): Payment {
$transformer = new CreditCardBookingTransformer( $transactionData );
if ( $this->isBooked() ) {
throw new DomainException( 'Payment is already completed' );
}
$this->bookingData = $transformer->getBookingData();
$this->valuationDate = $transformer->getValuationDate();
return $this;
}
protected function getPaymentName(): string {
return self::PAYMENT_METHOD;
}
protected function getPaymentSpecificLegacyData(): array {
if ( $this->isBooked() ) {
return ( new CreditCardBookingTransformer( $this->bookingData ) )->getLegacyData();
}
return [];
}
public function getDisplayValues(): array {
$parentValues = parent::getDisplayValues();
$subtypeValues = $this->getPaymentSpecificLegacyData();
return array_merge(
$parentValues,
$subtypeValues
);
}
}