Class: SpreeStripe::PaymentIntentPresenter
- Inherits:
-
Object
- Object
- SpreeStripe::PaymentIntentPresenter
- Defined in:
- app/presenters/spree_stripe/payment_intent_presenter.rb
Constant Summary collapse
- SETUP_FUTURE_USAGE =
'off_session'
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(amount:, order:, customer: nil, payment_method_id: nil, off_session: false) ⇒ PaymentIntentPresenter
constructor
A new instance of PaymentIntentPresenter.
- #ship_address_payload ⇒ Object
Constructor Details
#initialize(amount:, order:, customer: nil, payment_method_id: nil, off_session: false) ⇒ PaymentIntentPresenter
Returns a new instance of PaymentIntentPresenter.
5 6 7 8 9 10 11 12 |
# File 'app/presenters/spree_stripe/payment_intent_presenter.rb', line 5 def initialize(amount:, order:, customer: nil, payment_method_id: nil, off_session: false) @amount = amount @order = order @customer = customer @ship_address = order.ship_address @payment_method_id = payment_method_id @off_session = off_session end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/presenters/spree_stripe/payment_intent_presenter.rb', line 14 def call payload = if payment_method_id.present? saved_payment_method_payload else new_payment_method_payload end payload = payload.deep_merge(basic_payload) return payload unless ship_address # we don't validate address1, but it's required by Stripe if ship_address.invalid? || ship_address.address1.blank? ship_address.errors.clear return payload end payload.merge(ship_address_payload) end |
#ship_address_payload ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/presenters/spree_stripe/payment_intent_presenter.rb', line 34 def ship_address_payload { shipping: { address: { city: ship_address.city, country: ship_address.country_iso, line1: ship_address.address1, line2: ship_address.address2, postal_code: ship_address.zipcode, state: ship_address.state_abbr }, name: ship_address.full_name } } end |