Class: SolidusAfterpay::ExpressCallbacksController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/solidus_afterpay/express_callbacks_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/solidus_afterpay/express_callbacks_controller.rb', line 5

def create
  authorize! :update, order, order_token

  unless SolidusAfterpay.update_order_attributes_service_class.call(
    order: order,
    afterpay_order_token: params[:token],
    payment_method: payment_method,
    request_env: request.headers.env
  )
    render(
      json: {
        error: I18n.t('solidus_afterpay.express_checkout.errors.unable_place_order'),
        errorCode: :internal_server_error
      },
      status: :internal_server_error
    )
    return
  end

  order.next!
  order.next!

  render json: { redirect_url: checkout_state_url(order.state) }, status: :ok
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/solidus_afterpay/express_callbacks_controller.rb', line 30

def update
  authorize! :update, order, order_token

  unless SolidusAfterpay::UpdateOrderAddressesService.call(order: order, address_params: params[:address])
    render json: { errorCode: :internal_server_error }, status: :internal_server_error
    return
  end

  order.next!
  # rubocop:disable Rails/SkipsModelValidations
  order.update_columns(email: nil) if order.email == SolidusAfterpay.configuration.dummy_email
  # rubocop:enable Rails/SkipsModelValidations

  render(
    json: {
      data: ::SolidusAfterpay.shipping_rate_builder_service_class.call(order: order)
    },
    status: :ok
  )
end