Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Mar 4, 2021
0 parents commit 09bd63c
Show file tree
Hide file tree
Showing 48 changed files with 15,844 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Tests

on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:

jobs:
tests:

name: PHP ${{ matrix.php }}

runs-on: ubuntu-latest

strategy:
matrix:
php: ['7.3', '7.4']

steps:
- name: Checkout Akaunting
uses: actions/checkout@v2
with:
repository: akaunting/akaunting

- name: Checkout Offline Payments module
uses: actions/checkout@v2
with:
path: modules/OfflinePayments

- name: Cache Composer
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath, ctype, dom, fileinfo, intl, gd, json, mbstring, pdo, pdo_sqlite, openssl, sqlite, xml, zip
coverage: none

- name: Copy .env
run: cp .env.testing .env

- name: Install Composer
run: cd modules/OfflinePayments ; composer test ; cd ../.. ; composer test

- name: Execute tests
run: php artisan test --parallel
37 changes: 37 additions & 0 deletions .github/workflows/translations.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Translations

on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:

jobs:
sync:
name: Sync

runs-on: ubuntu-latest

steps:

- name: Checkout
uses: actions/checkout@v2

- name: Sync with Crowdin
uses: crowdin/github-action@master
with:
upload_sources: true
upload_translations: true
download_translations: true
skip_untranslated_files: true

localization_branch_name: 'translations'
commit_message: 'new crowdin translations'
pull_request_title: 'New Crowdin translations'
pull_request_body: 'https://crowdin.com/project/akaunting-apps'
pull_request_labels: 'Translation'

config: 'crowdin.yml'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_APPS_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.idea
/.history
/.vscode
/.vagrant
/node_modules
/storage/*.key
/vendor
96 changes: 96 additions & 0 deletions Http/Controllers/Payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Modules\OfflinePayments\Http\Controllers;

use App\Abstracts\Http\PaymentController;
use \App\Events\Document\PaymentReceived;
use App\Http\Requests\Portal\InvoicePayment as PaymentRequest;
use App\Models\Document\Document;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;

class Payment extends PaymentController
{
public $alias = 'offline-payments';

public $type = 'redirect';

public function show(Document $invoice, PaymentRequest $request)
{
$setting = [];

$payment_methods = json_decode(setting('offline-payments.methods'), true);

foreach ($payment_methods as $payment_method) {
if ($payment_method['code'] == $request['payment_method']) {
$setting = $payment_method;

break;
}
}

$html = view('offline-payments::show', compact('setting', 'invoice'))->render();

return response()->json([
'code' => $setting['code'],
'name' => $setting['name'],
'description' => $setting['description'],
'redirect' => false,
'html' => $html,
]);
}

public function signed(Document $invoice, PaymentRequest $request)
{
$setting = [];

$payment_methods = json_decode(setting('offline-payments.methods'), true);

foreach ($payment_methods as $payment_method) {
if ($payment_method['code'] == $request['payment_method']) {
$setting = $payment_method;

break;
}
}

$confirm_url = URL::signedRoute('signed.invoices.offline-payments.confirm', [$invoice->id, 'company_id' => session('company_id')]);

$html = view('offline-payments::signed', compact('setting', 'invoice', 'confirm_url'))->render();

return response()->json([
'code' => $setting['code'],
'name' => $setting['name'],
'description' => $setting['description'],
'redirect' => false,
'html' => $html,
]);
}

public function confirm(Document $invoice, Request $request)
{
try {
event(new PaymentReceived($invoice, $request));

$message = trans('messages.success.added', ['type' => trans_choice('general.payments', 1)]);

$response = [
'success' => true,
'error' => false,
'message' => $message,
'data' => false,
];
} catch(\Exception $e) {
$message = $e->getMessage();

$response = [
'success' => false,
'error' => true,
'message' => $message,
'data' => false,
];
}

return response()->json($response);
}
}
130 changes: 130 additions & 0 deletions Http/Controllers/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

namespace Modules\OfflinePayments\Http\Controllers;

use App\Abstracts\Http\Controller;
use Illuminate\Http\Response;
use Modules\OfflinePayments\Http\Requests\Setting as Request;
use Modules\OfflinePayments\Http\Requests\SettingGet as GRequest;
use Modules\OfflinePayments\Http\Requests\SettingDelete as DRequest;
use Modules\OfflinePayments\Jobs\CreatePaymentMethod;
use Modules\OfflinePayments\Jobs\DeletePaymentMethod;
use Modules\OfflinePayments\Jobs\UpdatePaymentMethod;

class Settings extends Controller
{
/**
* Show the form for editing the specified resource.
*
* @return Response
*/
public function edit()
{
$methods = json_decode(setting('offline-payments.methods'));

return view('offline-payments::edit', compact('methods'));
}

/**
* Update the specified resource in storage.
*
* @param Request $request
*
* @return Response
*/
public function update(Request $request)
{
$code_exists = true;
$methods = json_decode(setting('offline-payments.methods'), true);

if (array_search($request->update_code, array_column($methods, 'code')) == false) {
$code_exists = false;
}

if (!empty($request->get('update_code')) && $code_exists == true) {
$payment_method = $this->dispatch(new UpdatePaymentMethod($request));

$message = trans('messages.success.updated', ['type' => $payment_method['name']]);
} else {
$payment_method = $this->dispatch(new CreatePaymentMethod($request));

$message = trans('messages.success.added', ['type' => $payment_method['name']]);
}

flash($message)->success();

return response()->json([
'success' => true,
'error' => false,
'message' => $message,
'redirect' => route('offline-payments.settings.edit'),
]);
}

/**
* Remove the specified resource from storage.
*
* @param GRequest $request
*
* @return Response
*/
public function get(GRequest $request)
{
$data = [];

$code = $request->get('code');

$methods = json_decode(setting('offline-payments.methods'), true);

foreach ($methods as $key => $method) {
if ($method['code'] != $code) {
continue;
}

$method['title'] = trans('offline-payments::offline-payments.edit', ['method' => $method['name']]);
$method['update_code'] = $code;

$code = explode('.', $method['code']);

$method['code'] = $code[1];

$data = $method;

break;
}

return response()->json([
'errors' => false,
'success' => true,
'data' => $data,
]);
}

/**
* Remove the specified resource from storage.
*
* @param DRequest $request
*
* @return Response
*/
public function destroy(DRequest $request)
{
$response = $this->ajaxDispatch(new DeletePaymentMethod($request));

if ($response['success']) {
//$response['redirect'] = route('offline-payments.settings.edit');

$response['message'] = trans('messages.success.deleted', ['type' => $response['data']['name']]);

//flash($message)->success();
} else {
//$response['redirect'] = route('offline-payments.settings.edit');

$message = $response['message'];

//flash($message)->error()->important();
}

return response()->json($response);
}
}
31 changes: 31 additions & 0 deletions Http/Requests/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Modules\OfflinePayments\Http\Requests;

use App\Abstracts\Http\FormRequest as Request;

class Setting extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|string',
'code' => 'required|string',
];
}
}
30 changes: 30 additions & 0 deletions Http/Requests/SettingDelete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Modules\OfflinePayments\Http\Requests;

use App\Abstracts\Http\FormRequest as Request;

class SettingDelete extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'code' => 'required|string',
];
}
}
Loading

0 comments on commit 09bd63c

Please sign in to comment.