Class: SolidusBraintree::TransactionImport
- Inherits:
-
Object
- Object
- SolidusBraintree::TransactionImport
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/solidus_braintree/transaction_import.rb
Defined Under Namespace
Classes: InvalidImportError
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#transaction ⇒ Object
readonly
Returns the value of attribute transaction.
Instance Method Summary collapse
- #address ⇒ Object
- #import!(end_state, restart_checkout: false) ⇒ Object
-
#initialize(order, transaction) ⇒ TransactionImport
constructor
A new instance of TransactionImport.
- #source ⇒ Object
- #state_before_current?(state) ⇒ Boolean
Constructor Details
#initialize(order, transaction) ⇒ TransactionImport
Returns a new instance of TransactionImport.
24 25 26 27 |
# File 'app/models/solidus_braintree/transaction_import.rb', line 24 def initialize(order, transaction) @order = order @transaction = transaction end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
22 23 24 |
# File 'app/models/solidus_braintree/transaction_import.rb', line 22 def order @order end |
#transaction ⇒ Object (readonly)
Returns the value of attribute transaction.
22 23 24 |
# File 'app/models/solidus_braintree/transaction_import.rb', line 22 def transaction @transaction end |
Instance Method Details
#address ⇒ Object
68 69 70 71 72 |
# File 'app/models/solidus_braintree/transaction_import.rb', line 68 def address transaction.address && transaction.address.to_spree_address.tap do |address| address.phone = transaction.phone end end |
#import!(end_state, restart_checkout: false) ⇒ Object
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 |
# File 'app/models/solidus_braintree/transaction_import.rb', line 42 def import!(end_state, restart_checkout: false) if valid? order.email = user&.email || transaction.email if address order.shipping_address = order.billing_address = address # work around a bug in most solidus versions # about tax zone cachine between address changes order.instance_variable_set(:@tax_zone, nil) end payment = order.payments.new( source: source, payment_method: transaction.payment_method, amount: order.total ) order.save! order.restart_checkout_flow if restart_checkout advance_order(payment, end_state) else raise InvalidImportError, "Validation failed: #{errors..join(', ')}" end end |
#source ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/solidus_braintree/transaction_import.rb', line 29 def source SolidusBraintree::Source.new( nonce: transaction.nonce, payment_type: transaction.payment_type, payment_method: transaction.payment_method, paypal_funding_source: transaction.paypal_funding_source, device_data: transaction.device_data, user: user ) end |
#state_before_current?(state) ⇒ Boolean
74 75 76 77 |
# File 'app/models/solidus_braintree/transaction_import.rb', line 74 def state_before_current?(state) steps = order.checkout_steps steps.index(state) < (steps.index(order.state) || 0) end |