solidus_mollie 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.circleci/config.yml +41 -0
- data/.gem_release.yml +5 -0
- data/.github/stale.yml +17 -0
- data/.github_changelog_generator +2 -0
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +5 -0
- data/CHANGELOG.md +1 -0
- data/Gemfile +33 -0
- data/LICENSE +26 -0
- data/README.md +91 -0
- data/Rakefile +6 -0
- data/app/assets/javascripts/spree/backend/solidus_mollie.js +2 -0
- data/app/assets/javascripts/spree/frontend/solidus_mollie.js +2 -0
- data/app/assets/stylesheets/spree/backend/solidus_mollie.css +4 -0
- data/app/assets/stylesheets/spree/frontend/solidus_mollie.css +4 -0
- data/app/controllers/spree/api/mollie_controller.rb +31 -0
- data/app/controllers/spree/mollie_controller.rb +53 -0
- data/app/decorators/models/line_item_decorator.rb +21 -0
- data/app/decorators/models/payment_create_decorator.rb +22 -0
- data/app/models/spree/gateway/mollie_gateway.rb +155 -0
- data/app/models/spree/mollie/order_serializer.rb +169 -0
- data/app/models/spree/mollie/payment_state_updater.rb +62 -0
- data/app/models/spree/mollie_logger.rb +16 -0
- data/app/models/spree/mollie_payment_source.rb +57 -0
- data/app/models/spree/payment_method/mollie.rb +26 -0
- data/app/views/spree/admin/payments/source_forms/_mollie.html.erb +8 -0
- data/app/views/spree/admin/payments/source_views/_mollie.html.erb +27 -0
- data/app/views/spree/api/payments/show.json.jbuilder +5 -0
- data/app/views/spree/api/payments/source_views/_mollie.json.jbuilder +2 -0
- data/bin/console +17 -0
- data/bin/rails +7 -0
- data/bin/rails-engine +13 -0
- data/bin/rails-sandbox +16 -0
- data/bin/rake +7 -0
- data/bin/sandbox +86 -0
- data/bin/setup +8 -0
- data/config/locales/en.yml +7 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20201110194821_create_solidus_mollie_payment_source.rb +14 -0
- data/lib/generators/solidus_mollie/install/install_generator.rb +37 -0
- data/lib/generators/solidus_mollie/install/templates/initializer.rb +6 -0
- data/lib/solidus_mollie/configuration.rb +21 -0
- data/lib/solidus_mollie/engine.rb +26 -0
- data/lib/solidus_mollie/testing_support/factories.rb +4 -0
- data/lib/solidus_mollie/version.rb +5 -0
- data/lib/solidus_mollie.rb +5 -0
- data/solidus_mollie.code-workspace +8 -0
- data/solidus_mollie.gemspec +35 -0
- data/spec/solidus_mollie_gateway_spec.rb +5 -0
- data/spec/spec_helper.rb +31 -0
- metadata +161 -0
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Mollie
|
|
3
|
+
class OrderSerializer
|
|
4
|
+
# include ::Spree::Mollie::MoneyFormatter
|
|
5
|
+
|
|
6
|
+
def self.serialize(gateway_options)
|
|
7
|
+
new(gateway_options).serialize
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def initialize(gateway_options)
|
|
11
|
+
@gateway_options = gateway_options
|
|
12
|
+
@source = @gateway_options[:originator].source
|
|
13
|
+
@order = Spree::Order.find(@gateway_options[:originator].order_id)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def serialize
|
|
17
|
+
spree_routes = ::Spree::Core::Engine.routes.url_helpers
|
|
18
|
+
payment_identifier = @gateway_options[:order_id]
|
|
19
|
+
|
|
20
|
+
order_params = {
|
|
21
|
+
amount: price(@order.total),
|
|
22
|
+
metadata: {
|
|
23
|
+
order_number: @order.number,
|
|
24
|
+
payment_identifier: payment_identifier
|
|
25
|
+
},
|
|
26
|
+
orderNumber: payment_identifier,
|
|
27
|
+
redirectUrl: spree_routes.mollie_validate_payment_mollie_url(
|
|
28
|
+
order_number: payment_identifier,
|
|
29
|
+
host: Spree::Store.default.url
|
|
30
|
+
),
|
|
31
|
+
webhookUrl: spree_routes.mollie_update_payment_status_mollie_url(
|
|
32
|
+
payment_identifier: payment_identifier,
|
|
33
|
+
host: Spree::Store.default.url
|
|
34
|
+
),
|
|
35
|
+
locale: 'en_US',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if @gateway_options[:billing_address].present?
|
|
39
|
+
order_params.merge! ({
|
|
40
|
+
billingAddress: serialize_address(@gateway_options[:billing_address])
|
|
41
|
+
})
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
if @gateway_options[:shipping_address].present?
|
|
45
|
+
order_params.merge! ({
|
|
46
|
+
shippingAddress: serialize_address(@gateway_options[:shipping_address])
|
|
47
|
+
})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
order_params.merge! ({
|
|
51
|
+
lines: prepare_line_items
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
# User has already selected a payment method
|
|
55
|
+
if @source.try(:payment_method_name).present?
|
|
56
|
+
order_params.merge! ({
|
|
57
|
+
method: @source.payment_method_name
|
|
58
|
+
})
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# User has selected an issuer (available for iDEAL payments)
|
|
62
|
+
if @source.try(:issuer).present?
|
|
63
|
+
order_params.merge! ({
|
|
64
|
+
payment: {
|
|
65
|
+
issuer: @source.issuer
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
order_params
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
def prepare_line_items
|
|
76
|
+
order_lines = []
|
|
77
|
+
@order.line_items.each do |line|
|
|
78
|
+
order_lines << serialize_line_item(line)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
order_lines << serialize_discounts if @order.adjustments.any?
|
|
82
|
+
|
|
83
|
+
order_lines << serialize_shipping_costs
|
|
84
|
+
|
|
85
|
+
# if @order.shipping_discount.positive?
|
|
86
|
+
# order_lines << serialize_shipping_discounts
|
|
87
|
+
# end
|
|
88
|
+
|
|
89
|
+
order_lines
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def serialize_address(address)
|
|
93
|
+
{
|
|
94
|
+
streetAndNumber: [address[:address1], address[:address2]].join(" "),
|
|
95
|
+
city: address[:city],
|
|
96
|
+
postalCode: address[:zip],
|
|
97
|
+
country: address[:country],
|
|
98
|
+
region: address[:state],
|
|
99
|
+
givenName: address[:name],
|
|
100
|
+
familyName: address[:name],
|
|
101
|
+
email: @order.email
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def serialize_shipping_costs
|
|
106
|
+
{
|
|
107
|
+
type: 'shipping_fee',
|
|
108
|
+
name: 'Shipping',
|
|
109
|
+
quantity: 1, # Considering shipment as one line item per order and not per item or package
|
|
110
|
+
unitPrice: price(@order.shipments.map(&:cost).inject(0, &:+).to_f + @order.shipments.map(&:adjustment_total).inject(0, &:+).to_f),
|
|
111
|
+
totalAmount: price(@order.shipments.map(&:cost).inject(0, &:+).to_f + @order.shipments.map(&:adjustment_total).inject(0, &:+).to_f),
|
|
112
|
+
vatAmount: price(format_money(@order.shipments.map(&:included_tax_total).inject(0, &:+).to_f)), #TODO: Extract to its own method
|
|
113
|
+
vatRate: @order.shipments.first.tax_category.tax_rates.first.amount.to_f * 100 #TODO: Mollie allows only one tax rate, extract to method
|
|
114
|
+
}
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def serialize_discounts
|
|
118
|
+
binding.pry #TODO: Not implemented
|
|
119
|
+
{
|
|
120
|
+
type: 'discount',
|
|
121
|
+
name: 'Order discount',
|
|
122
|
+
quantity: 1,
|
|
123
|
+
unitPrice: price(@order.display_order_adjustment_total),
|
|
124
|
+
totalAmount: price(@order.display_order_adjustment_total),
|
|
125
|
+
vatAmount: price(0),
|
|
126
|
+
vatRate: '0'
|
|
127
|
+
}
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def serialize_shipping_discounts
|
|
131
|
+
binding.pry #TODO: Not implemented
|
|
132
|
+
{
|
|
133
|
+
type: 'discount',
|
|
134
|
+
name: 'Shipping discount',
|
|
135
|
+
quantity: 1,
|
|
136
|
+
unitPrice: price(@order.display_shipping_discount),
|
|
137
|
+
totalAmount: price(@order.display_shipping_discount),
|
|
138
|
+
vatAmount: price(0),
|
|
139
|
+
vatRate: '0'
|
|
140
|
+
}
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def serialize_line_item(line_item)
|
|
144
|
+
{
|
|
145
|
+
type: 'physical',
|
|
146
|
+
name: line_item.name,
|
|
147
|
+
quantity: line_item.quantity,
|
|
148
|
+
unitPrice: price(line_item.price),
|
|
149
|
+
discountAmount: price(line_item.promo_total),
|
|
150
|
+
totalAmount: price(line_item.total),
|
|
151
|
+
vatAmount: price(line_item.included_tax_total),
|
|
152
|
+
vatRate: line_item.tax_rate.to_f * 100, # TODO: Might need to verify this rates just one tax_rate
|
|
153
|
+
sku: line_item.sku
|
|
154
|
+
}
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def price(amount)
|
|
158
|
+
{
|
|
159
|
+
value: format_money(amount),
|
|
160
|
+
currency: @order.currency
|
|
161
|
+
}
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def format_money(money)
|
|
165
|
+
Spree::Money.new(money, { symbol: nil, thousands_separator: nil, decimal_mark: '.' }).format
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Mollie
|
|
3
|
+
class PaymentStateUpdater
|
|
4
|
+
|
|
5
|
+
attr_reader :payment
|
|
6
|
+
attr_reader :mollie_order
|
|
7
|
+
|
|
8
|
+
def initialize(mollie_order, payment)
|
|
9
|
+
@mollie_order = mollie_order
|
|
10
|
+
@payment = payment
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
case mollie_order.status
|
|
15
|
+
|
|
16
|
+
when 'created'
|
|
17
|
+
transition_to_created!
|
|
18
|
+
when 'expired'
|
|
19
|
+
transition_to_failed!
|
|
20
|
+
when 'authorized'
|
|
21
|
+
transition_to_pending!
|
|
22
|
+
when 'paid', 'completed'
|
|
23
|
+
transition_to_complete!
|
|
24
|
+
when 'canceled'
|
|
25
|
+
transition_to_void!
|
|
26
|
+
when 'shipping'
|
|
27
|
+
transition_to_shipping!
|
|
28
|
+
else
|
|
29
|
+
MollieLogger.debug("Unhandled Mollie payment state received: #{mollie_order.status}. Therefore we did not update the payment state.")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def transition_to_created!
|
|
37
|
+
true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def transition_to_failed!
|
|
41
|
+
payment.failure! unless @spree_payment.failed?
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def transition_to_pending!
|
|
45
|
+
payment.pend! unless @spree_payment.pending?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def transition_to_complete!
|
|
49
|
+
payment.complete! unless @payment.completed?
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def transition_to_void!
|
|
53
|
+
payment.void! unless @payment.void?
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def transition_to_shipping!
|
|
57
|
+
true
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class MollieLogger
|
|
3
|
+
def self.debug(message = nil)
|
|
4
|
+
return unless message.present?
|
|
5
|
+
|
|
6
|
+
@logger ||= Logger.new(File.join(Rails.root, 'log', 'solidus_mollie.log'))
|
|
7
|
+
|
|
8
|
+
# .datetime_format = "%Y-%m-%d %H:%M:%S"
|
|
9
|
+
@logger.debug(message)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class << self
|
|
13
|
+
attr_writer :logger
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class MolliePaymentSource < Spree::PaymentSource
|
|
3
|
+
|
|
4
|
+
self.table_name = "solidus_mollie_payment_sources"
|
|
5
|
+
|
|
6
|
+
def transaction_id
|
|
7
|
+
payment_id
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def method_type
|
|
11
|
+
'mollie_payment_source'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def name
|
|
15
|
+
case payment_method_name
|
|
16
|
+
when ::Mollie::Method::IDEAL then
|
|
17
|
+
'iDEAL'
|
|
18
|
+
when ::Mollie::Method::CREDITCARD then
|
|
19
|
+
'Credit card'
|
|
20
|
+
when ::Mollie::Method::BANCONTACT then
|
|
21
|
+
'Bancontact'
|
|
22
|
+
when ::Mollie::Method::SOFORT then
|
|
23
|
+
'SOFORT Banking'
|
|
24
|
+
when ::Mollie::Method::BANKTRANSFER then
|
|
25
|
+
'Bank transfer'
|
|
26
|
+
when ::Mollie::Method::PAYPAL then
|
|
27
|
+
'PayPal'
|
|
28
|
+
when ::Mollie::Method::KBC then
|
|
29
|
+
'KBC/CBC Payment Button'
|
|
30
|
+
when ::Mollie::Method::BELFIUS then
|
|
31
|
+
'Belfius Pay Button'
|
|
32
|
+
when ::Mollie::Method::PAYSAFECARD then
|
|
33
|
+
'paysafecard'
|
|
34
|
+
when ::Mollie::Method::GIFTCARD then
|
|
35
|
+
'Giftcard'
|
|
36
|
+
when ::Mollie::Method::INGHOMEPAY then
|
|
37
|
+
'ING Home\'Pay'
|
|
38
|
+
when ::Mollie::Method::EPS then
|
|
39
|
+
'EPS'
|
|
40
|
+
when ::Mollie::Method::GIROPAY then
|
|
41
|
+
'Giropay'
|
|
42
|
+
when ::Mollie::Method::DIRECTDEBIT then
|
|
43
|
+
'SEPA Direct debit'
|
|
44
|
+
when ::Mollie::Method::KLARNASLICEIT then
|
|
45
|
+
'Klarna Slice it'
|
|
46
|
+
when ::Mollie::Method::KLARNAPAYLATER then
|
|
47
|
+
'Klarna Pay Later'
|
|
48
|
+
when ::Mollie::Method::PRZELEWY24 then
|
|
49
|
+
'Przelewy24'
|
|
50
|
+
when ::Mollie::Method::APPLEPAY then
|
|
51
|
+
'Apple Pay'
|
|
52
|
+
else
|
|
53
|
+
'Mollie (Unknown method)'
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Spree
|
|
5
|
+
class PaymentMethod::Mollie < Spree::PaymentMethod
|
|
6
|
+
preference :api_key, :string
|
|
7
|
+
|
|
8
|
+
def payment_source_class
|
|
9
|
+
MolliePaymentSource
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def partial_name
|
|
13
|
+
"mollie"
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def auto_capture
|
|
17
|
+
false
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
protected
|
|
21
|
+
|
|
22
|
+
def gateway_class
|
|
23
|
+
Spree::Gateway::MollieGateway
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<fieldset class="no-border-bottom js-edit-credit-card">
|
|
2
|
+
<legend><%= payment_method.name %></legend>
|
|
3
|
+
|
|
4
|
+
<div id="card_form<%= payment_method.id %>" data-hook class="js-new-credit-card-form">
|
|
5
|
+
<% param_prefix = "payment_source[#{payment_method.id}]" %>
|
|
6
|
+
|
|
7
|
+
</div>
|
|
8
|
+
</fieldset>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<fieldset data-hook="credit_card">
|
|
2
|
+
<legend align="center"><%= Spree::MolliePaymentSource.model_name.human %></legend>
|
|
3
|
+
|
|
4
|
+
<div class="row">
|
|
5
|
+
<div class="col-12">
|
|
6
|
+
<dl>
|
|
7
|
+
<dt><%= t('spree.payment_method') %>:</dt>
|
|
8
|
+
<dd><%= payment.source.payment_method_name %></dd>
|
|
9
|
+
|
|
10
|
+
<dt><%= t('spree.transaction_id') %>:</dt>
|
|
11
|
+
<dd><%= payment.source.payment_id %></dd>
|
|
12
|
+
|
|
13
|
+
<dt><%= t('spree.Payment Link') %>:</dt>
|
|
14
|
+
<dd><a href="<%= payment.source.payment_url %>"><%= payment.source.payment_url %></a></dd>
|
|
15
|
+
|
|
16
|
+
<% if payment.source.issuer %>
|
|
17
|
+
<dt><%= t('spree.issuer') %>:</dt>
|
|
18
|
+
<dd><%= payment.source.issuer %></dd>
|
|
19
|
+
<% end %>
|
|
20
|
+
|
|
21
|
+
<dt><%= t('spree.payment_status') %>:</dt>
|
|
22
|
+
<dd><%= payment.source.status %></dd>
|
|
23
|
+
</dl>
|
|
24
|
+
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</fieldset>
|
data/bin/console
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
|
|
5
|
+
require "bundler/setup"
|
|
6
|
+
require "solidus_mollie"
|
|
7
|
+
|
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
10
|
+
$LOAD_PATH.unshift(*Dir["#{__dir__}/../app/*"])
|
|
11
|
+
|
|
12
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
13
|
+
# require "pry"
|
|
14
|
+
# Pry.start
|
|
15
|
+
|
|
16
|
+
require "irb"
|
|
17
|
+
IRB.start(__FILE__)
|
data/bin/rails
ADDED
data/bin/rails-engine
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
|
3
|
+
# installed from the root of your application.
|
|
4
|
+
|
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/solidus_mollie/engine', __dir__)
|
|
7
|
+
|
|
8
|
+
# Set up gems listed in the Gemfile.
|
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
11
|
+
|
|
12
|
+
require 'rails/all'
|
|
13
|
+
require 'rails/engine/commands'
|
data/bin/rails-sandbox
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
app_root = 'sandbox'
|
|
4
|
+
|
|
5
|
+
unless File.exist? "#{app_root}/bin/rails"
|
|
6
|
+
warn 'Creating the sandbox app...'
|
|
7
|
+
Dir.chdir "#{__dir__}/.." do
|
|
8
|
+
system "#{__dir__}/sandbox" or begin
|
|
9
|
+
warn 'Automatic creation of the sandbox app failed'
|
|
10
|
+
exit 1
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
Dir.chdir app_root
|
|
16
|
+
exec 'bin/rails', *ARGV
|
data/bin/rake
ADDED
data/bin/sandbox
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
case "$DB" in
|
|
6
|
+
postgres|postgresql)
|
|
7
|
+
RAILSDB="postgresql"
|
|
8
|
+
;;
|
|
9
|
+
mysql)
|
|
10
|
+
RAILSDB="mysql"
|
|
11
|
+
;;
|
|
12
|
+
sqlite|'')
|
|
13
|
+
RAILSDB="sqlite3"
|
|
14
|
+
;;
|
|
15
|
+
*)
|
|
16
|
+
echo "Invalid DB specified: $DB"
|
|
17
|
+
exit 1
|
|
18
|
+
;;
|
|
19
|
+
esac
|
|
20
|
+
|
|
21
|
+
if [ ! -z $SOLIDUS_BRANCH ]
|
|
22
|
+
then
|
|
23
|
+
BRANCH=$SOLIDUS_BRANCH
|
|
24
|
+
else
|
|
25
|
+
BRANCH="master"
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
extension_name="solidus_mollie"
|
|
29
|
+
|
|
30
|
+
# Stay away from the bundler env of the containing extension.
|
|
31
|
+
function unbundled {
|
|
32
|
+
ruby -rbundler -e'b = proc {system *ARGV}; Bundler.respond_to?(:with_unbundled_env) ? Bundler.with_unbundled_env(&b) : Bundler.with_clean_env(&b)' -- $@
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
rm -rf ./sandbox
|
|
36
|
+
unbundled bundle exec rails new sandbox --database="$RAILSDB" \
|
|
37
|
+
--skip-bundle \
|
|
38
|
+
--skip-git \
|
|
39
|
+
--skip-keeps \
|
|
40
|
+
--skip-rc \
|
|
41
|
+
--skip-spring \
|
|
42
|
+
--skip-test \
|
|
43
|
+
--skip-javascript
|
|
44
|
+
|
|
45
|
+
if [ ! -d "sandbox" ]; then
|
|
46
|
+
echo 'sandbox rails application failed'
|
|
47
|
+
exit 1
|
|
48
|
+
fi
|
|
49
|
+
|
|
50
|
+
cd ./sandbox
|
|
51
|
+
cat <<RUBY >> Gemfile
|
|
52
|
+
gem 'solidus', github: 'solidusio/solidus', branch: '$BRANCH'
|
|
53
|
+
gem 'solidus_auth_devise', '>= 2.1.0'
|
|
54
|
+
gem 'rails-i18n'
|
|
55
|
+
gem 'solidus_i18n'
|
|
56
|
+
|
|
57
|
+
gem '$extension_name', path: '..'
|
|
58
|
+
|
|
59
|
+
group :test, :development do
|
|
60
|
+
platforms :mri do
|
|
61
|
+
gem 'pry-byebug'
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
RUBY
|
|
65
|
+
|
|
66
|
+
unbundled bundle install --gemfile Gemfile
|
|
67
|
+
|
|
68
|
+
unbundled bundle exec rake db:drop db:create
|
|
69
|
+
|
|
70
|
+
unbundled bundle exec rails generate solidus:install \
|
|
71
|
+
--auto-accept \
|
|
72
|
+
--user_class=Spree::User \
|
|
73
|
+
--enforce_available_locales=true \
|
|
74
|
+
--with-authentication=false \
|
|
75
|
+
--payment-method=none \
|
|
76
|
+
$@
|
|
77
|
+
|
|
78
|
+
unbundled bundle exec rails generate solidus:auth:install
|
|
79
|
+
unbundled bundle exec rails generate ${extension_name}:install
|
|
80
|
+
|
|
81
|
+
echo
|
|
82
|
+
echo "🚀 Sandbox app successfully created for $extension_name!"
|
|
83
|
+
echo "🚀 Using $RAILSDB and Solidus $BRANCH"
|
|
84
|
+
echo "🚀 Use 'export DB=[postgres|mysql|sqlite]' to control the DB adapter"
|
|
85
|
+
echo "🚀 Use 'export SOLIDUS_BRANCH=<BRANCH-NAME>' to control the Solidus version"
|
|
86
|
+
echo "🚀 This app is intended for test purposes."
|
data/bin/setup
ADDED
data/config/routes.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Spree::Core::Engine.routes.draw do
|
|
4
|
+
resource :mollie, only: [], controller: :mollie do
|
|
5
|
+
post 'update_payment_status', action: :update_payment_status, as: 'mollie_update_payment_status'
|
|
6
|
+
# put 'validate_payment/:order_number', action: :validate_payment, as: 'mollie_validate_payment'
|
|
7
|
+
get 'validate_payment/:order_number', action: :validate_payment, as: 'mollie_validate_payment'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
namespace :api, defaults: { format: 'json' } do
|
|
11
|
+
resources :mollie do
|
|
12
|
+
member do
|
|
13
|
+
get :payment_methods
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class CreateSolidusMolliePaymentSource < ActiveRecord::Migration[6.0]
|
|
2
|
+
def change
|
|
3
|
+
create_table :solidus_mollie_payment_sources do |t|
|
|
4
|
+
t.timestamps
|
|
5
|
+
t.string :payment_id
|
|
6
|
+
t.string :payment_method_name
|
|
7
|
+
t.string :issuer
|
|
8
|
+
t.string :status
|
|
9
|
+
t.string :payment_url
|
|
10
|
+
t.integer :payment_method_id
|
|
11
|
+
t.integer :user_id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusMollie
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
|
8
|
+
|
|
9
|
+
def copy_initializer
|
|
10
|
+
template 'initializer.rb', 'config/initializers/solidus_mollie.rb'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def add_javascripts
|
|
14
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_mollie\n"
|
|
15
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_mollie\n"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_stylesheets
|
|
19
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/solidus_mollie\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
|
20
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/solidus_mollie\n", before: %r{\*/}, verbose: true # rubocop:disable Layout/LineLength
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_migrations
|
|
24
|
+
run 'bin/rails railties:install:migrations FROM=solidus_mollie'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def run_migrations
|
|
28
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]')) # rubocop:disable Layout/LineLength
|
|
29
|
+
if run_migrations
|
|
30
|
+
run 'bin/rails db:migrate'
|
|
31
|
+
else
|
|
32
|
+
puts 'Skipping bin/rails db:migrate, don\'t forget to run it!' # rubocop:disable Rails/Output
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SolidusMollie
|
|
4
|
+
class Configuration
|
|
5
|
+
# Define here the settings for this extension, e.g.:
|
|
6
|
+
#
|
|
7
|
+
# attr_accessor :my_setting
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def configuration
|
|
12
|
+
@configuration ||= Configuration.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
alias config configuration
|
|
16
|
+
|
|
17
|
+
def configure
|
|
18
|
+
yield configuration
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spree/core'
|
|
4
|
+
require 'solidus_mollie'
|
|
5
|
+
|
|
6
|
+
module SolidusMollie
|
|
7
|
+
class Engine < Rails::Engine
|
|
8
|
+
include SolidusSupport::EngineExtensions
|
|
9
|
+
|
|
10
|
+
isolate_namespace ::Spree
|
|
11
|
+
|
|
12
|
+
engine_name 'solidus_mollie'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# use rspec for tests
|
|
16
|
+
config.generators do |g|
|
|
17
|
+
g.test_framework :rspec
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
Spree::PermittedAttributes.source_attributes << :payment_method_id
|
|
21
|
+
|
|
22
|
+
initializer "register_spree_mollie_payment_method", after: "spree.register.payment_methods" do |app|
|
|
23
|
+
app.config.spree.payment_methods << Spree::PaymentMethod::Mollie
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|