-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPayment.php
More file actions
228 lines (203 loc) · 6.1 KB
/
Payment.php
File metadata and controls
228 lines (203 loc) · 6.1 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
namespace Bow\Payment;
use Bow\Payment\Common\ProcessorGatewayInterface;
class Payment implements ProcessorGatewayInterface
{
/**
* Orange Money payment provider identifier
* Used for mobile money transactions via Orange Money service
*/
public const ORANGE = 'orange';
/**
* Moov Money payment provider identifier
* Used for mobile money transactions via Moov Money service
*/
public const MOOV = 'moov';
/**
* Wave payment provider identifier
* Used for mobile money transactions via Wave service
*/
public const WAVE = 'wave';
/**
* MTN Mobile Money payment provider identifier
* Used for mobile money transactions via MTN service
*/
public const MTN = 'mtn';
/**
* Djamo payment provider identifier
* Used for digital payment transactions via Djamo service
*/
public const DJAMO = 'djamo';
/**
* Ivory Coast (Côte d'Ivoire) country identifier
* ISO 3166-1 alpha-2 country code for Ivory Coast
*/
public const CI = 'ivory_coast';
/**
* Senegal country identifier
* ISO 3166-1 alpha-2 country code for Senegal
*/
public const SN = 'senegal';
/**
* Ivory Coast payment provider mapping
* Maps payment provider identifiers to their respective service classes
* for payment processing in Ivory Coast (CI)
*
* @var array<string, class-string>
*/
public const CI_PROVIDER = [
Payment::ORANGE => \Bow\Payment\Gateway\IvoryCost\OrangeMoney\OrangeMoneyGateway::class,
Payment::MTN => \Bow\Payment\Gateway\IvoryCost\Mono\MonoGateway::class,
Payment::MOOV => \Bow\Payment\Gateway\IvoryCost\MoovFlooz\MoovFloozGateway::class,
Payment::WAVE => \Bow\Payment\Gateway\IvoryCost\Wave\WaveGateway::class,
Payment::DJAMO => \Bow\Payment\Gateway\IvoryCost\Djamo\DjamoGateway::class,
];
/**
* Senegal payment provider mapping
* Maps payment provider identifiers to their respective service classes
* for payment processing in Senegal (SN)
*
* @var array<string, class-string>
*/
public const SN_PROVIDER = [
Payment::ORANGE => \Bow\Payment\Gateway\Senegal\OrangeMoney\OrangeMoneyGateway::class,
Payment::WAVE => \Bow\Payment\Gateway\Senegal\Wave\WaveGateway::class,
];
/**
* The payment manager instance
*
* @var ProcessorGatewayInterface
*/
private static $providerGateway;
/**
* The payment instance
*
* @var Payment
*/
private static $instance;
/**
* ForPayment constructor
*
* @param array $config
* @return mixed
*/
public function __construct(private array $config)
{
$default = $this->config['default'];
$country = $default['country'] ?? 'ci';
$defaultProvider = $default['gateway'] ?? Payment::ORANGE;
$this->resolveGateway($country, $defaultProvider);
}
/**
* Resolve the payment gateway
*
* @param string $country
* @param string $provider
* @return void
*/
private function resolveGateway(string $country, string $provider)
{
switch ($country) {
case self::CI:
$provider = self::CI_PROVIDER[$provider] ?? null;
if ($provider === null) {
throw new \InvalidArgumentException("The payment gateway [{$provider}] is not supported in country [{$country}].");
}
$config = $this->resolveConfig('ivory_coast', $provider);
static::$providerGateway = new $provider($config);
break;
case self::SN:
$provider = self::SN_PROVIDER[$provider] ?? null;
if ($provider === null) {
throw new \InvalidArgumentException("The payment gateway [{$provider}] is not supported in country [{$country}].");
}
$config = $this->resolveConfig('senegal', $provider);
static::$providerGateway = new $provider($config);
break;
// Other gateways can be added here
default:
throw new \InvalidArgumentException("The payment gateway [{$provider}] is not supported.");
}
}
/**
* Resolve configuration for a specific country and provider
*
* @param string $country
* @param string $provider
* @return array|null
*/
public function resolveConfig(string $country, string $provider)
{
return $this->config[$country][$provider] ?? [];
}
/**
* Make configuration
*
* @return PaymentManagerContract
*/
public static function configure(array $configuration)
{
static::$instance = new Payment($configuration);
return static::$instance;
}
/**
* Switch payment provider
*
* @param string $country
* @param string $provider
* @return void
*/
public function withProvider(string $country, string $provider): void
{
$this->resolveGateway($country, $provider);
}
/**
* Make payment
*
* @return mixed
*/
public function payment(...$args)
{
return static::$providerGateway->payment(...$args);
}
/**
* Make transfer
*
* @return mixed
*/
public function transfer(...$args)
{
return static::$providerGateway->transfer(...$args);
}
/**
* Get balance
*
* @return mixed
*/
public function balance(...$args)
{
return static::$providerGateway->balance(...$args);
}
/**
* Verify payment
*
* @return void
*/
public function verify()
{
return static::$providerGateway->verify();
}
/**
* __callStatic
*
* @param string $methodName
* @param array $methodArguments
* @return mixed
*/
public static function __callStatic($methodName, $methodArguments)
{
if (method_exists(static::$instance, $methodName)) {
return call_user_func_array([static::$instance, $methodName], $methodArguments);
}
}
}