...
 
Commits (6)
......@@ -37,3 +37,6 @@ PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
RPC_URL=
WALLET_ADDRESS=
\ No newline at end of file
......@@ -4,6 +4,28 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* App\Deposit
*
* @property int $id
* @property string $payment_id
* @property string $amount
* @property string $time_received
* @property string $tx_id
* @property int $block_received
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Project $project
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit whereAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit whereBlockReceived($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit wherePaymentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit whereTimeReceived($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit whereTxId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Deposit whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Deposit extends Model
{
/**
......
......@@ -2,20 +2,27 @@
namespace App\Http\Controllers;
use App\Deposit;
use App\Http\Resources\ProjectResource;
use App\Project;
use Illuminate\Http\Request;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
class FundingController extends Controller
{
/**
* Shows all projects
*
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\View\View
*/
public function index()
public function index(Request $request)
{
$projects = Project::all();
$projects = Project::paginate(15);
// If the request has header `Accept: */json`, return JSON
if ($request->wantsJson())
{
return ProjectResource::collection($projects);
}
return view('projects.index')
->with('projects', $projects);
}
......@@ -23,23 +30,20 @@ class FundingController extends Controller
/**
* Shows the project based on the payment id
*
* @param Request $request
* @param $paymentId
*
* @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
* @return ProjectResource|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function show($paymentId)
public function show(Request $request, $paymentId)
{
$project = Project::where('payment_id', $paymentId)->first();
if (!$project) {
abort(404);
$project = Project::where('payment_id', $paymentId)->firstOrFail();
if ($request->wantsJson())
{
return new ProjectResource($project);
}
$contributions = $project->deposits->count();
$amountReceived = $project->deposits->sum('amount');
$percentage = round($amountReceived / $project->target_amount * 100);
return view('projects.show')
->with('project', $project)
->with('contributions', $contributions)
->with('percentage', $percentage)
->with('amount_received', $amountReceived);
->with('project', $project);
}
}
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ProjectCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'data' => $this->collection,
'links' => [
'self' => 'link-value',
],
];
}
}
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class ProjectResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'payment_id' => $this->payment_id,
'status' => $this->status,
'amount_received' => $this->amount_received,
'target_amount' => $this->target_amount,
'percentage_funded' => $this->percentage_funded,
'qrcode' => ['base64' => base64_encode($this->qrcode)],
'contributions' => $this->contributions,
];
}
}
......@@ -3,7 +3,31 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use SimpleSoftwareIO\QrCode\Facades\QrCode;
/**
* App\ProjectResource
*
* @property int $id
* @property string $payment_id
* @property string $target_amount
* @property string $status
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Deposit[] $deposits
* @property-read mixed $amount_received
* @property-read string $uri
* @property-read int $percentage_funded
* @property-read int $contributions
* @property-read string $qrcode
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project wherePaymentId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereStatus($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereTargetAmount($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Project whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Project extends Model
{
/**
......@@ -17,4 +41,20 @@ class Project extends Model
public function getAmountReceivedAttribute() {
return $this->deposits->sum('amount');
}
public function getUriAttribute() {
return 'monero:'.env('WALLET_ADDRESS').'tx_payment_id='.$this->payment_id;
}
public function getPercentageFundedAttribute() {
return round($this->amount_received / $this->target_amount * 100);
}
public function getContributionsAttribute() {
return $this->deposits->count() ?? 0;
}
public function getQrcodeAttribute() {
return QrCode::format('png')->size(500)->generate($this->uri);
}
}
......@@ -6,6 +6,28 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
/**
* App\User
*
* @property int $id
* @property string $name
* @property string $email
* @property string|null $email_verified_at
* @property string $password
* @property string|null $remember_token
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection|\Illuminate\Notifications\DatabaseNotification[] $notifications
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereEmailVerifiedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User wherePassword($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereRememberToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\User whereUpdatedAt($value)
* @mixin \Eloquent
*/
class User extends Authenticatable
{
use Notifiable;
......
......@@ -6,9 +6,12 @@
"type": "project",
"require": {
"php": "^7.1.3",
"barryvdh/laravel-ide-helper": "^2.5",
"doctrine/dbal": "^2.8",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.7.*",
"laravel/tinker": "^1.0"
"laravel/tinker": "^1.0",
"simplesoftwareio/simple-qrcode": "2.0.*"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
......
This diff is collapsed.
......@@ -4,7 +4,6 @@ namespace Monero;
use App\Project;
use Carbon\Carbon;
use jsonRPCClient;
class Wallet
{
......
......@@ -12,7 +12,7 @@
<tr>
<td><a href='{!! url('/projects/'.$project->payment_id); !!}'>{{ $project->payment_id }}</a></td>
<td>{{$project->status}}</td>
<td>{{$project->amountReceived}} XMR</td>
<td>{{$project->amount_received}} XMR</td>
<td>{{$project->target_amount}} XMR</td>
</tr>
@endforeach
......
XMR {{$amount_received}} / XMR {{$project->target_amount}} Target
XMR {{$project->amount_received}} / XMR {{$project->target_amount}} Target
{{$contributions}} contributions made. {{$percentage}}%
\ No newline at end of file
{{$project->contributions}} contributions made. {{$project->percentage_funded}}%
<br>
<img src="data:image/png;base64,{!! base64_encode($project->qrcode) !!}">
\ No newline at end of file