-
Notifications
You must be signed in to change notification settings - Fork 1
/
BankTransferPayment.php
83 lines (64 loc) · 2.2 KB
/
BankTransferPayment.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
<?php
declare( strict_types = 1 );
namespace WMDE\Fundraising\PaymentContext\Domain\Model;
use WMDE\Euro\Euro;
class BankTransferPayment extends Payment implements CancellablePayment {
private const PAYMENT_METHOD = 'UEB';
/**
* This field is nullable to allow for anonymisation
*
* @var PaymentReferenceCode|null
*/
private ?PaymentReferenceCode $paymentReferenceCode;
private bool $isCancelled = false;
private function __construct( int $id, Euro $amount, PaymentInterval $interval, ?PaymentReferenceCode $paymentReference ) {
parent::__construct( $id, $amount, $interval, self::PAYMENT_METHOD );
$this->paymentReferenceCode = $paymentReference;
}
public static function create( int $id, Euro $amount, PaymentInterval $interval, PaymentReferenceCode $paymentReference ): self {
return new self( $id, $amount, $interval, $paymentReference );
}
public function getPaymentReferenceCode(): string {
if ( $this->paymentReferenceCode === null ) {
return '';
}
return $this->paymentReferenceCode->getFormattedCode();
}
public function anonymise(): void {
$this->paymentReferenceCode = null;
}
protected function getPaymentName(): string {
return self::PAYMENT_METHOD;
}
protected function getPaymentSpecificLegacyData(): array {
// "ueb_code" is a column name in the legacy "spenden" (donations) database table.
// the donation repository code will have to put it there instead of the data blob
$paymentReferenceCode = $this->getPaymentReferenceCode();
return $paymentReferenceCode ? [ 'ueb_code' => $paymentReferenceCode ] : [];
}
public function isCancelled(): bool {
return $this->isCancelled;
}
public function cancel(): void {
$this->isCancelled = true;
}
public function isCancellable(): bool {
return !$this->isCancelled();
}
public function getDisplayValues(): array {
$parentValues = parent::getDisplayValues();
$subtypeValues = $this->getPaymentSpecificLegacyData();
return array_merge(
$parentValues,
$subtypeValues
);
}
/**
* @return string
*/
protected function getLegacyPaymentStatus(): string {
if ( $this->isCancelled() ) { return LegacyPaymentStatus::CANCELLED->value;
}
return LegacyPaymentStatus::BANK_TRANSFER->value;
}
}