This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgateway.php
109 lines (103 loc) · 3.44 KB
/
gateway.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace PaymentGatewayCloud;
trait PaymentGatewayCloudGateway
{
/**
* @return array
*/
private function getCardTypes()
{
/**
* Comment/disable adapters that are not applicable
*/
return [
'cc' => 'Credit Card',
'visa' => 'Visa',
'mastercard' => 'MasterCard',
'amex' => 'Amex',
'diners' => 'Diners',
'jcb' => 'JCB',
'discover' => 'Discover',
'unionpay' => 'UnionPay',
'maestro' => 'Maestro',
// 'uatp' => 'UATP',
];
}
/**
* @return array
*/
private function getMethods()
{
return [
PaymentGatewayCloudPlugin::METHOD_DEBIT,
PaymentGatewayCloudPlugin::METHOD_PREAUTHORIZE,
];
}
/**
* @return array
*/
private function getCreditCards()
{
$cardTypes = $this->getCardTypes();
$creditCards = [];
foreach ($cardTypes as $cardType => $cardName) {
$title = $this->getConfig('cc_title_' . $cardType) ?: $cardName;
$creditCards[$cardType] = [
'type' => $cardType,
'name' => $cardName,
'status' => $this->getConfig('cc_status_' . $cardType),
'title' => $title,
'api_user' => $this->getConfig('cc_api_user_' . $cardType),
'api_password' => $this->getConfig('cc_api_password_' . $cardType),
'api_key' => $this->getConfig('cc_api_key_' . $cardType),
'api_secret' => $this->getConfig('cc_api_secret_' . $cardType),
'integration_key' => $this->getConfig('cc_integration_key_' . $cardType),
'seamless' => $this->getConfig('cc_seamless_' . $cardType),
'method' => $this->getConfig('cc_method_' . $cardType),
];
}
return $creditCards;
}
/**
*
*/
private function getCreditCardsPublic()
{
$creditCards = $this->getCreditCards();
$creditCardsPublic = [];
foreach ($creditCards as $cardType => $creditCard) {
if (!$creditCard['status']) {
continue;
}
if (empty($creditCard['api_key']) || empty($creditCard['api_secret'])) {
continue;
}
if (!empty($creditCard['seamless']) && empty($creditCard['integration_key'])) {
continue;
}
$creditCardPublic = [
'type' => $creditCard['type'],
'name' => $creditCard['name'],
'title' => $creditCard['title'],
// 'viewUrl' => $this->url->link('extension/payment/payment_gateway_cloud_' . $this->type . '/creditCardView&cardType=' . $cardType),
];
if (!empty($creditCard['seamless']) && !empty($creditCard['integration_key'])) {
$creditCardPublic['integrationKey'] = $creditCard['integration_key'];
}
$creditCardsPublic[$cardType] = $creditCardPublic;
}
return $creditCardsPublic;
}
/**
* @param $key
* @return mixed
*/
private function getConfig($key)
{
$prefix = $this->prefix . $this->type . '_';
if ($this->config->get($prefix . $key) != null) {
return $this->config->get($prefix . $key);
}
return isset($this->default[$key]) ? $this->default[$key] : null;
}
}