Skip to content

Commit 09bd63c

Browse files
committed
first commit
0 parents  commit 09bd63c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+15844
-0
lines changed

.github/workflows/tests.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Tests
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0'
6+
workflow_dispatch:
7+
8+
jobs:
9+
tests:
10+
11+
name: PHP ${{ matrix.php }}
12+
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
php: ['7.3', '7.4']
18+
19+
steps:
20+
- name: Checkout Akaunting
21+
uses: actions/checkout@v2
22+
with:
23+
repository: akaunting/akaunting
24+
25+
- name: Checkout Offline Payments module
26+
uses: actions/checkout@v2
27+
with:
28+
path: modules/OfflinePayments
29+
30+
- name: Cache Composer
31+
uses: actions/cache@v1
32+
with:
33+
path: ~/.composer/cache/files
34+
key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
35+
36+
- name: Setup PHP
37+
uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: ${{ matrix.php }}
40+
extensions: bcmath, ctype, dom, fileinfo, intl, gd, json, mbstring, pdo, pdo_sqlite, openssl, sqlite, xml, zip
41+
coverage: none
42+
43+
- name: Copy .env
44+
run: cp .env.testing .env
45+
46+
- name: Install Composer
47+
run: cd modules/OfflinePayments ; composer test ; cd ../.. ; composer test
48+
49+
- name: Execute tests
50+
run: php artisan test --parallel

.github/workflows/translations.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Translations
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0'
6+
workflow_dispatch:
7+
8+
jobs:
9+
sync:
10+
name: Sync
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
16+
- name: Checkout
17+
uses: actions/checkout@v2
18+
19+
- name: Sync with Crowdin
20+
uses: crowdin/github-action@master
21+
with:
22+
upload_sources: true
23+
upload_translations: true
24+
download_translations: true
25+
skip_untranslated_files: true
26+
27+
localization_branch_name: 'translations'
28+
commit_message: 'new crowdin translations'
29+
pull_request_title: 'New Crowdin translations'
30+
pull_request_body: 'https://crowdin.com/project/akaunting-apps'
31+
pull_request_labels: 'Translation'
32+
33+
config: 'crowdin.yml'
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_APPS_ID }}
37+
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.idea
2+
/.history
3+
/.vscode
4+
/.vagrant
5+
/node_modules
6+
/storage/*.key
7+
/vendor

Http/Controllers/Payment.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
namespace Modules\OfflinePayments\Http\Controllers;
4+
5+
use App\Abstracts\Http\PaymentController;
6+
use \App\Events\Document\PaymentReceived;
7+
use App\Http\Requests\Portal\InvoicePayment as PaymentRequest;
8+
use App\Models\Document\Document;
9+
use Illuminate\Http\Request;
10+
use Illuminate\Support\Facades\URL;
11+
12+
class Payment extends PaymentController
13+
{
14+
public $alias = 'offline-payments';
15+
16+
public $type = 'redirect';
17+
18+
public function show(Document $invoice, PaymentRequest $request)
19+
{
20+
$setting = [];
21+
22+
$payment_methods = json_decode(setting('offline-payments.methods'), true);
23+
24+
foreach ($payment_methods as $payment_method) {
25+
if ($payment_method['code'] == $request['payment_method']) {
26+
$setting = $payment_method;
27+
28+
break;
29+
}
30+
}
31+
32+
$html = view('offline-payments::show', compact('setting', 'invoice'))->render();
33+
34+
return response()->json([
35+
'code' => $setting['code'],
36+
'name' => $setting['name'],
37+
'description' => $setting['description'],
38+
'redirect' => false,
39+
'html' => $html,
40+
]);
41+
}
42+
43+
public function signed(Document $invoice, PaymentRequest $request)
44+
{
45+
$setting = [];
46+
47+
$payment_methods = json_decode(setting('offline-payments.methods'), true);
48+
49+
foreach ($payment_methods as $payment_method) {
50+
if ($payment_method['code'] == $request['payment_method']) {
51+
$setting = $payment_method;
52+
53+
break;
54+
}
55+
}
56+
57+
$confirm_url = URL::signedRoute('signed.invoices.offline-payments.confirm', [$invoice->id, 'company_id' => session('company_id')]);
58+
59+
$html = view('offline-payments::signed', compact('setting', 'invoice', 'confirm_url'))->render();
60+
61+
return response()->json([
62+
'code' => $setting['code'],
63+
'name' => $setting['name'],
64+
'description' => $setting['description'],
65+
'redirect' => false,
66+
'html' => $html,
67+
]);
68+
}
69+
70+
public function confirm(Document $invoice, Request $request)
71+
{
72+
try {
73+
event(new PaymentReceived($invoice, $request));
74+
75+
$message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);
76+
77+
$response = [
78+
'success' => true,
79+
'error' => false,
80+
'message' => $message,
81+
'data' => false,
82+
];
83+
} catch(\Exception $e) {
84+
$message = $e->getMessage();
85+
86+
$response = [
87+
'success' => false,
88+
'error' => true,
89+
'message' => $message,
90+
'data' => false,
91+
];
92+
}
93+
94+
return response()->json($response);
95+
}
96+
}

Http/Controllers/Settings.php

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
namespace Modules\OfflinePayments\Http\Controllers;
4+
5+
use App\Abstracts\Http\Controller;
6+
use Illuminate\Http\Response;
7+
use Modules\OfflinePayments\Http\Requests\Setting as Request;
8+
use Modules\OfflinePayments\Http\Requests\SettingGet as GRequest;
9+
use Modules\OfflinePayments\Http\Requests\SettingDelete as DRequest;
10+
use Modules\OfflinePayments\Jobs\CreatePaymentMethod;
11+
use Modules\OfflinePayments\Jobs\DeletePaymentMethod;
12+
use Modules\OfflinePayments\Jobs\UpdatePaymentMethod;
13+
14+
class Settings extends Controller
15+
{
16+
/**
17+
* Show the form for editing the specified resource.
18+
*
19+
* @return Response
20+
*/
21+
public function edit()
22+
{
23+
$methods = json_decode(setting('offline-payments.methods'));
24+
25+
return view('offline-payments::edit', compact('methods'));
26+
}
27+
28+
/**
29+
* Update the specified resource in storage.
30+
*
31+
* @param Request $request
32+
*
33+
* @return Response
34+
*/
35+
public function update(Request $request)
36+
{
37+
$code_exists = true;
38+
$methods = json_decode(setting('offline-payments.methods'), true);
39+
40+
if (array_search($request->update_code, array_column($methods, 'code')) == false) {
41+
$code_exists = false;
42+
}
43+
44+
if (!empty($request->get('update_code')) && $code_exists == true) {
45+
$payment_method = $this->dispatch(new UpdatePaymentMethod($request));
46+
47+
$message = trans('messages.success.updated', ['type' => $payment_method['name']]);
48+
} else {
49+
$payment_method = $this->dispatch(new CreatePaymentMethod($request));
50+
51+
$message = trans('messages.success.added', ['type' => $payment_method['name']]);
52+
}
53+
54+
flash($message)->success();
55+
56+
return response()->json([
57+
'success' => true,
58+
'error' => false,
59+
'message' => $message,
60+
'redirect' => route('offline-payments.settings.edit'),
61+
]);
62+
}
63+
64+
/**
65+
* Remove the specified resource from storage.
66+
*
67+
* @param GRequest $request
68+
*
69+
* @return Response
70+
*/
71+
public function get(GRequest $request)
72+
{
73+
$data = [];
74+
75+
$code = $request->get('code');
76+
77+
$methods = json_decode(setting('offline-payments.methods'), true);
78+
79+
foreach ($methods as $key => $method) {
80+
if ($method['code'] != $code) {
81+
continue;
82+
}
83+
84+
$method['title'] = trans('offline-payments::offline-payments.edit', ['method' => $method['name']]);
85+
$method['update_code'] = $code;
86+
87+
$code = explode('.', $method['code']);
88+
89+
$method['code'] = $code[1];
90+
91+
$data = $method;
92+
93+
break;
94+
}
95+
96+
return response()->json([
97+
'errors' => false,
98+
'success' => true,
99+
'data' => $data,
100+
]);
101+
}
102+
103+
/**
104+
* Remove the specified resource from storage.
105+
*
106+
* @param DRequest $request
107+
*
108+
* @return Response
109+
*/
110+
public function destroy(DRequest $request)
111+
{
112+
$response = $this->ajaxDispatch(new DeletePaymentMethod($request));
113+
114+
if ($response['success']) {
115+
//$response['redirect'] = route('offline-payments.settings.edit');
116+
117+
$response['message'] = trans('messages.success.deleted', ['type' => $response['data']['name']]);
118+
119+
//flash($message)->success();
120+
} else {
121+
//$response['redirect'] = route('offline-payments.settings.edit');
122+
123+
$message = $response['message'];
124+
125+
//flash($message)->error()->important();
126+
}
127+
128+
return response()->json($response);
129+
}
130+
}

Http/Requests/Setting.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Modules\OfflinePayments\Http\Requests;
4+
5+
use App\Abstracts\Http\FormRequest as Request;
6+
7+
class Setting extends Request
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* Get the validation rules that apply to the request.
21+
*
22+
* @return array
23+
*/
24+
public function rules()
25+
{
26+
return [
27+
'name' => 'required|string',
28+
'code' => 'required|string',
29+
];
30+
}
31+
}

Http/Requests/SettingDelete.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Modules\OfflinePayments\Http\Requests;
4+
5+
use App\Abstracts\Http\FormRequest as Request;
6+
7+
class SettingDelete extends Request
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* Get the validation rules that apply to the request.
21+
*
22+
* @return array
23+
*/
24+
public function rules()
25+
{
26+
return [
27+
'code' => 'required|string',
28+
];
29+
}
30+
}

0 commit comments

Comments
 (0)