Browse Source

init

tags/2.0.3
0nepeop1e 4 years ago
commit
227e4d696c
9 changed files with 314 additions and 0 deletions
  1. 2
    0
      .gitignore
  2. 21
    0
      .idea/.gitignore
  3. 46
    0
      .idea/laravel-payment-senangpay.iml
  4. 8
    0
      .idea/modules.xml
  5. 47
    0
      .idea/php.xml
  6. 17
    0
      README.md
  7. 36
    0
      composer.json
  8. 94
    0
      src/RazerPayDriver.php
  9. 43
    0
      src/RazerPayServiceProvider.php

+ 2
- 0
.gitignore View File

1
+/vendor/
2
+composer.lock

+ 21
- 0
.idea/.gitignore View File

1
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
2
+# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
3
+
4
+# User-specific stuff
5
+**/workspace.xml
6
+**/tasks.xml
7
+**/usage.statistics.xml
8
+**/dictionaries
9
+**/shelf
10
+
11
+# Generated files
12
+**/contentModel.xml
13
+
14
+# Sensitive or high-churn files
15
+**/dataSources/
16
+**/dataSources.ids
17
+**/dataSources.local.xml
18
+**/sqlDataSources.xml
19
+**/dynamic.xml
20
+**/uiDesigner.xml
21
+**/dbnavigator.xml

+ 46
- 0
.idea/laravel-payment-senangpay.iml View File

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="WEB_MODULE" version="4">
3
+  <component name="NewModuleRootManager">
4
+    <content url="file://$MODULE_DIR$">
5
+      <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
6
+      <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
7
+      <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="MirfalahTech\Laravel\Payment\Gateway\RazerPay\" />
8
+      <excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
9
+      <excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/inflector" />
10
+      <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/contracts" />
11
+      <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/filesystem" />
12
+      <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/http" />
13
+      <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/session" />
14
+      <excludeFolder url="file://$MODULE_DIR$/vendor/illuminate/support" />
15
+      <excludeFolder url="file://$MODULE_DIR$/vendor/mirfalah/laravel-payment" />
16
+      <excludeFolder url="file://$MODULE_DIR$/vendor/nesbot/carbon" />
17
+      <excludeFolder url="file://$MODULE_DIR$/vendor/paragonie/random_compat" />
18
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/container" />
19
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/event-dispatcher" />
20
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/log" />
21
+      <excludeFolder url="file://$MODULE_DIR$/vendor/psr/simple-cache" />
22
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/deprecation-contracts" />
23
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/error-handler" />
24
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher" />
25
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher-contracts" />
26
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/finder" />
27
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-foundation" />
28
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-kernel" />
29
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/mime" />
30
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
31
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-idn" />
32
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-normalizer" />
33
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
34
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php70" />
35
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php72" />
36
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php73" />
37
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
38
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation" />
39
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation-contracts" />
40
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/var-dumper" />
41
+      <excludeFolder url="file://$MODULE_DIR$/vendor/voku/portable-ascii" />
42
+    </content>
43
+    <orderEntry type="inheritedJdk" />
44
+    <orderEntry type="sourceFolder" forTests="false" />
45
+  </component>
46
+</module>

+ 8
- 0
.idea/modules.xml View File

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/.idea/laravel-payment-senangpay.iml" filepath="$PROJECT_DIR$/.idea/laravel-payment-senangpay.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 47
- 0
.idea/php.xml View File

1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="PhpIncludePathManager">
4
+    <include_path>
5
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-idn" />
6
+      <path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher-contracts" />
7
+      <path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" />
8
+      <path value="$PROJECT_DIR$/vendor/mirfalah/laravel-payment" />
9
+      <path value="$PROJECT_DIR$/vendor/voku/portable-ascii" />
10
+      <path value="$PROJECT_DIR$/vendor/doctrine/inflector" />
11
+      <path value="$PROJECT_DIR$/vendor/composer" />
12
+      <path value="$PROJECT_DIR$/vendor/nesbot/carbon" />
13
+      <path value="$PROJECT_DIR$/vendor/symfony/var-dumper" />
14
+      <path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" />
15
+      <path value="$PROJECT_DIR$/vendor/psr/simple-cache" />
16
+      <path value="$PROJECT_DIR$/vendor/psr/container" />
17
+      <path value="$PROJECT_DIR$/vendor/paragonie/random_compat" />
18
+      <path value="$PROJECT_DIR$/vendor/psr/log" />
19
+      <path value="$PROJECT_DIR$/vendor/symfony/error-handler" />
20
+      <path value="$PROJECT_DIR$/vendor/illuminate/contracts" />
21
+      <path value="$PROJECT_DIR$/vendor/illuminate/session" />
22
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
23
+      <path value="$PROJECT_DIR$/vendor/illuminate/support" />
24
+      <path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
25
+      <path value="$PROJECT_DIR$/vendor/illuminate/filesystem" />
26
+      <path value="$PROJECT_DIR$/vendor/symfony/http-foundation" />
27
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php70" />
28
+      <path value="$PROJECT_DIR$/vendor/illuminate/http" />
29
+      <path value="$PROJECT_DIR$/vendor/symfony/finder" />
30
+      <path value="$PROJECT_DIR$/vendor/symfony/http-kernel" />
31
+      <path value="$PROJECT_DIR$/vendor/symfony/deprecation-contracts" />
32
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
33
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-mbstring" />
34
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-intl-normalizer" />
35
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php73" />
36
+      <path value="$PROJECT_DIR$/vendor/symfony/mime" />
37
+      <path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
38
+      <path value="$PROJECT_DIR$/vendor/symfony/translation" />
39
+    </include_path>
40
+  </component>
41
+  <component name="PhpProjectSharedConfiguration" php_language_level="7.1" />
42
+  <component name="PhpUnit">
43
+    <phpunit_settings>
44
+      <PhpUnitSettings custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" />
45
+    </phpunit_settings>
46
+  </component>
47
+</project>

+ 17
- 0
README.md View File

1
+# mirfalah/laravel-payment-razerpay
2
+
3
+## Installation
4
+Add the following repository to composer.json
5
+```json
6
+{
7
+    "repositories": [
8
+        {
9
+            "type": "composer",
10
+            "url": "https://composer.mirfalah.my"
11
+        }
12
+    ]
13
+}
14
+```
15
+```shell script
16
+composer install mirfalah/laravel-payment-razerpay ^1.0
17
+```

+ 36
- 0
composer.json View File

1
+{
2
+    "name": "mirfalah/laravel-payment-razerpay",
3
+    "description": "Laravel payment razerpay driver",
4
+    "type": "library",
5
+    "homepage": "https://git.mirfalah.my/mirfalah-tech/laravel-payment-razerpay.git",
6
+    "readme": "README.md",
7
+    "require": {
8
+        "php": ">=7.1",
9
+        "mirfalah/laravel-payment": "^1.0"
10
+    },
11
+    "license": "Mirfalah-Tech",
12
+    "authors": [
13
+        {
14
+            "name": "Lim Eng Shun",
15
+            "email": "engshun@mirfalah.my"
16
+        }
17
+    ],
18
+    "autoload": {
19
+        "psr-4": {
20
+            "MirfalahTech\\Laravel\\Payment\\Gateway\\RazerPay\\": "src/"
21
+        }
22
+    },
23
+    "extra": {
24
+        "laravel": {
25
+            "providers": [
26
+                "MirfalahTech\\Laravel\\Payment\\Gateway\\RazerPay\\RazerPayServiceProvider"
27
+            ]
28
+        }
29
+    },
30
+    "repositories": [
31
+        {
32
+            "type": "composer",
33
+            "url": "https://composer.mirfalah.my"
34
+        }
35
+    ]
36
+}

+ 94
- 0
src/RazerPayDriver.php View File

1
+<?php
2
+
3
+
4
+namespace MirfalahTech\Laravel\Payment\Gateway\RazerPay;
5
+
6
+
7
+use Illuminate\Http\Request;
8
+use Illuminate\Support\Arr;
9
+use Illuminate\Support\Facades\Response as Res;
10
+use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
11
+use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
12
+use Symfony\Component\HttpFoundation\Response;
13
+
14
+class RazerPayDriver implements PaymentGatewayDriver
15
+{
16
+    /**
17
+     * @var string
18
+     */
19
+    protected $endpoint;
20
+
21
+    /**
22
+     * @var string
23
+     */
24
+    protected $merchant_id;
25
+
26
+    /**
27
+     * @var string
28
+     */
29
+    protected $secret_key;
30
+    /**
31
+     * @var string
32
+     */
33
+    protected $verify_key;
34
+
35
+    public function __construct(string $endpoint, string $merchant_id, string $verify_key, string $secret_key)
36
+    {
37
+        $this->endpoint = rtrim($endpoint, '/');
38
+        $this->merchant_id = $merchant_id;
39
+        $this->secret_key = $secret_key;
40
+        $this->verify_key = $verify_key;
41
+    }
42
+
43
+    public function createPaymentURL(PayableEntity $payable, array $options = []): string
44
+    {
45
+        $order_id = urlencode($payable->getBillId());
46
+        $bill_name = urlencode($payable->getBillName());
47
+        $bill_email = $payable->getBillEmail();
48
+        $bill_mobile = $payable->getBillPhoneNumber();
49
+        $detail = urlencode($payable->getBillDescription());
50
+        $country = $payable->getBillCountry();
51
+        $bill_desc = urlencode(preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail));
52
+        $amount = sprintf('%0.2f', $payable->getBillAmount());
53
+        $currency = $payable->getBillCurrency();
54
+        $verify_code = md5($amount . $this->merchant_id . $payable->getBillId() . $this->verify_key);
55
+
56
+        $query = array_merge(
57
+            compact(
58
+                'amount', 'order_id', 'bill_name', 'bill_email', 'bill_mobile',
59
+                'bill_desc', 'country', 'verify_code', 'currency'
60
+            ),
61
+            Arr::only($options, ['channel'])
62
+        );
63
+
64
+        return "$this->endpoint/MOLPay/pay/$this->merchant_id/?" .
65
+            http_build_query($query);
66
+    }
67
+
68
+    public function verifyGatewayReturn(Request $request): bool
69
+    {
70
+        $tranID = $request->request->get('tranID');
71
+        $order_id = $request->request->get('orderid');
72
+        $status = $request->request->get('status');
73
+        $domain = $request->request->get('domain');
74
+        $amount = $request->request->get('amount');
75
+        $currency = $request->request->get('currency');
76
+        $appcode = $request->request->get('appcode');
77
+        $pay_date = $request->request->get('paydate');
78
+
79
+        $key0 = md5($tranID . $order_id . $status . $domain . $amount . $currency);
80
+
81
+        $key1 = md5($pay_date . $domain . $key0 . $appcode . $this->secret_key);
82
+
83
+        return $key1 == $request->request->get('skey');
84
+    }
85
+
86
+    public function verifyGatewayCallback(Request $request, Response &$response = null): bool
87
+    {
88
+        $response = $request->request->has('nbcb') ?
89
+            Res::make('CBTOKEN:MPSTATOK') :
90
+            Res::make('OK');
91
+
92
+        return $this->verifyGatewayReturn($request);
93
+    }
94
+}

+ 43
- 0
src/RazerPayServiceProvider.php View File

1
+<?php
2
+
3
+
4
+namespace MirfalahTech\Laravel\Payment\Gateway\RazerPay;
5
+
6
+
7
+use Illuminate\Contracts\Config\Repository;
8
+use Illuminate\Contracts\Container\BindingResolutionException;
9
+use Illuminate\Support\ServiceProvider;
10
+use MirfalahTech\Laravel\Payment\Manager\PaymentManager;
11
+
12
+class RazerPayServiceProvider extends ServiceProvider
13
+{
14
+    /**
15
+     * @throws BindingResolutionException
16
+     */
17
+    public function boot()
18
+    {
19
+        /** @var Repository $config */
20
+        $config = $this->app->make('config');
21
+
22
+        $config->set('payment.gateway.razerpay', array_merge(
23
+            [
24
+                'endpoint' => env('RAZER_ENDPOINT', 'https://www.onlinepayment.com.my/'),
25
+                'merchant_id' => env('RAZER_MERCHANT_ID'),
26
+                'verify_key' => env('RAZER_VERIFY_KEY'),
27
+                'secret_key' => env('RAZER_SECRET_KEY'),
28
+            ],
29
+            $config->get('payment.gateway.razerpay')
30
+        ));
31
+
32
+        $this->app->afterResolving('payment', function (PaymentManager $manager) use ($config) {
33
+            $manager->extend('razerpay', function () use ($config) {
34
+                return new RazerPayDriver(
35
+                    $config->get('payment.gateway.senangpay.endpoint'),
36
+                    $config->get('payment.gateway.senangpay.merchant_id'),
37
+                    $config->get('payment.gateway.senangpay.verify_key'),
38
+                    $config->get('payment.gateway.senangpay.secret_key')
39
+                );
40
+            });
41
+        });
42
+    }
43
+}

Loading…
Cancel
Save