Allow Refunds of individual tickets

Fixed use statement

Fixed a spelling mistake
This commit is contained in:
JapSeyz 2016-06-14 14:09:55 +02:00
parent bc6232c520
commit 2daa2e1b99
5 changed files with 121 additions and 0 deletions

View File

@ -17,6 +17,7 @@ use Auth;
use DB;
use Excel;
use Mail;
use Omnipay\Omnipay;
use Response;
use Validator;
use Config;
@ -716,6 +717,62 @@ class EventAttendeesController extends MyBaseController
});
}
if($request->get('refund_attendee') == '1') {
try {
// This does not account for an increased/decreased ticket price
// after the original purchase.
$refund_amount = $attendee->ticket->price;
$data['refund_amount'] = $refund_amount;
$gateway = Omnipay::create($attendee->order->payment_gateway->name);
// Only works for stripe
$gateway->initialize($attendee->order->account->getGateway($attendee->order->payment_gateway->id)->config);
$request = $gateway->refund([
'transactionReference' => $attendee->order->transaction_id,
'amount' => $refund_amount,
'refundApplicationFee' => false,
]);
$response = $request->send();
if ($response->isSuccessful()) {
// Update the attendee and their order
$attendee->is_refunded = 1;
$attendee->order->is_partially_refunded = 1;
$attendee->order->amount_refunded += $refund_amount;
$attendee->order->save();
$attendee->save();
// Let the user know that they have received a refund.
Mail::send('Emails.notifyRefundedAttendee', $data, function ($message) use ($attendee) {
$message->to($attendee->email, $attendee->full_name)
->from(config('attendize.outgoing_email_noreply'), $attendee->event->organiser->name)
->replyTo($attendee->event->organiser->email, $attendee->event->organiser->name)
->subject('You have received a refund from ' . $attendee->event->organiser->name);
});
} else {
$error_message = $response->getMessage();
}
} catch (\Exception $e) {
\Log::error($e);
$error_message = 'There has been a problem processing your refund. Please check your information and try again.';
}
}
if ($error_message) {
return response()->json([
'status' => 'error',
'message' => $error_message,
]);
}
session()->flash('message', 'Successfully Cancelled Attenddee');
return response()->json([

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddIsRefundedColumnToAttendees extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('attendees', function($t)
{
$t->boolean('is_refunded')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('attendees', function($t)
{
$t->dropColumn('is_refunded');
});
}
}

View File

@ -0,0 +1,18 @@
@extends('Emails.Layouts.Master')
@section('message_content')
<p>Hi there,</p>
<p>
You have received a refund on behalf of your cancelled ticket for <b>{{{$attendee->event->title}}}</b>.
<b>{{{ $refund_amount }}} has been refunded to the original payee, you should see the payment in a few days.</b>
</p>
<p>
You can contact <b>{{{ $attendee->event->organiser->name }}}</b> directly at <a href='mailto:{{{$attendee->event->organiser->email}}}'>{{{$attendee->event->organiser->email}}}</a> or by replying to this email should you require any more information.
</p>
@stop
@section('footer')
@stop

View File

@ -24,6 +24,14 @@
<label for="notify_attendee">&nbsp;&nbsp;Notify <b>{{$attendee->full_name}}</b> their ticket has been cancelled.</label>
</div>
</div>
@if(config('attendize.default_payment_gateway') == config('attendize.payment_gateway_stripe'))
<div class="form-group">
<div class="checkbox custom-checkbox">
<input type="checkbox" name="refund_attendee" id="refund_attendee" value="1">
<label for="refund_attendee">&nbsp;&nbsp;Refund <b>{{$attendee->full_name}}</b> for their ticket.</label>
</div>
</div>
@endif
</div> <!-- /end modal body-->
<div class="modal-footer">
{!! Form::hidden('attendee_id', $attendee->id) !!}

View File

@ -157,6 +157,11 @@
Cancelled
</span>
@endif
@if($attendee->is_refunded)
<span class="label label-danger">
Refunded
</span>
@endif
{{$attendee->first_name}}
{{$attendee->last_name}}
</td>