1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PayumTW\Ecpay; |
4
|
|
|
|
5
|
|
|
use Payum\Core\GatewayFactory; |
6
|
|
|
use PayumTW\Ecpay\Action\SyncAction; |
7
|
|
|
use Payum\Core\Bridge\Spl\ArrayObject; |
8
|
|
|
use PayumTW\Ecpay\Action\CancelAction; |
9
|
|
|
use PayumTW\Ecpay\Action\NotifyAction; |
10
|
|
|
use PayumTW\Ecpay\Action\RefundAction; |
11
|
|
|
use PayumTW\Ecpay\Action\StatusAction; |
12
|
|
|
use PayumTW\Ecpay\Action\CaptureAction; |
13
|
|
|
use PayumTW\Ecpay\Action\ConvertPaymentAction; |
14
|
|
|
use PayumTW\Ecpay\Action\Api\CancelTransactionAction; |
15
|
|
|
use PayumTW\Ecpay\Action\Api\CreateTransactionAction; |
16
|
|
|
use PayumTW\Ecpay\Action\Api\RefundTransactionAction; |
17
|
|
|
use PayumTW\Ecpay\Action\Api\GetTransactionDataAction; |
18
|
|
|
|
19
|
|
|
class EcpayGatewayFactory extends GatewayFactory |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
1 |
|
protected function populateConfig(ArrayObject $config) |
25
|
|
|
{ |
26
|
1 |
|
$config->defaults([ |
27
|
1 |
|
'payum.factory_name' => 'ecpay', |
28
|
1 |
|
'payum.factory_title' => 'Ecpay', |
29
|
1 |
|
'payum.action.capture' => new CaptureAction(), |
30
|
1 |
|
'payum.action.notify' => new NotifyAction(), |
31
|
1 |
|
'payum.action.refund' => new RefundAction(), |
32
|
1 |
|
'payum.action.cancel' => new CancelAction(), |
33
|
1 |
|
'payum.action.sync' => new SyncAction(), |
34
|
1 |
|
'payum.action.status' => new StatusAction(), |
35
|
1 |
|
'payum.action.convert_payment' => new ConvertPaymentAction(), |
36
|
|
|
|
37
|
1 |
|
'payum.action.api.create_transaction' => new CreateTransactionAction(), |
38
|
1 |
|
'payum.action.api.refund_transaction' => new RefundTransactionAction(), |
39
|
1 |
|
'payum.action.api.cancel_transaction' => new CancelTransactionAction(), |
40
|
1 |
|
'payum.action.api.get_transaction_data' => new GetTransactionDataAction(), |
41
|
1 |
|
]); |
42
|
|
|
|
43
|
1 |
View Code Duplication |
if (false == $config['payum.api']) { |
|
|
|
|
44
|
1 |
|
$config['payum.default_options'] = [ |
45
|
1 |
|
'MerchantID' => '2000132', |
46
|
1 |
|
'HashKey' => '5294y06JbISpM5x9', |
47
|
1 |
|
'HashIV' => 'v77hoKGq4kWxNNIS', |
48
|
1 |
|
'sandbox' => true, |
49
|
|
|
]; |
50
|
|
|
|
51
|
1 |
|
$config->defaults($config['payum.default_options']); |
52
|
1 |
|
$config['payum.required_options'] = ['MerchantID', 'HashKey', 'HashIV']; |
53
|
|
|
|
54
|
1 |
|
$config['payum.api'] = function (ArrayObject $config) { |
55
|
1 |
|
$config->validateNotEmpty($config['payum.required_options']); |
56
|
|
|
|
57
|
1 |
|
return new EcpayApi((array) $config, $config['payum.http_client'], $config['httplug.message_factory']); |
58
|
|
|
}; |
59
|
1 |
|
} |
60
|
1 |
|
} |
61
|
|
|
} |
62
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.