|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Factories; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use WMDE\Euro\Euro; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\BucketTesting\FeatureToggle; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\UrlGenerator; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Factory for generating classes whose implementations differ due to A/B testing. |
|
15
|
|
|
* |
|
16
|
|
|
* @license GPL-2.0-or-later |
|
17
|
|
|
*/ |
|
18
|
|
|
class ChoiceFactory { |
|
19
|
|
|
|
|
20
|
100 |
|
private $featureToggle; |
|
21
|
100 |
|
|
|
22
|
100 |
|
public function __construct( FeatureToggle $featureToggle ) { |
|
23
|
|
|
$this->featureToggle = $featureToggle; |
|
24
|
14 |
|
} |
|
25
|
|
|
|
|
26
|
14 |
|
public function getMembershipCallToActionTemplate(): string { |
|
27
|
10 |
|
if ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.regular' ) ) { |
|
28
|
|
|
return 'partials/donation_confirmation/feature_toggle/call_to_action_regular.html.twig'; |
|
29
|
4 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.membership_call_to_action.video' ) ) { |
|
30
|
4 |
|
return 'partials/donation_confirmation/feature_toggle/call_to_action_video.html.twig'; |
|
31
|
|
|
} |
|
32
|
|
|
throw new UnknownChoiceDefinition( 'Membership Call to Action Template configuration failure.' ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getAmountOption(): array { |
|
36
|
|
|
if ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300_0' ) ) { |
|
37
|
100 |
|
return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] ); |
|
38
|
100 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to300' ) ) { |
|
39
|
19 |
|
return $this->getAmountOptionInEuros( [ 500, 1500, 2500, 5000, 7500, 10000, 25000, 30000 ] ); |
|
40
|
81 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.5to100' ) ) { |
|
41
|
1 |
|
return $this->getAmountOptionInEuros( [ 500, 1000, 1500, 2000, 3000, 5000, 7500, 10000 ] ); |
|
42
|
80 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.15to250' ) ) { |
|
43
|
80 |
|
return $this->getAmountOptionInEuros( [ 1500, 2000, 2500, 3000, 5000, 7500, 10000, 25000 ] ); |
|
44
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.30to250' ) ) { |
|
45
|
|
|
return $this->getAmountOptionInEuros( [ 3000, 4000, 5000, 7500, 10000, 15000, 20000, 25000 ] ); |
|
46
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.amount_options.50to500' ) ) { |
|
47
|
|
|
return $this->getAmountOptionInEuros( [ 5000, 10000, 15000, 20000, 25000, 30000, 50000 ] ); |
|
48
|
15 |
|
} |
|
49
|
15 |
|
throw new UnknownChoiceDefinition( 'Amount option selection configuration failure.' ); |
|
50
|
15 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getAmountOptionInEuros( array $amountOption ): array { |
|
53
|
|
|
return array_map( function ( int $amount ) { |
|
54
|
|
|
return Euro::newFromCents( $amount ); |
|
55
|
|
|
}, $amountOption ); |
|
56
|
|
|
} |
|
57
|
1 |
|
|
|
58
|
1 |
|
public function getAddressType(): ?string { |
|
59
|
|
|
if ( $this->featureToggle->featureIsActive( 'campaigns.address_type.no_preselection' ) ) { |
|
60
|
1 |
|
return null; |
|
61
|
1 |
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.address_type.preselection' ) ) { |
|
62
|
|
|
return 'person'; |
|
63
|
|
|
} |
|
64
|
|
|
throw new UnknownChoiceDefinition( 'Address type configuration failure.' ); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function getDefaultIncentives(): array { |
|
68
|
|
|
if ( $this->featureToggle->featureIsActive( 'campaigns.membership_incentive.incentive' ) ) { |
|
69
|
|
|
// TODO: This is currently hardcoded, we should make the list of incentives and defaults configurable |
|
70
|
|
|
return [ 'tote_bag' ]; |
|
71
|
|
|
} elseif ( $this->featureToggle->featureIsActive( 'campaigns.membership_incentive.no_incentive' ) ) { |
|
72
|
|
|
return []; |
|
73
|
|
|
} |
|
74
|
100 |
|
throw new UnknownChoiceDefinition( 'Address type configuration failure.' ); |
|
75
|
100 |
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|