|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\Afterpay; |
|
9
|
|
|
|
|
10
|
|
|
use Spryker\Yves\Kernel\AbstractFactory; |
|
11
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface; |
|
12
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface; |
|
13
|
|
|
use SprykerEco\Client\Afterpay\AfterpayClientInterface; |
|
14
|
|
|
use SprykerEco\Shared\Afterpay\AfterpayConfig; |
|
|
|
|
|
|
15
|
|
|
use SprykerEco\Shared\Afterpay\AfterpayConstants; |
|
16
|
|
|
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface; |
|
17
|
|
|
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\OneStepAuthorizeWorkflow; |
|
18
|
|
|
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\AvailablePaymentMethodsStep; |
|
19
|
|
|
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\AvailablePaymentMethodsStepInterface; |
|
20
|
|
|
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\PaymentSubFormsFilterStep; |
|
21
|
|
|
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\PaymentSubFormsFilterStepInterface; |
|
|
|
|
|
|
22
|
|
|
use SprykerEco\Yves\Afterpay\AuthorizeWorkflow\TwoStepsAuthorizeWorkflow; |
|
23
|
|
|
use SprykerEco\Yves\Afterpay\Dependency\Client\AfterpayToQuoteClientInterface; |
|
24
|
|
|
use SprykerEco\Yves\Afterpay\Form\DataProvider\InvoiceDataProvider; |
|
25
|
|
|
use SprykerEco\Yves\Afterpay\Form\InvoiceSubForm; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @method \SprykerEco\Yves\Afterpay\AfterpayConfig getConfig() |
|
29
|
|
|
*/ |
|
30
|
|
|
class AfterpayFactory extends AbstractFactory |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* @return \Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
public function createInvoiceForm(): SubFormInterface |
|
36
|
|
|
{ |
|
37
|
|
|
return new InvoiceSubForm(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return \Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface |
|
42
|
|
|
*/ |
|
43
|
|
|
public function createInvoiceFormDataProvider(): StepEngineFormDataProviderInterface |
|
44
|
|
|
{ |
|
45
|
|
|
return new InvoiceDataProvider(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface |
|
50
|
|
|
*/ |
|
51
|
|
|
public function createAfterpayAuthorizeWorkflow() |
|
52
|
|
|
{ |
|
53
|
|
|
$authorizeWorkflow = $this->getConfig()->getAfterpayAuthorizeWorkflow(); |
|
54
|
|
|
|
|
55
|
|
|
switch ($authorizeWorkflow) { |
|
56
|
|
|
case AfterpayConfig::AFTERPAY_AUTHORIZE_WORKFLOW_ONE_STEP: |
|
57
|
|
|
return $this->createOneStepAuthorizeWorkflow(); |
|
58
|
|
|
case AfterpayConfig::AFTERPAY_AUTHORIZE_WORKFLOW_TWO_STEPS: |
|
59
|
|
|
return $this->createTwoStepsAuthorizeWorkflow(); |
|
60
|
|
|
default: |
|
61
|
|
|
return $this->createOneStepAuthorizeWorkflow(); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface |
|
67
|
|
|
*/ |
|
68
|
|
|
public function createOneStepAuthorizeWorkflow(): AfterpayAuthorizeWorkflowInterface |
|
69
|
|
|
{ |
|
70
|
|
|
return new OneStepAuthorizeWorkflow(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\AfterpayAuthorizeWorkflowInterface |
|
75
|
|
|
*/ |
|
76
|
|
|
public function createTwoStepsAuthorizeWorkflow(): AfterpayAuthorizeWorkflowInterface |
|
77
|
|
|
{ |
|
78
|
|
|
return new TwoStepsAuthorizeWorkflow( |
|
79
|
|
|
$this->createAvailablePaymentMethodsStep(), |
|
80
|
|
|
$this->createPaymentSubformsFilter() |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\AvailablePaymentMethodsStepInterface |
|
86
|
|
|
*/ |
|
87
|
|
|
public function createAvailablePaymentMethodsStep(): AvailablePaymentMethodsStepInterface |
|
88
|
|
|
{ |
|
89
|
|
|
return new AvailablePaymentMethodsStep($this->getAfterpayClient()); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return \SprykerEco\Yves\Afterpay\AuthorizeWorkflow\Steps\PaymentSubFormsFilterStepInterface |
|
94
|
|
|
*/ |
|
95
|
|
|
public function createPaymentSubformsFilter(): PaymentSubFormsFilterStepInterface |
|
96
|
|
|
{ |
|
97
|
|
|
return new PaymentSubFormsFilterStep( |
|
98
|
|
|
$this->getConfig(), |
|
99
|
|
|
$this->getQuoteClient() |
|
100
|
|
|
); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return \SprykerEco\Client\Afterpay\AfterpayClientInterface |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getAfterpayClient(): AfterpayClientInterface |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getProvidedDependency(AfterpayDependencyProvider::CLIENT_AFTERPAY); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return \SprykerEco\Yves\Afterpay\Dependency\Client\AfterpayToQuoteClientInterface |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getQuoteClient(): AfterpayToQuoteClientInterface |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->getProvidedDependency(AfterpayDependencyProvider::CLIENT_QUOTE); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: