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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b93ec5f4b4a21514882eb71bbe99ba37826ad0cbbd83421b3661b2251cc2e589
|
|
4
|
+
data.tar.gz: af024b49050bbeaf8e186b0b4b338e8e8893fe507087d369a417e152aaa052b2
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: f3ad564dcc8d5ea425b5cfe5c9887a74deb903acba47bcc4f30cc40600243dc42d8a433350a1533875bf180f3adc14c723582f495592ed747a28ab76876ebc6e
|
|
7
|
+
data.tar.gz: 89a485930ff1261aa2d49bb24061305a45eb7f5ea6a00116d6c00aa82759c175385017ff5bbf0a193176b208650960e20ab088b9b8f1f891449dce5df5a8ae74
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
orbs:
|
|
4
|
+
# Always take the latest version of the orb, this allows us to
|
|
5
|
+
# run specs against Solidus supported versions only without the need
|
|
6
|
+
# to change this configuration every time a Solidus version is released
|
|
7
|
+
# or goes EOL.
|
|
8
|
+
solidusio_extensions: solidusio/extensions@volatile
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
run-specs-with-postgres:
|
|
12
|
+
executor: solidusio_extensions/postgres
|
|
13
|
+
steps:
|
|
14
|
+
- solidusio_extensions/run-tests
|
|
15
|
+
run-specs-with-mysql:
|
|
16
|
+
executor: solidusio_extensions/mysql
|
|
17
|
+
steps:
|
|
18
|
+
- solidusio_extensions/run-tests
|
|
19
|
+
lint-code:
|
|
20
|
+
executor: solidusio_extensions/sqlite-memory
|
|
21
|
+
steps:
|
|
22
|
+
- solidusio_extensions/lint-code
|
|
23
|
+
|
|
24
|
+
workflows:
|
|
25
|
+
"Run specs on supported Solidus versions":
|
|
26
|
+
jobs:
|
|
27
|
+
- run-specs-with-postgres
|
|
28
|
+
- run-specs-with-mysql
|
|
29
|
+
- lint-code
|
|
30
|
+
|
|
31
|
+
"Weekly run specs against master":
|
|
32
|
+
triggers:
|
|
33
|
+
- schedule:
|
|
34
|
+
cron: "0 0 * * 4" # every Thursday
|
|
35
|
+
filters:
|
|
36
|
+
branches:
|
|
37
|
+
only:
|
|
38
|
+
- master
|
|
39
|
+
jobs:
|
|
40
|
+
- run-specs-with-postgres
|
|
41
|
+
- run-specs-with-mysql
|
data/.gem_release.yml
ADDED
data/.github/stale.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Number of days of inactivity before an issue becomes stale
|
|
2
|
+
daysUntilStale: 60
|
|
3
|
+
# Number of days of inactivity before a stale issue is closed
|
|
4
|
+
daysUntilClose: false
|
|
5
|
+
# Issues with these labels will never be considered stale
|
|
6
|
+
exemptLabels:
|
|
7
|
+
- pinned
|
|
8
|
+
- security
|
|
9
|
+
# Label to use when marking an issue as stale
|
|
10
|
+
staleLabel: stale
|
|
11
|
+
# Comment to post when marking an issue as stale. Set to `false` to disable
|
|
12
|
+
markComment: >
|
|
13
|
+
This issue has been automatically marked as stale because it has not had
|
|
14
|
+
recent activity. It might be closed if no further activity occurs. Thank you
|
|
15
|
+
for your contributions.
|
|
16
|
+
# Comment to post when closing a stale issue. Set to `false` to disable
|
|
17
|
+
closeComment: false
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Changelog
|
data/Gemfile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
5
|
+
|
|
6
|
+
branch = ENV.fetch('SOLIDUS_BRANCH', 'master')
|
|
7
|
+
gem 'solidus', github: 'solidusio/solidus', branch: branch
|
|
8
|
+
|
|
9
|
+
# Needed to help Bundler figure out how to resolve dependencies,
|
|
10
|
+
# otherwise it takes forever to resolve them.
|
|
11
|
+
# See https://github.com/bundler/bundler/issues/6677
|
|
12
|
+
gem 'rails', '>0.a'
|
|
13
|
+
|
|
14
|
+
# Provides basic authentication functionality for testing parts of your engine
|
|
15
|
+
gem 'solidus_auth_devise'
|
|
16
|
+
|
|
17
|
+
case ENV['DB']
|
|
18
|
+
when 'mysql'
|
|
19
|
+
gem 'mysql2'
|
|
20
|
+
when 'postgresql'
|
|
21
|
+
gem 'pg'
|
|
22
|
+
else
|
|
23
|
+
gem 'sqlite3'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
gemspec
|
|
27
|
+
|
|
28
|
+
# Use a local Gemfile to include development dependencies that might not be
|
|
29
|
+
# relevant for the project or for other contributors, e.g. pry-byebug.
|
|
30
|
+
#
|
|
31
|
+
# We use `send` instead of calling `eval_gemfile` to work around an issue with
|
|
32
|
+
# how Dependabot parses projects: https://github.com/dependabot/dependabot-core/issues/1658.
|
|
33
|
+
send(:eval_gemfile, 'Gemfile-local') if File.exist? 'Gemfile-local'
|
data/LICENSE
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) 2021 [name of plugin creator]
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
|
5
|
+
are permitted provided that the following conditions are met:
|
|
6
|
+
|
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
|
8
|
+
this list of conditions and the following disclaimer.
|
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
|
11
|
+
and/or other materials provided with the distribution.
|
|
12
|
+
* Neither the name Solidus nor the names of its contributors may be used to
|
|
13
|
+
endorse or promote products derived from this software without specific
|
|
14
|
+
prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Solidus Mollie
|
|
2
|
+
|
|
3
|
+
[](https://circleci.com/gh/solidusio-contrib/solidus_mollie)
|
|
4
|
+
[](https://codecov.io/gh/solidusio-contrib/solidus_mollie)
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add solidus\_mollie to your Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'solidus_mollie'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Bundle your dependencies and run the installation generator:
|
|
15
|
+
|
|
16
|
+
```shell
|
|
17
|
+
bin/rails generate solidus_mollie:install
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
<!-- Explain how to use your extension once it's been installed. -->
|
|
23
|
+
|
|
24
|
+
## Development
|
|
25
|
+
|
|
26
|
+
### Testing the extension
|
|
27
|
+
|
|
28
|
+
First bundle your dependencies, then run `bin/rake`. `bin/rake` will default to building the dummy
|
|
29
|
+
app if it does not exist, then it will run specs. The dummy app can be regenerated by using
|
|
30
|
+
`bin/rake extension:test_app`.
|
|
31
|
+
|
|
32
|
+
```shell
|
|
33
|
+
bin/rake
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
To run [Rubocop](https://github.com/bbatsov/rubocop) static code analysis run
|
|
37
|
+
|
|
38
|
+
```shell
|
|
39
|
+
bundle exec rubocop
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
When testing your application's integration with this extension you may use its factories.
|
|
43
|
+
Simply add this require statement to your `spec/spec_helper.rb`:
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
require 'solidus_mollie/testing_support/factories'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or, if you are using `FactoryBot.definition_file_paths`, you can load Solidus core
|
|
50
|
+
factories along with this extension's factories using this statement:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
SolidusDevSupport::TestingSupport::Factories.load_for(SolidusMollie::Engine)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Running the sandbox
|
|
57
|
+
|
|
58
|
+
To run this extension in a sandboxed Solidus application, you can run `bin/sandbox`. The path for
|
|
59
|
+
the sandbox app is `./sandbox` and `bin/rails` will forward any Rails commands to
|
|
60
|
+
`sandbox/bin/rails`.
|
|
61
|
+
|
|
62
|
+
Here's an example:
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
$ bin/rails server
|
|
66
|
+
=> Booting Puma
|
|
67
|
+
=> Rails 6.0.2.1 application starting in development
|
|
68
|
+
* Listening on tcp://127.0.0.1:3000
|
|
69
|
+
Use Ctrl-C to stop
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Updating the changelog
|
|
73
|
+
|
|
74
|
+
Before and after releases the changelog should be updated to reflect the up-to-date status of
|
|
75
|
+
the project:
|
|
76
|
+
|
|
77
|
+
```shell
|
|
78
|
+
bin/rake changelog
|
|
79
|
+
git add CHANGELOG.md
|
|
80
|
+
git commit -m "Update the changelog"
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Releasing new versions
|
|
84
|
+
|
|
85
|
+
Please refer to the dedicated [page](https://github.com/solidusio/solidus/wiki/How-to-release-extensions) on Solidus wiki.
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Copyright (c) 2021 Victor ter Hark.
|
|
90
|
+
Copyright (c) 2026 Kalopa Robotics Limited.
|
|
91
|
+
Released under the New BSD License.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
module Api
|
|
3
|
+
class MollieController < Spree::Api::BaseController
|
|
4
|
+
def payment_methods
|
|
5
|
+
#FIXME: This is not safe.
|
|
6
|
+
order = Spree::Order.find_by(number: params[:id])
|
|
7
|
+
method_params = payload(order)
|
|
8
|
+
|
|
9
|
+
payment_methods = Spree::PaymentMethod::Mollie.first.gateway.available_methods(method_params).map(&:attributes)
|
|
10
|
+
|
|
11
|
+
render json: payment_methods
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def validate_payment
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def payload(order)
|
|
20
|
+
{
|
|
21
|
+
amount: {
|
|
22
|
+
currency: order.currency,
|
|
23
|
+
value: Spree::Money.new(order.order_total_after_store_credit, { symbol: nil, thousands_separator: nil, decimal_mark: '.' }).format
|
|
24
|
+
},
|
|
25
|
+
resource: 'orders',
|
|
26
|
+
billingCountry: order.bill_address.country.iso
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Spree
|
|
2
|
+
class MollieController < BaseController
|
|
3
|
+
skip_before_action :verify_authenticity_token, only: [:update_payment_status]
|
|
4
|
+
|
|
5
|
+
# We might need this if the Webhook is late
|
|
6
|
+
def validate_payment
|
|
7
|
+
payment_number = split_payment_identifier(params[:order_number])
|
|
8
|
+
payment = Spree::Payment.find_by(number: payment_number)
|
|
9
|
+
payment.payment_method.gateway.update_payment_status(payment)
|
|
10
|
+
|
|
11
|
+
order = payment.order
|
|
12
|
+
order.reload
|
|
13
|
+
|
|
14
|
+
binding.pry
|
|
15
|
+
|
|
16
|
+
# Order is paid for or authorized (e.g. Klarna Pay Later)
|
|
17
|
+
if (order.paid? && (order.can_complete?))
|
|
18
|
+
order.complete
|
|
19
|
+
|
|
20
|
+
redirect_to "https://bitter-lizard-32.loca.lt/checkout/success/#{order.number}"
|
|
21
|
+
# redirect_to order_path(payment.order)
|
|
22
|
+
else payment.pending?
|
|
23
|
+
redirect_to "https://bitter-lizard-32.loca.ltcheckout/#{params[:order_number]}"
|
|
24
|
+
# redirect_to checkout_state_path(:payment)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Mollie might send us information about a transaction through the webhook.
|
|
29
|
+
# We should update the payment state accordingly.
|
|
30
|
+
def update_payment_status
|
|
31
|
+
payment_number = split_payment_identifier(params[:payment_identifier])
|
|
32
|
+
payment = Spree::Payment.find_by(number: payment_number)
|
|
33
|
+
payment.payment_method.gateway.update_payment_status(payment)
|
|
34
|
+
|
|
35
|
+
head :ok
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
# Payment identifier is a combination of order_number and payment_id.
|
|
41
|
+
def split_payment_identifier(payment_identifier)
|
|
42
|
+
payment_identifier.split('-')[1]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def payment_status_params
|
|
46
|
+
params.permit(:payment_identifier, :id)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def load_order
|
|
50
|
+
@order = ::Spree::Order.find_by!(number: params[:order_id])
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module SolidusMollie
|
|
2
|
+
module LineItemDecorator
|
|
3
|
+
|
|
4
|
+
def tax_rate
|
|
5
|
+
if adjustments.tax.any?
|
|
6
|
+
# Solidus allows line items to have multiple TaxRate adjustments.
|
|
7
|
+
# Mollie does not support this. Raise an error if there > 1 TaxRate adjustment.
|
|
8
|
+
|
|
9
|
+
if adjustments.tax.count > 1
|
|
10
|
+
raise 'Mollie does not support multiple TaxRate adjustments per line item'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
adjustments.tax.first.source.amount
|
|
14
|
+
else
|
|
15
|
+
0.00
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
::Spree::LineItem.prepend self
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module SolidusMollie
|
|
2
|
+
module PaymentCreateDecorator
|
|
3
|
+
|
|
4
|
+
def authorized?
|
|
5
|
+
if source.is_a? Spree::MolliePaymentSource
|
|
6
|
+
pending?
|
|
7
|
+
else
|
|
8
|
+
false
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def after_pay_method?
|
|
13
|
+
if source.is_a? Spree::MolliePaymentSource
|
|
14
|
+
return source.payment_method_name == ::Mollie::Method::KLARNAPAYLATER || source.payment_method_name == ::Mollie::Method::KLARNASLICEIT
|
|
15
|
+
else
|
|
16
|
+
false
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
::Spree::PaymentCreate.prepend self
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Credit
|
|
2
|
+
|
|
3
|
+
# 1. Webhook Callbacks
|
|
4
|
+
# 2. Payment Methods through API
|
|
5
|
+
# 3. Create Mollie User
|
|
6
|
+
# 4. Mollie shipments
|
|
7
|
+
|
|
8
|
+
# X. Client wrapper like PayPal
|
|
9
|
+
# X. Ugly functions in serializer
|
|
10
|
+
# x. Nice helper for Payment ID
|
|
11
|
+
# X. Check if we pass only variables needed
|
|
12
|
+
|
|
13
|
+
module Spree
|
|
14
|
+
class Gateway::MollieGateway
|
|
15
|
+
|
|
16
|
+
def initialize(options)
|
|
17
|
+
::Mollie::Client.configure do |config|
|
|
18
|
+
config.api_key = options[:api_key]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def format_money(money)
|
|
23
|
+
Spree::Money.new(money, { symbol: nil, thousands_separator: nil, decimal_mark: '.' }).format
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def authorize(_money, _source, gateway_options = {})
|
|
27
|
+
begin
|
|
28
|
+
payment = gateway_options[:originator]
|
|
29
|
+
invalidate_previous_orders(payment.order_id)
|
|
30
|
+
|
|
31
|
+
# Create a new Mollie order and update the payment source
|
|
32
|
+
mollie_order = create_mollie_order(gateway_options)
|
|
33
|
+
payment.source.update(status: mollie_order.status, payment_id: mollie_order.id, payment_url: mollie_order.checkout_url)
|
|
34
|
+
|
|
35
|
+
ActiveMerchant::Billing::Response.new(true, 'Order created')
|
|
36
|
+
rescue ::Mollie::Exception => e
|
|
37
|
+
ActiveMerchant::Billing::Response.new(false, "Order could not be created: #{e.message}")
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def capture(_money, _response_code, gateway_options = {})
|
|
42
|
+
authorize(_money, nil, gateway_options)
|
|
43
|
+
# ActiveMerchant::Billing::Response.new(true, 'Mollie will automatically capture the amount.')
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def purchase(money, source, gateway_options = {})
|
|
47
|
+
authorize(money, source, gateway_options = {})
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def void(_respoonse_code, gateway_options = {})
|
|
51
|
+
begin
|
|
52
|
+
payment_id = gateway_options[:originator].source.payment_id
|
|
53
|
+
|
|
54
|
+
if cancel_mollie_order!(payment_id)
|
|
55
|
+
ActiveMerchant::Billing::Response.new(true, 'Mollie order has been cancelled.')
|
|
56
|
+
else
|
|
57
|
+
ActiveMerchant::Billing::Response.new(true, 'Spree order has been canceled, could not cancel Mollie order.')
|
|
58
|
+
end
|
|
59
|
+
rescue ::Mollie::Exception => e
|
|
60
|
+
ActiveMerchant::Billing::Response.new(false, 'Order cancellation unsuccessful.')
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def credit(_money_cents, _transaction_id, options)
|
|
65
|
+
refund = options[:originator]
|
|
66
|
+
|
|
67
|
+
payment = refund.try(:payment)
|
|
68
|
+
order = payment.try(:order)
|
|
69
|
+
reimbursement = refund.try(:reimbursement)
|
|
70
|
+
|
|
71
|
+
# binding.pry
|
|
72
|
+
begin
|
|
73
|
+
if reimbursement
|
|
74
|
+
mollie_order = ::Mollie::Order.get(payment.source.payment_id)
|
|
75
|
+
|
|
76
|
+
mollie_order_refund_lines = reimbursement.return_items.map do |reimbursement|
|
|
77
|
+
line_item = mollie_order.lines.detect { |line|
|
|
78
|
+
line_item.sku == reimbursement.inventory_unit.line_item.mollie_identifier
|
|
79
|
+
}
|
|
80
|
+
{ id: line_item.id, quantity: ri.inventory_unit.line_item.quantity } if line_item
|
|
81
|
+
end.compact
|
|
82
|
+
|
|
83
|
+
mollie_order.refund!({lines: mollie_order_refund_lines})
|
|
84
|
+
else
|
|
85
|
+
::Mollie::Payment::Refund.create(
|
|
86
|
+
payment_id: payment_id,
|
|
87
|
+
amount: {
|
|
88
|
+
value: format_money(refund.amount),
|
|
89
|
+
currency: refund.currency
|
|
90
|
+
},
|
|
91
|
+
description: "Refund Order ID: #{order.number}",
|
|
92
|
+
|
|
93
|
+
)
|
|
94
|
+
end
|
|
95
|
+
ActiveMerchant::Billing::Response.new(true, "Successfully refunded #{order.display_total} for order #{order_number}")
|
|
96
|
+
rescue ::Mollie::Exception => e
|
|
97
|
+
ActiveMerchant::Billing::Response.new(false, e.message)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def available_methods(params = nil)
|
|
102
|
+
method_params = {
|
|
103
|
+
include: 'issuers',
|
|
104
|
+
resource: 'orders'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
method_params.merge! params if params.present?
|
|
108
|
+
|
|
109
|
+
::Mollie::Method.all(method_params)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def available_methods_for_order(order)
|
|
113
|
+
params = {
|
|
114
|
+
amount: {
|
|
115
|
+
currency: order.currency,
|
|
116
|
+
value: format_money(order.total)
|
|
117
|
+
},
|
|
118
|
+
resource: 'orders',
|
|
119
|
+
billingCountry: order.billing_address.country.try(:iso)
|
|
120
|
+
}
|
|
121
|
+
available_methods(params)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def update_payment_status(payment)
|
|
125
|
+
mollie_order = ::Mollie::Order.get(payment.source.payment_id, embed: 'payments')
|
|
126
|
+
|
|
127
|
+
Spree::Mollie::PaymentStateUpdater.new(mollie_order, payment).call
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
private
|
|
131
|
+
|
|
132
|
+
def create_mollie_order(gateway_options)
|
|
133
|
+
order_params = Spree::Mollie::OrderSerializer.serialize(gateway_options)
|
|
134
|
+
|
|
135
|
+
::Mollie::Order.create(order_params)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def cancel_mollie_order!(payment_id)
|
|
139
|
+
mollie_order = ::Mollie::Order.get(payment_id)
|
|
140
|
+
mollie_order.cancel if mollie_order.cancelable?
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def invalidate_previous_orders(order_id)
|
|
144
|
+
#TODO: Nice scope that checks for Payment Source
|
|
145
|
+
# Spree::Payment.by_mollie_and_order(order_id).each { cancel_mollie_order(paymnet) }
|
|
146
|
+
|
|
147
|
+
Spree::Payment.where(order_id: order_id).where("state = ? OR state = ?", 'pending', 'processing').each do |payment|
|
|
148
|
+
if payment.source_type == "Spree::MolliePaymentSource"
|
|
149
|
+
payment.void!
|
|
150
|
+
cancel_mollie_order!(payment.source.payment_id)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
end
|