Browse Source

3.0

tags/3.0
Lim Eng Shun 3 years ago
parent
commit
ee9d4e9504
4 changed files with 37 additions and 2 deletions
  1. 1
    1
      README.md
  2. 10
    1
      config/payment.php
  3. 7
    0
      src/Contracts/PaymentGatewayDriver.php
  4. 19
    0
      src/Manager/PaymentManager.php

+ 1
- 1
README.md View File

@@ -13,5 +13,5 @@ Add the following repository to composer.json
13 13
 }
14 14
 ```
15 15
 ```shell script
16
-composer install mirfalah/laravel-payment ^1.0
16
+composer require mirfalah/laravel-payment ^1.0
17 17
 ```

+ 10
- 1
config/payment.php View File

@@ -1,7 +1,16 @@
1 1
 <?php
2 2
 
3 3
 return [
4
-    'default' => env('PAYMENT_GATEWAY'),
4
+    'default' => env('PAYMENT_GATEWAY', 'default'),
5
+
6
+    'options' => [
7
+        'razerpay' => [
8
+            'driver' => 'MirfalahTech\Laravel\Payment\Gateway\RazerPay\RazerPayDriver',
9
+        ],
10
+        'senangpay' => [
11
+            'driver' => 'MirfalahTech\Laravel\Payment\Gateway\SenangPay\SenangPayDriver',
12
+        ],
13
+    ],
5 14
 
6 15
     'gateway' => [
7 16
         'razerpay' => [

+ 7
- 0
src/Contracts/PaymentGatewayDriver.php View File

@@ -4,11 +4,14 @@
4 4
 namespace MirfalahTech\Laravel\Payment\Contracts;
5 5
 
6 6
 
7
+use Illuminate\Contracts\Config\Repository;
7 8
 use Illuminate\Http\Request;
8 9
 use Symfony\Component\HttpFoundation\Response;
9 10
 
10 11
 interface PaymentGatewayDriver
11 12
 {
13
+    public function __construct(Repository $config,  array $options);
14
+
12 15
     public function createPaymentURL(PayableEntity $payable, array $options = []): string;
13 16
 
14 17
     public function verifyGatewayReturn(Request $request): bool;
@@ -24,4 +27,8 @@ interface PaymentGatewayDriver
24 27
     public function isBillFailed(Request $request): ?bool;
25 28
 
26 29
     public function isBillPending(Request $request): ?bool;
30
+
31
+    public function isPostMethodSupported(): bool;
32
+
33
+    public function createPostMethodPayment(PayableEntity $payable, array $options = []): Response;
27 34
 }

+ 19
- 0
src/Manager/PaymentManager.php View File

@@ -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;

Loading…
Cancel
Save