|
@@ -7,6 +7,7 @@ namespace MirfalahTech\Laravel\Payment\Manager;
|
7
|
7
|
use Illuminate\Contracts\Container\Container;
|
8
|
8
|
use Illuminate\Http\Request;
|
9
|
9
|
use Illuminate\Support\Manager;
|
|
10
|
+use InvalidArgumentException;
|
10
|
11
|
use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
|
11
|
12
|
use MirfalahTech\Laravel\Payment\Contracts\PaymentFactory;
|
12
|
13
|
use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
|
|
@@ -20,6 +21,7 @@ use Symfony\Component\HttpFoundation\Response;
|
20
|
21
|
* @method string createPaymentURL(PayableEntity $payable, array $options = [])
|
21
|
22
|
* @method bool verifyGatewayReturn(Request $request)
|
22
|
23
|
* @method bool verifyGatewayCallback(Request $request, Response &$response = null)
|
|
24
|
+ *
|
23
|
25
|
*/
|
24
|
26
|
class PaymentManager extends Manager implements PaymentFactory
|
25
|
27
|
{
|
|
@@ -39,6 +41,23 @@ class PaymentManager extends Manager implements PaymentFactory
|
39
|
41
|
return $this->driver($gateway);
|
40
|
42
|
}
|
41
|
43
|
|
|
44
|
+ public function custom(string $driverClass, array $options): PaymentGatewayDriver{
|
|
45
|
+ $kelas = new \ReflectionClass($driverClass);
|
|
46
|
+ if($kelas->isSubclassOf(PaymentGatewayDriver::class)){
|
|
47
|
+ throw new InvalidArgumentException("[$driverClass] is not a payment gateway driver.");
|
|
48
|
+ }
|
|
49
|
+ return new $driverClass($this->config, $options);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ protected function createDriver($driver)
|
|
53
|
+ {
|
|
54
|
+ $options = $this->config->get('payment.options');
|
|
55
|
+ if(key_exists($driver, $options) && class_exists($options['driver'])){
|
|
56
|
+ return $this->custom($options['driver'], $options);
|
|
57
|
+ }
|
|
58
|
+ throw new InvalidArgumentException("Driver [$driver] not supported.");
|
|
59
|
+ }
|
|
60
|
+
|
42
|
61
|
public function getDefaultDriver()
|
43
|
62
|
{
|
44
|
63
|
return $this->defaultGateway;
|