Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 10 additions & 11 deletions app/Models/Account.php → app/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Models;

use App\Attendize\Utils;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\App\Utils;
use DB;
use Illuminate\Database\Eloquent\SoftDeletes;

class Account extends MyBaseModel
{
Expand All @@ -13,7 +13,7 @@ class Account extends MyBaseModel
/**
* The validation rules
*
* @var array $rules
* @var array
*/
protected $rules = [
'first_name' => ['required'],
Expand All @@ -24,21 +24,21 @@ class Account extends MyBaseModel
/**
* The attributes that should be mutated to dates.
*
* @var array $dates
* @var array
*/
public $dates = ['deleted_at'];

/**
* The validation error messages.
*
* @var array $messages
* @var array
*/
protected $messages = [];

/**
* The attributes that are mass assignable.
*
* @var array $fillable
* @var array
*/
protected $fillable = [
'first_name',
Expand All @@ -65,7 +65,7 @@ class Account extends MyBaseModel
'stripe_refresh_token',
'stripe_secret_key',
'stripe_publishable_key',
'stripe_data_raw'
'stripe_data_raw',
];

/**
Expand Down Expand Up @@ -113,7 +113,8 @@ public function account_payment_gateways()
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function gateways() {
public function gateways()
{
return $this->account_payment_gateways();
}

Expand Down Expand Up @@ -149,15 +150,13 @@ public function getGatewayConfigVal($gateway_id, $key)
{
$gateway = $this->getGateway($gateway_id);

if($gateway && is_array($gateway->config)) {
if ($gateway && is_array($gateway->config)) {
return isset($gateway->config[$key]) ? $gateway->config[$key] : false;
}

return false;
}



/**
* Get the stripe api key.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

use Illuminate\Database\Eloquent\SoftDeletes;


class AccountPaymentGateway extends MyBaseModel
{

use softDeletes;

/**
Expand All @@ -17,15 +15,16 @@ class AccountPaymentGateway extends MyBaseModel
*/
protected $fillable = [
'payment_gateway_id',
'config'
'config',
];

/**
* Account associated with gateway
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function account() {
public function account()
{
return $this->belongsTo(\App\Models\Account::class);
}

Expand All @@ -44,11 +43,13 @@ public function payment_gateway()
*
* @return mixed
*/
public function getConfigAttribute($value) {
public function getConfigAttribute($value)
{
return json_decode($value, true);
}

public function setConfigAttribute($value) {
public function setConfigAttribute($value)
{
$this->attributes['config'] = json_encode($value);
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions app/Models/Affiliate.php → app/Affiliate.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class Affiliate extends \Illuminate\Database\Eloquent\Model
/**
* The attributes that are mass assignable.
*
* @var array $fillable
* @var array
*/
protected $fillable = [
'name',
'visits',
'tickets_sold',
'event_id',
'account_id',
'sales_volume'
'sales_volume',
];

/**
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions app/Attendize/PaymentUtils.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
<?php


namespace App\Attendize;

/**
* Class Payment
*
* Payment functions and utilities
*
* @package App\Attendize
*/
class PaymentUtils
{
Expand All @@ -21,7 +18,7 @@ class PaymentUtils
*/
public static function requiresPayment($amount)
{
return !self::isFree($amount);
return ! self::isFree($amount);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions app/Attendize/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static function isAttendizeDev()

public static function isDownForMaintenance()
{
return file_exists(storage_path() . '/framework/down');
return file_exists(storage_path().'/framework/down');
}

/**
Expand All @@ -87,16 +87,14 @@ public static function isDownForMaintenance()
*/
public static function userOwns($object)
{
if (!Auth::check()) {
if (! Auth::check()) {
return false;
}

try {

if (Auth::user()->account_id === $object->account_id) {
return true;
}

} catch (Exception $e) {
return false;
}
Expand Down Expand Up @@ -166,6 +164,7 @@ public static function parse_version($string): string
if (preg_match('/(\d+\.?\d+\.?\d+)/', $string, $matches) === 1) {
return $matches[0];
}

return '';
}
}
5 changes: 2 additions & 3 deletions app/Cancellation/OrderCancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

use App\Models\Attendee;
use App\Models\EventStats;
use Superbalist\Money\Money;
use Services\PaymentGateway\Factory;
use Log;
use Services\PaymentGateway\Factory;
use Superbalist\Money\Money;

class OrderCancel extends OrderRefundAbstract
{

public function __construct($order, $attendees)
{
$this->order = $order;
Expand Down
17 changes: 11 additions & 6 deletions app/Cancellation/OrderCancellation.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php namespace App\Cancellation;
<?php

namespace App\Cancellation;

use App\Models\Attendee;
use App\Models\Order;
use Superbalist\Money\Money;

class OrderCancellation
{
/** @var Order $order */
/** @var Order */
private $order;
/** @var array $attendees */

/** @var array */
private $attendees;
/** @var OrderRefund $orderRefund */

/** @var OrderRefund */
private $orderRefund;

/**
Expand All @@ -32,7 +36,7 @@ public function __construct(Order $order, $attendees)
* @param $attendees
* @return OrderCancellation
*/
public static function make(Order $order, $attendees): OrderCancellation
public static function make(Order $order, $attendees): self
{
return new static($order, $attendees);
}
Expand All @@ -51,7 +55,7 @@ public function cancel(): void
$orderCancel->cancel();
}
// If order can do a refund then refund first
if ($this->order->canRefund() && !$orderAwaitingPayment) {
if ($this->order->canRefund() && ! $orderAwaitingPayment) {
$orderRefund = OrderRefund::make($this->order, $this->attendees);
$orderRefund->refund();
$this->orderRefund = $orderRefund;
Expand All @@ -74,6 +78,7 @@ public function getRefundAmount()
if ($this->orderRefund === null) {
return new Money('0');
}

return $this->orderRefund->getRefundAmount();
}
}
13 changes: 7 additions & 6 deletions app/Cancellation/OrderRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use App\Models\Attendee;
use App\Models\EventStats;
use Superbalist\Money\Money;
use Services\PaymentGateway\Factory;
use Log;
use Services\PaymentGateway\Factory;
use Superbalist\Money\Money;

class OrderRefund extends OrderRefundAbstract
{
Expand All @@ -21,7 +21,7 @@ public function __construct($order, $attendees)
$paymentGateway = $order->payment_gateway;
$accountPaymentGateway = $order->account->getGateway($paymentGateway->id);
$config = array_merge($accountPaymentGateway->config, [
'testMode' => config('attendize.enable_test_payments')
'testMode' => config('attendize.enable_test_payments'),
]);
$this->gateway = (new Factory())->create($paymentGateway->name, $config);
}
Expand All @@ -37,7 +37,7 @@ public function refund()
$response = $this->sendRefundRequest();
} catch (\Exception $e) {
Log::error($e->getMessage());
throw new OrderRefundException(trans("Controllers.refund_exception"));
throw new OrderRefundException(trans('Controllers.refund_exception'));
}
if ($response['successful']) { // Successful is a Boolean
// New refunded amount needs to be saved on the order
Expand Down Expand Up @@ -100,14 +100,15 @@ private function sendRefundRequest()
'amount' => $this->refundAmount->toFloat(),
'refundApplicationFee' => floatval($this->order->booking_fee) > 0 ? true : false,
]);

return $response;
}

private function checkValidRefundState()
{
$errorMessage = false;
if (!$this->order->transaction_id) {
$errorMessage = trans("Controllers.order_cant_be_refunded");
if (! $this->order->transaction_id) {
$errorMessage = trans('Controllers.order_cant_be_refunded');
}
if ($this->order->is_refunded) {
$errorMessage = trans('Controllers.order_already_refunded');
Expand Down
30 changes: 20 additions & 10 deletions app/Cancellation/OrderRefundAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,44 @@
namespace App\Cancellation;

use App\Models\Attendee;
use Superbalist\Money\Money;
use Log;
use Superbalist\Money\Money;

abstract class OrderRefundAbstract
abstract class OrderRefundAbstract
{
protected $order;

protected $attendees;

protected $currency;

protected $organiserAmount;

protected $refundedAmount;

protected $maximumRefundableAmount;

protected $organiserTaxRate;

protected $refundAmount;

protected $gateway;

protected function setRefundAmounts()
{
$this->currency = $this->order->getEventCurrency();
// Get the full order amount, tax and booking fees included
$this->organiserAmount = new Money($this->order->organiser_amount, $this->currency);
Log::debug(sprintf("Total Order Value: %s", $this->organiserAmount->display()));
Log::debug(sprintf('Total Order Value: %s', $this->organiserAmount->display()));
$this->refundedAmount = new Money($this->order->amount_refunded, $this->currency);
Log::debug(sprintf("Already refunded amount: %s", $this->refundedAmount->display()));
Log::debug(sprintf('Already refunded amount: %s', $this->refundedAmount->display()));
$this->maximumRefundableAmount = $this->organiserAmount->subtract($this->refundedAmount);
Log::debug(sprintf("Maxmimum refundable amount: %s", $this->maximumRefundableAmount->display()));
Log::debug(sprintf('Maxmimum refundable amount: %s', $this->maximumRefundableAmount->display()));
// We need the organiser tax value to calculate what the attendee would've paid
$event = $this->order->event;
$organiserTaxAmount = new Money($event->organiser->tax_value);
$this->organiserTaxRate = $organiserTaxAmount->divide(100)->__toString();
Log::debug(sprintf("Organiser Tax Rate: %s", $organiserTaxAmount->format() . '%'));
Log::debug(sprintf('Organiser Tax Rate: %s', $organiserTaxAmount->format().'%'));
// Sets refund total based on attendees, their ticket prices and the organiser tax rate
$this->setRefundTotal();
}
Expand Down Expand Up @@ -60,14 +68,16 @@ protected function setRefundTotal()
$ticketPrice = new Money($attendee->ticket->price, $currency);
$organiserFee = new Money($attendee->event->getOrganiserFee($ticketPrice), $currency);
$subTotal = $ticketPrice->add($organiserFee);
Log::debug(sprintf("Ticket Price: %s", $ticketPrice->display()));
Log::debug(sprintf("Ticket Organiser Fee: %s", $organiserFee->display()));
Log::debug(sprintf("Ticket Tax: %s", $subTotal->multiply($organiserTaxRate)->display()));
Log::debug(sprintf('Ticket Price: %s', $ticketPrice->display()));
Log::debug(sprintf('Ticket Organiser Fee: %s', $organiserFee->display()));
Log::debug(sprintf('Ticket Tax: %s', $subTotal->multiply($organiserTaxRate)->display()));

return $subTotal->add($subTotal->multiply($organiserTaxRate));
})->reduce(function ($carry, $singleTicketWithTax) use ($currency) {
$refundTotal = (new Money($carry, $currency));

return $refundTotal->add($singleTicketWithTax)->format();
}), $currency);
Log::debug(sprintf("Requested Refund should include Tax: %s", $this->refundAmount->display()));
Log::debug(sprintf('Requested Refund should include Tax: %s', $this->refundAmount->display()));
}
}
Loading