Class: Spree::Api::V2::Storefront::Stripe::PaymentIntentsController
- Inherits:
-
BaseController
- Object
- BaseController
- BaseController
- Spree::Api::V2::Storefront::Stripe::PaymentIntentsController
- Includes:
- OrderConcern
- Defined in:
- app/controllers/spree/api/v2/storefront/stripe/payment_intents_controller.rb
Instance Method Summary collapse
- #confirm ⇒ Object
-
#create ⇒ Object
POST /api/v2/storefront/stripe/payment_intents.
-
#show ⇒ Object
GET /api/v2/storefront/stripe/payment_intents.
-
#update ⇒ Object
PATCH /api/v2/storefront/stripe/payment_intents/:id.
Methods inherited from BaseController
#require_stripe_gateway, #stripe_gateway
Instance Method Details
#confirm ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/spree/api/v2/storefront/stripe/payment_intents_controller.rb', line 47 def confirm @payment_intent = SpreeStripe::PaymentIntent.find(params[:id]) stripe_payment_intent = @payment_intent.stripe_payment_intent order = @payment_intent.order if order.canceled? render_error_payload(Spree.t('order_canceled')) elsif order.completed? render_error_payload(Spree.t('order_already_completed')) elsif order != spree_current_order raise ActiveRecord::RecordNotFound elsif @payment_intent.accepted? :update, spree_current_order, order_token SpreeStripe::CompleteOrder.new(payment_intent: @payment_intent).call render_serialized_payload { serialize_resource(@payment_intent) } else render_error_payload(Spree.t("stripe.payment_intent_errors.#{stripe_payment_intent.status}")) end rescue Spree::Core::GatewayError => e render_error_payload(e.) end |
#create ⇒ Object
POST /api/v2/storefront/stripe/payment_intents
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/spree/api/v2/storefront/stripe/payment_intents_controller.rb', line 11 def create :update, spree_current_order, order_token stripe_payment_method_id = permitted_attributes[:stripe_payment_method_id].presence stripe_payment_method_id ||= spree_current_order.valid_credit_cards.where(payment_method: stripe_gateway).first&.gateway_payment_profile_id @payment_intent = SpreeStripe::CreatePaymentIntent.new.call( spree_current_order, stripe_gateway, stripe_payment_method_id: stripe_payment_method_id, off_session: permitted_attributes[:off_session].to_b || false ) render_serialized_payload { serialize_resource(@payment_intent) } end |
#show ⇒ Object
GET /api/v2/storefront/stripe/payment_intents
28 29 30 31 32 33 34 |
# File 'app/controllers/spree/api/v2/storefront/stripe/payment_intents_controller.rb', line 28 def show :show, spree_current_order, order_token @payment_intent = spree_current_order.payment_intents.find(params[:id]) render_serialized_payload { serialize_resource(@payment_intent) } end |
#update ⇒ Object
PATCH /api/v2/storefront/stripe/payment_intents/:id
37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/spree/api/v2/storefront/stripe/payment_intents_controller.rb', line 37 def update :update, spree_current_order, order_token @payment_intent = spree_current_order.payment_intents.find(params[:id]) @payment_intent.attributes = permitted_attributes.except(:off_session) @payment_intent.save! render_serialized_payload { serialize_resource(@payment_intent) } end |