Class: Workarea::Storefront::PaypalController
- Inherits:
-
Storefront::ApplicationController
- Object
- Storefront::ApplicationController
- Workarea::Storefront::PaypalController
- Includes:
- Storefront::CurrentCheckout
- Defined in:
- app/controllers/workarea/storefront/paypal_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/workarea/storefront/paypal_controller.rb', line 8 def create unless current_order.checking_out? if logged_in? current_checkout.start_as(current_user) else current_checkout.start_as(:guest) end end self.current_order = current_checkout.order check_inventory || (return) if current_checkout.payment.paypal? current_checkout.payment.paypal.update!(approved: false) render json: { id: current_checkout.payment.paypal_id } else response = Paypal::CreateOrder.new(current_checkout).perform render json: { id: response.id } end rescue Paypal::Gateway::RequestError => e Rails.logger.error(e) flash[:error] = t('workarea.storefront.paypal.errors.request_failed') head :internal_server_error end |
#event ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'app/controllers/workarea/storefront/paypal_controller.rb', line 48 def event Paypal::HandleWebhookEvent.perform_async( params[:event_type], params[:resource].to_unsafe_h ) head :ok end |
#update ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/workarea/storefront/paypal_controller.rb', line 34 def update check_inventory || (return) Paypal::ApproveOrder.new(current_checkout, params[:id]).perform complete = current_checkout.complete? flash[:error] = t('workarea.storefront.paypal.errors.order_incomplete') unless complete render json: { success: complete, redirect_url: checkout_payment_path } end |