浏览代码

init

tags/1.0
0nepeop1e 4 年前
当前提交
85c1d4afc4
共有 9 个文件被更改,包括 278 次插入0 次删除
  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. 60
    0
      src/SenangPayDriver.php
  9. 41
    0
      src/SenangPayServiceProvider.php

+ 2
- 0
.gitignore 查看文件

@@ -0,0 +1,2 @@
1
+/vendor/
2
+composer.lock

+ 21
- 0
.idea/.gitignore 查看文件

@@ -0,0 +1,21 @@
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 查看文件

@@ -0,0 +1,46 @@
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$/src" isTestSource="false" packagePrefix="MirfalahTech\Laravel\Payment\Gateway\SenangPay\" />
7
+      <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
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 查看文件

@@ -0,0 +1,8 @@
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 查看文件

@@ -0,0 +1,47 @@
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 查看文件

@@ -0,0 +1,17 @@
1
+# mirfalah/laravel-payment-senangpay
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-senangpay ^1.0
17
+```

+ 36
- 0
composer.json 查看文件

@@ -0,0 +1,36 @@
1
+{
2
+    "name": "mirfalah/laravel-payment-senangpay",
3
+    "description": "Laravel payment senangpay driver",
4
+    "type": "library",
5
+    "homepage": "https://git.mirfalah.my/mirfalah-tech/laravel-payment-senangpay.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\\SenangPay\\": "src/"
21
+        }
22
+    },
23
+    "extra": {
24
+        "laravel": {
25
+            "providers": [
26
+                "MirfalahTech\\Laravel\\Payment\\Gateway\\SenangPay\\SenangPayServiceProvider"
27
+            ]
28
+        }
29
+    },
30
+    "repositories": [
31
+        {
32
+            "type": "composer",
33
+            "url": "https://composer.mirfalah.my"
34
+        }
35
+    ]
36
+}

+ 60
- 0
src/SenangPayDriver.php 查看文件

@@ -0,0 +1,60 @@
1
+<?php
2
+
3
+
4
+namespace MirfalahTech\Laravel\Payment\Gateway\SenangPay;
5
+
6
+
7
+use Illuminate\Http\Request;
8
+use Illuminate\Support\Facades\Response as Res;
9
+use MirfalahTech\Laravel\Payment\Contracts\PayableEntity;
10
+use MirfalahTech\Laravel\Payment\Contracts\PaymentGatewayDriver;
11
+use Symfony\Component\HttpFoundation\Response;
12
+
13
+class SenangPayDriver implements PaymentGatewayDriver
14
+{
15
+    /**
16
+     * @var string
17
+     */
18
+    protected $endpoint;
19
+
20
+    /**
21
+     * @var string
22
+     */
23
+    protected $merchant_id;
24
+
25
+    /**
26
+     * @var string
27
+     */
28
+    protected $secret_key;
29
+
30
+    public function __construct(string $endpoint, string $merchant_id, string $secret_key){
31
+        $this->endpoint = rtrim($endpoint, '/');
32
+        $this->merchant_id = $merchant_id;
33
+        $this->secret_key = $secret_key;
34
+    }
35
+
36
+    public function createPaymentURL(PayableEntity $payable, array $options = []): string
37
+    {
38
+        $detail = $payable->getBillDescription();
39
+        $amount = $payable->getBillAmount();
40
+        $order_id = $payable->getBillId();
41
+
42
+        $detail = preg_replace('/[^A-Z0-9,\-_]/i', '_', $detail);
43
+        $amount = sprintf('%0.2f', $amount);
44
+        $hash = md5($this->secret_key.$detail.$amount.$order_id);
45
+
46
+        return "$this->endpoint/payment/$this->merchant_id?'".
47
+            http_build_query(compact('detail', 'order_id', 'amount', 'hash'));
48
+    }
49
+
50
+    public function verifyGatewayReturn(Request $request): bool
51
+    {
52
+        return true;
53
+    }
54
+
55
+    public function verifyGatewayCallback(Request $request, Response &$response = null): bool
56
+    {
57
+        $response = Res::make('OK');
58
+        return true;
59
+    }
60
+}

+ 41
- 0
src/SenangPayServiceProvider.php 查看文件

@@ -0,0 +1,41 @@
1
+<?php
2
+
3
+
4
+namespace MirfalahTech\Laravel\Payment\Gateway\SenangPay;
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 SenangPayServiceProvider 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.senangpay', array_merge(
23
+            [
24
+                'endpoint' => env('SENANGPAY_ENDPOINT', 'https://app.senangpay.my/'),
25
+                'merchant_id' => env('SENANGPAY_MERCHANT_ID'),
26
+                'secret_key' => env('SENANGPAY_SECRET_KEY'),
27
+            ],
28
+            $config->get('payment.gateway.senangpay')
29
+        ));
30
+
31
+        $this->app->afterResolving('payment', function (PaymentManager $manager) use ($config) {
32
+            $manager->extend('senangpay', function () use ($config) {
33
+                return new SenangPayDriver(
34
+                    $config->get('payment.gateway.senangpay.endpoint'),
35
+                    $config->get('payment.gateway.senangpay.merchant_id'),
36
+                    $config->get('payment.gateway.senangpay.secret_key')
37
+                );
38
+            });
39
+        });
40
+    }
41
+}

正在加载...
取消
保存