flowcommerce-solidus 0.1.11 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0101a0d46954d016cd3dac32a96708081c02d77
4
- data.tar.gz: 7311c515495ab8d4f004c641619e590c17c70a2d
3
+ metadata.gz: 7dc5caf05326a4cca8e512be102b74b784f48145
4
+ data.tar.gz: 42063f71e4af7586d9989627a78eeeb2cbd5e9ea
5
5
  SHA512:
6
- metadata.gz: e6a81592b490a7ea0b8efe4f1a9673eb1e3a606798d81c862a7cf8eb66595bf03be586504dc2986bce2cc184fe9aeaacb0016a3b02306d52be5ae72d67d34747
7
- data.tar.gz: 7c2ba0914d7c8d5e39435e9711b1daf15dec210eca659d244caae85fa0719b1a9968c61064107281f694d90a83373833b979120b27c51af94fb980e45fe8173d
6
+ metadata.gz: df425ba922fce210fcee1bad090af046bacb685be895a563d85fa67d98c5284c1669d97f41c257252c7a556989222095c78f866a7ab7ef84005ffb369105638c
7
+ data.tar.gz: 1e2efbe81e86efa045ae51db86d038b9a6abaf0b2388333e2fe70f463419736b00939329999077733052f9e15bbce587f005c06465c027a56fc17c99610f4a0d
data/.version CHANGED
@@ -1 +1 @@
1
- 0.1.11
1
+ 0.1.12
@@ -3,12 +3,13 @@
3
3
  Spree::Product.class_eval do
4
4
 
5
5
  # returns price tied to local experience from master variant
6
- def flow_local_price(flow_exp)
7
- variants.first.flow_local_price(flow_exp)
6
+ def flow_local_price flow_exp
7
+ variants.first.flow_local_price flow_exp
8
8
  end
9
9
 
10
- def flow_included?(flow_exp)
10
+ def flow_included? flow_exp
11
11
  return true unless flow_exp
12
+
12
13
  flow_data['%s.excluded' % flow_exp.key].to_i == 1 ? false : true
13
14
  end
14
15
 
@@ -2,13 +2,14 @@
2
2
  # for now all in same class
3
3
 
4
4
  require 'logger'
5
+ require 'awesome_print'
5
6
 
6
7
  module Flow
7
- extend self
8
+ mattr_accessor :organization
9
+ mattr_accessor :base_country
10
+ mattr_accessor :api_key
8
11
 
9
- def organization() ENV.fetch('FLOW_ORGANIZATION') end
10
- def base_country() ENV.fetch('FLOW_BASE_COUNTRY') end
11
- def api_key() ENV.fetch('FLOW_API_KEY') end
12
+ extend self
12
13
 
13
14
  # builds curl command and gets remote data
14
15
  def api action, path, params={}, body=nil
@@ -40,12 +41,9 @@ module Flow
40
41
 
41
42
  data = JSON.load `#{command}`
42
43
 
43
- if data.kind_of?(Hash) && data['code'] == 'generic_error'
44
- ap data
45
- data
46
- else
47
- data
48
- end
44
+ ap data if data.kind_of?(Hash) && data['code'] == 'generic_error'
45
+
46
+ data
49
47
  end
50
48
 
51
49
  def log_api_error
@@ -34,7 +34,7 @@ module Flow::Experience
34
34
  def get_from_flow
35
35
  return cached_experinces if cache_valid?
36
36
 
37
- experiences = FlowCommerce.instance.experiences.get(Flow.organization)
37
+ experiences = FlowCommerce.instance.experiences.get Flow.organization
38
38
  @cache = [experiences, Time.now]
39
39
  experiences
40
40
  end
@@ -102,10 +102,10 @@ class Flow::SimpleGateway
102
102
 
103
103
  # gets credit card token
104
104
  def cc_get_token
105
- cards = @order.credit_cards.select{ |cc| cc[:flow_data]['cc_token'] }
106
- raise StandarError.new('Credit card not found') unless cards.first
105
+ cards = @order.credit_cards.select{ |cc| cc.gateway_customer_profile_id }
106
+ raise StandarError.new('Credit card with token not found') unless cards.first
107
107
 
108
- cards.first.flow_data['cc_token'] || raise(StandardError.new 'Flow credit card token not found')
108
+ cards.first.gateway_customer_profile_id
109
109
  end
110
110
 
111
111
  # we want to return errors in standardized format
@@ -1,8 +1,6 @@
1
1
  # Flow.io (2017)
2
2
  # adapter for Solidus/Spree that talks to activemerchant_flow
3
3
 
4
- # load '/Users/dux/dev/org/flow.io/activemerchant_flow/lib/active_merchant/billing/gateways/flow.rb'
5
-
6
4
  module Spree
7
5
  class Gateway::Flow < Gateway
8
6
  def provider_class
@@ -19,7 +17,7 @@ module Spree
19
17
  end
20
18
 
21
19
  def payment_profiles_supported?
22
- false
20
+ true
23
21
  end
24
22
 
25
23
  def method_type
@@ -30,32 +28,22 @@ module Spree
30
28
  {}
31
29
  end
32
30
 
33
- # def create_profile(payment)
34
- # # binding.pry
35
- # # ActiveMerchant::Billing::FlowGateway.new(token: Flow.api_key, organization: Flow.organization)
36
-
37
- # case payment.order.state
38
- # when 'payment'
39
- # when 'confirm'
40
- # end
41
- # end
42
-
43
- def supports?(source)
31
+ def supports? source
44
32
  # flow supports credit cards
45
33
  source.class == Spree::CreditCard
46
34
  end
47
35
 
48
- def authorize(amount, payment_method, options={})
36
+ def authorize amount, payment_method, options={}
49
37
  order = load_order options
50
38
  order.cc_authorization
51
39
  end
52
40
 
53
- def capture(amount, payment_method, options={})
41
+ def capture amount, payment_method, options={}
54
42
  order = load_order options
55
43
  order.cc_capture
56
44
  end
57
45
 
58
- def purchase(amount, payment_method, options={})
46
+ def purchase amount, payment_method, options={}
59
47
  order = load_order options
60
48
  flow_auth = order.cc_authorization
61
49
 
@@ -66,18 +54,57 @@ module Spree
66
54
  end
67
55
  end
68
56
 
69
- def refund(money, authorization_key, options={})
57
+ def refund money, authorization_key, options={}
70
58
  order = load_order options
71
59
  order.cc_refund
72
60
  end
73
61
 
74
- def void(money, authorization_key, options={})
62
+ def void money, authorization_key, options={}
63
+ # binding.pry
64
+ end
65
+
66
+ def create_profile payment
75
67
  # binding.pry
68
+
69
+ # payment.order.state
70
+ @credit_card = payment.source
71
+
72
+ profile_ensure_payment_method_is_present!
73
+ create_flow_cc_profile!
76
74
  end
77
75
 
78
76
  private
79
77
 
80
- def load_order(options)
78
+ # hard inject Flow as payment method unless defined
79
+ def profile_ensure_payment_method_is_present!
80
+ return if @credit_card.payment_method_id
81
+
82
+ flow_payment = Spree::PaymentMethod.where(active: true, type:'Spree::Gateway::Flow').first
83
+ @credit_card.payment_method_id = flow_payment.id if flow_payment
84
+ end
85
+
86
+ # create payment profile with Flow and tokenize Credit Card
87
+ def create_flow_cc_profile!
88
+ return if @credit_card.gateway_customer_profile_id
89
+ return unless @credit_card.verification_value
90
+
91
+ # build credit card hash
92
+ data = {}
93
+ data[:number] = @credit_card.number
94
+ data[:name] = @credit_card.name
95
+ data[:cvv] = @credit_card.verification_value
96
+ data[:expiration_year] = @credit_card.year.to_i
97
+ data[:expiration_month] = @credit_card.month.to_i
98
+
99
+ # tokenize with Flow
100
+ # rescue Io::Flow::V0::HttpClient::ServerError
101
+ card_form = ::Io::Flow::V0::Models::CardForm.new(data)
102
+ result = FlowCommerce.instance.cards.post(::Flow.organization, card_form)
103
+
104
+ @credit_card.update_column :gateway_customer_profile_id, result.token
105
+ end
106
+
107
+ def load_order options
81
108
  order_number = options[:order_id].split('-').first
82
109
  spree_order = Spree::Order.find_by number: order_number
83
110
  ::Flow::SimpleGateway.new spree_order
@@ -20,6 +20,7 @@ task :flow do |t|
20
20
  puts ' -'
21
21
  print 'Task number: '
22
22
  task = $stdin.gets.to_i
23
+ exit if task == 0
23
24
  task = tasks[task - 1].to_s.split(/\s+/)[1]
24
25
 
25
26
  if task.present?
@@ -227,7 +228,6 @@ namespace :flow do
227
228
  desc 'Ensure we have DB prepared for flow'
228
229
  task :migrate => :environment do |t|
229
230
  migrate = []
230
- migrate.push [:spree_credit_cards, :flow_data, :jsonb, default: {}]
231
231
  migrate.push [:spree_products, :flow_data, :jsonb, default: {}]
232
232
  migrate.push [:spree_variants, :flow_data, :jsonb, default: {}]
233
233
  migrate.push [:spree_orders, :flow_data, :jsonb, default: {}]
@@ -244,5 +244,11 @@ namespace :flow do
244
244
  end
245
245
  end
246
246
  end
247
+
248
+ desc 'Pretty print flow_data of last updated product variant'
249
+ task :sync_check => :environment do |t|
250
+ data = Spree::Variant.order('updated_at desc').first.flow_data
251
+ puts JSON.pretty_generate(data).gsub(/"(\w+)":/) { '"%s":' % $1.yellow }
252
+ end
247
253
  end
248
254
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flowcommerce-solidus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flow.io (Dino Reic)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,7 +108,6 @@ files:
108
108
  - "./static/app/flow/SOLIDUS_FLOW.md"
109
109
  - "./static/app/flow/decorators/admin_decorators.rb"
110
110
  - "./static/app/flow/decorators/localized_coupon_code_decorator.rb"
111
- - "./static/app/flow/decorators/spree_credit_card_decorator.rb"
112
111
  - "./static/app/flow/decorators/spree_order_decorator.rb"
113
112
  - "./static/app/flow/decorators/spree_product_decorator.rb"
114
113
  - "./static/app/flow/decorators/spree_user_decorator.rb"
@@ -124,7 +123,6 @@ files:
124
123
  - "./static/app/flow/flow/webhook.rb"
125
124
  - "./static/app/flow/lib/flow_api_refresh.rb"
126
125
  - "./static/app/flow/lib/spree_flow_gateway.rb"
127
- - "./static/app/flow/lib/spree_stripe_gateway.rb"
128
126
  - "./static/app/views/spree/admin/payments/index.html.erb"
129
127
  - "./static/app/views/spree/admin/promotions/edit.html.erb"
130
128
  - "./static/app/views/spree/admin/shared/_order_summary.html.erb"
@@ -1,35 +0,0 @@
1
- # added flow specific methods to Spree::CreditCard
2
-
3
- Spree::CreditCard.class_eval do
4
-
5
- validate :flow_fetch_cc_token
6
-
7
- def flow_fetch_cc_token
8
- return false unless respond_to?(:flow_data) # Flow not installed
9
- return false if flow_data['cc_token']
10
- return false unless number
11
- return errors.add(:verification_value, 'CVV verification value is required') unless verification_value.present?
12
-
13
- # build cc hash
14
- data = {}
15
- data[:number] = number
16
- data[:name] = name
17
- data[:cvv] = verification_value
18
- data[:expiration_year] = year.to_i
19
- data[:expiration_month] = month.to_i
20
-
21
- card_form = ::Io::Flow::V0::Models::CardForm.new(data)
22
- result = FlowCommerce.instance.cards.post(Flow.organization, card_form)
23
-
24
- # cache the result
25
- flow_data['cc_token'] = result.token
26
-
27
- true
28
- rescue Io::Flow::V0::HttpClient::ServerError
29
- puts $!.message
30
- flow_error = $!.message.split(':', 2).first
31
- errors.add(:base, flow_error)
32
- end
33
-
34
- end
35
-
@@ -1,142 +0,0 @@
1
- # require 'flowcommerce-activemerchant'
2
-
3
- # module Spree
4
- # class Gateway::StripeGateway < Gateway
5
- # # https://dashboard.stripe.com/account/apikeys
6
-
7
- # preference :secret_key, :string
8
- # preference :publishable_key, :string
9
-
10
- # CARD_TYPE_MAPPING = {
11
- # 'American Express' => 'american_express',
12
- # 'Diners Club' => 'diners_club',
13
- # 'Visa' => 'visa'
14
- # }
15
-
16
- # def method_type
17
- # 'gateway'
18
- # end
19
-
20
- # def provider_class
21
- # ActiveMerchant::Billing::FlowGatewaya
22
- # end
23
-
24
- # def payment_profiles_supported?
25
- # true
26
- # end
27
-
28
- # def purchase(money, creditcard, gateway_options)
29
- # ap [:purchase, money, creditcard, gateway_options]
30
- # binding.pry
31
- # provider.purchase(*options_for_purchase_or_auth(money, creditcard, gateway_options))
32
- # end
33
-
34
- # def authorize(money, creditcard, gateway_options)
35
- # ap [:authorize, money, creditcard, gateway_options]
36
- # binding.pry
37
- # provider.authorize(*options_for_purchase_or_auth(money, creditcard, gateway_options))
38
- # end
39
-
40
- # def capture(money, response_code, gateway_options)
41
- # ap [:capture, money, response_code, gateway_options]
42
- # binding.pry
43
- # provider.capture(money, response_code, gateway_options)
44
- # end
45
-
46
- # def credit(money, creditcard, response_code, gateway_options)
47
- # ap [:credit, money, creditcard, response_code, gateway_options]
48
- # binding.pry
49
- # provider.refund(money, response_code, {})
50
- # end
51
-
52
- # def void(response_code, creditcard, gateway_options)
53
- # ap [:void, response_code, creditcard, gateway_options]
54
- # binding.pry
55
- # provider.void(response_code, {})
56
- # end
57
-
58
- # def cancel(response_code)
59
- # ap [:cancel, response_code]
60
- # provider.void(response_code, {})
61
- # end
62
-
63
- # def create_profile(payment)
64
- # ap [:create_profile, payment]
65
- # return unless payment.source.gateway_customer_profile_id.nil?
66
- # options = {
67
- # email: payment.order.email,
68
- # login: preferred_secret_key,
69
- # }.merge! address_for(payment)
70
-
71
- # source = update_source!(payment.source)
72
- # if source.number.blank? && source.gateway_payment_profile_id.present?
73
- # creditcard = source.gateway_payment_profile_id
74
- # else
75
- # creditcard = source
76
- # end
77
-
78
- # response = provider.store(creditcard, options)
79
- # if response.success?
80
- # payment.source.update_attributes!({
81
- # cc_type: payment.source.cc_type, # side-effect of update_source!
82
- # gateway_customer_profile_id: response.params['id'],
83
- # gateway_payment_profile_id: response.params['default_source'] || response.params['default_card']
84
- # })
85
-
86
- # else
87
- # payment.send(:gateway_error, response.message)
88
- # end
89
- # end
90
-
91
- # private
92
-
93
- # # In this gateway, what we call 'secret_key' is the 'login'
94
- # def options
95
- # options = super
96
- # options.merge(:login => preferred_secret_key)
97
- # end
98
-
99
- # def options_for_purchase_or_auth(money, creditcard, gateway_options)
100
- # options = {}
101
- # options[:description] = "Spree Order ID: #{gateway_options[:order_id]}"
102
- # options[:currency] = gateway_options[:currency]
103
-
104
- # if customer = creditcard.gateway_customer_profile_id
105
- # options[:customer] = customer
106
- # end
107
- # if token_or_card_id = creditcard.gateway_payment_profile_id
108
- # # The Stripe ActiveMerchant gateway supports passing the token directly as the creditcard parameter
109
- # # The Stripe ActiveMerchant gateway supports passing the customer_id and credit_card id
110
- # # https://github.com/Shopify/active_merchant/issues/770
111
- # creditcard = token_or_card_id
112
- # end
113
- # return money, creditcard, options
114
- # end
115
-
116
- # def address_for(payment)
117
- # {}.tap do |options|
118
- # if address = payment.order.bill_address
119
- # options.merge!(address: {
120
- # address1: address.address1,
121
- # address2: address.address2,
122
- # city: address.city,
123
- # zip: address.zipcode
124
- # })
125
-
126
- # if country = address.country
127
- # options[:address].merge!(country: country.name)
128
- # end
129
-
130
- # if state = address.state
131
- # options[:address].merge!(state: state.name)
132
- # end
133
- # end
134
- # end
135
- # end
136
-
137
- # def update_source!(source)
138
- # source.cc_type = CARD_TYPE_MAPPING[source.cc_type] if CARD_TYPE_MAPPING.include?(source.cc_type)
139
- # source
140
- # end
141
- # end
142
- # end