- Removed Stripe libs from composer requirements

- Checkout and refunds now use Omnipay
This commit is contained in:
Dave 2016-03-07 17:18:55 +00:00
parent b4efd67257
commit ce50408b7e
3 changed files with 87 additions and 70 deletions

View File

@ -23,13 +23,12 @@ use Redirect;
use Request;
use Response;
use Session;
use Stripe;
use Stripe_Charge;
use Stripe_Customer;
use Validator;
use View;
use Omnipay;
class EventCheckoutController extends Controller
{
protected $is_embedded;
@ -474,4 +473,12 @@ class EventCheckoutController extends Controller
return View::make('Public.ViewEvent.Partials.PDFTicket', $data);
}
public function handleStripePayment() {
}
public function handlePaypalPayment() {
}
}

View File

@ -12,10 +12,9 @@ use Input;
use Log;
use Mail;
use Response;
use Stripe;
use Stripe_Charge;
use Validator;
use View;
use Omnipay;
class EventOrdersController extends MyBaseController
{
@ -41,10 +40,10 @@ class EventOrdersController extends MyBaseController
$orders = $event->orders()
->where(function ($query) use ($searchQuery) {
$query->where('order_reference', 'like', $searchQuery.'%')
->orWhere('first_name', 'like', $searchQuery.'%')
->orWhere('email', 'like', $searchQuery.'%')
->orWhere('last_name', 'like', $searchQuery.'%');
$query->where('order_reference', 'like', $searchQuery . '%')
->orWhere('first_name', 'like', $searchQuery . '%')
->orWhere('email', 'like', $searchQuery . '%')
->orWhere('last_name', 'like', $searchQuery . '%');
})
->orderBy($sort_by, $sort_order)
->paginate();
@ -127,33 +126,53 @@ class EventOrdersController extends MyBaseController
} elseif ($order->organiser_amount == 0) {
$error_message = 'Nothing to refund';
} elseif ($refund_amount > ($order->organiser_amount - $order->amount_refunded)) {
$error_message = 'The maximum amount you can refund is '.(money($order->organiser_amount - $order->amount_refunded, $order->event->currency->code));
$error_message = 'The maximum amount you can refund is ' . (money($order->organiser_amount - $order->amount_refunded, $order->event->currency->code));
}
if (!$error_message) {
# @todo - remove the code repetition here
try {
Stripe::setApiKey($order->account->stripe_api_key);
$charge = Stripe_Charge::retrieve($order->transaction_id);
$gateway = Omnipay::gateway('stripe');
$gateway->initialize([
'apiKey' => $order->account->stripe_api_key
]);
if ($refund_type === 'full') { /* Full refund */
$refund_amount = $order->organiser_amount - $order->amount_refunded;
$refund = $charge->refund([
'refund_application_fee' => floatval($order->booking_fee) > 0 ? true : false,
$request = $gateway->refund([
'transactionReference' => $order->transaction_id,
'amount' => $refund_amount,
'refundApplicationFee' => floatval($order->booking_fee) > 0 ? true : false
]);
$response = $request->send();
if ($response->isSuccessful()) {
/* Update the event sales volume*/
$order->event->decrement('sales_volume', $refund_amount);
$order->is_refunded = 1;
$order->amount_refunded = $order->organiser_amount;
$order->order_status_id = config('attendize.order_refunded');
} else {
$error_message = $response->getMessage();
}
} else { /* Partial refund */
$refund = $charge->refund([
'amount' => $refund_amount * 100,
'refund_application_fee' => floatval($order->booking_fee) > 0 ? true : false,
$refund = $gateway->refund([
'transactionReference' => $order->transaction_id,
'amount' => floatval($refund_amount),
'refundApplicationFee' => floatval($order->booking_fee) > 0 ? true : false,
]);
$response = $refund->send();
if ($response->isSuccessful()) {
/* Update the event sales volume*/
$order->event->decrement('sales_volume', $refund_amount);
@ -165,24 +184,16 @@ class EventOrdersController extends MyBaseController
}
$order->is_partially_refunded = 1;
} else {
$error_message = $response->getMessage();
}
$order->amount_refunded = round($refund->amount_refunded / 100, 2);
}
$order->amount_refunded = round(($order->amount_refunded + $refund_amount), 2);
$order->save();
} catch (\Stripe_InvalidRequestError $e) {
} catch (\Exeption $e) {
Log::error($e);
$error_message = 'There has been a problem processing your refund. Please check your information and try again.';
} catch (\Stripe_AuthenticationError $e) {
Log::error($e);
$error_message = 'There has been a problem processing your refund. Please try again.';
} catch (\Stripe_ApiConnectionError $e) {
Log::error($e);
$error_message = 'There has been a problem processing your refund. Please try again.';
} catch (\Stripe_Error $e) {
Log::error($e);
$error_message = 'There has been a problem processing your refund. Please try again.';
} catch (Exception $e) {
Log::error($e);
$error_message = 'There has been a problem processing your refund. Please try again.';
}
}
@ -206,7 +217,7 @@ class EventOrdersController extends MyBaseController
}
\Session::flash('message',
(!$refund_amount && !$attendees) ? 'Nothing To Do' : 'Successfully '.($refund_order ? ' Refunded Order' : ' ').($attendees && $refund_order ? ' & ' : '').($attendees ? 'Cancelled Attendee(s)' : ''));
(!$refund_amount && !$attendees) ? 'Nothing To Do' : 'Successfully ' . ($refund_order ? ' Refunded Order' : ' ') . ($attendees && $refund_order ? ' & ' : '') . ($attendees ? 'Cancelled Attendee(s)' : ''));
return Response::json([
'status' => 'success',
@ -222,9 +233,9 @@ class EventOrdersController extends MyBaseController
{
$event = Event::scope()->findOrFail($event_id);
Excel::create('orders-as-of-'.date('d-m-Y-g.i.a'), function ($excel) use ($event) {
Excel::create('orders-as-of-' . date('d-m-Y-g.i.a'), function ($excel) use ($event) {
$excel->setTitle('Orders For Event: '.$event->title);
$excel->setTitle('Orders For Event: ' . $event->title);
// Chain the setters
$excel->setCreator(config('attendize.app_name'))
@ -315,7 +326,7 @@ class EventOrdersController extends MyBaseController
$message->to($order->event->organiser->email)
->from(config('attendize.outgoing_email_noreply'), $order->event->organiser->name)
->replyTo($order->event->organiser->email, $order->event->organiser->name)
->subject($data['subject'].' [Organiser copy]');
->subject($data['subject'] . ' [Organiser copy]');
});
}

View File

@ -9,7 +9,6 @@
"laravel/framework": "5.1.20",
"illuminate/html": "~5.0",
"milon/barcode": "dev-master",
"stripe/stripe-php": "1.*",
"iron-io/iron_mq": "2.*",
"intervention/image": "dev-master",
"nitmedia/wkhtml2pdf": "dev-master",