Class: Workarea::Storefront::AfterpayController
- Inherits:
-
Storefront::ApplicationController
- Object
- Storefront::ApplicationController
- Workarea::Storefront::AfterpayController
- Includes:
- Storefront::CurrentCheckout
- Defined in:
- app/controllers/workarea/storefront/afterpay_controller.rb
Instance Method Summary collapse
Instance Method Details
#cancel ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/workarea/storefront/afterpay_controller.rb', line 74 def cancel self.current_order = Order.where(afterpay_token: params[:orderToken]).first current_order.user_id = current_user.try(:id) payment = current_checkout.payment payment.clear_afterpay flash[:success] = t('workarea.storefront.afterpay.cancel_message') redirect_to checkout_payment_path end |
#complete ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/workarea/storefront/afterpay_controller.rb', line 37 def complete self.current_order = Order.where(afterpay_token: params[:orderToken]).first payment = current_checkout.payment if params[:status] != "SUCCESS" flash[:error] = t('workarea.storefront.afterpay.payment_error') payment.clear_afterpay redirect_to(checkout_payment_path) && (return) end current_order.user_id = current_user.try(:id) check_inventory || (return) shipping = current_shipping Pricing.perform(current_order, shipping) payment.adjust_tender_amounts(current_order.total_price) ap_order_details = gateway.get_order(params[:orderToken]) tender = payment.afterpay unless (ap_order_details.body["amount"]["amount"].to_m == tender.amount.to_m && current_checkout.complete?) flash[:error] = t('workarea.storefront.afterpay.payment_error') payment.clear_afterpay redirect_to(checkout_payment_path) && (return) end payment.afterpay.update_attributes!(ready_to_capture: true) # place the order. if current_checkout.place_order completed_place_order else incomplete_place_order end end |
#start ⇒ Object
7 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 33 34 35 |
# File 'app/controllers/workarea/storefront/afterpay_controller.rb', line 7 def start self.current_order = current_checkout.order Pricing.perform(current_order, current_shipping) check_inventory || (return) # get a token for the current order order_payload = Afterpay::OrderBuilder.new(current_order).build response = gateway.create_order(order_payload) if !response.success? flash[:error] = t('workarea.storefront.afterpay.payment_error') redirect_to(checkout_payment_path) && (return) end token = response.body["token"] payment = Workarea::Payment.find(current_order.id) payment.clear_credit_card payment.set_afterpay(token: token) # set the token on the order so we can more easily look up the order # when returning from afterpay current_order.update_attributes!(afterpay_token: token) redirect_to checkout_payment_path end |