├── .github └── workflows │ ├── build.yml │ ├── codeql.yml │ └── push.yml ├── .gitignore ├── .rubocop.yml ├── .rubocop_todo.yml ├── CHANGELOG.md ├── Gemfile ├── LICENSE ├── Makefile ├── README.md ├── Rakefile ├── bin ├── console └── setup ├── docs ├── migration_v2_2_x.md └── migration_v3_x.md ├── examples ├── balances │ ├── get-primary.rb │ ├── get-report.rb │ ├── get.rb │ ├── list-transactions.rb │ └── list.rb ├── captures │ ├── get-payment.rb │ ├── get-settlement.rb │ ├── get-shipment.rb │ ├── get.rb │ └── list.rb ├── chargebacks │ ├── get.rb │ └── list.rb ├── connect │ ├── authorize.rb │ └── tokens.rb ├── customers │ ├── create-payment.rb │ ├── create.rb │ ├── delete.rb │ ├── get.rb │ ├── list-payments.rb │ ├── list.rb │ └── update.rb ├── invoices │ ├── get.rb │ └── list.rb ├── mandates │ ├── create.rb │ ├── delete.rb │ ├── get.rb │ └── list.rb ├── methods │ ├── get.rb │ └── list.rb ├── onboarding │ ├── get.rb │ └── submit.rb ├── orders │ ├── cancel-lines.rb │ ├── cancel.rb │ ├── create-payment.rb │ ├── create-refund.rb │ ├── create.rb │ ├── get.rb │ ├── list-refunds.rb │ ├── list.rb │ ├── update-orderline.rb │ └── update.rb ├── organisations │ ├── get-current.rb │ ├── get-partner.rb │ └── get.rb ├── payment-links │ ├── create.rb │ ├── delete.rb │ ├── get.rb │ ├── list-payments.rb │ ├── list.rb │ └── update.rb ├── payments │ ├── create.rb │ ├── delete.rb │ ├── get-customer.rb │ ├── get-mandate.rb │ ├── get-order.rb │ ├── get-settlement.rb │ ├── get-subscription.rb │ ├── get.rb │ ├── list.rb │ ├── update.rb │ └── webhook.rb ├── permissions │ ├── get.rb │ └── list.rb ├── profiles │ ├── create.rb │ ├── delete.rb │ ├── get.rb │ ├── list-chargebacks.rb │ ├── list-methods.rb │ ├── list-payments.rb │ ├── list-refunds.rb │ ├── list.rb │ └── update.rb ├── refunds │ ├── create.rb │ ├── delete.rb │ ├── get-order.rb │ ├── get-payment.rb │ ├── get.rb │ └── list.rb ├── settlements │ ├── get.rb │ ├── list-captures.rb │ ├── list-chargebacks.rb │ ├── list-payments.rb │ ├── list-refunds.rb │ ├── list.rb │ ├── next.rb │ └── open.rb ├── shipments │ ├── create.rb │ ├── get-order.rb │ ├── get.rb │ ├── list.rb │ └── update.rb ├── subscriptions │ ├── create.rb │ ├── delete.rb │ ├── get.rb │ ├── list.rb │ └── update.rb └── terminals │ ├── get.rb │ └── list.rb ├── lib ├── cacert.pem ├── mollie-api-ruby.rb ├── mollie.rb └── mollie │ ├── amount.rb │ ├── balance.rb │ ├── balance │ ├── report.rb │ └── transaction.rb │ ├── base.rb │ ├── chargeback.rb │ ├── client.rb │ ├── customer.rb │ ├── customer │ ├── mandate.rb │ ├── payment.rb │ └── subscription.rb │ ├── exception.rb │ ├── invoice.rb │ ├── list.rb │ ├── method.rb │ ├── onboarding.rb │ ├── order.rb │ ├── order │ ├── line.rb │ ├── payment.rb │ ├── refund.rb │ └── shipment.rb │ ├── organization.rb │ ├── partner.rb │ ├── payment.rb │ ├── payment │ ├── capture.rb │ ├── chargeback.rb │ └── refund.rb │ ├── payment_link.rb │ ├── permission.rb │ ├── profile.rb │ ├── refund.rb │ ├── settlement.rb │ ├── settlement │ ├── capture.rb │ ├── chargeback.rb │ ├── payment.rb │ └── refund.rb │ ├── subscription.rb │ ├── terminal.rb │ ├── util.rb │ └── version.rb ├── mollie-api-ruby.gemspec └── test ├── fixtures ├── balances │ ├── get.json │ ├── list.json │ ├── list_transactions.json │ └── report.json ├── captures │ ├── get.json │ └── list.json ├── customer │ ├── get.json │ ├── list-payments-next.json │ └── list-payments.json ├── methods │ ├── all.json │ └── get-includes-pricing.json ├── onboarding │ ├── me.json │ └── submit.json ├── orders │ ├── cancel_line.json │ ├── cancel_line_qty.json │ ├── create.json │ ├── create_payment.json │ ├── create_refund.json │ ├── get.json │ ├── get_embedded_resources.json │ ├── list.json │ ├── list_refunds.json │ ├── refund.json │ ├── refund_all.json │ ├── update.json │ └── update_line.json ├── organizations │ └── partner.json ├── payment_links │ ├── create.json │ ├── get.json │ ├── list-payments.json │ ├── list.json │ └── update.json ├── payments │ ├── get.json │ └── get_embedded_resources.json ├── refunds │ └── get.json ├── shipments │ ├── create.json │ ├── get.json │ ├── list.json │ └── update.json ├── subscriptions │ ├── get.json │ └── get_payments.json └── terminals │ ├── get.json │ └── list.json ├── helper.rb ├── mollie ├── amount_test.rb ├── balance │ └── transaction_test.rb ├── balance_test.rb ├── base_test.rb ├── chargeback_test.rb ├── client_test.rb ├── customer │ ├── mandate_test.rb │ ├── payment_test.rb │ └── subscription_test.rb ├── customer_test.rb ├── exception_test.rb ├── invoice_test.rb ├── list_test.rb ├── method_test.rb ├── onboarding_test.rb ├── order │ ├── create_payment_test.rb │ ├── line_test.rb │ └── shipment_test.rb ├── order_test.rb ├── organization_test.rb ├── partner_test.rb ├── payment │ ├── capture_test.rb │ ├── chargeback_test.rb │ └── refund_test.rb ├── payment_link_test.rb ├── payment_test.rb ├── permission_test.rb ├── profile_test.rb ├── refund_test.rb ├── settlement │ ├── chargeback_test.rb │ ├── payment_test.rb │ └── refund_test.rb ├── settlement_test.rb ├── terminal_test.rb └── util_test.rb └── run-test.rb /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | test: 11 | 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3'] 16 | 17 | name: Ruby (${{ matrix.ruby-version }}) 18 | steps: 19 | - uses: actions/checkout@v2 20 | - name: Set up Ruby 21 | uses: ruby/setup-ruby@v1 22 | with: 23 | ruby-version: ${{ matrix.ruby-version }} 24 | - name: Run tests 25 | run: bundle install && bundle exec rake test 26 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "master" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "master" ] 20 | schedule: 21 | - cron: '30 20 * * 4' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'ruby' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v2 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v2 73 | -------------------------------------------------------------------------------- /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: Publish gem 2 | 3 | on: 4 | push: 5 | tags: 6 | - v[0-9]+.[0-9]+.[0-9]+* 7 | 8 | jobs: 9 | publish: 10 | name: Push gem to RubyGems.org 11 | runs-on: ubuntu-latest 12 | 13 | permissions: 14 | id-token: write # IMPORTANT: this permission is mandatory for trusted publishing 15 | contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag 16 | 17 | steps: 18 | # Set up 19 | - uses: actions/checkout@v4 20 | - name: Set up Ruby 21 | uses: ruby/setup-ruby@v1 22 | with: 23 | bundler-cache: true 24 | ruby-version: ruby 25 | 26 | # Release 27 | - uses: rubygems/release-gem@v1 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | .DS_Store 3 | mollie-api-ruby*.gem 4 | Gemfile.lock 5 | .ruby-gemset 6 | /mk-ca-bundle.pl 7 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | inherit_from: .rubocop_todo.yml 2 | 3 | Lint/UselessAssignment: 4 | Exclude: 5 | - 'examples/**/*' 6 | 7 | # Configuration parameters: AllowedVariables. 8 | Style/GlobalVars: 9 | Exclude: 10 | - 'test/run-test.rb' 11 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2018-08-19 13:42:13 +0200 using RuboCop version 0.58.0. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 1 10 | # Configuration parameters: Include. 11 | # Include: **/*.gemspec 12 | Gemspec/RequiredRubyVersion: 13 | Exclude: 14 | - 'mollie-api-ruby.gemspec' 15 | 16 | # Offense count: 45 17 | Lint/DuplicateMethods: 18 | Exclude: 19 | - 'lib/mollie/amount.rb' 20 | - 'lib/mollie/chargeback.rb' 21 | - 'lib/mollie/client.rb' 22 | - 'lib/mollie/customer.rb' 23 | - 'lib/mollie/customer/mandate.rb' 24 | - 'lib/mollie/customer/subscription.rb' 25 | - 'lib/mollie/invoice.rb' 26 | - 'lib/mollie/order.rb' 27 | - 'lib/mollie/order/line.rb' 28 | - 'lib/mollie/order/shipment.rb' 29 | - 'lib/mollie/payment/capture.rb' 30 | - 'lib/mollie/organization.rb' 31 | - 'lib/mollie/payment.rb' 32 | - 'lib/mollie/profile.rb' 33 | - 'lib/mollie/refund.rb' 34 | - 'lib/mollie/settlement.rb' 35 | 36 | # Offense count: 15 37 | Metrics/AbcSize: 38 | Max: 227 39 | 40 | # Offense count: 7 41 | # Configuration parameters: CountComments. 42 | Metrics/ClassLength: 43 | Max: 295 44 | Exclude: 45 | - 'test/**/*' 46 | 47 | # Offense count: 1 48 | Metrics/CyclomaticComplexity: 49 | Max: 13 50 | 51 | # Offense count: 37 52 | # Configuration parameters: CountComments. 53 | Metrics/MethodLength: 54 | Max: 140 55 | 56 | # Offense count: 1 57 | Metrics/PerceivedComplexity: 58 | Max: 10 59 | 60 | # Offense count: 1 61 | # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. 62 | # AllowedNames: io, id, to, by, on, in, at 63 | Naming/UncommunicativeMethodParamName: 64 | Exclude: 65 | - 'lib/mollie/client.rb' 66 | 67 | # Offense count: 3 68 | # Cop supports --auto-correct. 69 | # Configuration parameters: EnforcedStyle. 70 | # SupportedStyles: braces, no_braces, context_dependent 71 | Style/BracesAroundHashParameters: 72 | Exclude: 73 | - 'test/mollie/client_test.rb' 74 | 75 | # Offense count: 21 76 | Style/Documentation: 77 | Enabled: false 78 | 79 | # Offense count: 2 80 | Style/DoubleNegation: 81 | Exclude: 82 | - 'lib/mollie/base.rb' 83 | - 'lib/mollie/chargeback.rb' 84 | 85 | # Offense count: 4 86 | # Cop supports --auto-correct. 87 | # Configuration parameters: EnforcedStyle, AllowInnerSlashes. 88 | # SupportedStyles: slashes, percent_r, mixed 89 | Style/RegexpLiteral: 90 | Exclude: 91 | - 'lib/mollie/util.rb' 92 | - 'test/mollie/client_test.rb' 93 | 94 | # Offense count: 164 95 | # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. 96 | # URISchemes: http, https 97 | Metrics/LineLength: 98 | Max: 157 99 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Mollie B.V. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | lib/cacert.pem: certdata.txt 2 | mv ca-bundle.crt lib/cacert.pem 3 | rm certdata.txt 4 | 5 | mk-ca-bundle.pl: 6 | curl -q https://raw.githubusercontent.com/curl/curl/master/lib/mk-ca-bundle.pl --output mk-ca-bundle.pl 7 | chmod +x mk-ca-bundle.pl 8 | 9 | certdata.txt: mk-ca-bundle.pl 10 | ./mk-ca-bundle.pl -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | 3 | task default: %w[test] 4 | 5 | task :test do 6 | ruby 'test/run-test.rb' 7 | end 8 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bundler/setup' 4 | require 'mollie' 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require 'irb' 14 | require 'pp' 15 | IRB.start(__FILE__) 16 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /docs/migration_v2_2_x.md: -------------------------------------------------------------------------------- 1 | # Migration from v2.2.x 2 | 3 | The version 2.2.x used a client that contained methods to call API methods on the mollie servers. 4 | The responses were converted in to Mollie objects and attributes could be retrieved. 5 | Version 3.1.x uses a more Resource oriented approach that fits better with the Active Record principle. 6 | Instead of calling the methods on the client, you now use the Resource class or instance to call the API methods. 7 | 8 | You can now require the mollie client by using the gem name. 9 | If you are using bundler and Rails you don't even need to require it anymore. 10 | 11 | ```ruby 12 | # require 'mollie/api/client' 13 | require 'mollie-api-ruby' 14 | ``` 15 | 16 | Instead of creating a client with an API key, the client is now stored as a threadsafe singleton object. 17 | Configuration can now be simplified by adding a global configure block in a Rails initializer or a Rack loader file. 18 | 19 | ```ruby 20 | # mollie = Mollie::API::Client.new('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM') 21 | 22 | # config/initializers/mollie.rb or in your app.rb 23 | Mollie::Client.configure do |config| 24 | config.api_key = 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' 25 | end 26 | 27 | # You may also pass a specific API key in the params for each request. 28 | payment = Mollie::Payment.get(api_key: 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM') 29 | 30 | # Or in a Rails around filter 31 | around_action :set_mollie_key 32 | 33 | def set_mollie_key 34 | Mollie::Client.with_api_key('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM') do 35 | yield 36 | end 37 | end 38 | 39 | ``` 40 | 41 | Change the client calls to Resource calls 42 | 43 | ```ruby 44 | # mollie = Mollie::API::Client.new('test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM') 45 | # payment = mollie.payments.create( 46 | # amount: 10.00, 47 | # description: 'My first API payment', 48 | # redirect_url: 'https://webshop.example.org/order/12345/', 49 | # webhook_url: 'https://webshop.example.org/mollie-webhook/' 50 | #) 51 | 52 | payment = Mollie::Payment.create( 53 | amount: { value: '10.00', currency: 'EUR' }, 54 | description: 'My first API payment', 55 | redirect_url: 'https://webshop.example.org/order/12345/', 56 | webhook_url: 'https://webshop.example.org/mollie-webhook/' 57 | ) 58 | ``` 59 | 60 | The resources created are similar to the old resources but have an extra option to retrieve nested resources 61 | 62 | ```ruby 63 | # payment = mollie.payments.get(payment.id) 64 | # refund = mollie.payments_refunds.with(payment).create 65 | payment = Mollie::Payment.get("id") 66 | refund = payment.refunds.create({ amount: '10.00', currency: 'EUR' }) 67 | ``` 68 | -------------------------------------------------------------------------------- /examples/balances/get-primary.rb: -------------------------------------------------------------------------------- 1 | primary_balance = Mollie::Balance.primary 2 | -------------------------------------------------------------------------------- /examples/balances/get-report.rb: -------------------------------------------------------------------------------- 1 | balance = Mollie::Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH") 2 | report = balance.report 3 | -------------------------------------------------------------------------------- /examples/balances/get.rb: -------------------------------------------------------------------------------- 1 | balance = Mollie::Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH") 2 | -------------------------------------------------------------------------------- /examples/balances/list-transactions.rb: -------------------------------------------------------------------------------- 1 | balance = Mollie::Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH") 2 | transactions = balance.transactions 3 | -------------------------------------------------------------------------------- /examples/balances/list.rb: -------------------------------------------------------------------------------- 1 | balances = Mollie::Balance.all 2 | -------------------------------------------------------------------------------- /examples/captures/get-payment.rb: -------------------------------------------------------------------------------- 1 | capture = Mollie::Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 2 | payment = capture.payment 3 | -------------------------------------------------------------------------------- /examples/captures/get-settlement.rb: -------------------------------------------------------------------------------- 1 | capture = Mollie::Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 2 | settlement = capture.settlement 3 | -------------------------------------------------------------------------------- /examples/captures/get-shipment.rb: -------------------------------------------------------------------------------- 1 | capture = Mollie::Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 2 | shipment = capture.shipment 3 | -------------------------------------------------------------------------------- /examples/captures/get.rb: -------------------------------------------------------------------------------- 1 | capture = Mollie::Payment::Capture.get( 2 | 'cpt_4qqhO89gsT', 3 | payment_id: 'tr_WDqYK6vllg' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/captures/list.rb: -------------------------------------------------------------------------------- 1 | capture = Mollie::Payment::Capture.all(payment_id: 'tr_WDqYK6vllg') 2 | -------------------------------------------------------------------------------- /examples/chargebacks/get.rb: -------------------------------------------------------------------------------- 1 | chargeback = Mollie::Payment::Chargeback.get( 2 | 'chb_n9z0tp', 3 | payment_id: 'tr_7UhSN1zuXS' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/chargebacks/list.rb: -------------------------------------------------------------------------------- 1 | chargebacks = Mollie::Chargeback.all 2 | -------------------------------------------------------------------------------- /examples/connect/authorize.rb: -------------------------------------------------------------------------------- 1 | require 'rack/oauth2' 2 | 3 | client = Rack::OAuth2::Client.new( 4 | identifier: client_id, 5 | secret: secret, 6 | state: 'some_state', 7 | redirect_uri: redirect_url, 8 | authorization_endpoint: 'https://my.mollie.com/oauth2/authorize', 9 | token_endpoint: 'https://api.mollie.com/oauth2/tokens' 10 | ) 11 | 12 | redirect_to client.authorization_uri( 13 | state: 'some_state', 14 | scope: 'payments.read refunds.write', 15 | approval_prompt: 'auto' 16 | ) 17 | -------------------------------------------------------------------------------- /examples/connect/tokens.rb: -------------------------------------------------------------------------------- 1 | require 'rack/oauth2' 2 | 3 | client = Rack::OAuth2::Client.new( 4 | identifier: client_id, 5 | secret: secret, 6 | state: 'some_state', 7 | redirect_uri: redirect_url, 8 | authorization_endpoint: 'https://my.mollie.com/oauth2/authorize', 9 | token_endpoint: 'https://api.mollie.com/oauth2/tokens' 10 | ) 11 | 12 | # Use the code returned as parameter on the redirect endpoint 13 | client.authorization_code = params['code'] 14 | client.access_token!.access_token 15 | -------------------------------------------------------------------------------- /examples/customers/create-payment.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Customer::Payment.create( 2 | customer_id: 'cst_8wmqcHMN4U', 3 | amount: { value: '10.00', currency: 'EUR' }, 4 | description: 'First payment', 5 | redirect_url: 'https://webshop.example.org/order/12345/' 6 | ) 7 | -------------------------------------------------------------------------------- /examples/customers/create.rb: -------------------------------------------------------------------------------- 1 | customer = Mollie::Customer.create( 2 | name: 'John', 3 | email: 'john@example.com', 4 | locale: 'en_US' 5 | ) 6 | -------------------------------------------------------------------------------- /examples/customers/delete.rb: -------------------------------------------------------------------------------- 1 | Mollie::Customer.delete('cst_8wmqcHMN4U') 2 | -------------------------------------------------------------------------------- /examples/customers/get.rb: -------------------------------------------------------------------------------- 1 | customer = Mollie::Customer.get('cst_8wmqcHMN4U') 2 | -------------------------------------------------------------------------------- /examples/customers/list-payments.rb: -------------------------------------------------------------------------------- 1 | payments = Mollie::Customer::Payment.all(customer_id: 'cst_8wmqcHMN4U') 2 | -------------------------------------------------------------------------------- /examples/customers/list.rb: -------------------------------------------------------------------------------- 1 | customers = Mollie::Customer.all 2 | -------------------------------------------------------------------------------- /examples/customers/update.rb: -------------------------------------------------------------------------------- 1 | customer = Mollie::Customer.update( 2 | 'cst_8wmqcHMN4U', 3 | email: 'otherjohn@example.com' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/invoices/get.rb: -------------------------------------------------------------------------------- 1 | invoice = Mollie::Invoice.get('inv_xBEbP9rvAq') 2 | -------------------------------------------------------------------------------- /examples/invoices/list.rb: -------------------------------------------------------------------------------- 1 | invoices = Mollie::Invoice.all 2 | -------------------------------------------------------------------------------- /examples/mandates/create.rb: -------------------------------------------------------------------------------- 1 | mandate = Mollie::Customer::Mandate.create( 2 | customer_id: 'cst_4qqhO89gsT', 3 | method: 'directdebit', 4 | consumer_name: 'John Doe', 5 | consumer_account: 'NL55INGB0000000000', 6 | consumer_bic: 'INGBNL2A', 7 | signature_date: '2018-05-07', 8 | mandate_reference: 'YOUR-COMPANY-MD13804' 9 | ) 10 | -------------------------------------------------------------------------------- /examples/mandates/delete.rb: -------------------------------------------------------------------------------- 1 | Mollie::Customer::Mandate.delete('mdt_h3gAaD5zP', customer_id: 'cst_4qqhO89gsT') 2 | -------------------------------------------------------------------------------- /examples/mandates/get.rb: -------------------------------------------------------------------------------- 1 | mandate = Mollie::Customer::Mandate.get('mdt_h3gAaD5zP', customer_id: 'cst_4qqhO89gsT') 2 | -------------------------------------------------------------------------------- /examples/mandates/list.rb: -------------------------------------------------------------------------------- 1 | mandates = Mollie::Customer::Mandate.all(customer_id: 'cst_4qqhO89gsT') 2 | -------------------------------------------------------------------------------- /examples/methods/get.rb: -------------------------------------------------------------------------------- 1 | method = Mollie::Method.get('ideal') 2 | 3 | # Include issuer details such as which iDEAL or gift card issuers are available 4 | method = Mollie::Method.get('ideal', include: 'issuers') 5 | -------------------------------------------------------------------------------- /examples/methods/list.rb: -------------------------------------------------------------------------------- 1 | # Retrieve all enabled payment methods 2 | methods = Mollie::Method.all 3 | 4 | # Filter by amount and currency 5 | methods = Mollie::Method.all(amount: { value: '100.00', currency: 'EUR' }) 6 | 7 | # Retrieve all payment methods that Mollie offers and can be activated by the Organization 8 | methods = Mollie::Method.all_available 9 | 10 | # Include issuer details such as which iDEAL or gift card issuers are available 11 | methods = Mollie::Method.all_available(include: "issuers") 12 | 13 | # Include pricing for each payment method 14 | methods = Mollie::Method.all_available(include: "pricing") 15 | 16 | # Include issuer details and pricing 17 | methods = Mollie::Method.all_available(include: "issuers,pricing") 18 | -------------------------------------------------------------------------------- /examples/onboarding/get.rb: -------------------------------------------------------------------------------- 1 | Mollie::Onboarding.me 2 | -------------------------------------------------------------------------------- /examples/onboarding/submit.rb: -------------------------------------------------------------------------------- 1 | Mollie::Onboarding.submit( 2 | organization: { 3 | name: "Mollie B.V.", 4 | address: { 5 | streetAndNumber: "Keizersgracht 313", 6 | postalCode: "1018 EE", 7 | city: "Amsterdam", 8 | country: "NL" 9 | }, 10 | registrationNumber: "30204462", 11 | vatNumber: "NL815839091B01" 12 | }, 13 | profile: { 14 | name: "Mollie", 15 | url: "https://www.mollie.com", 16 | email: "info@mollie.com", 17 | phone: "+31208202070", 18 | categoryCode: 6012 19 | } 20 | ) 21 | -------------------------------------------------------------------------------- /examples/orders/cancel-lines.rb: -------------------------------------------------------------------------------- 1 | order = Mollie::Order.get('ord_kEn1PlbGa') 2 | order.lines[0].cancel 3 | -------------------------------------------------------------------------------- /examples/orders/cancel.rb: -------------------------------------------------------------------------------- 1 | Mollie::Order.cancel('ord_kEn1PlbGa') 2 | 3 | # Cancel an order instance 4 | order = Mollie::Order.get('ord_kEn1PlbGa') 5 | order.cancel 6 | -------------------------------------------------------------------------------- /examples/orders/create-payment.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Order::Payment.create(order_id: "ord_kEn1PlbGa") 2 | -------------------------------------------------------------------------------- /examples/orders/create-refund.rb: -------------------------------------------------------------------------------- 1 | # Refund all order lines 2 | order = Mollie::Order.get('ord_kEn1PlbGa') 3 | refund = order.refund! 4 | 5 | # Refund a specific order line 6 | order = Mollie::Order.get('ord_kEn1PlbGa') 7 | refund = order.refund!( 8 | lines: [ 9 | { 10 | id: 'odl_dgtxyl', 11 | quantity: 1 12 | } 13 | ], 14 | description: 'Required quantity not in stock, refunding one photo book.' 15 | ) 16 | -------------------------------------------------------------------------------- /examples/orders/create.rb: -------------------------------------------------------------------------------- 1 | order = Mollie::Order.create( 2 | amount: { 3 | value: '1027.99', 4 | currency: 'EUR' 5 | }, 6 | billingAddress: { 7 | streetAndNumber: 'Keizersgracht 313', 8 | city: 'Amsterdam', 9 | region: 'Noord-Holland', 10 | postalCode: '1234AB', 11 | country: 'NL', 12 | title: 'Dhr', 13 | givenName: 'Piet', 14 | familyName: 'Mondriaan', 15 | email: 'piet@mondriaan.com', 16 | phone: '+31208202070' 17 | }, 18 | shippingAddress: { 19 | streetAndNumber: 'Prinsengracht 313', 20 | streetAdditional: '4th floor', 21 | city: 'Haarlem', 22 | region: 'Noord-Holland', 23 | postalCode: '5678AB', 24 | country: 'NL', 25 | title: 'Mr', 26 | givenName: 'Chuck', 27 | familyName: 'Norris', 28 | email: 'norris@chucknorrisfacts.net' 29 | }, 30 | metadata: { 31 | order_id: '1337', 32 | description: 'Lego cars' 33 | }, 34 | consumerDateOfBirth: '1958-01-31', 35 | locale: 'nl_NL', 36 | orderNumber: '1337', 37 | redirectUrl: 'https://example.org/redirect', 38 | webhookUrl: 'https://example.org/webhook', 39 | method: 'klarnapaylater', 40 | lines: [ 41 | { 42 | type: 'physical', 43 | sku: '5702016116977', 44 | name: 'LEGO 42083 Bugatti Chiron', 45 | productUrl: 'https://shop.lego.com/nl-NL/Bugatti-Chiron-42083', 46 | imageUrl: 'https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$', 47 | quantity: 2, 48 | vatRate: '21.00', 49 | unitPrice: { 50 | currency: 'EUR', 51 | value: '399.00' 52 | }, 53 | totalAmount: { 54 | currency: 'EUR', 55 | value: '698.00' 56 | }, 57 | discountAmount: { 58 | currency: 'EUR', 59 | value: '100.00' 60 | }, 61 | vatAmount: { 62 | currency: 'EUR', 63 | value: '121.14' 64 | } 65 | }, 66 | { 67 | type: 'physical', 68 | sku: '5702015594028', 69 | name: 'LEGO 42056 Porsche 911 GT3 RS', 70 | productUrl: 'https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056', 71 | imageUrl: 'https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$', 72 | quantity: 1, 73 | vatRate: '21.00', 74 | unitPrice: { 75 | currency: 'EUR', 76 | value: '329.99' 77 | }, 78 | totalAmount: { 79 | currency: 'EUR', 80 | value: '329.99' 81 | }, 82 | vatAmount: { 83 | currency: 'EUR', 84 | value: '57.27' 85 | } 86 | } 87 | ] 88 | ) 89 | -------------------------------------------------------------------------------- /examples/orders/get.rb: -------------------------------------------------------------------------------- 1 | order = Mollie::Order.get("ord_kEn1PlbGa") 2 | 3 | # Embed related resources 4 | order = Mollie::Order.get("ord_kEn1PlbGa", embed: "payments,refunds,shipments") 5 | -------------------------------------------------------------------------------- /examples/orders/list-refunds.rb: -------------------------------------------------------------------------------- 1 | refunds = Order::Refund.all(order_id: 'ord_kEn1PlbGa') 2 | -------------------------------------------------------------------------------- /examples/orders/list.rb: -------------------------------------------------------------------------------- 1 | orders = Mollie::Order.all 2 | -------------------------------------------------------------------------------- /examples/orders/update-orderline.rb: -------------------------------------------------------------------------------- 1 | orderline_id = "odl_dgtxyl" 2 | 3 | order = Mollie::Order::Line.update( 4 | orderline_id, 5 | order_id: "ord_kEn1PlbGa", 6 | sku: "new-sku-12345678" 7 | ) 8 | -------------------------------------------------------------------------------- /examples/orders/update.rb: -------------------------------------------------------------------------------- 1 | order = Mollie::Order.update( 2 | 'ord_kEn1PlbGa', 3 | billingAddress: { 4 | city: 'Amsterdam', 5 | country: 'NL', 6 | email: 'piet@mondriaan.com', 7 | familyName: 'Mondriaan', 8 | givenName: 'Piet', 9 | phone: '+31208202070', 10 | postalCode: '1234AB', 11 | region: 'Noord-Holland', 12 | streetAndNumber: 'Keizersgracht 313', 13 | title: 'Dhr' 14 | } 15 | ) 16 | -------------------------------------------------------------------------------- /examples/organisations/get-current.rb: -------------------------------------------------------------------------------- 1 | organization = Mollie::Organization.current 2 | -------------------------------------------------------------------------------- /examples/organisations/get-partner.rb: -------------------------------------------------------------------------------- 1 | partner = Mollie::Partner.current 2 | -------------------------------------------------------------------------------- /examples/organisations/get.rb: -------------------------------------------------------------------------------- 1 | organization = Mollie::Organization.get('org_1234567') 2 | -------------------------------------------------------------------------------- /examples/payment-links/create.rb: -------------------------------------------------------------------------------- 1 | payment_link = Mollie::PaymentLink.create( 2 | description: "Bicycle tires", 3 | amount: { currency: "EUR", value: "24.95" } 4 | ) 5 | 6 | -------------------------------------------------------------------------------- /examples/payment-links/delete.rb: -------------------------------------------------------------------------------- 1 | Mollie::PaymentLink.delete("pl_4Y0eZitmBnQ6IDoMqZQKh") 2 | -------------------------------------------------------------------------------- /examples/payment-links/get.rb: -------------------------------------------------------------------------------- 1 | payment_link = Mollie::PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh") 2 | -------------------------------------------------------------------------------- /examples/payment-links/list-payments.rb: -------------------------------------------------------------------------------- 1 | payment_link = Mollie::PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh") 2 | payments = payment_link.payments 3 | -------------------------------------------------------------------------------- /examples/payment-links/list.rb: -------------------------------------------------------------------------------- 1 | payment_links = Mollie::PaymentLink.all 2 | -------------------------------------------------------------------------------- /examples/payment-links/update.rb: -------------------------------------------------------------------------------- 1 | payment_link = Mollie::PaymentLink.update( 2 | "pl_4Y0eZitmBnQ6IDoMqZQKh", 3 | description: "Bicycle tires", 4 | archived: true 5 | ) 6 | -------------------------------------------------------------------------------- /examples/payments/create.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.create( 2 | amount: { value: '10.00', currency: 'EUR' }, 3 | description: 'My first payment', 4 | redirect_url: 'https://webshop.example.org/order/12345/', 5 | webhook_url: 'https://webshop.example.org/payments/webhook/', 6 | metadata: { 7 | order_id: '12345' 8 | } 9 | ) 10 | -------------------------------------------------------------------------------- /examples/payments/delete.rb: -------------------------------------------------------------------------------- 1 | Mollie::Payment.delete('tr_7UhSN1zuXS') 2 | -------------------------------------------------------------------------------- /examples/payments/get-customer.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.get('tr_7UhSN1zuXS') 2 | customer = payment.customer 3 | -------------------------------------------------------------------------------- /examples/payments/get-mandate.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.get('tr_7UhSN1zuXS') 2 | mandate = payment.mandate 3 | -------------------------------------------------------------------------------- /examples/payments/get-order.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.get('tr_7UhSN1zuXS') 2 | order = payment.order 3 | -------------------------------------------------------------------------------- /examples/payments/get-settlement.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.get('tr_7UhSN1zuXS') 2 | settlement = payment.settlement 3 | -------------------------------------------------------------------------------- /examples/payments/get-subscription.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.get('tr_7UhSN1zuXS') 2 | subscription = payment.subscription 3 | -------------------------------------------------------------------------------- /examples/payments/get.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.get('tr_7UhSN1zuXS') 2 | 3 | # With embedded resources 4 | payment = Mollie::Payment.get('tr_7UhSN1zuXS', embed: 'captures,chargebacks,refunds') 5 | -------------------------------------------------------------------------------- /examples/payments/list.rb: -------------------------------------------------------------------------------- 1 | payments = Mollie::Payment.all 2 | -------------------------------------------------------------------------------- /examples/payments/update.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.update( 2 | 'tr_7UhSN1zuXS', 3 | description: 'Order #98765', 4 | metadata: { 5 | order_id: '98765' 6 | } 7 | ) 8 | -------------------------------------------------------------------------------- /examples/payments/webhook.rb: -------------------------------------------------------------------------------- 1 | payment = Mollie::Payment.get('tr_7UhSN1zuXS') 2 | 3 | if payment.paid? 4 | # 5 | # At this point you'd probably want to start the process of delivering the 6 | # product to the customer. 7 | # 8 | elsif !payment.open? 9 | # 10 | # The payment isn't paid and isn't open anymore. We can assume it was aborted. 11 | # 12 | end 13 | -------------------------------------------------------------------------------- /examples/permissions/get.rb: -------------------------------------------------------------------------------- 1 | permission = Mollie::Permission.get('payments.read') 2 | -------------------------------------------------------------------------------- /examples/permissions/list.rb: -------------------------------------------------------------------------------- 1 | permissions = Mollie::Permission.all 2 | -------------------------------------------------------------------------------- /examples/profiles/create.rb: -------------------------------------------------------------------------------- 1 | profile = Mollie::Profile.create( 2 | name: 'My website name', 3 | website: 'https://www.mywebsite.com', 4 | email: 'info@mywebsite.com', 5 | phone: '+31208202070', 6 | business_category: 'OTHER_MERCHANDISE', 7 | mode: 'live' 8 | ) 9 | -------------------------------------------------------------------------------- /examples/profiles/delete.rb: -------------------------------------------------------------------------------- 1 | Mollie::Profile.delete('pfl_v9hTwCvYqw') 2 | -------------------------------------------------------------------------------- /examples/profiles/get.rb: -------------------------------------------------------------------------------- 1 | profile = Mollie::Profile.get('pfl_v9hTwCvYqw') 2 | -------------------------------------------------------------------------------- /examples/profiles/list-chargebacks.rb: -------------------------------------------------------------------------------- 1 | profile = Profile.get('pfl_v9hTwCvYqw') 2 | chargebacks = profile.chargebacks 3 | -------------------------------------------------------------------------------- /examples/profiles/list-methods.rb: -------------------------------------------------------------------------------- 1 | profile = Profile.get('pfl_v9hTwCvYqw') 2 | methods = profile.methods 3 | -------------------------------------------------------------------------------- /examples/profiles/list-payments.rb: -------------------------------------------------------------------------------- 1 | profile = Profile.get('pfl_v9hTwCvYqw') 2 | payments = profile.payments 3 | -------------------------------------------------------------------------------- /examples/profiles/list-refunds.rb: -------------------------------------------------------------------------------- 1 | profile = Profile.get('pfl_v9hTwCvYqw') 2 | refunds = profile.refunds 3 | -------------------------------------------------------------------------------- /examples/profiles/list.rb: -------------------------------------------------------------------------------- 1 | profiles = Mollie::Profile.all 2 | -------------------------------------------------------------------------------- /examples/profiles/update.rb: -------------------------------------------------------------------------------- 1 | profile = Mollie::Profile.update( 2 | 'pfl_v9hTwCvYqw', 3 | name: 'My website name', 4 | website: 'https://www.mywebsite.com' 5 | ) 6 | -------------------------------------------------------------------------------- /examples/refunds/create.rb: -------------------------------------------------------------------------------- 1 | refund = Mollie::Payment::Refund.create( 2 | payment_id: 'tr_7UhSN1zuXS', 3 | amount: { value: '5.00', currency: 'EUR' }, 4 | description: 'Did not like it' 5 | ) 6 | -------------------------------------------------------------------------------- /examples/refunds/delete.rb: -------------------------------------------------------------------------------- 1 | Mollie::Payment::Refund.delete( 2 | 're_4qqhO89gsT', 3 | payment_id: 'tr_7UhSN1zuXS' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/refunds/get-order.rb: -------------------------------------------------------------------------------- 1 | refund = Mollie::Payment::Refund.get('re_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 2 | order = refund.order 3 | -------------------------------------------------------------------------------- /examples/refunds/get-payment.rb: -------------------------------------------------------------------------------- 1 | refund = Mollie::Payment::Refund.get('re_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 2 | payment = refund.payment 3 | -------------------------------------------------------------------------------- /examples/refunds/get.rb: -------------------------------------------------------------------------------- 1 | refund = Mollie::Payment::Refund.get( 2 | 're_4qqhO89gsT', 3 | payment_id: 'tr_7UhSN1zuXS' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/refunds/list.rb: -------------------------------------------------------------------------------- 1 | refunds = Mollie::Refund.all 2 | -------------------------------------------------------------------------------- /examples/settlements/get.rb: -------------------------------------------------------------------------------- 1 | settlement = Mollie::Settlement.get('stl_jDk30akdN') 2 | -------------------------------------------------------------------------------- /examples/settlements/list-captures.rb: -------------------------------------------------------------------------------- 1 | captures = Mollie::Settlement::Capture.all(settlement_id: 'stl_jDk30akdN') 2 | -------------------------------------------------------------------------------- /examples/settlements/list-chargebacks.rb: -------------------------------------------------------------------------------- 1 | chargebacks = Mollie::Settlement::Chargeback.all(settlement_id: 'stl_jDk30akdN') 2 | -------------------------------------------------------------------------------- /examples/settlements/list-payments.rb: -------------------------------------------------------------------------------- 1 | payments = Mollie::Settlement::Payment.all(settlement_id: 'stl_jDk30akdN') 2 | -------------------------------------------------------------------------------- /examples/settlements/list-refunds.rb: -------------------------------------------------------------------------------- 1 | refunds = Mollie::Settlement::Refund.all(settlement_id: 'stl_jDk30akdN') 2 | -------------------------------------------------------------------------------- /examples/settlements/list.rb: -------------------------------------------------------------------------------- 1 | settlements = Mollie::Settlement.all 2 | -------------------------------------------------------------------------------- /examples/settlements/next.rb: -------------------------------------------------------------------------------- 1 | settlement = Mollie::Settlement.next 2 | -------------------------------------------------------------------------------- /examples/settlements/open.rb: -------------------------------------------------------------------------------- 1 | settlement = Mollie::Settlement.open 2 | -------------------------------------------------------------------------------- /examples/shipments/create.rb: -------------------------------------------------------------------------------- 1 | shipment = Mollie::Order::Shipment.create( 2 | order_id: 'ord_kEn1PlbGa', 3 | lines: [ 4 | { 5 | id: 'odl_dgtxyl', 6 | quantity: 1 7 | }, 8 | { 9 | id: 'odl_jp31jz' 10 | } 11 | ], 12 | tracking: { 13 | carrier: 'PostNL', 14 | code: '3SKABA000000000', 15 | url: 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C' 16 | } 17 | ) 18 | -------------------------------------------------------------------------------- /examples/shipments/get-order.rb: -------------------------------------------------------------------------------- 1 | shipment = Mollie::Order::Shipment.get('shp_3wmsgCJN4U', order_id: 'ord_kEn1PlbGa') 2 | order = shipment.order 3 | -------------------------------------------------------------------------------- /examples/shipments/get.rb: -------------------------------------------------------------------------------- 1 | shipment = Mollie::Order::Shipment.get( 2 | 'shp_3wmsgCJN4U', 3 | order_id: 'ord_kEn1PlbGa' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/shipments/list.rb: -------------------------------------------------------------------------------- 1 | shipments = Mollie::Order::Shipment.all(order_id: 'ord_kEn1PlbGa') 2 | -------------------------------------------------------------------------------- /examples/shipments/update.rb: -------------------------------------------------------------------------------- 1 | shipment = Mollie::Order::Shipment.update( 2 | 'shp_3wmsgCJN4U', 3 | order_id: 'ord_kEn1PlbGa', 4 | tracking: { 5 | carrier: 'PostNL', 6 | code: '3SKABA000000000', 7 | url: 'http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C' 8 | } 9 | ) 10 | -------------------------------------------------------------------------------- /examples/subscriptions/create.rb: -------------------------------------------------------------------------------- 1 | subscription = Mollie::Customer::Subscription.create( 2 | customer_id: 'cst_5a2pPrwaWy', 3 | amount: { value: '20.00', currency: 'EUR' }, 4 | times: 4, 5 | interval: '3 months', 6 | description: 'Quarterly payment', 7 | metadata: { my_field: 'value' }, 8 | webhook_url: 'https://webshop.example.org/payments/webhook/', 9 | ) 10 | -------------------------------------------------------------------------------- /examples/subscriptions/delete.rb: -------------------------------------------------------------------------------- 1 | Mollie::Customer::Subscription.delete( 2 | 'sub_rVKGtNd6s3', 3 | customer_id: 'cst_5a2pPrwaWy' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/subscriptions/get.rb: -------------------------------------------------------------------------------- 1 | subscription = Mollie::Customer::Subscription.get( 2 | 'sub_rVKGtNd6s3', 3 | customer_id: 'cst_5a2pPrwaWy' 4 | ) 5 | -------------------------------------------------------------------------------- /examples/subscriptions/list.rb: -------------------------------------------------------------------------------- 1 | # List all subscriptions 2 | subscriptions = Mollie::Subscription.all 3 | 4 | # List all subscriptions for a customer 5 | subscriptions = Mollie::Customer::Subscription.all(customer_id: 'cst_5a2pPrwaWy') 6 | -------------------------------------------------------------------------------- /examples/subscriptions/update.rb: -------------------------------------------------------------------------------- 1 | subscription = Mollie::Customer::Subscription.update( 2 | 'sub_rVKGtNd6s3', 3 | customer_id: 'cst_5a2pPrwaWy', 4 | amount: { value: '20.00', currency: 'EUR' } 5 | ) 6 | -------------------------------------------------------------------------------- /examples/terminals/get.rb: -------------------------------------------------------------------------------- 1 | terminal = Mollie::Terminal.get("term_7MgL4wea46qkRcoTZjWEH") 2 | -------------------------------------------------------------------------------- /examples/terminals/list.rb: -------------------------------------------------------------------------------- 1 | terminals = Mollie::Terminal.all 2 | -------------------------------------------------------------------------------- /lib/mollie-api-ruby.rb: -------------------------------------------------------------------------------- 1 | require_relative './mollie' 2 | -------------------------------------------------------------------------------- /lib/mollie.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'time' 3 | require 'ostruct' 4 | require 'bigdecimal' 5 | require 'net/https' 6 | 7 | module Mollie 8 | end 9 | 10 | require 'mollie/exception' 11 | require 'mollie/util' 12 | require 'mollie/version' 13 | 14 | require 'mollie/base' 15 | require 'mollie/amount' 16 | require 'mollie/balance' 17 | require 'mollie/chargeback' 18 | require 'mollie/client' 19 | require 'mollie/customer' 20 | require 'mollie/invoice' 21 | require 'mollie/list' 22 | require 'mollie/method' 23 | require 'mollie/order' 24 | require 'mollie/organization' 25 | require 'mollie/partner' 26 | require 'mollie/payment' 27 | require 'mollie/payment_link' 28 | require 'mollie/permission' 29 | require 'mollie/profile' 30 | require 'mollie/refund' 31 | require 'mollie/settlement' 32 | require 'mollie/subscription' 33 | require 'mollie/terminal' 34 | 35 | require 'mollie/balance/report' 36 | require 'mollie/balance/transaction' 37 | require 'mollie/customer/mandate' 38 | require 'mollie/customer/payment' 39 | require 'mollie/customer/subscription' 40 | require 'mollie/onboarding' 41 | require 'mollie/order/line' 42 | require 'mollie/order/payment' 43 | require 'mollie/order/refund' 44 | require 'mollie/order/shipment' 45 | require 'mollie/payment/capture' 46 | require 'mollie/payment/chargeback' 47 | require 'mollie/payment/refund' 48 | require 'mollie/settlement/capture' 49 | require 'mollie/settlement/chargeback' 50 | require 'mollie/settlement/payment' 51 | require 'mollie/settlement/refund' 52 | -------------------------------------------------------------------------------- /lib/mollie/amount.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Amount < Base 3 | attr_accessor :value, :currency 4 | 5 | def initialize(attributes) 6 | super unless attributes.nil? 7 | end 8 | 9 | def value=(val) 10 | @value = BigDecimal(val.to_s) 11 | end 12 | 13 | def to_h 14 | { 15 | value: attributes['value'], 16 | currency: attributes['currency'] 17 | } 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/mollie/balance.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Balance < Base 3 | attr_accessor :id, 4 | :mode, 5 | :currency, 6 | :description, 7 | :status, 8 | :transfer_frequency, 9 | :transfer_reference, 10 | :_links 11 | 12 | attr_reader :transfer_threshold, 13 | :transfer_destination, 14 | :available_amount, 15 | :pending_amount, 16 | :created_at 17 | 18 | alias links _links 19 | 20 | def self.primary(options = {}) 21 | get('primary', options) 22 | end 23 | 24 | def transfer_threshold=(amount) 25 | @transfer_threshold = Mollie::Amount.new(amount) 26 | end 27 | 28 | def transfer_destination=(transfer_destination) 29 | @transfer_destination = OpenStruct.new(transfer_destination) if transfer_destination.is_a?(Hash) 30 | end 31 | 32 | def available_amount=(amount) 33 | @available_amount = Mollie::Amount.new(amount) 34 | end 35 | 36 | def pending_amount=(amount) 37 | @pending_amount = Mollie::Amount.new(amount) 38 | end 39 | 40 | def created_at=(created_at) 41 | @created_at = Time.parse(created_at.to_s) 42 | end 43 | 44 | def report(options = {}) 45 | response = Client.instance.perform_http_call("GET", "balances/#{id}", "report", {}, options) 46 | Balance::Report.new(response) 47 | end 48 | 49 | def transactions(options = {}) 50 | Balance::Transaction.all(options.merge(balance_id: id)) 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/mollie/balance/report.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Balance 3 | class Report < Base 4 | attr_accessor :balance_id, 5 | :time_zone, 6 | :grouping, 7 | :totals, 8 | :_links 9 | 10 | attr_reader :from, 11 | :until 12 | 13 | alias links _links 14 | 15 | def from=(from) 16 | @from = Date.parse(from) 17 | end 18 | 19 | def until=(until_date) 20 | # `until` is a reserved keyword 21 | @until = Date.parse(until_date) 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/mollie/balance/transaction.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Balance 3 | class Transaction < Base 4 | attr_accessor :id, 5 | :type, 6 | :_links 7 | 8 | attr_reader :result_amount, 9 | :initial_amount, 10 | :deductions, 11 | :context, 12 | :created_at 13 | 14 | alias links _links 15 | 16 | def self.embedded_resource_name 17 | "balance_transactions" 18 | end 19 | 20 | def result_amount=(amount) 21 | @result_amount = Mollie::Amount.new(amount) 22 | end 23 | 24 | def initial_amount=(amount) 25 | @initial_amount = Mollie::Amount.new(amount) 26 | end 27 | 28 | def deductions=(amount) 29 | @deductions = Mollie::Amount.new(amount) 30 | end 31 | 32 | def context=(context) 33 | @context = OpenStruct.new(context) if context.is_a?(Hash) 34 | end 35 | 36 | def created_at=(created_at) 37 | @created_at = Time.parse(created_at.to_s) 38 | end 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/mollie/base.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Base 3 | attr_reader :attributes 4 | 5 | def initialize(attributes) 6 | @attributes = attributes 7 | assign_attributes(attributes) 8 | end 9 | 10 | def assign_attributes(attributes) 11 | attributes.each do |key, value| 12 | public_send("#{key}=", value) if respond_to?("#{key}=") 13 | end 14 | end 15 | 16 | class << self 17 | def create(data = {}, options = {}) 18 | request('POST', nil, data, options) do |response| 19 | new(response) 20 | end 21 | end 22 | 23 | def all(options = {}) 24 | id = nil 25 | data = {} 26 | 27 | request('GET', id, data, options) do |response| 28 | Mollie::List.new(response, self) 29 | end 30 | end 31 | 32 | def get(id, options = {}) 33 | raise Mollie::Exception, "Invalid resource ID: #{id.inspect}" if id.nil? || id.strip.empty? 34 | 35 | request('GET', id, {}, options) do |response| 36 | new(response) 37 | end 38 | end 39 | 40 | def update(id, data = {}) 41 | request('PATCH', id, data) do |response| 42 | new(response) 43 | end 44 | end 45 | 46 | def delete(id, options = {}) 47 | request('DELETE', id, options) 48 | end 49 | alias cancel delete 50 | 51 | def request(method, id = 0, data = {}, options = {}) 52 | parent_id = options.delete(self.parent_id) || data.delete(self.parent_id) 53 | response = Mollie::Client.instance.perform_http_call(method, resource_name(parent_id), id, data, options) 54 | yield(response) if block_given? 55 | end 56 | 57 | def id_param 58 | "#{name.downcase.split('::')[-1]}_id".to_sym 59 | end 60 | 61 | def parent_id 62 | "#{name.downcase.split('::')[-2]}_id".to_sym 63 | end 64 | 65 | def resource_name(parent_id = nil) 66 | path = name.downcase.split('::').slice(1..-1).map(&Util.method(:pluralize)) 67 | 68 | if path.size == 2 && parent_id 69 | path.join("/#{parent_id}/") 70 | else 71 | path.last 72 | end 73 | end 74 | 75 | alias_method :embedded_resource_name, :resource_name 76 | end 77 | 78 | def update(data = {}) 79 | if (parent_id = attributes[self.class.parent_id]) 80 | data[self.class.parent_id] = parent_id 81 | end 82 | 83 | if (resource = self.class.update(id, data)) 84 | !!assign_attributes(resource.attributes) 85 | else 86 | resource 87 | end 88 | end 89 | 90 | def delete(options = {}) 91 | if (parent_id = attributes[self.class.parent_id]) 92 | options[self.class.parent_id] = parent_id 93 | end 94 | self.class.delete(id, options) 95 | end 96 | alias cancel delete 97 | end 98 | end 99 | -------------------------------------------------------------------------------- /lib/mollie/chargeback.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Chargeback < Base 3 | attr_accessor :id, 4 | :payment, 5 | :amount, 6 | :settlement_amount, 7 | :created_at, 8 | :payment_id, 9 | :reversed_at, 10 | :_links 11 | 12 | alias links _links 13 | 14 | def reversed? 15 | !!reversed_at 16 | end 17 | 18 | def reversed_at=(reversed_at) 19 | @reversed_at = begin 20 | Time.parse(reversed_at) 21 | rescue StandardError 22 | nil 23 | end 24 | end 25 | 26 | def created_at=(created_at) 27 | @created_at = begin 28 | Time.parse(created_at) 29 | rescue StandardError 30 | nil 31 | end 32 | end 33 | 34 | def amount=(amount) 35 | @amount = Mollie::Amount.new(amount) 36 | end 37 | 38 | def settlement_amount=(settlement_amount) 39 | @settlement_amount = Mollie::Amount.new(settlement_amount) 40 | end 41 | 42 | def payment(options = {}) 43 | Payment.get(payment_id, options) 44 | end 45 | 46 | def settlement(options = {}) 47 | settlement_id = Util.extract_id(links, 'settlement') 48 | return if settlement_id.nil? 49 | Settlement.get(settlement_id, options) 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/mollie/customer.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Customer < Base 3 | attr_accessor :id, 4 | :mode, 5 | :name, 6 | :email, 7 | :locale, 8 | :metadata, 9 | :created_at 10 | 11 | def created_at=(created_at) 12 | @created_at = Time.parse(created_at.to_s) 13 | end 14 | 15 | def metadata=(metadata) 16 | @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) 17 | end 18 | 19 | def mandates(options = {}) 20 | Mandate.all(options.merge(customer_id: id)) 21 | end 22 | 23 | def payments(options = {}) 24 | Payment.all(options.merge(customer_id: id)) 25 | end 26 | 27 | def subscriptions(options = {}) 28 | Subscription.all(options.merge(customer_id: id)) 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/mollie/customer/mandate.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Customer 3 | class Mandate < Base 4 | STATUS_VALID = 'valid'.freeze 5 | STATUS_INVALID = 'invalid'.freeze 6 | STATUS_PENDING = 'pending'.freeze 7 | 8 | attr_accessor :id, 9 | :mode, 10 | :status, 11 | :method, 12 | :details, 13 | :mandate_reference, 14 | :signature_date, 15 | :created_at, 16 | :_links 17 | 18 | alias links _links 19 | 20 | def details=(details) 21 | @details = OpenStruct.new(details) if details.is_a?(Hash) 22 | end 23 | 24 | def created_at=(created_at) 25 | @created_at = begin 26 | Time.parse(created_at.to_s) 27 | rescue StandardError 28 | nil 29 | end 30 | end 31 | 32 | def valid? 33 | status == STATUS_VALID 34 | end 35 | 36 | def pending? 37 | status == STATUS_PENDING 38 | end 39 | 40 | def invalid? 41 | status == STATUS_INVALID 42 | end 43 | 44 | def customer(options = {}) 45 | customer_id = Util.extract_id(links, 'customer') 46 | Customer.get(customer_id, options) 47 | end 48 | end 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/mollie/customer/payment.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Customer 3 | class Payment < Mollie::Payment 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/customer/subscription.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Customer 3 | class Subscription < Mollie::Subscription 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/exception.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Exception < StandardError 3 | end 4 | 5 | class RequestError < Mollie::Exception 6 | attr_accessor :status, :title, :detail, :field, :links 7 | 8 | def initialize(error, response = nil) 9 | exception.status = error['status'] 10 | exception.title = error['title'] 11 | exception.detail = error['detail'] 12 | exception.field = error['field'] 13 | exception.links = error['_links'] 14 | self.response = response 15 | end 16 | 17 | def to_s 18 | "#{status} #{title}: #{detail}" 19 | end 20 | 21 | def http_headers 22 | response.to_hash if response 23 | end 24 | 25 | def http_body 26 | response.body if response 27 | end 28 | 29 | private 30 | 31 | attr_accessor :response 32 | end 33 | 34 | class ResourceNotFoundError < RequestError 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/mollie/invoice.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Invoice < Base 3 | STATUS_OPEN = 'open'.freeze 4 | STATUS_PAID = 'paid'.freeze 5 | STATUS_OVERDUE = 'overdue'.freeze 6 | 7 | class Line < Base 8 | attr_accessor :period, :description, :count, :vat_percentage, :amount 9 | 10 | def amount=(amount) 11 | @amount = Mollie::Amount.new(amount) 12 | end 13 | end 14 | 15 | attr_accessor :id, 16 | :reference, 17 | :vat_number, 18 | :status, 19 | :issued_at, 20 | :paid_at, 21 | :due_at, 22 | :net_amount, 23 | :vat_amount, 24 | :gross_amount, 25 | :lines, 26 | :_links 27 | 28 | alias links _links 29 | 30 | def open? 31 | status == STATUS_OPEN 32 | end 33 | 34 | def paid? 35 | status == STATUS_PAID 36 | end 37 | 38 | def overdue? 39 | status == STATUS_OVERDUE 40 | end 41 | 42 | def net_amount=(net_amount) 43 | @net_amount = Mollie::Amount.new(net_amount) 44 | end 45 | 46 | def vat_amount=(vat_amount) 47 | @vat_amount = Mollie::Amount.new(vat_amount) 48 | end 49 | 50 | def gross_amount=(gross_amount) 51 | @gross_amount = Mollie::Amount.new(gross_amount) 52 | end 53 | 54 | def issued_at=(issued_at) 55 | @issued_at = begin 56 | Time.parse(issued_at) 57 | rescue StandardError 58 | nil 59 | end 60 | end 61 | 62 | def due_at=(due_at) 63 | @due_at = begin 64 | Time.parse(due_at) 65 | rescue StandardError 66 | nil 67 | end 68 | end 69 | 70 | def lines=(lines) 71 | @lines = lines.map { |line| Line.new(line) } 72 | end 73 | 74 | def pdf 75 | Util.extract_url(links, 'pdf') 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /lib/mollie/list.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class List < Base 3 | include Enumerable 4 | 5 | attr_accessor :klass, :items, :_links 6 | alias links _links 7 | 8 | def initialize(list_attributes, klass) 9 | @klass = klass 10 | 11 | list_attributes['items'] ||= if list_attributes['_embedded'] 12 | list_attributes['_embedded'].fetch(klass.embedded_resource_name, []) 13 | else 14 | [] 15 | end 16 | super list_attributes 17 | 18 | @items = items.map do |attributes| 19 | klass.new attributes 20 | end 21 | end 22 | 23 | def [](index) 24 | @items[index] 25 | end 26 | 27 | def size 28 | @items.size 29 | end 30 | 31 | def each(&block) 32 | @items.each(&block) 33 | end 34 | 35 | def next(options = {}) 36 | return self.class.new({}, klass) if links['next'].nil? 37 | 38 | href = URI.parse(links['next']['href']) 39 | query = URI.decode_www_form(href.query).to_h 40 | 41 | response = Mollie::Client.instance.perform_http_call('GET', links['next']['href'], nil, {}, options.merge(query)) 42 | self.class.new(response, klass) 43 | end 44 | 45 | def previous(options = {}) 46 | return self.class.new({}, klass) if links['previous'].nil? 47 | 48 | href = URI.parse(links['previous']['href']) 49 | query = URI.decode_www_form(href.query).to_h 50 | 51 | response = Mollie::Client.instance.perform_http_call('GET', links['previous']['href'], nil, {}, options.merge(query)) 52 | self.class.new(response, klass) 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/mollie/method.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Method < Base 3 | ALMA = 'alma'.freeze 4 | APPLEPAY = 'applepay'.freeze 5 | BANCONTACT = 'bancontact'.freeze 6 | BANCOMAT_PAY = 'bancomatpay'.freeze 7 | BANKTRANSFER = 'banktransfer'.freeze 8 | BELFIUS = 'belfius'.freeze 9 | BILLIE = 'billie'.freeze 10 | BLIK = 'bilk'.freeze 11 | CREDITCARD = 'creditcard'.freeze 12 | DIRECTDEBIT = 'directdebit'.freeze 13 | EPS = 'eps'.freeze 14 | GIFTCARD = 'giftcard'.freeze 15 | GIROPAY = 'giropay'.freeze 16 | IDEAL = 'ideal'.freeze 17 | IN3 = 'in3'.freeze 18 | INGHOMEPAY = 'inghomepay'.freeze 19 | KBC = 'kbc'.freeze 20 | MYBANK = 'mybank'.freeze 21 | PAYPAL = 'paypal'.freeze 22 | PAYSAFECARD = 'paysafecard'.freeze 23 | PRZELEWY24 = 'przelewy24'.freeze 24 | RIVERTY = 'riverty'.freeze 25 | SOFORT = 'sofort'.freeze 26 | SATISPAY = 'satispay'.freeze 27 | TRUSTLY = 'trustly'.freeze 28 | TWINT = 'twint'.freeze 29 | VOUCHER = 'voucher'.freeze 30 | KLARNA = 'klarna'.freeze 31 | KLARNASLICEIT = 'klarnasliceit'.freeze 32 | KLARNAPAYLATER = 'klarnapaylater'.freeze 33 | 34 | attr_accessor :id, 35 | :description, 36 | :minimum_amount, 37 | :maximum_amount, 38 | :image, 39 | :issuers, 40 | :pricing, 41 | :status 42 | 43 | def self.all_available(options = {}) 44 | response = Client.instance.perform_http_call("GET", "methods", "all", {}, options) 45 | Mollie::List.new(response, Mollie::Method) 46 | end 47 | 48 | def minimum_amount=(minimum_amount) 49 | @minimum_amount = Mollie::Amount.new(minimum_amount) 50 | end 51 | 52 | def maximum_amount=(maximum_amount) 53 | @maximum_amount = Mollie::Amount.new(maximum_amount) 54 | end 55 | 56 | def normal_image 57 | image['size1x'] 58 | end 59 | 60 | def bigger_image 61 | image['size2x'] 62 | end 63 | 64 | def pricing=(pricing) 65 | @pricing = pricing.map do |price| 66 | OpenStruct.new( 67 | description: price['description'], 68 | fixed: Mollie::Amount.new(price['fixed']), 69 | variable: price['variable'], 70 | fee_region: price['fee_region'] 71 | ) 72 | end 73 | end 74 | end 75 | end 76 | -------------------------------------------------------------------------------- /lib/mollie/onboarding.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Onboarding < Base 3 | attr_accessor :name, 4 | :signed_up_at, 5 | :status, 6 | :can_receive_payments, 7 | :can_receive_settlements, 8 | :_links 9 | 10 | alias links _links 11 | 12 | def self.me(options = {}) 13 | response = Client.instance.perform_http_call('GET', 'onboarding', 'me', {}, options) 14 | new(response) 15 | end 16 | 17 | def self.submit(data = {}, options = {}) 18 | Client.instance.perform_http_call('POST', 'onboarding', 'me', data, options) 19 | nil 20 | end 21 | 22 | def dashboard 23 | Util.extract_url(links, 'dashboard') 24 | end 25 | 26 | def organization(options = {}) 27 | resource_url = Util.extract_url(links, 'organization') 28 | response = Client.instance.perform_http_call('GET', resource_url, nil, {}, options) 29 | Organization.new(response) 30 | end 31 | 32 | def signed_up_at=(signed_up_at) 33 | @signed_up_at = Time.parse(signed_up_at.to_s) 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/mollie/order.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Order < Base 3 | STATUS_PENDING = 'pending'.freeze 4 | STATUS_AUTHORIZED = 'authorized'.freeze 5 | STATUS_PAID = 'paid'.freeze 6 | STATUS_SHIPPING = 'shipping'.freeze 7 | STATUS_EXPIRED = 'expired'.freeze 8 | STATUS_CANCELED = 'canceled'.freeze 9 | STATUS_COMPLETED = 'completed'.freeze 10 | 11 | attr_accessor :id, 12 | :profile_id, 13 | :method, 14 | :mode, 15 | :amount, 16 | :amount_captured, 17 | :amount_refunded, 18 | :status, 19 | :is_cancelable, 20 | :billing_address, 21 | :shopper_country_must_match_billing_country, 22 | :consumer_date_of_birth, 23 | :order_number, 24 | :shipping_address, 25 | :locale, 26 | :metadata, 27 | :redirect_url, 28 | :cancel_url, 29 | :webhook_url, 30 | :created_at, 31 | :expires_at, 32 | :expired_at, 33 | :paid_at, 34 | :authorized_at, 35 | :canceled_at, 36 | :completed_at, 37 | :lines, 38 | :_links 39 | 40 | alias links _links 41 | 42 | def pending? 43 | status == STATUS_PENDING 44 | end 45 | 46 | def authorized? 47 | status == STATUS_AUTHORIZED 48 | end 49 | 50 | def paid? 51 | status == STATUS_PAID 52 | end 53 | 54 | def shipping? 55 | status == STATUS_SHIPPING 56 | end 57 | 58 | def expired? 59 | status == STATUS_EXPIRED 60 | end 61 | 62 | def canceled? 63 | status == STATUS_CANCELED 64 | end 65 | 66 | def completed? 67 | status == STATUS_COMPLETED 68 | end 69 | 70 | def cancelable? 71 | is_cancelable 72 | end 73 | 74 | def checkout_url 75 | Util.extract_url(links, 'checkout') 76 | end 77 | 78 | def lines=(lines) 79 | @lines = lines.map { |line| Order::Line.new(line) } 80 | end 81 | 82 | def amount=(amount) 83 | @amount = Mollie::Amount.new(amount) 84 | end 85 | 86 | def amount_captured=(amount) 87 | @amount_captured = Mollie::Amount.new(amount) 88 | end 89 | 90 | def amount_refunded=(amount) 91 | @amount_refunded = Mollie::Amount.new(amount) 92 | end 93 | 94 | def billing_address=(address) 95 | @billing_address = OpenStruct.new(address) if address.is_a?(Hash) 96 | end 97 | 98 | def shipping_address=(address) 99 | @shipping_address = OpenStruct.new(address) if address.is_a?(Hash) 100 | end 101 | 102 | def metadata=(metadata) 103 | @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) 104 | end 105 | 106 | def created_at=(created_at) 107 | @created_at = Time.parse(created_at.to_s) 108 | end 109 | 110 | def expires_at=(expires_at) 111 | @expires_at = Time.parse(expires_at.to_s) 112 | end 113 | 114 | def expired_at=(expired_at) 115 | @expired_at = Time.parse(expired_at.to_s) 116 | end 117 | 118 | def paid_at=(paid_at) 119 | @paid_at = Time.parse(paid_at.to_s) 120 | end 121 | 122 | def authorized_at=(authorized_at) 123 | @authorized_at = Time.parse(authorized_at.to_s) 124 | end 125 | 126 | def canceled_at=(canceled_at) 127 | @canceled_at = Time.parse(canceled_at.to_s) 128 | end 129 | 130 | def completed_at=(completed_at) 131 | @completed_at = Time.parse(completed_at.to_s) 132 | end 133 | 134 | def payments 135 | resources = (attributes['_embedded']['payments'] if attributes['_embedded']) 136 | 137 | if resources.nil? 138 | List.new({}, Order::Payment) 139 | else 140 | List.new({ '_embedded' => { 'payments' => resources } }, Order::Payment) 141 | end 142 | end 143 | 144 | def refunds(options = {}) 145 | resources = (attributes['_embedded']['refunds'] if attributes['_embedded']) 146 | 147 | if resources.nil? 148 | # To avoid breaking changes, fallback to /v2/order/*orderId*/refunds 149 | # if the order was retrieved without embedded refunds. 150 | Order::Refund.all(options.merge(order_id: id)) 151 | else 152 | List.new({ '_embedded' => { 'refunds' => resources } }, Order::Refund) 153 | end 154 | end 155 | 156 | def shipments 157 | resources = (attributes['_embedded']['shipments'] if attributes['_embedded']) 158 | 159 | if resources.nil? 160 | List.new({}, Order::Shipment) 161 | else 162 | List.new({ '_embedded' => { 'shipments' => resources } }, Order::Shipment) 163 | end 164 | end 165 | 166 | def refund!(options = {}) 167 | options[:order_id] = id 168 | options[:lines] ||= [] 169 | Order::Refund.create(options) 170 | end 171 | end 172 | end 173 | -------------------------------------------------------------------------------- /lib/mollie/order/line.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Order 3 | class Line < Base 4 | attr_accessor :id, 5 | :order_id, 6 | :type, 7 | :name, 8 | :status, 9 | :metadata, 10 | :is_cancelable, 11 | :quantity, 12 | :quantity_shipped, 13 | :amount_shipped, 14 | :quantity_refunded, 15 | :amount_refunded, 16 | :quantity_canceled, 17 | :amount_canceled, 18 | :shippable_quantity, 19 | :refundable_quantity, 20 | :cancelable_quantity, 21 | :unit_price, 22 | :discount_amount, 23 | :total_amount, 24 | :vat_rate, 25 | :vat_amount, 26 | :sku, 27 | :created_at, 28 | :_links 29 | 30 | alias links _links 31 | 32 | def self.update(id, data = {}) 33 | request('PATCH', id, data) { |response| Order.new(response) } 34 | end 35 | 36 | def cancelable? 37 | is_cancelable == true 38 | end 39 | 40 | def discounted? 41 | !@discount_amount.nil? 42 | end 43 | 44 | def shippable? 45 | shippable_quantity.to_i > 0 46 | end 47 | 48 | def refundable? 49 | refundable_quantity.to_i > 0 50 | end 51 | 52 | def product_url 53 | Util.extract_url(links, 'product_url') 54 | end 55 | 56 | def image_url 57 | Util.extract_url(links, 'image_url') 58 | end 59 | 60 | def metadata=(metadata) 61 | @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) 62 | end 63 | 64 | def amount_shipped=(amount) 65 | @amount_shipped = Mollie::Amount.new(amount) 66 | end 67 | 68 | def amount_refunded=(amount) 69 | @amount_refunded = Mollie::Amount.new(amount) 70 | end 71 | 72 | def amount_canceled=(amount) 73 | @amount_canceled = Mollie::Amount.new(amount) 74 | end 75 | 76 | def unit_price=(amount) 77 | @unit_price = Mollie::Amount.new(amount) 78 | end 79 | 80 | def discount_amount=(amount) 81 | @discount_amount = Mollie::Amount.new(amount) 82 | end 83 | 84 | def total_amount=(amount) 85 | @total_amount = Mollie::Amount.new(amount) 86 | end 87 | 88 | def vat_amount=(amount) 89 | @vat_amount = Mollie::Amount.new(amount) 90 | end 91 | 92 | def created_at=(created_at) 93 | @created_at = Time.parse(created_at.to_s) 94 | end 95 | 96 | def cancel(options = {}) 97 | qty = options.delete(:quantity) || quantity 98 | options[:lines] = [{ id: id, quantity: qty }] 99 | options[:order_id] = order_id 100 | Mollie::Order::Line.delete(nil, options) 101 | end 102 | end 103 | end 104 | end 105 | -------------------------------------------------------------------------------- /lib/mollie/order/payment.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Order 3 | class Payment < ::Mollie::Payment 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/order/refund.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Order 3 | class Refund < ::Mollie::Refund 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/order/shipment.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Order 3 | class Shipment < Base 4 | attr_accessor :id, 5 | :order_id, 6 | :created_at, 7 | :tracking, 8 | :lines, 9 | :_links 10 | 11 | alias links _links 12 | 13 | def tracking 14 | @tracking || OpenStruct.new 15 | end 16 | 17 | def tracking=(tracking) 18 | @tracking = OpenStruct.new(tracking) if tracking.is_a?(Hash) 19 | end 20 | 21 | def lines=(lines) 22 | @lines = lines.map { |line| Order::Line.new(line) } 23 | end 24 | 25 | def created_at=(created_at) 26 | @created_at = Time.parse(created_at.to_s) 27 | end 28 | 29 | def order(options = {}) 30 | Order.get(order_id, options) 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/mollie/organization.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Organization < Base 3 | attr_accessor :id, 4 | :name, 5 | :locale, 6 | :email, 7 | :address, 8 | :registration_number, 9 | :vat_number, 10 | :vat_regulation, 11 | :_links 12 | 13 | alias links _links 14 | 15 | def self.current(options = {}) 16 | get('me', options) 17 | end 18 | 19 | def address=(address) 20 | @address = OpenStruct.new(address) if address.is_a?(Hash) 21 | end 22 | 23 | def dashboard_url 24 | Util.extract_url(links, 'dashboard') 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/mollie/partner.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Partner < Base 3 | attr_accessor :partner_type, 4 | :is_commission_partner, 5 | :partner_contract_signed_at, 6 | :partner_contract_update_available, 7 | :_links 8 | 9 | attr_reader :user_agent_tokens 10 | 11 | alias links _links 12 | 13 | def self.current(options = {}) 14 | response = Client.instance.perform_http_call('GET', 'organizations/me/partner', nil, {}, options) 15 | new(response) 16 | end 17 | 18 | def type 19 | partner_type 20 | end 21 | 22 | def commission_partner? 23 | is_commission_partner 24 | end 25 | 26 | def contract_signed_at 27 | @contract_signed_at = begin 28 | Time.parse(partner_contract_signed_at) 29 | rescue StandardError 30 | nil 31 | end 32 | end 33 | 34 | def contract_update_available? 35 | partner_contract_update_available 36 | end 37 | 38 | def user_agent_tokens=(tokens) 39 | @user_agent_tokens = tokens.map do |token| 40 | OpenStruct.new( 41 | token: token['token'], 42 | starts_at: Time.parse(token['starts_at']), 43 | ends_at: (Time.parse(token['ends_at']) unless token['ends_at'].nil?) 44 | ) 45 | end 46 | end 47 | 48 | def signuplink 49 | Util.extract_url(links, 'signuplink') 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/mollie/payment/capture.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Payment 3 | class Capture < Base 4 | attr_accessor :id, 5 | :mode, 6 | :amount, 7 | :settlement_amount, 8 | :payment_id, 9 | :shipment_id, 10 | :settlement_id, 11 | :created_at, 12 | :_links 13 | 14 | alias links _links 15 | 16 | def amount=(amount) 17 | @amount = Mollie::Amount.new(amount) 18 | end 19 | 20 | def settlement_amount=(amount) 21 | @settlement_amount = Mollie::Amount.new(amount) 22 | end 23 | 24 | def created_at=(created_at) 25 | @created_at = Time.parse(created_at.to_s) 26 | end 27 | 28 | def payment(options = {}) 29 | Payment.get(payment_id, options) 30 | end 31 | 32 | def shipment(options = {}) 33 | resource_url = Util.extract_url(links, 'shipment') 34 | response = Client.instance.perform_http_call('GET', resource_url, nil, {}, options) 35 | Order::Shipment.new(response) 36 | end 37 | 38 | def settlement(options = {}) 39 | return if settlement_id.nil? 40 | Settlement.get(settlement_id, options) 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/mollie/payment/chargeback.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Payment 3 | class Chargeback < Mollie::Chargeback 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/payment/refund.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Payment 3 | class Refund < Mollie::Refund 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/payment_link.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class PaymentLink < Base 3 | attr_accessor :id, 4 | :mode, 5 | :description, 6 | :archived, 7 | :redirect_url, 8 | :webhook_url, 9 | :profile_id, 10 | :_links 11 | 12 | attr_reader :amount, 13 | :created_at, 14 | :paid_at, 15 | :updated_at, 16 | :expires_at 17 | 18 | alias_method :links, :_links 19 | 20 | def self.embedded_resource_name(_parent_id = nil) 21 | "payment_links" 22 | end 23 | 24 | def self.resource_name(_parent_id = nil) 25 | "payment-links" 26 | end 27 | 28 | def amount=(amount) 29 | @amount = Mollie::Amount.new(amount) 30 | end 31 | 32 | def archived? 33 | archived 34 | end 35 | 36 | def created_at=(created_at) 37 | @created_at = Time.parse(created_at.to_s) 38 | end 39 | 40 | def paid_at=(paid_at) 41 | @paid_at = Time.parse(paid_at.to_s) 42 | rescue 43 | nil 44 | end 45 | 46 | def updated_at=(updated_at) 47 | @updated_at = Time.parse(updated_at.to_s) 48 | rescue 49 | nil 50 | end 51 | 52 | def expires_at=(expires_at) 53 | @expires_at = Time.parse(expires_at.to_s) 54 | rescue 55 | nil 56 | end 57 | 58 | def payment_link 59 | Util.extract_url(links, "payment_link") 60 | end 61 | 62 | def payments(options = {}) 63 | resource_url = Util.extract_url(links, "self") 64 | payments_url = File.join(resource_url, "/payments") 65 | 66 | response = Mollie::Client.instance.perform_http_call("GET", payments_url, nil, {}, options) 67 | Mollie::List.new(response, Mollie::Payment) 68 | end 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/mollie/permission.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Permission < Base 3 | AVAILABLE = %w[ 4 | payments.read 5 | payments.write 6 | refunds.read 7 | refunds.write 8 | customers.read 9 | customers.write 10 | mandates.read 11 | mandates.write 12 | subscriptions.read 13 | subscriptions.write 14 | profiles.read 15 | profiles.write 16 | invoices.read 17 | settlements.read 18 | organizations.read 19 | organizations.write 20 | ].freeze 21 | 22 | attr_accessor :id, 23 | :description, 24 | :granted 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/mollie/profile.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Profile < Base 3 | CATEGORY_CODE_GENERAL_MERCHANDISE = 5399 4 | CATEGORY_CODE_ELECTRONICS_COMPUTERS_AND_SOFTWARE = 5732 5 | CATEGORY_CODE_TRAVEL_RENTAL_AND_TRANSPORTATION = 4121 6 | CATEGORY_CODE_FINANCIAL_SERVICES = 6012 7 | CATEGORY_CODE_FOOD_AND_DRINKS = 5499 8 | CATEGORY_CODE_EVENTS_FESTIVALS_AND_RECREATION = 7999 9 | CATEGORY_CODE_BOOKS_MAGAZINES_AND_NEWSPAPERS = 5192 10 | CATEGORY_CODE_PERSONAL_SERVICES = 7299 11 | CATEGORY_CODE_CHARITY_AND_DONATIONS = 8398 12 | CATEGORY_CODE_OTHER = 0 13 | 14 | STATUS_UNVERIFIED = 'unverified'.freeze 15 | STATUS_VERIFIED = 'verified'.freeze 16 | STATUS_BLOCKED = 'blocked'.freeze 17 | 18 | REVIEW_STATUS_PENDING = 'pending'.freeze 19 | REVIEW_STATUS_REJECTED = 'rejected'.freeze 20 | 21 | attr_accessor :id, 22 | :mode, 23 | :name, 24 | :website, 25 | :email, 26 | :phone, 27 | :business_category, 28 | :category_code, # This parameter is deprecated and will be removed in 2022. 29 | # Please use the businessCategory parameter instead. 30 | :status, 31 | :review, 32 | :created_at, 33 | :_links 34 | 35 | alias links _links 36 | 37 | def unverified? 38 | status == STATUS_UNVERIFIED 39 | end 40 | 41 | def verified? 42 | status == STATUS_VERIFIED 43 | end 44 | 45 | def blocked? 46 | status == STATUS_BLOCKED 47 | end 48 | 49 | def review=(review) 50 | @review = OpenStruct.new(review) if review.is_a?(Hash) 51 | end 52 | 53 | def review_pending? 54 | @review && @review.status == REVIEW_STATUS_PENDING 55 | end 56 | 57 | def review_rejected? 58 | @review && @review.status == REVIEW_STATUS_REJECTED 59 | end 60 | 61 | def created_at=(created_at) 62 | @created_at = begin 63 | Time.parse(created_at.to_s) 64 | rescue StandardError 65 | nil 66 | end 67 | end 68 | 69 | def checkout_preview_url 70 | Util.extract_url(links, 'checkout_preview_url') 71 | end 72 | 73 | def chargebacks(options = {}) 74 | Chargeback.all(options.merge(profile_id: id)) 75 | end 76 | 77 | def methods(options = {}) 78 | Method.all(options.merge(profile_id: id)) 79 | end 80 | 81 | def payments(options = {}) 82 | Payment.all(options.merge(profile_id: id)) 83 | end 84 | 85 | def refunds(options = {}) 86 | Refund.all(options.merge(profile_id: id)) 87 | end 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /lib/mollie/refund.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Refund < Base 3 | STATUS_QUEUED = 'queued'.freeze 4 | STATUS_PENDING = 'pending'.freeze 5 | STATUS_PROCESSING = 'processing'.freeze 6 | STATUS_REFUNDED = 'refunded'.freeze 7 | STATUS_FAILED = 'failed'.freeze 8 | 9 | attr_accessor :id, 10 | :amount, 11 | :settlement_id, 12 | :settlement_amount, 13 | :status, 14 | :lines, 15 | :payment_id, 16 | :order_id, 17 | :description, 18 | :metadata, 19 | :created_at, 20 | :_links 21 | 22 | alias links _links 23 | 24 | def queued? 25 | status == STATUS_QUEUED 26 | end 27 | 28 | def pending? 29 | status == STATUS_PENDING 30 | end 31 | 32 | def processing? 33 | status == STATUS_PROCESSING 34 | end 35 | 36 | def refunded? 37 | status == STATUS_REFUNDED 38 | end 39 | 40 | def failed? 41 | status == STATUS_FAILED 42 | end 43 | 44 | def amount=(amount) 45 | @amount = Amount.new(amount) 46 | end 47 | 48 | def settlement_amount=(settlement_amount) 49 | @settlement_amount = Amount.new(settlement_amount) 50 | end 51 | 52 | def metadata=(metadata) 53 | @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) 54 | end 55 | 56 | def lines=(lines) 57 | @lines = lines.map { |line| Order::Line.new(line) } 58 | end 59 | 60 | def created_at=(created_at) 61 | @created_at = begin 62 | Time.parse(created_at) 63 | rescue StandardError 64 | nil 65 | end 66 | end 67 | 68 | def payment(options = {}) 69 | Payment.get(payment_id, options) 70 | end 71 | 72 | def settlement(options = {}) 73 | return if settlement_id.nil? 74 | Settlement.get(settlement_id, options) 75 | end 76 | 77 | def order(options = {}) 78 | return if order_id.nil? 79 | Order.get(order_id, options) 80 | end 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /lib/mollie/settlement.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Settlement < Base 3 | STATUS_OPEN = 'open'.freeze 4 | STATUS_PENDING = 'pending'.freeze 5 | STATUS_PAIDOUT = 'paidout'.freeze 6 | STATUS_FAILED = 'failed'.freeze 7 | 8 | attr_accessor :id, 9 | :reference, 10 | :created_at, 11 | :settled_at, 12 | :status, 13 | :amount, 14 | :periods, 15 | :invoice_id, 16 | :_links 17 | 18 | alias links _links 19 | 20 | def self.open(options = {}) 21 | get('open', options) 22 | end 23 | 24 | def self.next(options = {}) 25 | get('next', options) 26 | end 27 | 28 | def open? 29 | status == STATUS_OPEN 30 | end 31 | 32 | def pending? 33 | status == STATUS_PENDING 34 | end 35 | 36 | def paidout? 37 | status == STATUS_PAIDOUT 38 | end 39 | 40 | def failed? 41 | status == STATUS_FAILED 42 | end 43 | 44 | def created_at=(created_at) 45 | @created_at = begin 46 | Time.parse(created_at.to_s) 47 | rescue StandardError 48 | nil 49 | end 50 | end 51 | 52 | def settled_at=(settled_at) 53 | @settled_at = begin 54 | Time.parse(settled_at.to_s) 55 | rescue StandardError 56 | nil 57 | end 58 | end 59 | 60 | def amount=(amount) 61 | @amount = Mollie::Amount.new(amount) 62 | end 63 | 64 | def periods=(periods) 65 | @periods = Util.nested_openstruct(periods) if periods.is_a?(Hash) 66 | end 67 | 68 | def payments(options = {}) 69 | Settlement::Payment.all(options.merge(settlement_id: id)) 70 | end 71 | 72 | def refunds(options = {}) 73 | Settlement::Refund.all(options.merge(settlement_id: id)) 74 | end 75 | 76 | def chargebacks(options = {}) 77 | Settlement::Chargeback.all(options.merge(settlement_id: id)) 78 | end 79 | 80 | def captures(options = {}) 81 | Settlement::Capture.all(options.merge(settlement_id: id)) 82 | end 83 | 84 | def invoice(options = {}) 85 | return if invoice_id.nil? 86 | Invoice.get(invoice_id, options) 87 | end 88 | end 89 | end 90 | -------------------------------------------------------------------------------- /lib/mollie/settlement/capture.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Settlement 3 | class Capture < Mollie::Payment::Capture 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/settlement/chargeback.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Settlement 3 | class Chargeback < Mollie::Chargeback 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/settlement/payment.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Settlement 3 | class Payment < Mollie::Payment 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/settlement/refund.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Settlement 3 | class Refund < Mollie::Refund 4 | end 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/mollie/subscription.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Subscription < Base 3 | STATUS_ACTIVE = 'active'.freeze 4 | STATUS_PENDING = 'pending'.freeze # Waiting for a valid mandate. 5 | STATUS_CANCELED = 'canceled'.freeze 6 | STATUS_SUSPENDED = 'suspended'.freeze # Active, but mandate became invalid. 7 | STATUS_COMPLETED = 'completed'.freeze 8 | 9 | attr_accessor :id, 10 | :customer_id, 11 | :mode, 12 | :created_at, 13 | :status, 14 | :amount, 15 | :times, 16 | :times_remaining, 17 | :interval, 18 | :next_payment_date, 19 | :description, 20 | :method, 21 | :mandate_id, 22 | :canceled_at, 23 | :webhook_url, 24 | :metadata, 25 | :application_fee, 26 | :_links 27 | 28 | alias links _links 29 | 30 | def active? 31 | status == STATUS_ACTIVE 32 | end 33 | 34 | def pending? 35 | status == STATUS_PENDING 36 | end 37 | 38 | def suspended? 39 | status == STATUS_SUSPENDED 40 | end 41 | 42 | def canceled? 43 | status == STATUS_CANCELED 44 | end 45 | 46 | def completed? 47 | status == STATUS_COMPLETED 48 | end 49 | 50 | def created_at=(created_at) 51 | @created_at = begin 52 | Time.parse(created_at.to_s) 53 | rescue StandardError 54 | nil 55 | end 56 | end 57 | 58 | def canceled_at=(canceled_at) 59 | @canceled_at = begin 60 | Time.parse(canceled_at.to_s) 61 | rescue StandardError 62 | nil 63 | end 64 | end 65 | 66 | def amount=(amount) 67 | @amount = Mollie::Amount.new(amount) 68 | end 69 | 70 | def times=(times) 71 | @times = times.to_i 72 | end 73 | 74 | def next_payment_date=(next_payment_date) 75 | @next_payment_date = begin 76 | Date.parse(next_payment_date) 77 | rescue StandardError 78 | nil 79 | end 80 | end 81 | 82 | def customer(options = {}) 83 | Customer.get(customer_id, options) 84 | end 85 | 86 | def payments(options = {}) 87 | resource_url = Util.extract_url(links, 'payments') 88 | return if resource_url.nil? 89 | response = Mollie::Client.instance.perform_http_call('GET', resource_url, nil, {}, options) 90 | Mollie::List.new(response, Mollie::Payment) 91 | end 92 | 93 | def metadata=(metadata) 94 | @metadata = OpenStruct.new(metadata) if metadata.is_a?(Hash) 95 | end 96 | 97 | def application_fee=(application_fee) 98 | amount = Amount.new(application_fee['amount']) 99 | description = application_fee['description'] 100 | 101 | @application_fee = OpenStruct.new( 102 | amount: amount, 103 | description: description 104 | ) 105 | end 106 | end 107 | end 108 | -------------------------------------------------------------------------------- /lib/mollie/terminal.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | class Terminal < Base 3 | 4 | STATUS_PENDING = "pending".freeze 5 | STATUS_ACTIVE = "active".freeze 6 | STATUS_INACTIVE = "inactive".freeze 7 | 8 | attr_accessor :id, 9 | :profile_id, 10 | :status, 11 | :brand, 12 | :model, 13 | :serial_number, 14 | :currency, 15 | :description, 16 | :created_at, 17 | :updated_at, 18 | :deactivated_at, 19 | :_links 20 | 21 | alias links _links 22 | 23 | def pending? 24 | status == STATUS_PENDING 25 | end 26 | 27 | def active? 28 | status == STATUS_ACTIVE 29 | end 30 | 31 | def inactive? 32 | status == STATUS_INACTIVE 33 | end 34 | 35 | def created_at=(created_at) 36 | @created_at = begin 37 | Time.parse(created_at.to_s) 38 | rescue StandardError 39 | nil 40 | end 41 | end 42 | 43 | def updated_at=(updated_at) 44 | @updated_at = begin 45 | Time.parse(updated_at.to_s) 46 | rescue StandardError 47 | nil 48 | end 49 | end 50 | 51 | def deactivated_at=(deactivated_at) 52 | @deactivated_at = begin 53 | Time.parse(deactivated_at.to_s) 54 | rescue StandardError 55 | nil 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /lib/mollie/util.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | module Util 3 | module_function 4 | 5 | def nested_underscore_keys(obj) 6 | if obj.is_a?(Hash) 7 | obj.each_with_object({}) do |(key, value), underscored| 8 | underscored[underscore(key)] = nested_underscore_keys(value) 9 | end 10 | elsif obj.is_a?(Array) 11 | obj.map { |v| nested_underscore_keys(v) } 12 | else 13 | obj 14 | end 15 | end 16 | 17 | def camelize_keys(hash) 18 | hash.each_with_object({}) do |(key, value), camelized| 19 | camelized[camelize(key)] = value 20 | end 21 | end 22 | 23 | def underscore(string) 24 | string.to_s.gsub(/::/, '/') 25 | .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') 26 | .gsub(/([a-z\d])([A-Z])/, '\1_\2') 27 | .tr('-', '_') 28 | .downcase.to_s 29 | end 30 | 31 | # Dirty pluralize function, but currently holds for all required plurals 32 | # Not worth to include another library like ActiveSupport 33 | def pluralize(string) 34 | "#{string}s" 35 | end 36 | 37 | def camelize(term) 38 | string = term.to_s 39 | string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/, &:downcase) 40 | string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" } 41 | string.gsub!('/'.freeze, '::'.freeze) 42 | string 43 | end 44 | 45 | def nested_openstruct(obj) 46 | if obj.is_a?(Hash) 47 | obj.each_with_object(OpenStruct.new) do |(key, value), openstructed| 48 | openstructed[key] = nested_openstruct(value) 49 | end 50 | elsif obj.is_a?(Array) 51 | obj.map { |v| nested_openstruct(v) } 52 | else 53 | obj 54 | end 55 | end 56 | 57 | def extract_url(links, type) 58 | links && links[type] && links[type]['href'] 59 | end 60 | 61 | def extract_id(links, type) 62 | href = extract_url(links, type) 63 | return if href.nil? 64 | uri = URI.parse(href) 65 | File.basename(uri.path) 66 | end 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /lib/mollie/version.rb: -------------------------------------------------------------------------------- 1 | module Mollie 2 | VERSION = '4.17.0'.freeze 3 | end 4 | -------------------------------------------------------------------------------- /mollie-api-ruby.gemspec: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.push File.expand_path('lib', __dir__) 2 | 3 | require 'mollie/version' 4 | 5 | Gem::Specification.new do |s| 6 | s.name = 'mollie-api-ruby' 7 | s.version = Mollie::VERSION 8 | s.summary = 'Official Mollie API Client for Ruby' 9 | s.description = %(Accepting iDEAL, Bancontact, SOFORT Banking, Creditcard, 10 | SEPA Bank transfer, SEPA Direct debit, PayPal, 11 | KBC Payment Button, CBC Payment Button, Belfius Direct 12 | Net, paysafecard, PODIUM Cadeaukaart and ING Home’Pay online 13 | payments without fixed monthly costs or any punishing registration 14 | procedures.') 15 | s.authors = ['Mollie B.V.'] 16 | s.email = ['info@mollie.com'] 17 | s.homepage = 'https://github.com/mollie/mollie-api-ruby' 18 | s.license = 'BSD' 19 | s.metadata = { 20 | 'changelog_uri' => 'https://github.com/mollie/mollie-api-ruby/blob/master/CHANGELOG.md' 21 | } 22 | 23 | s.required_ruby_version = '>= 2.5' 24 | 25 | s.files = `git ls-files`.split("\n") 26 | s.test_files = Dir['test/**/*'] 27 | 28 | s.add_dependency('ostruct', '~> 0.6.0') 29 | s.add_dependency('bigdecimal', '~> 3.1', '>= 3.1.8') 30 | 31 | s.add_development_dependency('rake') 32 | s.add_development_dependency('rubocop', '~> 0.57.2') 33 | s.add_development_dependency('test-unit') 34 | s.add_development_dependency('webmock') 35 | end 36 | -------------------------------------------------------------------------------- /test/fixtures/balances/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "balance", 3 | "id": "bal_gVMhHKqSSRYJyPsuoPNFH", 4 | "mode": "live", 5 | "currency": "EUR", 6 | "description": "Primary balance", 7 | "availableAmount": { 8 | "currency": "EUR", 9 | "value": "905.25" 10 | }, 11 | "pendingAmount": { 12 | "currency": "EUR", 13 | "value": "0.00" 14 | }, 15 | "transferFrequency": "twice-a-month", 16 | "transferThreshold": { 17 | "currency": "EUR", 18 | "value": "5.00" 19 | }, 20 | "transferReference": "Mollie settlement", 21 | "transferDestination": { 22 | "type": "bank-account", 23 | "beneficiaryName": "John Doe", 24 | "bankAccount": "NL55INGB0000000000" 25 | }, 26 | "status": "active", 27 | "createdAt": "2019-01-10T12:06:28+00:00", 28 | "_links": { 29 | "self": { 30 | "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH", 31 | "type": "application/hal+json" 32 | }, 33 | "documentation": { 34 | "href": "https://docs.mollie.com/reference/get-balance", 35 | "type": "text/html" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/fixtures/balances/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 1, 3 | "_embedded": { 4 | "balances": [ 5 | { 6 | "resource": "balance", 7 | "id": "bal_one" 8 | }, 9 | { 10 | "resource": "balance", 11 | "id": "bal_two" 12 | }, 13 | { 14 | "resource": "balance", 15 | "id": "bal_three" 16 | } 17 | ] 18 | }, 19 | "_links": { 20 | "documentation": { 21 | "href": "https://docs.mollie.com/reference/v2/balances-api/list-balances", 22 | "type": "text/html" 23 | }, 24 | "self": { 25 | "href": "https://api.mollie.com/v2/balances?limit=5", 26 | "type": "application/hal+json" 27 | }, 28 | "previous": null, 29 | "next": { 30 | "href": "https://api.mollie.com/v2/balances?from=bal_gVMhHKqSSRYJyPsuoPABC&limit=5", 31 | "type": "application/hal+json" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/fixtures/balances/list_transactions.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 2, 3 | "_embedded": { 4 | "balance_transactions": [ 5 | { 6 | "resource": "balance_transaction", 7 | "id": "baltr_QM24QwzUWR4ev4Xfgyt29A", 8 | "type": "refund", 9 | "resultAmount": { 10 | "currency": "EUR", 11 | "value": "-10.25" 12 | }, 13 | "initialAmount": { 14 | "currency": "EUR", 15 | "value": "-10.00" 16 | }, 17 | "deductions": { 18 | "currency": "EUR", 19 | "value": "-0.25" 20 | }, 21 | "context": { 22 | "paymentId": "tr_7UhSN1zuXS", 23 | "refundId": "re_4qqhO89gsT" 24 | }, 25 | "createdAt": "2021-01-10T12:06:28+00:00" 26 | }, 27 | { 28 | "resource": "balance_transaction", 29 | "id": "baltr_WhmDwNYR87FPDbiwBhUXCh", 30 | "type": "payment", 31 | "resultAmount": { 32 | "currency": "EUR", 33 | "value": "9.71" 34 | }, 35 | "initialAmount": { 36 | "currency": "EUR", 37 | "value": "10.00" 38 | }, 39 | "deductions": { 40 | "currency": "EUR", 41 | "value": "-0.29" 42 | }, 43 | "context": { 44 | "paymentId": "tr_7UhSN1zuXS" 45 | }, 46 | "createdAt": "2021-01-10T12:06:28+00:00" 47 | } 48 | ] 49 | }, 50 | "_links": { 51 | "self": { 52 | "href": "...", 53 | "type": "application/hal+json" 54 | }, 55 | "previous": null, 56 | "next": { 57 | "href": "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions?from=baltr_rXeW2yPqqDUyfAqq8fS5Bg&limit=5", 58 | "type": "application/hal+json" 59 | }, 60 | "documentation": { 61 | "href": "...", 62 | "type": "text/html" 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /test/fixtures/balances/report.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "balance-report", 3 | "balanceId": "bal_gVMhHKqSSRYJyPsuoPNFH", 4 | "timeZone": "Europe/Amsterdam", 5 | "from": "2024-01-01", 6 | "until": "2024-01-31", 7 | "grouping": "transaction-categories", 8 | "totals": { 9 | "open": { 10 | "available": { 11 | "amount": { 12 | "currency": "EUR", 13 | "value": "0.00" 14 | } 15 | }, 16 | "pending": { 17 | "amount": { 18 | "currency": "EUR", 19 | "value": "0.00" 20 | } 21 | } 22 | }, 23 | "payments": { 24 | "immediatelyAvailable": { 25 | "amount": { 26 | "currency": "EUR", 27 | "value": "0.00" 28 | } 29 | }, 30 | "pending": { 31 | "amount": { 32 | "currency": "EUR", 33 | "value": "4.98" 34 | }, 35 | "subtotals": [ 36 | { 37 | "transactionType": "payment", 38 | "count": 1, 39 | "amount": { 40 | "currency": "EUR", 41 | "value": "4.98" 42 | }, 43 | "subtotals": [ 44 | { 45 | "method": "ideal", 46 | "count": 1, 47 | "amount": { 48 | "currency": "EUR", 49 | "value": "4.98" 50 | } 51 | } 52 | ] 53 | } 54 | ] 55 | }, 56 | "movedToAvailable": { 57 | "amount": { 58 | "currency": "EUR", 59 | "value": "0.00" 60 | } 61 | } 62 | }, 63 | "refunds": {}, 64 | "capital": {}, 65 | "chargebacks": {}, 66 | "transfers": {}, 67 | "fee-prepayments": { 68 | "immediatelyAvailable": { 69 | "amount": { 70 | "currency": "EUR", 71 | "value": "0.00" 72 | } 73 | }, 74 | "movedToAvailable": { 75 | "amount": { 76 | "currency": "EUR", 77 | "value": "-0.36" 78 | }, 79 | "subtotals": [ 80 | { 81 | "prepaymentPartType": "fee", 82 | "count": 1, 83 | "amount": { 84 | "currency": "EUR", 85 | "value": "-0.29" 86 | }, 87 | "subtotals": [ 88 | { 89 | "feeType": "payment-fee", 90 | "method": "ideal", 91 | "count": 1, 92 | "amount": { 93 | "currency": "EUR", 94 | "value": "-0.29" 95 | } 96 | } 97 | ] 98 | }, 99 | { 100 | "prepaymentPartType": "fee-vat", 101 | "amount": { 102 | "currency": "EUR", 103 | "value": "-0.0609" 104 | } 105 | }, 106 | { 107 | "prepaymentPartType": "fee-rounding-compensation", 108 | "amount": { 109 | "currency": "EUR", 110 | "value": "-0.0091" 111 | } 112 | } 113 | ] 114 | }, 115 | "pending": { 116 | "amount": { 117 | "currency": "EUR", 118 | "value": "-0.36" 119 | }, 120 | "subtotals": [] 121 | } 122 | }, 123 | "corrections": {}, 124 | "close": { 125 | "available": { 126 | "amount": { 127 | "currency": "EUR", 128 | "value": "0.00" 129 | } 130 | }, 131 | "pending": { 132 | "amount": { 133 | "currency": "EUR", 134 | "value": "4.32" 135 | } 136 | } 137 | } 138 | }, 139 | "_links": { 140 | "self": { 141 | "href": "...", 142 | "type": "application/hal+json" 143 | }, 144 | "documentation": { 145 | "href": "...", 146 | "type": "text/html" 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /test/fixtures/captures/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "capture", 3 | "id": "cpt_4qqhO89gsT", 4 | "mode": "live", 5 | "amount": { 6 | "value": "1027.99", 7 | "currency": "EUR" 8 | }, 9 | "settlementAmount": { 10 | "value": "399.00", 11 | "currency": "EUR" 12 | }, 13 | "paymentId": "tr_WDqYK6vllg", 14 | "shipmentId": "shp_3wmsgCJN4U", 15 | "settlementId": "stl_jDk30akdN", 16 | "createdAt": "2018-08-02T09:29:56+00:00", 17 | "_links": { 18 | "self": { 19 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT", 20 | "type": "application/hal+json" 21 | }, 22 | "payment": { 23 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 24 | "type": "application/hal+json" 25 | }, 26 | "shipment": { 27 | "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U", 28 | "type": "application/hal+json" 29 | }, 30 | "settlement": { 31 | "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", 32 | "type": "application/hal+json" 33 | }, 34 | "documentation": { 35 | "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture", 36 | "type": "text/html" 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/fixtures/captures/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "_embedded": { 3 | "captures": [ 4 | { 5 | "resource": "capture", 6 | "id": "cpt_4qqhO89gsT", 7 | "mode": "live", 8 | "amount": { 9 | "value": "1027.99", 10 | "currency": "EUR" 11 | }, 12 | "settlementAmount": { 13 | "value": "399.00", 14 | "currency": "EUR" 15 | }, 16 | "paymentId": "tr_WDqYK6vllg", 17 | "shipmentId": "shp_3wmsgCJN4U", 18 | "settlementId": "stl_jDk30akdN", 19 | "createdAt": "2018-08-02T09:29:56+00:00", 20 | "_links": { 21 | "self": { 22 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT", 23 | "type": "application/hal+json" 24 | }, 25 | "payment": { 26 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 27 | "type": "application/hal+json" 28 | }, 29 | "shipment": { 30 | "href": "https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U", 31 | "type": "application/hal+json" 32 | }, 33 | "settlement": { 34 | "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", 35 | "type": "application/hal+json" 36 | }, 37 | "documentation": { 38 | "href": "https://docs.mollie.com/reference/v2/captures-api/get-capture", 39 | "type": "text/html" 40 | } 41 | } 42 | } 43 | ] 44 | }, 45 | "count": 1, 46 | "_links": { 47 | "documentation": { 48 | "href": "https://docs.mollie.com/reference/v2/captures-api/list-captures", 49 | "type": "text/html" 50 | }, 51 | "self": { 52 | "href": "https://api.mollie.dev/v2/payments/tr_WDqYK6vllg/captures?limit=50", 53 | "type": "application/hal+json" 54 | }, 55 | "previous": null, 56 | "next": null 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /test/fixtures/customer/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "customer", 3 | "id": "cst_8wmqcHMN4U", 4 | "mode": "test", 5 | "name": "Customer A", 6 | "email": "customer@example.org", 7 | "locale": "nl_NL", 8 | "metadata": null, 9 | "createdAt": "2018-04-06T13:23:21.0Z", 10 | "_links": { 11 | "self": { 12 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U", 13 | "type": "application/hal+json" 14 | }, 15 | "dashboard": { 16 | "href": "https://www.mollie.com/dashboard/org_123456789/customers/cst_8wmqcHMN4U", 17 | "type": "text/html" 18 | }, 19 | "mandates": { 20 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates", 21 | "type": "application/hal+json" 22 | }, 23 | "subscriptions": { 24 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions", 25 | "type": "application/hal+json" 26 | }, 27 | "payments": { 28 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/payments", 29 | "type": "application/hal+json" 30 | }, 31 | "documentation": { 32 | "href": "https://docs.mollie.com/reference/v2/customers-api/get-customer", 33 | "type": "text/html" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /test/fixtures/customer/list-payments-next.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 2, 3 | "_embedded": { 4 | "payments": [ 5 | { 6 | "resource": "payment", 7 | "id":"tr_3" 8 | }, 9 | { 10 | "resource": "payment", 11 | "id":"tr_4" 12 | } 13 | ] 14 | }, 15 | "_links": { 16 | "documentation": { 17 | "href": "https://docs.mollie.com/reference/v2/customers-api/list-customer-payments", 18 | "type": "text/html" 19 | }, 20 | "self": { 21 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/payments?from=tr_3&limit=2", 22 | "type": "application/hal+json" 23 | }, 24 | "previous": { 25 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/payments?from=tr_1&limit=2", 26 | "type": "application/hal+json" 27 | }, 28 | "next": null 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/customer/list-payments.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 2, 3 | "_embedded": { 4 | "payments": [ 5 | { 6 | "resource": "payment", 7 | "id":"tr_1" 8 | }, 9 | { 10 | "resource": "payment", 11 | "id":"tr_2" 12 | } 13 | ] 14 | }, 15 | "_links": { 16 | "documentation": { 17 | "href": "https://docs.mollie.com/reference/v2/customers-api/list-customer-payments", 18 | "type": "text/html" 19 | }, 20 | "self": { 21 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/payments?limit=2", 22 | "type": "application/hal+json" 23 | }, 24 | "previous": null, 25 | "next": { 26 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/payments?from=tr_3&limit=2", 27 | "type": "application/hal+json" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/methods/all.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 3, 3 | "_embedded": { 4 | "methods": [ 5 | { 6 | "resource": "method", 7 | "id": "ideal", 8 | "description": "iDEAL", 9 | "minimumAmount": { 10 | "value": "0.01", 11 | "currency": "EUR" 12 | }, 13 | "maximumAmount": { 14 | "value": "50000.00", 15 | "currency": "EUR" 16 | }, 17 | "image": { 18 | "size1x": "https://www.mollie.com/external/icons/payment-methods/ideal.png", 19 | "size2x": "https://www.mollie.com/external/icons/payment-methods/ideal%402x.png", 20 | "svg": "https://www.mollie.com/external/icons/payment-methods/ideal.svg" 21 | }, 22 | "status": "pending-boarding", 23 | "_links": { 24 | "self": { 25 | "href": "https://api.mollie.com/v2/methods/ideal", 26 | "type": "application/hal+json" 27 | } 28 | } 29 | }, 30 | { 31 | "resource": "method", 32 | "id": "creditcard", 33 | "description": "Credit card", 34 | "minimumAmount": { 35 | "value": "0.01", 36 | "currency": "EUR" 37 | }, 38 | "maximumAmount": { 39 | "value": "2000.00", 40 | "currency": "EUR" 41 | }, 42 | "image": { 43 | "size1x": "https://www.mollie.com/external/icons/payment-methods/creditcard.png", 44 | "size2x": "https://www.mollie.com/external/icons/payment-methods/creditcard%402x.png", 45 | "svg": "https://www.mollie.com/external/icons/payment-methods/creditcard.svg" 46 | }, 47 | "status": "pending-boarding", 48 | "_links": { 49 | "self": { 50 | "href": "https://api.mollie.com/v2/methods/creditcard", 51 | "type": "application/hal+json" 52 | } 53 | } 54 | }, 55 | { 56 | "resource": "method", 57 | "id": "bancontact", 58 | "description": "Bancontact", 59 | "minimumAmount": { 60 | "value": "0.02", 61 | "currency": "EUR" 62 | }, 63 | "maximumAmount": { 64 | "value": "50000.00", 65 | "currency": "EUR" 66 | }, 67 | "image": { 68 | "size1x": "https://www.mollie.com/external/icons/payment-methods/bancontact.png", 69 | "size2x": "https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png", 70 | "svg": "https://www.mollie.com/external/icons/payment-methods/bancontact.svg" 71 | }, 72 | "status": null, 73 | "_links": { 74 | "self": { 75 | "href": "https://api.mollie.com/v2/methods/bancontact", 76 | "type": "application/hal+json" 77 | } 78 | } 79 | } 80 | ] 81 | }, 82 | "_links": { 83 | "documentation": { 84 | "href": "https://docs.mollie.com/reference/v2/methods-api/list-all-methods", 85 | "type": "text/html" 86 | }, 87 | "self": { 88 | "href": "https://api.mollie.com/v2/methods/all", 89 | "type": "application/hal+json" 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /test/fixtures/methods/get-includes-pricing.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "method", 3 | "id": "creditcard", 4 | "description": "Credit card", 5 | "minimumAmount": { 6 | "value": "0.01", 7 | "currency": "EUR" 8 | }, 9 | "maximumAmount": { 10 | "value": "2000.00", 11 | "currency": "EUR" 12 | }, 13 | "image": { 14 | "size1x": "https://www.mollie.com/external/icons/payment-methods/creditcard.png", 15 | "size2x": "https://www.mollie.com/external/icons/payment-methods/creditcard%402x.png", 16 | "svg": "https://www.mollie.com/external/icons/payment-methods/creditcard.svg" 17 | }, 18 | "pricing": [ 19 | { 20 | "description": "Commercial & non-European cards", 21 | "fixed": { 22 | "value": "0.25", 23 | "currency": "EUR" 24 | }, 25 | "variable": "2.8", 26 | "feeRegion": "other" 27 | }, 28 | { 29 | "description": "European cards", 30 | "fixed": { 31 | "value": "0.25", 32 | "currency": "EUR" 33 | }, 34 | "variable": "1.8", 35 | "feeRegion": "eu-cards" 36 | }, 37 | { 38 | "description": "Maestro", 39 | "fixed": { 40 | "value": "0.39", 41 | "currency": "EUR" 42 | }, 43 | "variable": "0", 44 | "feeRegion": "maestro" 45 | } 46 | ], 47 | "_links": { 48 | "self": { 49 | "href": "https://api.mollie.com/v2/methods/creditcard?include=pricing", 50 | "type": "application/hal+json" 51 | }, 52 | "documentation": { 53 | "href": "https://docs.mollie.com/reference/v2/methods-api/get-method", 54 | "type": "text/html" 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /test/fixtures/onboarding/me.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "onboarding", 3 | "name": "Mollie B.V.", 4 | "signedUpAt": "2018-12-20T10:49:08+00:00", 5 | "status": "completed", 6 | "canReceivePayments": true, 7 | "canReceiveSettlements": true, 8 | "_links": { 9 | "self": { 10 | "href": "https://api.mollie.com/v2/onboarding/me", 11 | "type": "application/hal+json" 12 | }, 13 | "dashboard": { 14 | "href": "https://www.mollie.com/dashboard/onboarding", 15 | "type": "text/html" 16 | }, 17 | "organization": { 18 | "href": "https://api.mollie.com/v2/organization/org_12345", 19 | "type": "application/hal+json" 20 | }, 21 | "documentation": { 22 | "href": "https://docs.mollie.com/reference/v2/onboarding-api/get-onboarding-status", 23 | "type": "text/html" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/fixtures/onboarding/submit.json: -------------------------------------------------------------------------------- 1 | { 2 | "organization": { 3 | "name": "Mollie B.V.", 4 | "address": { 5 | "streetAndNumber": "Keizersgracht 313", 6 | "postalCode": "1018 EE", 7 | "city": "Amsterdam", 8 | "country": "NL" 9 | }, 10 | "registrationNumber": "30204462", 11 | "vatNumber": "NL815839091B01" 12 | }, 13 | "profile": { 14 | "name": "Mollie", 15 | "url": "https://www.mollie.com", 16 | "email": "info@mollie.com", 17 | "phone": "+31208202070", 18 | "categoryCode": 6012 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /test/fixtures/orders/cancel_line.json: -------------------------------------------------------------------------------- 1 | { 2 | "lines": [ 3 | { 4 | "id": "odl_dgtxyl", 5 | "quantity": 2 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/orders/cancel_line_qty.json: -------------------------------------------------------------------------------- 1 | { 2 | "lines": [ 3 | { 4 | "id": "odl_dgtxyl", 5 | "quantity": 1 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/orders/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "amount": { 3 | "value": "1027.99", 4 | "currency": "EUR" 5 | }, 6 | "billingAddress": { 7 | "organizationName": "Mollie B.V.", 8 | "streetAndNumber": "Keizersgracht 313", 9 | "city": "Amsterdam", 10 | "region": "Noord-Holland", 11 | "postalCode": "1234AB", 12 | "country": "NL", 13 | "title": "Dhr", 14 | "givenName": "Piet", 15 | "familyName": "Mondriaan", 16 | "email": "piet@mondriaan.com", 17 | "phone": "+31208202070" 18 | }, 19 | "shippingAddress": { 20 | "organizationName": "Mollie B.V.", 21 | "streetAndNumber": "Prinsengracht 313", 22 | "streetAdditional": "4th floor", 23 | "city": "Haarlem", 24 | "region": "Noord-Holland", 25 | "postalCode": "5678AB", 26 | "country": "NL", 27 | "title": "Mr", 28 | "givenName": "Chuck", 29 | "familyName": "Norris", 30 | "email": "norris@chucknorrisfacts.net" 31 | }, 32 | "metadata": { 33 | "order_id": "1337", 34 | "description": "Lego cars" 35 | }, 36 | "consumerDateOfBirth": "1958-01-31", 37 | "locale": "nl_NL", 38 | "orderNumber": "1337", 39 | "redirectUrl": "https://example.org/redirect", 40 | "webhookUrl": "https://example.org/webhook", 41 | "method": "klarnapaylater", 42 | "lines": [ 43 | { 44 | "type": "physical", 45 | "sku": "5702016116977", 46 | "name": "LEGO 42083 Bugatti Chiron", 47 | "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", 48 | "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", 49 | "metadata": { 50 | "order_id": "1337", 51 | "description": "Bugatti Chiron" 52 | }, 53 | "quantity": 2, 54 | "vatRate": "21.00", 55 | "unitPrice": { 56 | "currency": "EUR", 57 | "value": "399.00" 58 | }, 59 | "totalAmount": { 60 | "currency": "EUR", 61 | "value": "698.00" 62 | }, 63 | "discountAmount": { 64 | "currency": "EUR", 65 | "value": "100.00" 66 | }, 67 | "vatAmount": { 68 | "currency": "EUR", 69 | "value": "121.14" 70 | } 71 | }, 72 | { 73 | "type": "physical", 74 | "sku": "5702015594028", 75 | "name": "LEGO 42056 Porsche 911 GT3 RS", 76 | "productUrl": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", 77 | "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", 78 | "quantity": 1, 79 | "vatRate": "21.00", 80 | "unitPrice": { 81 | "currency": "EUR", 82 | "value": "329.99" 83 | }, 84 | "totalAmount": { 85 | "currency": "EUR", 86 | "value": "329.99" 87 | }, 88 | "vatAmount": { 89 | "currency": "EUR", 90 | "value": "57.27" 91 | } 92 | } 93 | ] 94 | } 95 | -------------------------------------------------------------------------------- /test/fixtures/orders/create_payment.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "payment", 3 | "id": "tr_ncaPcAhuUV", 4 | "mode": "live", 5 | "createdAt": "2018-09-07T12:00:05+00:00", 6 | "amount": { 7 | "value": "1027.99", 8 | "currency": "EUR" 9 | }, 10 | "description": "Order #1337 (Lego cars)", 11 | "method": null, 12 | "metadata": null, 13 | "status": "open", 14 | "isCancelable": false, 15 | "locale": "nl_NL", 16 | "profileId": "pfl_URR55HPMGx", 17 | "orderId": "ord_kEn1PlbGa", 18 | "sequenceType": "oneoff", 19 | "redirectUrl": "https://example.org/redirect", 20 | "_links": { 21 | "self": { 22 | "href": "https://api.mollie.com/v2/payments/tr_ncaPcAhuUV", 23 | "type": "application/hal+json" 24 | }, 25 | "checkout": { 26 | "href": "https://www.mollie.com/payscreen/select-method/ncaPcAhuUV", 27 | "type": "text/html" 28 | }, 29 | "dashboard": { 30 | "href": "https://www.mollie.com/dashboard/org_123456789/payments/tr_ncaPcAhuUV", 31 | "type": "text/html" 32 | }, 33 | "order": { 34 | "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", 35 | "type": "application/hal+json" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /test/fixtures/orders/create_refund.json: -------------------------------------------------------------------------------- 1 | { 2 | "lines": [ 3 | { 4 | "id": "odl_dgtxyl", 5 | "quantity": 1 6 | } 7 | ], 8 | "description": "Required quantity not in stock, refunding one photo book." 9 | } 10 | -------------------------------------------------------------------------------- /test/fixtures/orders/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 3, 3 | "_embedded": { 4 | "orders": [ 5 | { 6 | "resource": "order", 7 | "id": "ord_one" 8 | }, 9 | { 10 | "resource": "order", 11 | "id": "ord_two" 12 | }, 13 | { 14 | "resource": "order", 15 | "id": "ord_three" 16 | } 17 | ] 18 | }, 19 | "_links": { 20 | "self": { 21 | "href": "https://api.mollie.com/v2/orders", 22 | "type": "application/hal+json" 23 | }, 24 | "previous": null, 25 | "next": { 26 | "href": "https://api.mollie.com/v2/orders?from=ord_stTC2WHAuS", 27 | "type": "application/hal+json" 28 | }, 29 | "documentation": { 30 | "href": "https://docs.mollie.com/reference/v2/orders-api/list-orders", 31 | "type": "text/html" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/fixtures/orders/list_refunds.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 1, 3 | "_embedded": { 4 | "refunds": [ 5 | { 6 | "resource": "refund", 7 | "id": "re_4qqhO89gsT", 8 | "amount": { 9 | "currency": "EUR", 10 | "value": "698.00" 11 | }, 12 | "status": "processing", 13 | "createdAt": "2018-03-14T17:09:02.0Z", 14 | "description": "Required quantity not in stock, refunding one photo book.", 15 | "paymentId": "tr_WDqYK6vllg", 16 | "orderId": "ord_kEn1PlbGa", 17 | "lines": [ 18 | { 19 | "resource": "orderline", 20 | "id": "odl_dgtxyl", 21 | "orderId": "ord_kEn1PlbGa", 22 | "name": "LEGO 42083 Bugatti Chiron", 23 | "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", 24 | "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", 25 | "sku": "5702016116977", 26 | "type": "physical", 27 | "status": "refunded", 28 | "quantity": 2, 29 | "unitPrice": { 30 | "value": "399.00", 31 | "currency": "EUR" 32 | }, 33 | "vatRate": "21.00", 34 | "vatAmount": { 35 | "value": "121.14", 36 | "currency": "EUR" 37 | }, 38 | "discountAmount": { 39 | "value": "100.00", 40 | "currency": "EUR" 41 | }, 42 | "totalAmount": { 43 | "value": "698.00", 44 | "currency": "EUR" 45 | }, 46 | "createdAt": "2018-08-02T09:29:56+00:00" 47 | } 48 | ], 49 | "_links": { 50 | "self": { 51 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", 52 | "type": "application/hal+json" 53 | }, 54 | "payment": { 55 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 56 | "type": "application/hal+json" 57 | }, 58 | "order": { 59 | "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", 60 | "type": "application/hal+json" 61 | }, 62 | "documentation": { 63 | "href": "https://docs.mollie.com/reference/v2/refunds-api/get-refund", 64 | "type": "text/html" 65 | } 66 | } 67 | } 68 | ] 69 | }, 70 | "_links": { 71 | "self": { 72 | "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/refunds?limit=5", 73 | "type": "application/hal+json" 74 | }, 75 | "previous": null, 76 | "next": { 77 | "href": "https://api.mollie.com/v2/payments/tr_7UhSN1zuXS/refunds?from=re_APBiGPH2vV&limit=5", 78 | "type": "application/hal+json" 79 | }, 80 | "documentation": { 81 | "href": "https://docs.mollie.com/reference/v2/orders-api/list-order-refunds", 82 | "type": "text/html" 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /test/fixtures/orders/refund.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "refund", 3 | "id": "re_4qqhO89gsT", 4 | "amount": { 5 | "currency": "EUR", 6 | "value": "698.00" 7 | }, 8 | "status": "pending", 9 | "createdAt": "2018-03-14T17:09:02.0Z", 10 | "description": "Required quantity not in stock, refunding one photo book.", 11 | "paymentId": "tr_WDqYK6vllg", 12 | "orderId": "ord_kEn1PlbGa", 13 | "lines": [ 14 | { 15 | "resource": "orderline", 16 | "id": "odl_dgtxyl", 17 | "orderId": "ord_kEn1PlbGa", 18 | "name": "LEGO 42083 Bugatti Chiron", 19 | "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", 20 | "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", 21 | "sku": "5702016116977", 22 | "type": "physical", 23 | "status": "refunded", 24 | "quantity": 2, 25 | "unitPrice": { 26 | "value": "399.00", 27 | "currency": "EUR" 28 | }, 29 | "vatRate": "21.00", 30 | "vatAmount": { 31 | "value": "121.14", 32 | "currency": "EUR" 33 | }, 34 | "discountAmount": { 35 | "value": "100.00", 36 | "currency": "EUR" 37 | }, 38 | "totalAmount": { 39 | "value": "698.00", 40 | "currency": "EUR" 41 | }, 42 | "createdAt": "2018-08-02T09:29:56+00:00" 43 | } 44 | ], 45 | "_links": { 46 | "self": { 47 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", 48 | "type": "application/hal+json" 49 | }, 50 | "payment": { 51 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 52 | "type": "application/hal+json" 53 | }, 54 | "order": { 55 | "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", 56 | "type": "application/hal+json" 57 | }, 58 | "documentation": { 59 | "href": "https://docs.mollie.com/reference/v2/orders-api/create-order-refund", 60 | "type": "text/html" 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/fixtures/orders/refund_all.json: -------------------------------------------------------------------------------- 1 | { 2 | "lines": [] 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/orders/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "billingAddress": { 3 | "city": "Amsterdam", 4 | "country": "NL", 5 | "email": "piet@mondriaan.com", 6 | "familyName": "Mondriaan", 7 | "givenName": "Piet", 8 | "phone": "+31208202070", 9 | "postalCode": "1234AB", 10 | "region": "Noord-Holland", 11 | "streetAndNumber": "Keizersgracht 313", 12 | "title": "Dhr" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/organizations/partner.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "partner", 3 | "partnerType": "signuplink", 4 | "isCommissionPartner": true, 5 | "userAgentTokens": [{ 6 | "token": "unique-token", 7 | "startsAt": "2018-03-20T13:13:37+00:00", 8 | "endsAt": null 9 | }], 10 | "partnerContractSignedAt": "2018-03-20T13:13:37+00:00", 11 | "partnerContractUpdateAvailable": true, 12 | "_links": { 13 | "self": { 14 | "href": "https://api.mollie.com/v2/organizations/me/partner", 15 | "type": "application/hal+json" 16 | }, 17 | "documentation": { 18 | "href": "https://docs.mollie.com/reference/v2/organizations-api/get-partner", 19 | "type": "text/html" 20 | }, 21 | "signuplink": { 22 | "href": "https://www.mollie.com/dashboard/signup/myCode?lang=en", 23 | "type": "text/html" 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /test/fixtures/payment_links/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Bicycle tires", 3 | "amount": { 4 | "currency": "EUR", 5 | "value": "24.95" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/payment_links/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "payment-link", 3 | "id": "pl_4Y0eZitmBnQ6IDoMqZQKh", 4 | "mode": "test", 5 | "description": "Bicycle tires", 6 | "archived": false, 7 | "profile_id": "pfl_QkEhN94Ba", 8 | "amount": { 9 | "currency": "EUR", 10 | "value": "24.95" 11 | }, 12 | "webhook_url": "https://webshop.example.org/payment-links/webhook", 13 | "redirect_url": "https://webshop.example.org/thanks", 14 | "created_at": "2024-09-24T12:16:44+00:00", 15 | "paid_at": null, 16 | "updated_at": null, 17 | "expires_at": null, 18 | "_links": { 19 | "self": { 20 | "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh", 21 | "type": "application/hal+json" 22 | }, 23 | "paymentLink": { 24 | "href": "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", 25 | "type": "text/html" 26 | }, 27 | "documentation": { 28 | "href": "https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link", 29 | "type": "text/html" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /test/fixtures/payment_links/list-payments.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 3, 3 | "_embedded": { 4 | "payments": [ 5 | { 6 | "resource": "payment", 7 | "id": "tr_one" 8 | }, 9 | { 10 | "resource": "payment", 11 | "id": "tr_two" 12 | }, 13 | { 14 | "resource": "payment", 15 | "id": "tr_three" 16 | } 17 | ] 18 | }, 19 | "_links": { 20 | "self": { 21 | "href": "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments?limit=50", 22 | "type": "application/hal+json" 23 | }, 24 | "previous": null, 25 | "next": null, 26 | "documentation": { 27 | "href": "https://docs.mollie.com/reference/get-payment-link-payments", 28 | "type": "text/html" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/payment_links/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 3, 3 | "_embedded": { 4 | "payment_links": [ 5 | { 6 | "resource": "payment-link", 7 | "id": "pl_one" 8 | }, 9 | { 10 | "resource": "payment-link", 11 | "id": "pl_two" 12 | }, 13 | { 14 | "resource": "payment-link", 15 | "id": "pl_three" 16 | } 17 | ] 18 | }, 19 | "_links": { 20 | "self": { 21 | "href": "https://api.mollie.com/v2/payment-links?limit=50", 22 | "type": "application/hal+json" 23 | }, 24 | "previous": null, 25 | "next": null, 26 | "documentation": { 27 | "href": "https://docs.mollie.com/reference/v2/payment-links-api/list-payment-links", 28 | "type": "text/html" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/payment_links/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Car tires", 3 | "archived": true 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/payments/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "payment", 3 | "id": "tr_WDqYK6vllg", 4 | "mode": "test", 5 | "createdAt": "2018-03-20T13:13:37+00:00", 6 | "amount": { 7 | "value": "10.00", 8 | "currency": "EUR" 9 | }, 10 | "description": "Order #12345", 11 | "method": null, 12 | "metadata": { 13 | "order_id": "12345" 14 | }, 15 | "status": "open", 16 | "isCancelable": false, 17 | "locale": "nl_NL", 18 | "restrictPaymentMethodsToCountry": "NL", 19 | "expiresAt": "2018-03-20T13:28:37+00:00", 20 | "details": null, 21 | "profileId": "pfl_QkEhN94Ba", 22 | "sequenceType": "oneoff", 23 | "redirectUrl": "https://webshop.example.org/order/12345/", 24 | "webhookUrl": "https://webshop.example.org/payments/webhook/", 25 | "_links": { 26 | "self": { 27 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 28 | "type": "application/hal+json" 29 | }, 30 | "checkout": { 31 | "href": "https://www.mollie.com/payscreen/select-method/WDqYK6vllg", 32 | "type": "text/html" 33 | }, 34 | "documentation": { 35 | "href": "https://docs.mollie.com/reference/v2/payments-api/get-payment", 36 | "type": "text/html" 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /test/fixtures/payments/get_embedded_resources.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "payment", 3 | "id": "tr_WDqYK6vllg", 4 | "mode": "test", 5 | "createdAt": "2018-03-20T13:13:37+00:00", 6 | "amount": { 7 | "value": "10.00", 8 | "currency": "EUR" 9 | }, 10 | "description": "Order #12345", 11 | "method": null, 12 | "metadata": { 13 | "order_id": "12345" 14 | }, 15 | "status": "open", 16 | "isCancelable": false, 17 | "locale": "nl_NL", 18 | "restrictPaymentMethodsToCountry": "NL", 19 | "expiresAt": "2018-03-20T13:28:37+00:00", 20 | "details": null, 21 | "profileId": "pfl_QkEhN94Ba", 22 | "sequenceType": "oneoff", 23 | "redirectUrl": "https://webshop.example.org/order/12345/", 24 | "webhookUrl": "https://webshop.example.org/payments/webhook/", 25 | "_embedded": { 26 | "captures": [ 27 | { 28 | "resource": "capture", 29 | "id": "cpt_mNepDkEtco6ah3QNPUGYH", 30 | "mode": "test", 31 | "amount": { 32 | "value": "10.00", 33 | "currency": "EUR" 34 | }, 35 | "status": "succeeded", 36 | "createdAt": "2025-03-19T15:03:34+00:00", 37 | "description": "Capture for order #12345", 38 | "settlementAmount": { 39 | "value": "10.00", 40 | "currency": "EUR" 41 | }, 42 | "paymentId": "tr_WDqYK6vllg", 43 | "_links": { 44 | "self": { 45 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_mNepDkEtco6ah3QNPUGYH", 46 | "type": "application/hal+json" 47 | }, 48 | "payment": { 49 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 50 | "type": "application/hal+json" 51 | } 52 | } 53 | } 54 | ], 55 | "chargebacks": [ 56 | { 57 | "resource": "chargeback", 58 | "id": "chb_ls7ahg", 59 | "amount": { 60 | "value": "10.00", 61 | "currency": "EUR" 62 | }, 63 | "created_at": "2022-01-03T13:20:37+00:00", 64 | "payment_id": "tr_WDqYK6vllg", 65 | "settlement_amount": { 66 | "value": "-10.00", 67 | "currency": "EUR" 68 | }, 69 | "_links": { 70 | "self": { 71 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_ls7ahg", 72 | "type": "application/hal+json" 73 | }, 74 | "payment": { 75 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 76 | "type": "application/hal+json" 77 | } 78 | } 79 | } 80 | ], 81 | "refunds": [ 82 | { 83 | "resource": "refund", 84 | "id": "re_vD3Jm32wQt", 85 | "mode": "test", 86 | "amount": { 87 | "value": "329.99", 88 | "currency": "EUR" 89 | }, 90 | "status": "pending", 91 | "createdAt": "2019-01-15T15:41:21+00:00", 92 | "description": "Required quantity not in stock, refunding one photo book.", 93 | "metadata": null, 94 | "paymentId": "tr_WDqYK6vllg", 95 | "settlementAmount": { 96 | "value": "-329.99", 97 | "currency": "EUR" 98 | }, 99 | "_links": { 100 | "self": { 101 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_vD3Jm32wQt", 102 | "type": "application/hal+json" 103 | }, 104 | "payment": { 105 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 106 | "type": "application/hal+json" 107 | } 108 | } 109 | } 110 | ] 111 | }, 112 | "_links": { 113 | "self": { 114 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 115 | "type": "application/hal+json" 116 | }, 117 | "checkout": { 118 | "href": "https://www.mollie.com/payscreen/select-method/WDqYK6vllg", 119 | "type": "text/html" 120 | }, 121 | "documentation": { 122 | "href": "https://docs.mollie.com/reference/v2/payments-api/get-payment", 123 | "type": "text/html" 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /test/fixtures/refunds/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "refund", 3 | "id": "re_4qqhO89gsT", 4 | "amount": { 5 | "value": "1027.99", 6 | "currency": "EUR" 7 | }, 8 | "status": "pending", 9 | "createdAt": "2018-09-25T17:40:23+00:00", 10 | "description": "Required quantity not in stock, refunding one photo book.", 11 | "metadata": { 12 | "bookkeeping_id": 12345 13 | }, 14 | "orderId": "ord_stTC2WHAuS", 15 | "paymentId": "tr_WDqYK6vllg", 16 | "settlementAmount": { 17 | "value": "-1027.99", 18 | "currency": "EUR" 19 | }, 20 | "lines": [ 21 | { 22 | "resource": "orderline", 23 | "id": "odl_d1ec55", 24 | "orderId": "ord_stTC2WHAuS", 25 | "name": "LEGO 42083 Bugatti Chiron", 26 | "sku": "5702016116977", 27 | "type": "physical", 28 | "status": "completed", 29 | "isCancelable": false, 30 | "quantity": 2, 31 | "unitPrice": { 32 | "value": "399.00", 33 | "currency": "EUR" 34 | }, 35 | "vatRate": "21.00", 36 | "vatAmount": { 37 | "value": "121.14", 38 | "currency": "EUR" 39 | }, 40 | "totalAmount": { 41 | "value": "698.00", 42 | "currency": "EUR" 43 | }, 44 | "createdAt": "2018-09-23T17:23:13+00:00", 45 | "discountAmount": { 46 | "value": "100.00", 47 | "currency": "EUR" 48 | }, 49 | "_links": { 50 | "productUrl": { 51 | "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", 52 | "type": "text/html" 53 | }, 54 | "imageUrl": { 55 | "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", 56 | "type": "text/html" 57 | } 58 | } 59 | }, 60 | { 61 | "resource": "orderline", 62 | "id": "odl_j3eusr", 63 | "orderId": "ord_stTC2WHAuS", 64 | "name": "LEGO 42056 Porsche 911 GT3 RS", 65 | "sku": "5702015594028", 66 | "type": "physical", 67 | "status": "completed", 68 | "isCancelable": false, 69 | "quantity": 1, 70 | "unitPrice": { 71 | "value": "329.99", 72 | "currency": "EUR" 73 | }, 74 | "vatRate": "21.00", 75 | "vatAmount": { 76 | "value": "57.27", 77 | "currency": "EUR" 78 | }, 79 | "totalAmount": { 80 | "value": "329.99", 81 | "currency": "EUR" 82 | }, 83 | "createdAt": "2018-09-23T17:23:13+00:00", 84 | "_links": { 85 | "productUrl": { 86 | "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", 87 | "type": "text/html" 88 | }, 89 | "imageUrl": { 90 | "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", 91 | "type": "text/html" 92 | } 93 | } 94 | } 95 | ], 96 | "_links": { 97 | "self": { 98 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg/refunds/re_4qqhO89gsT", 99 | "type": "application/hal+json" 100 | }, 101 | "payment": { 102 | "href": "https://api.mollie.com/v2/payments/tr_WDqYK6vllg", 103 | "type": "application/hal+json" 104 | }, 105 | "order": { 106 | "href": "https://api.mollie.com/v2/orders/ord_stTC2WHAuS", 107 | "type": "application/hal+json" 108 | }, 109 | "documentation": { 110 | "href": "https://docs.mollie.com/reference/v2/refunds-api/get-refund", 111 | "type": "text/html" 112 | } 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /test/fixtures/shipments/create.json: -------------------------------------------------------------------------------- 1 | { 2 | "lines": [ 3 | { 4 | "id": "odl_dgtxyl", 5 | "quantity": 1 6 | }, 7 | { 8 | "id": "odl_jp31jz" 9 | } 10 | ], 11 | "tracking": { 12 | "carrier": "PostNL", 13 | "code": "3SKABA000000000", 14 | "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /test/fixtures/shipments/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "shipment", 3 | "id": "shp_3wmsgCJN4U", 4 | "orderId": "ord_kEn1PlbGa", 5 | "createdAt": "2018-08-09T14:33:54+00:00", 6 | "tracking": { 7 | "carrier": "PostNL", 8 | "code": "3SKABA000000000", 9 | "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" 10 | }, 11 | "lines": [ 12 | { 13 | "resource": "orderline", 14 | "id": "odl_dgtxyl", 15 | "orderId": "ord_kEn1PlbGa", 16 | "name": "LEGO 42083 Bugatti Chiron", 17 | "sku": "5702016116977", 18 | "type": "physical", 19 | "status": "shipping", 20 | "isCancelable": true, 21 | "quantity": 2, 22 | "unitPrice": { 23 | "value": "399.00", 24 | "currency": "EUR" 25 | }, 26 | "vatRate": "21.00", 27 | "vatAmount": { 28 | "value": "121.14", 29 | "currency": "EUR" 30 | }, 31 | "totalAmount": { 32 | "value": "698.00", 33 | "currency": "EUR" 34 | }, 35 | "createdAt": "2018-09-23T17:23:13+00:00", 36 | "discountAmount": { 37 | "value": "100.00", 38 | "currency": "EUR" 39 | }, 40 | "_links": { 41 | "productUrl": { 42 | "href": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", 43 | "type": "text/html" 44 | }, 45 | "imageUrl": { 46 | "href": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", 47 | "type": "text/html" 48 | } 49 | } 50 | }, 51 | { 52 | "resource": "orderline", 53 | "id": "odl_j3eusr", 54 | "orderId": "ord_kEn1PlbGa", 55 | "name": "LEGO 42056 Porsche 911 GT3 RS", 56 | "sku": "5702015594028", 57 | "type": "physical", 58 | "status": "shipping", 59 | "isCancelable": true, 60 | "quantity": 1, 61 | "unitPrice": { 62 | "value": "329.99", 63 | "currency": "EUR" 64 | }, 65 | "vatRate": "21.00", 66 | "vatAmount": { 67 | "value": "57.27", 68 | "currency": "EUR" 69 | }, 70 | "totalAmount": { 71 | "value": "329.99", 72 | "currency": "EUR" 73 | }, 74 | "createdAt": "2018-09-23T17:23:13+00:00", 75 | "_links": { 76 | "productUrl": { 77 | "href": "https://shop.lego.com/nl-NL/Porsche-911-GT3-RS-42056", 78 | "type": "text/html" 79 | }, 80 | "imageUrl": { 81 | "href": "https://sh-s7-live-s.legocdn.com/is/image/LEGO/42056?$PDPDefault$", 82 | "type": "text/html" 83 | } 84 | } 85 | } 86 | ], 87 | "_links": { 88 | "self": { 89 | "href": "https://api.mollie.com/v2/order/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U", 90 | "type": "application/hal+json" 91 | }, 92 | "order": { 93 | "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", 94 | "type": "application/hal+json" 95 | }, 96 | "documentation": { 97 | "href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment", 98 | "type": "text/html" 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /test/fixtures/shipments/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 1, 3 | "_embedded": { 4 | "shipments": [ 5 | { 6 | "resource": "shipment", 7 | "id": "shp_3wmsgCJN4U", 8 | "orderId": "ord_kEn1PlbGa", 9 | "createdAt": "2018-08-09T14:33:54+00:00", 10 | "tracking": { 11 | "carrier": "PostNL", 12 | "code": "3SKABA000000000", 13 | "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" 14 | }, 15 | "lines": [ 16 | { 17 | "resource": "orderline", 18 | "id": "odl_dgtxyl", 19 | "orderId": "ord_pbjz8x", 20 | "name": "LEGO 42083 Bugatti Chiron", 21 | "productUrl": "https://shop.lego.com/nl-NL/Bugatti-Chiron-42083", 22 | "imageUrl": "https://sh-s7-live-s.legocdn.com/is/image//LEGO/42083_alt1?$main$", 23 | "sku": "5702016116977", 24 | "type": "physical", 25 | "status": "shipping", 26 | "quantity": 2, 27 | "unitPrice": { 28 | "value": "399.00", 29 | "currency": "EUR" 30 | }, 31 | "vatRate": "21.00", 32 | "vatAmount": { 33 | "value": "121.14", 34 | "currency": "EUR" 35 | }, 36 | "discountAmount": { 37 | "value": "100.00", 38 | "currency": "EUR" 39 | }, 40 | "totalAmount": { 41 | "value": "698.00", 42 | "currency": "EUR" 43 | }, 44 | "createdAt": "2018-08-02T09:29:56+00:00" 45 | } 46 | ], 47 | "_links": { 48 | "self": { 49 | "href": "https://api.mollie.com/v2/order/ord_kEn1PlbGa/shipments/shp_3wmsgCJN4U", 50 | "type": "application/hal+json" 51 | }, 52 | "order": { 53 | "href": "https://api.mollie.com/v2/orders/ord_kEn1PlbGa", 54 | "type": "application/hal+json" 55 | }, 56 | "documentation": { 57 | "href": "https://docs.mollie.com/reference/v2/shipments-api/get-shipment", 58 | "type": "text/html" 59 | } 60 | } 61 | } 62 | ] 63 | }, 64 | "_links": { 65 | "self": { 66 | "href": "https://api.mollie.com/v2/order/ord_kEn1PlbGa/shipments", 67 | "type": "application/hal+json" 68 | }, 69 | "documentation": { 70 | "href": "https://docs.mollie.com/reference/v2/shipments-api/list-shipments", 71 | "type": "text/html" 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /test/fixtures/shipments/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "tracking": { 3 | "carrier": "PostNL", 4 | "code": "3SKABA000000000", 5 | "url": "http://postnl.nl/tracktrace/?B=3SKABA000000000&P=1016EE&D=NL&T=C" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/subscriptions/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "subscription", 3 | "id": "sub_8JfGzs6v3K", 4 | "mode": "live", 5 | "createdAt": "2016-06-01T12:23:34+00:00", 6 | "status": "active", 7 | "amount": { 8 | "value": "25.00", 9 | "currency": "EUR" 10 | }, 11 | "times": 4, 12 | "timesRemaining": 4, 13 | "interval": "3 months", 14 | "startDate": "2016-06-01", 15 | "nextPaymentDate": "2016-09-01", 16 | "description": "Quarterly payment", 17 | "method": null, 18 | "mandateId": "mdt_aGQNkteF6w", 19 | "webhookUrl": "https://webshop.example.org/payments/webhook", 20 | "metadata": { 21 | "plan": "small" 22 | }, 23 | "_links": { 24 | "self": { 25 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K", 26 | "type": "application/hal+json" 27 | }, 28 | "customer": { 29 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U", 30 | "type": "application/hal+json" 31 | }, 32 | "payments": { 33 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K/payments", 34 | "type": "application/hal+json" 35 | }, 36 | "profile": { 37 | "href": "https://api.mollie.com/v2/profiles/pfl_URR55HPMGx", 38 | "type": "application/hal+json" 39 | }, 40 | "documentation": { 41 | "href": "https://docs.mollie.com/reference/v2/subscriptions-api/get-subscription", 42 | "type": "text/html" 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/fixtures/subscriptions/get_payments.json: -------------------------------------------------------------------------------- 1 | { 2 | "_embedded": { 3 | "payments": [ 4 | { 5 | "resource": "payment", 6 | "id": "tr_DtKxVP2AgW", 7 | "mode": "live", 8 | "createdAt": "2018-09-19T12:49:52+00:00", 9 | "amount": { 10 | "value": "10.00", 11 | "currency": "EUR" 12 | }, 13 | "description": "Some subscription 19 sep. 2018", 14 | "method": "directdebit", 15 | "metadata": null, 16 | "status": "pending", 17 | "isCancelable": true, 18 | "expiresAt": "2019-09-19T12:49:52+00:00", 19 | "locale": "nl_NL", 20 | "profileId": "pfl_URR55HPMGx", 21 | "customerId": "cst_8wmqcHMN4U", 22 | "mandateId": "mdt_aGQNkteF6w", 23 | "subscriptionId": "sub_8JfGzs6v3K", 24 | "sequenceType": "recurring", 25 | "redirectUrl": null, 26 | "webhookUrl": "https://example.org/webhook", 27 | "settlementAmount": { 28 | "value": "10.00", 29 | "currency": "EUR" 30 | }, 31 | "details": { 32 | "transferReference": "SD67-6850-2204-6029", 33 | "creditorIdentifier": "NL08ZZZ502057730000", 34 | "consumerName": "Customer A", 35 | "consumerAccount": "NL50INGB0006588912", 36 | "consumerBic": "INGBNL2A", 37 | "dueDate": "2018-09-21", 38 | "signatureDate": "2018-09-19" 39 | }, 40 | "_links": { 41 | "self": { 42 | "href": "https://api.mollie.com/v2/payments/tr_DtKxVP2AgW", 43 | "type": "application/hal+json" 44 | }, 45 | "checkout": null, 46 | "customer": { 47 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U", 48 | "type": "application/hal+json" 49 | }, 50 | "mandate": { 51 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/mandates/mdt_aGQNkteF6w", 52 | "type": "application/hal+json" 53 | }, 54 | "subscription": { 55 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K", 56 | "type": "application/hal+json" 57 | } 58 | } 59 | } 60 | ] 61 | }, 62 | "count": 1, 63 | "_links": { 64 | "documentation": { 65 | "href": "https://docs.mollie.com/reference/v2/subscriptions-api/list-subscriptions-payments", 66 | "type": "text/html" 67 | }, 68 | "self": { 69 | "href": "https://api.mollie.com/v2/customers/cst_8wmqcHMN4U/subscriptions/sub_8JfGzs6v3K/payments?limit=50", 70 | "type": "application/hal+json" 71 | }, 72 | "previous": null, 73 | "next": null 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/fixtures/terminals/get.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "term_7MgL4wea46qkRcoTZjWEH", 3 | "profileId": "pfl_QkEhN94Ba", 4 | "status": "active", 5 | "brand": "PAX", 6 | "model": "A920", 7 | "serialNumber": "1234567890", 8 | "currency": "EUR", 9 | "description": "Terminal #12345", 10 | "createdAt": "2022-02-12T11:58:35.0Z", 11 | "updatedAt": "2022-11-15T13:32:11+00:00", 12 | "deactivatedAt": "2022-02-12T12:13:35.0Z", 13 | "_links": { 14 | "self": { 15 | "href": "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH", 16 | "type": "application/hal+json" 17 | }, 18 | "documentation": { 19 | "href": "https://docs.mollie.com/reference/v2/terminals-api/get-terminal", 20 | "type": "text/html" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /test/fixtures/terminals/list.json: -------------------------------------------------------------------------------- 1 | { 2 | "count": 3, 3 | "_embedded": { 4 | "terminals": [ 5 | { 6 | "resource": "terminal", 7 | "id": "terminal_one" 8 | }, 9 | { 10 | "resource": "terminal", 11 | "id": "terminal_two" 12 | }, 13 | { 14 | "resource": "terminal", 15 | "id": "terminal_three" 16 | } 17 | ] 18 | }, 19 | "_links": { 20 | "self": { 21 | "href": "https://api.mollie.com/v2/terminals", 22 | "type": "application/hal+json" 23 | }, 24 | "previous": null, 25 | "next": { 26 | "href": "https://api.mollie.com/v2/terminals?from=term_7MgL4wea46qkRcoTZjWEH", 27 | "type": "application/hal+json" 28 | }, 29 | "documentation": { 30 | "href": "https://docs.mollie.com/reference/v2/terminals-api/list-terminals", 31 | "type": "text/html" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/helper.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'webmock/test_unit' 3 | 4 | require 'mollie' 5 | 6 | Mollie::Client.configure do |config| 7 | config.api_key = 'test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM' 8 | end 9 | 10 | def read_fixture(path) 11 | File.read(File.join(File.dirname(__FILE__), 'fixtures', path)) 12 | end 13 | -------------------------------------------------------------------------------- /test/mollie/amount_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class AmountTest < Test::Unit::TestCase 5 | def test_value 6 | amount = Amount.new('value' => '42.10', 'currency' => 'EUR') 7 | assert_equal 0.421e2, amount.value 8 | end 9 | 10 | def test_currency 11 | amount = Amount.new('currency' => 'EUR') 12 | assert_equal 'EUR', amount.currency 13 | end 14 | 15 | def test_to_hash 16 | amount = Amount.new('value' => '42.10', 'currency' => 'EUR') 17 | 18 | assert_equal( 19 | { value: '42.10', currency: 'EUR' }, 20 | amount.to_h 21 | ) 22 | end 23 | 24 | def test_nil 25 | amount = Mollie::Amount.new(nil) 26 | assert_nil amount.value 27 | assert_nil amount.currency 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /test/mollie/balance/transaction_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Balance 5 | class TransactionTest < Test::Unit::TestCase 6 | def test_setting_attributes 7 | attributes = { 8 | id: "baltr_QM24QwzUWR4ev4Xfgyt29A", 9 | type: "refund", 10 | result_amount: { "value" => "-10.25", "currency" => "EUR" }, 11 | initial_amount: { "value" => "-10.00", "currency" => "EUR" }, 12 | deductions: { "value" => "0.25", "currency" => "EUR" }, 13 | context: { 14 | "paymentId" => "tr_7UhSN1zuXS", 15 | "refundId" => "re_4qqhO89gsT" 16 | }, 17 | created_at: "2021-01-10T12:06:28+00:00" 18 | } 19 | 20 | balance = Balance::Transaction.new(attributes) 21 | 22 | assert_equal "baltr_QM24QwzUWR4ev4Xfgyt29A", balance.id 23 | assert_equal "refund", balance.type 24 | assert_equal BigDecimal("-10.25"), balance.result_amount.value 25 | assert_equal "EUR", balance.result_amount.currency 26 | assert_equal BigDecimal("-10.00"), balance.initial_amount.value 27 | assert_equal "EUR", balance.initial_amount.currency 28 | assert_equal BigDecimal("0.25"), balance.deductions.value 29 | assert_equal "EUR", balance.deductions.currency 30 | assert_equal "tr_7UhSN1zuXS", balance.context.paymentId 31 | assert_equal "re_4qqhO89gsT", balance.context.refundId 32 | assert_equal Time.parse("2021-01-10T12:06:28+00:00"), balance.created_at 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /test/mollie/balance_test.rb: -------------------------------------------------------------------------------- 1 | require "helper" 2 | 3 | module Mollie 4 | class BalanceTest < Test::Unit::TestCase 5 | GET_BALANCE = read_fixture('balances/get.json') 6 | GET_BALANCE_REPORT = read_fixture('balances/report.json') 7 | LIST_BALANCES = read_fixture('balances/list.json') 8 | LIST_BALANCE_TRANSACTIONS = read_fixture('balances/list_transactions.json') 9 | 10 | def test_setting_attributes 11 | attributes = { 12 | id: "bal_gVMhHKqSSRYJyPsuoPNFH", 13 | mode: "live", 14 | currency: "EUR", 15 | description: "Primary balance", 16 | available_amount: { "value" => "0.00", "currency" => "EUR" }, 17 | pending_amount: { "value" => "0.00", "currency" => "EUR" }, 18 | transfer_frequency: "twice-a-month", 19 | transfer_threshold: { "value" => "5.00", "currency" => "EUR" }, 20 | transfer_reference: "Mollie settlement", 21 | transfer_destination: { 22 | type: "bank-account", 23 | beneficiary_name: "John Doe", 24 | bank_account: "NL55INGB0000000000" 25 | }, 26 | status: "active", 27 | created_at: "2018-03-20T09:13:37+00:00", 28 | } 29 | 30 | balance = Mollie::Balance.new(attributes) 31 | 32 | assert_equal "bal_gVMhHKqSSRYJyPsuoPNFH", balance.id 33 | assert_equal "live", balance.mode 34 | assert_equal "EUR", balance.currency 35 | assert_equal "Primary balance", balance.description 36 | assert_equal BigDecimal("0.00"), balance.available_amount.value 37 | assert_equal "EUR", balance.available_amount.currency 38 | assert_equal BigDecimal("0.00"), balance.pending_amount.value 39 | assert_equal "EUR", balance.pending_amount.currency 40 | assert_equal "twice-a-month", balance.transfer_frequency 41 | assert_equal BigDecimal("5.00"), balance.transfer_threshold.value 42 | assert_equal "EUR", balance.transfer_threshold.currency 43 | assert_equal "Mollie settlement", balance.transfer_reference 44 | assert_equal "bank-account", balance.transfer_destination.type 45 | assert_equal "John Doe", balance.transfer_destination.beneficiary_name 46 | assert_equal "NL55INGB0000000000", balance.transfer_destination.bank_account 47 | assert_equal "active", balance.status 48 | assert_equal Time.parse('2018-03-20T09:13:37+00:00'), balance.created_at 49 | end 50 | 51 | def test_get_balance 52 | stub_request(:get, "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH") 53 | .to_return(status: 200, body: GET_BALANCE, headers: {}) 54 | 55 | balance = Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH") 56 | assert_equal "bal_gVMhHKqSSRYJyPsuoPNFH", balance.id 57 | end 58 | 59 | def test_list_balances 60 | stub_request(:get, 'https://api.mollie.com/v2/balances') 61 | .to_return(status: 200, body: LIST_BALANCES, headers: {}) 62 | 63 | balances = Balance.all 64 | assert_equal 3, balances.size 65 | assert_equal 'bal_one', balances[0].id 66 | assert_equal 'bal_two', balances[1].id 67 | assert_equal 'bal_three', balances[2].id 68 | end 69 | 70 | def test_primary 71 | stub_request(:get, "https://api.mollie.com/v2/balances/primary") 72 | .to_return(status: 200, body: GET_BALANCE, headers: {}) 73 | 74 | balance = Balance.primary 75 | assert_equal "bal_gVMhHKqSSRYJyPsuoPNFH", balance.id 76 | end 77 | 78 | def test_report 79 | stub_request(:get, "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH") 80 | .to_return(status: 200, body: GET_BALANCE, headers: {}) 81 | 82 | stub_request(:get, 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/report') 83 | .to_return(status: 200, body: GET_BALANCE_REPORT, headers: {}) 84 | 85 | report = Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH").report 86 | 87 | assert_equal Date.parse("2024-01-01"), report.from 88 | assert_equal Date.parse("2024-01-31"), report.until 89 | assert_equal "transaction-categories", report.grouping 90 | assert_equal "4.98", report.totals.dig("payments", "pending", "amount", "value") 91 | assert_equal "-0.36", report.totals.dig("fee_prepayments", "moved_to_available", "amount", "value") 92 | end 93 | 94 | def test_list_transactions 95 | stub_request(:get, "https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH") 96 | .to_return(status: 200, body: GET_BALANCE, headers: {}) 97 | 98 | stub_request(:get, 'https://api.mollie.com/v2/balances/bal_gVMhHKqSSRYJyPsuoPNFH/transactions') 99 | .to_return(status: 200, body: LIST_BALANCE_TRANSACTIONS, headers: {}) 100 | 101 | transactions = Balance.get("bal_gVMhHKqSSRYJyPsuoPNFH").transactions 102 | assert_equal 2, transactions.size 103 | 104 | assert_equal "baltr_QM24QwzUWR4ev4Xfgyt29A", transactions[0].id 105 | assert_equal "baltr_WhmDwNYR87FPDbiwBhUXCh", transactions[1].id 106 | end 107 | end 108 | end 109 | -------------------------------------------------------------------------------- /test/mollie/chargeback_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class ChargebackTest < Test::Unit::TestCase 5 | def test_setting_attributes 6 | attributes = { 7 | id: 're_4qqhO89gsT', 8 | amount: { 'value' => '5.95', 'currency' => 'EUR' }, 9 | created_at: '2016-10-08T07:59:53.0Z', 10 | reversed_at: '2016-10-08T07:59:53.0Z', 11 | payment_id: 'tr_WDqYK6vllg', 12 | settlement_amount: { 'value' => '-5.95', 'currency' => 'EUR' } 13 | } 14 | 15 | chargeback = Chargeback.new(attributes) 16 | 17 | assert_equal 're_4qqhO89gsT', chargeback.id 18 | assert_equal BigDecimal('5.95'), chargeback.amount.value 19 | assert_equal 'EUR', chargeback.amount.currency 20 | assert_equal Time.parse('2016-10-08T07:59:53.0Z'), chargeback.created_at 21 | assert_equal Time.parse('2016-10-08T07:59:53.0Z'), chargeback.reversed_at 22 | assert_equal 'tr_WDqYK6vllg', chargeback.payment_id 23 | assert_equal BigDecimal('-5.95'), chargeback.settlement_amount.value 24 | assert_equal 'EUR', chargeback.settlement_amount.currency 25 | end 26 | 27 | def test_reversed? 28 | assert Chargeback.new(reversed_at: '2016-10-08T07:59:53.0Z').reversed? 29 | assert !Chargeback.new(reversed_at: nil).reversed? 30 | end 31 | 32 | def test_get_chargeback 33 | stub_request(:get, 'https://api.mollie.com/v2/payments/pay-id/chargebacks/chb-id') 34 | .to_return(status: 200, body: %({"id":"chb-id"}), headers: {}) 35 | 36 | chargeback = Payment::Chargeback.get('chb-id', payment_id: 'pay-id') 37 | assert_equal 'chb-id', chargeback.id 38 | end 39 | 40 | def test_get_payment 41 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_n9z0tp') 42 | .to_return(status: 200, body: %( 43 | { 44 | "resource": "chargeback", 45 | "id": "chb_n9z0tp", 46 | "paymentId": "tr_WDqYK6vllg" 47 | } 48 | ), headers: {}) 49 | 50 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg') 51 | .to_return(status: 200, body: %( 52 | { 53 | "resource": "payment", 54 | "id": "tr_WDqYK6vllg" 55 | } 56 | ), headers: {}) 57 | 58 | chargeback = Payment::Chargeback.get('chb_n9z0tp', payment_id: 'tr_WDqYK6vllg') 59 | assert_equal 'tr_WDqYK6vllg', chargeback.payment.id 60 | end 61 | 62 | def test_get_settlement 63 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/chargebacks/chb_n9z0tp') 64 | .to_return(status: 200, body: %( 65 | { 66 | "resource": "chargeback", 67 | "id": "chb_n9z0tp", 68 | "paymentId": "tr_WDqYK6vllg", 69 | "_links": { 70 | "settlement": { 71 | "href": "https://api.mollie.com/v2/settlements/stl_jDk30akdN", 72 | "type": "application/hal+json" 73 | } 74 | } 75 | } 76 | ), headers: {}) 77 | 78 | stub_request(:get, 'https://api.mollie.com/v2/settlements/stl_jDk30akdN') 79 | .to_return(status: 200, body: %( 80 | { 81 | "resource": "settlement", 82 | "id": "stl_jDk30akdN" 83 | } 84 | ), headers: {}) 85 | 86 | chargeback = Payment::Chargeback.get('chb_n9z0tp', payment_id: 'tr_WDqYK6vllg') 87 | assert_equal 'stl_jDk30akdN', chargeback.settlement.id 88 | end 89 | 90 | def test_nil_settlement 91 | chargeback = Payment::Chargeback.new(id: 'chb_n9z0tp') 92 | assert_nil chargeback.settlement 93 | end 94 | end 95 | end 96 | -------------------------------------------------------------------------------- /test/mollie/customer/mandate_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Customer 5 | class MandateTest < Test::Unit::TestCase 6 | def test_setting_attributes 7 | attributes = { 8 | id: 'mdt_h3gAaD5zP', 9 | mode: 'test', 10 | status: 'valid', 11 | method: 'creditcard', 12 | details: { 13 | card_holder: 'John Doe', 14 | card_expiry_date: '2016-03-31' 15 | }, 16 | mandate_reference: 'YOUR-COMPANY-MD1380', 17 | signature_date: '2018-05-07', 18 | created_at: '2016-04-13T11:32:38.0Z', 19 | _links: { 20 | 'self' => { 21 | 'href' => 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT/mandates/mdt_h3gAaD5zP', 22 | 'type' => 'application/hal+json' 23 | }, 24 | 'customer' => { 25 | 'href' => 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT', 26 | 'type' => 'application/hal+json' 27 | }, 28 | 'documentation' => { 29 | 'href' => 'https://docs.mollie.com/reference/v2/mandates-api/get-mandate', 30 | 'type' => 'text/html' 31 | } 32 | } 33 | } 34 | 35 | mandate = Mandate.new(attributes) 36 | 37 | assert_equal 'mdt_h3gAaD5zP', mandate.id 38 | assert_equal 'test', mandate.mode 39 | assert_equal 'valid', mandate.status 40 | assert_equal 'creditcard', mandate.method 41 | assert_equal 'YOUR-COMPANY-MD1380', mandate.mandate_reference 42 | assert_equal '2018-05-07', mandate.signature_date 43 | assert_equal Time.parse('2016-04-13T11:32:38.0Z'), mandate.created_at 44 | 45 | assert_equal 'John Doe', mandate.details.card_holder 46 | assert_equal '2016-03-31', mandate.details.card_expiry_date 47 | assert_equal nil, mandate.details.non_existing 48 | end 49 | 50 | def test_valid_invalid_pending 51 | mandate = Mandate.new(status: Mandate::STATUS_VALID) 52 | assert mandate.valid? 53 | 54 | mandate = Mandate.new(status: Mandate::STATUS_INVALID) 55 | assert mandate.invalid? 56 | 57 | mandate = Mandate.new(status: Mandate::STATUS_PENDING) 58 | assert mandate.pending? 59 | end 60 | 61 | def test_get_mandate 62 | stub_request(:get, 'https://api.mollie.com/v2/customers/cus-id/mandates/man-id') 63 | .to_return(status: 200, body: %({"id":"man-id", "method":"directdebit"}), headers: {}) 64 | 65 | mandate = Customer::Mandate.get('man-id', customer_id: 'cus-id') 66 | 67 | assert_equal 'man-id', mandate.id 68 | assert_equal 'directdebit', mandate.method 69 | end 70 | 71 | def test_create_mandate 72 | stub_request(:post, 'https://api.mollie.com/v2/customers/cus-id/mandates') 73 | .with(body: %({"method":"directdebit"})) 74 | .to_return(status: 201, body: %({"id":"my-id", "method":"directdebit"}), headers: {}) 75 | 76 | mandate = Customer::Mandate.create( 77 | method: 'directdebit', 78 | customer_id: 'cus-id' 79 | ) 80 | 81 | assert_equal 'my-id', mandate.id 82 | assert_equal 'directdebit', mandate.method 83 | end 84 | 85 | def test_delete_mandate 86 | stub_request(:delete, 'https://api.mollie.com/v2/customers/cus-id/mandates/man-id') 87 | .to_return(status: 204, headers: {}) 88 | 89 | mandate = Customer::Mandate.delete('man-id', customer_id: 'cus-id') 90 | assert_equal nil, mandate 91 | end 92 | 93 | def test_get_customer 94 | stub_request(:get, 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT/mandates/mdt_h3gAaD5zP') 95 | .to_return(status: 200, body: %( 96 | { 97 | "resource": "mandate", 98 | "id": "mdt_h3gAaD5zP", 99 | "_links": { 100 | "customer": { 101 | "href": "https://api.mollie.com/v2/customers/cst_4qqhO89gsT", 102 | "type": "application/hal+json" 103 | } 104 | } 105 | } 106 | ), headers: {}) 107 | 108 | stub_request(:get, 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT') 109 | .to_return(status: 200, body: %( 110 | { 111 | "resource": "customer", 112 | "id": "cst_4qqhO89gsT" 113 | } 114 | ), headers: {}) 115 | 116 | mandate = Customer::Mandate.get('mdt_h3gAaD5zP', customer_id: 'cst_4qqhO89gsT') 117 | assert_equal 'cst_4qqhO89gsT', mandate.customer.id 118 | end 119 | end 120 | end 121 | end 122 | -------------------------------------------------------------------------------- /test/mollie/customer/payment_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Customer 5 | class PaymentTest < Test::Unit::TestCase 6 | def test_kind_of_payment 7 | payment = Mollie::Customer::Payment.new({}) 8 | assert_kind_of Mollie::Payment, payment 9 | end 10 | 11 | def test_list_payments 12 | stub_request(:get, 'https://api.mollie.com/v2/customers/cus-id/payments') 13 | .to_return(status: 200, body: %({"_embedded" : { "payments" : [{"id":"pay-id", "customer_id":"cus-id"}]}}), headers: {}) 14 | 15 | payments = Payment.all(customer_id: 'cus-id') 16 | 17 | assert_equal 'pay-id', payments.first.id 18 | assert_equal 'cus-id', payments.first.customer_id 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /test/mollie/customer_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class CustomerTest < Test::Unit::TestCase 5 | def test_setting_attributes 6 | attributes = { 7 | id: 'cst_vsKJpSsabw', 8 | mode: 'test', 9 | name: 'Customer A', 10 | email: 'customer@example.org', 11 | locale: 'nl_NL', 12 | metadata: { my_field: 'value' }, 13 | created_at: '2016-04-06T13:23:21.0Z' 14 | } 15 | 16 | customer = Customer.new(attributes) 17 | 18 | assert_equal 'cst_vsKJpSsabw', customer.id 19 | assert_equal 'test', customer.mode 20 | assert_equal 'Customer A', customer.name 21 | assert_equal 'customer@example.org', customer.email 22 | assert_equal 'nl_NL', customer.locale 23 | assert_equal Time.parse('2016-04-06T13:23:21.0Z'), customer.created_at 24 | 25 | assert_equal 'value', customer.metadata.my_field 26 | assert_equal nil, customer.metadata.non_existing 27 | end 28 | 29 | def test_list_mandates 30 | stub_request(:get, 'https://api.mollie.com/v2/customers/cus-id/mandates') 31 | .to_return(status: 200, body: %({"_embedded" : { "mandates" : [{"id":"man-id", "customer_id":"cus-id"}]}} ), headers: {}) 32 | 33 | mandates = Customer.new(id: 'cus-id').mandates 34 | 35 | assert_equal 'man-id', mandates.first.id 36 | end 37 | 38 | def test_list_subscriptions 39 | stub_request(:get, 'https://api.mollie.com/v2/customers/cus-id/subscriptions') 40 | .to_return(status: 200, body: %({"_embedded" : {"subscriptions" : [{"id":"sub-id", "customer_id":"cus-id"}]}} ), headers: {}) 41 | 42 | subscriptions = Customer.new(id: 'cus-id').subscriptions 43 | 44 | assert_equal 'sub-id', subscriptions.first.id 45 | end 46 | 47 | def test_list_payments 48 | stub_request(:get, 'https://api.mollie.com/v2/customers/cus-id/payments') 49 | .to_return(status: 200, body: %({"_embedded" : { "payments" : [{"id":"sub-id", "customer_id":"cus-id"}]}}), headers: {}) 50 | 51 | payments = Customer.new(id: 'cus-id').payments 52 | 53 | assert_equal 'sub-id', payments.first.id 54 | end 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /test/mollie/exception_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class ExceptionTest < Test::Unit::TestCase 5 | def test_attributes 6 | stub_request(:post, 'https://api.mollie.com/v2/payments') 7 | .to_return(status: 422, headers: { "Content-Type" => "application/hal+json}" }, body: %( 8 | { 9 | "status": 422, 10 | "title": "Unprocessable Entity", 11 | "detail": "The amount is higher than the maximum", 12 | "field": "amount", 13 | "_links": { 14 | "documentation": { 15 | "href": "https://docs.mollie.com/errors", 16 | "type": "text/html" 17 | } 18 | } 19 | } 20 | )) 21 | 22 | exception = assert_raise(Mollie::RequestError) do 23 | Mollie::Payment.create( 24 | amount: { value: "1000000000.00", currency: "EUR" }, 25 | description: "Order #66", 26 | redirect_url: "https://www.example.org/payment/completed", 27 | ) 28 | end 29 | 30 | assert_equal 422, exception.status 31 | assert_equal "Unprocessable Entity", exception.title 32 | assert_equal "The amount is higher than the maximum", exception.detail 33 | assert_equal "amount", exception.field 34 | assert_equal "https://docs.mollie.com/errors", exception.links["documentation"]["href"] 35 | assert_equal "text/html", exception.links["documentation"]["type"] 36 | end 37 | 38 | def test_exception_message 39 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg') 40 | .to_return(status: 401, headers: { "Content-Type" => "application/hal+json}" }, body: %( 41 | { 42 | "status": 401, 43 | "title": "Unauthorized Request", 44 | "detail": "Missing authentication, or failed to authenticate", 45 | "_links": { 46 | "documentation": { 47 | "href": "https://docs.mollie.com/overview/authentication", 48 | "type": "text/html" 49 | } 50 | } 51 | } 52 | )) 53 | 54 | exception = assert_raise(Mollie::RequestError) { Payment.get('tr_WDqYK6vllg') } 55 | assert_equal '401 Unauthorized Request: Missing authentication, or failed to authenticate', exception.message 56 | end 57 | 58 | def test_http_attributes 59 | body = %({ 60 | "status": 422, 61 | "title": "Unprocessable Entity", 62 | "detail": "The amount is higher than the maximum", 63 | "field": "amount", 64 | "_links": { 65 | "documentation": { 66 | "href": "https://docs.mollie.com/errors", 67 | "type": "text/html" 68 | } 69 | } 70 | }) 71 | 72 | stub_request(:post, 'https://api.mollie.com/v2/payments') 73 | .to_return(status: 422, headers: { "Content-Type" => "application/hal+json" }, body: body) 74 | 75 | exception = assert_raise(Mollie::RequestError) do 76 | Mollie::Payment.create( 77 | amount: { value: "1000000000.00", currency: "EUR" }, 78 | description: "Order #66", 79 | redirect_url: "https://www.example.org/payment/completed", 80 | ) 81 | end 82 | 83 | assert_equal({ "content-type" => ["application/hal+json"] }, exception.http_headers) 84 | assert_equal(body, exception.http_body) 85 | end 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /test/mollie/invoice_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class InvoiceTest < Test::Unit::TestCase 5 | def test_setting_attributes 6 | attributes = { 7 | id: 'inv_xBEbP9rvAq', 8 | reference: '2016.10000', 9 | vat_number: 'NL001234567B01', 10 | status: 'open', 11 | issued_at: '2016-08-31', 12 | due_at: '2016-09-14', 13 | net_amount: { 14 | value: '45.00', 15 | currency: 'EUR' 16 | }, 17 | vat_amount: { 18 | value: '9.45', 19 | currency: 'EUR' 20 | }, 21 | gross_amount: { 22 | value: '54.45', 23 | currency: 'EUR' 24 | }, 25 | lines: [ 26 | { 27 | period: '2016-09', 28 | description: 'iDEAL transactiekosten', 29 | count: 100, 30 | vat_percentage: 21, 31 | amount: { 32 | value: '45.00', 33 | currency: 'EUR' 34 | } 35 | } 36 | ], 37 | _links: { 38 | 'pdf' => { 39 | 'href' => 'https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/', 40 | 'type' => 'application/pdf' 41 | } 42 | } 43 | } 44 | 45 | invoice = Invoice.new(attributes) 46 | 47 | assert_equal 'inv_xBEbP9rvAq', invoice.id 48 | assert_equal '2016.10000', invoice.reference 49 | assert_equal 'NL001234567B01', invoice.vat_number 50 | assert_equal 'open', invoice.status 51 | assert_equal Time.parse('2016-08-31'), invoice.issued_at 52 | assert_equal Time.parse('2016-09-14'), invoice.due_at 53 | assert_equal 45.0, invoice.net_amount.value 54 | assert_equal 'EUR', invoice.net_amount.currency 55 | assert_equal BigDecimal(9.45, 3), invoice.vat_amount.value 56 | assert_equal 'EUR', invoice.vat_amount.currency 57 | assert_equal 54.45, invoice.gross_amount.value 58 | assert_equal 'EUR', invoice.gross_amount.currency 59 | 60 | line = invoice.lines.first 61 | assert_equal '2016-09', line.period 62 | assert_equal 'iDEAL transactiekosten', line.description 63 | assert_equal 100, line.count 64 | assert_equal 21, line.vat_percentage 65 | assert_equal 45.0, line.amount.value 66 | assert_equal 'EUR', line.amount.currency 67 | 68 | assert_equal 'https://www.mollie.com/beheer/facturen/2016.10000/52981a39788e5e0acaf71bbf570e941f/', invoice.pdf 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /test/mollie/method_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class MethodTest < Test::Unit::TestCase 5 | def test_setting_attributes 6 | attributes = { 7 | id: 'creditcard', 8 | description: 'Credit card', 9 | minimum_amount: { value: '0.01', currency: 'EUR' }, 10 | maximum_amount: { value: '2000.00', currency: 'EUR' }, 11 | status: 'approved', 12 | image: { 13 | 'size1x' => 'https://www.mollie.com/external/icons/payment-methods/creditcard.png', 14 | 'size2x' => 'https://www.mollie.com/external/icons/payment-methods/creditcard%402x.png', 15 | 'svg' => 'https://www.mollie.com/external/icons/payment-methods/creditcard.svg' 16 | } 17 | } 18 | 19 | method = Method.new(attributes) 20 | 21 | assert_equal 'creditcard', method.id 22 | assert_equal 'Credit card', method.description 23 | assert_equal BigDecimal('0.01'), method.minimum_amount.value 24 | assert_equal 'EUR', method.minimum_amount.currency 25 | assert_equal BigDecimal('2000.00'), method.maximum_amount.value 26 | assert_equal 'EUR', method.maximum_amount.currency 27 | assert_equal 'approved', method.status 28 | assert_equal 'https://www.mollie.com/external/icons/payment-methods/creditcard.png', method.normal_image 29 | assert_equal 'https://www.mollie.com/external/icons/payment-methods/creditcard%402x.png', method.bigger_image 30 | assert_equal 'https://www.mollie.com/external/icons/payment-methods/creditcard.svg', method.image['svg'] 31 | end 32 | 33 | def test_all_available 34 | stub_request(:get, 'https://api.mollie.com/v2/methods/all') 35 | .to_return(status: 200, body: read_fixture('methods/all.json'), headers: {}) 36 | 37 | available_methods = Method.all_available 38 | assert_equal 3, available_methods.size 39 | 40 | ideal_method = available_methods.first 41 | assert_equal "pending-boarding", ideal_method.status 42 | end 43 | 44 | def test_pricing 45 | stub_request(:get, 'https://api.mollie.com/v2/methods/creditcard?include=pricing') 46 | .to_return(status: 200, body: read_fixture('methods/get-includes-pricing.json'), headers: {}) 47 | 48 | creditcard = Method.get('creditcard', include: 'pricing') 49 | creditcard_pricing = creditcard.pricing 50 | 51 | assert_equal 3, creditcard_pricing.size 52 | assert_equal 'Commercial & non-European cards', creditcard_pricing.first.description 53 | assert_equal BigDecimal('0.25'), creditcard_pricing.first.fixed.value 54 | assert_equal 'EUR', creditcard_pricing.first.fixed.currency 55 | assert_equal '2.8', creditcard_pricing.first.variable 56 | assert_equal 'other', creditcard_pricing.first.fee_region 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /test/mollie/onboarding_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class OnboardingTest < Test::Unit::TestCase 5 | def test_get_onboarding 6 | stub_request(:get, 'https://api.mollie.com/v2/onboarding/me') 7 | .to_return(status: 200, body: read_fixture('onboarding/me.json'), headers: {}) 8 | 9 | onboarding = Onboarding.me 10 | assert_equal 'Mollie B.V.', onboarding.name 11 | assert_equal 'completed', onboarding.status 12 | assert_equal true, onboarding.can_receive_payments 13 | assert_equal true, onboarding.can_receive_settlements 14 | assert_equal Time.parse('2018-12-20T10:49:08+00:00'), onboarding.signed_up_at 15 | assert_equal 'https://www.mollie.com/dashboard/onboarding', onboarding.dashboard 16 | end 17 | 18 | def test_submit_onboarding_data 19 | minified_body = JSON.parse(read_fixture('onboarding/submit.json')).to_json 20 | 21 | stub_request(:post, 'https://api.mollie.com/v2/onboarding/me') 22 | .with(body: minified_body).to_return(status: 204) 23 | 24 | assert_nil Onboarding.submit( 25 | organization: { 26 | name: "Mollie B.V.", 27 | address: { 28 | streetAndNumber: "Keizersgracht 313", 29 | postalCode: "1018 EE", 30 | city: "Amsterdam", 31 | country: "NL" 32 | }, 33 | registrationNumber: "30204462", 34 | vatNumber: "NL815839091B01" 35 | }, 36 | profile: { 37 | name: "Mollie", 38 | url: "https://www.mollie.com", 39 | email: "info@mollie.com", 40 | phone: "+31208202070", 41 | categoryCode: 6012 42 | } 43 | ) 44 | end 45 | 46 | def test_get_organization 47 | stub_request(:get, 'https://api.mollie.com/v2/onboarding/me') 48 | .to_return(status: 200, body: read_fixture('onboarding/me.json'), headers: {}) 49 | 50 | stub_request(:get, 'https://api.mollie.com/v2/organization/org_12345') 51 | .to_return(status: 200, body: %({"id": "org_12345"}), headers: {}) 52 | 53 | onboarding = Onboarding.me 54 | organization = onboarding.organization 55 | 56 | assert_equal 'org_12345', organization.id 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /test/mollie/order/create_payment_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Order 5 | class PaymentTest < Test::Unit::TestCase 6 | CREATE_PAYMENT = read_fixture("orders/create_payment.json") 7 | 8 | def test_create_payment 9 | stub_request(:post, "https://api.mollie.com/v2/orders/ord_kEn1PlbGa/payments") 10 | .to_return(status: 201, body: CREATE_PAYMENT, headers: {}) 11 | 12 | payment = Order::Payment.create(order_id: "ord_kEn1PlbGa") 13 | 14 | assert_kind_of Order::Payment, payment 15 | assert_equal "tr_ncaPcAhuUV", payment.id 16 | assert_equal "ord_kEn1PlbGa", payment.order_id 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/mollie/order/line_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Order 5 | class LineTest < Test::Unit::TestCase 6 | GET_ORDER = read_fixture('orders/get.json') 7 | CANCEL_LINE = read_fixture('orders/cancel_line.json') 8 | CANCEL_QTY = read_fixture('orders/cancel_line_qty.json') 9 | UPDATE_LINE = read_fixture('orders/update_line.json') 10 | 11 | def test_discounted 12 | stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa') 13 | .to_return(status: 200, body: GET_ORDER, headers: {}) 14 | 15 | order = Order.get('ord_kEn1PlbGa') 16 | assert order.lines[0].discounted? 17 | assert order.lines[1].discounted? == false 18 | end 19 | 20 | def test_cancel_order_line 21 | stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa') 22 | .to_return(status: 200, body: GET_ORDER, headers: {}) 23 | 24 | stub_request(:delete, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/lines') 25 | .with(body: JSON.parse(CANCEL_LINE).to_json) 26 | .to_return(status: 204, body: GET_ORDER, headers: {}) 27 | 28 | order = Order.get('ord_kEn1PlbGa') 29 | assert_nil order.lines.first.cancel 30 | end 31 | 32 | def test_cancel_order_line_with_quantity 33 | stub_request(:get, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa') 34 | .to_return(status: 200, body: GET_ORDER, headers: {}) 35 | 36 | stub_request(:delete, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/lines') 37 | .with(body: JSON.parse(CANCEL_QTY).to_json) 38 | .to_return(status: 204, body: GET_ORDER, headers: {}) 39 | 40 | order = Order.get('ord_kEn1PlbGa') 41 | assert_nil order.lines.first.cancel(quantity: 1) 42 | end 43 | 44 | def test_update_orderline 45 | stub_request(:patch, 'https://api.mollie.com/v2/orders/ord_kEn1PlbGa/lines/odl_dgtxyl') 46 | .with(body: { sku: "new-sku-12345678" }.to_json) 47 | .to_return(status: 200, body: UPDATE_LINE, headers: {}) 48 | 49 | order = Mollie::Order::Line.update( 50 | 'odl_dgtxyl', 51 | order_id: 'ord_kEn1PlbGa', 52 | sku: "new-sku-12345678" 53 | ) 54 | 55 | # The `update order line`-API returns an `order` instead of `orderline` 56 | assert_equal Mollie::Order, order.class 57 | 58 | line = order.lines.find { |line| line.id == 'odl_dgtxyl' } 59 | assert_equal "new-sku-12345678", line.sku 60 | end 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /test/mollie/organization_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class OrganizationTest < Test::Unit::TestCase 5 | def test_setting_attributes 6 | attributes = { 7 | id: 'org_12345678', 8 | name: 'Mollie B.V.', 9 | locale: 'nl_NL', 10 | email: 'info@mollie.com', 11 | address: { 12 | street_and_number: 'Keizersgracht 313', 13 | postal_code: '1016 EE', 14 | city: 'Amsterdam', 15 | country: 'NL' 16 | }, 17 | registration_number: '30204462', 18 | vat_number: 'NL815839091B01', 19 | vat_regulation: 'dutch', 20 | _links: { 21 | 'self' => { 22 | 'href' => 'https://api.mollie.com/v2/organizations/org_12345678', 23 | 'type' => 'application/hal+json' 24 | }, 25 | 'dashboard' => { 26 | 'href' => 'https://mollie.com/dashboard/org_12345678', 27 | 'type' => 'text/html' 28 | }, 29 | 'documentation' => { 30 | 'href' => 'https://docs.mollie.com/reference/v2/organizations-api/get-organization', 31 | 'type' => 'text/html' 32 | } 33 | } 34 | } 35 | 36 | organization = Organization.new(attributes) 37 | 38 | assert_equal 'org_12345678', organization.id 39 | assert_equal 'Mollie B.V.', organization.name 40 | assert_equal 'nl_NL', organization.locale 41 | assert_equal 'info@mollie.com', organization.email 42 | assert_equal 'Keizersgracht 313', organization.address.street_and_number 43 | assert_equal '1016 EE', organization.address.postal_code 44 | assert_equal 'Amsterdam', organization.address.city 45 | assert_equal 'NL', organization.address.country 46 | assert_equal '30204462', organization.registration_number 47 | assert_equal 'NL815839091B01', organization.vat_number 48 | assert_equal 'dutch', organization.vat_regulation 49 | assert_equal 'https://api.mollie.com/v2/organizations/org_12345678', organization.links['self']['href'] 50 | assert_equal 'https://mollie.com/dashboard/org_12345678', organization.dashboard_url 51 | end 52 | 53 | def test_current_organization 54 | stub_request(:get, 'https://api.mollie.com/v2/organizations/me') 55 | .to_return(status: 200, body: %( 56 | { 57 | "resource": "organization", 58 | "id": "org_12345678" 59 | } 60 | ), headers: {}) 61 | 62 | organization = Organization.current 63 | assert_equal 'org_12345678', organization.id 64 | end 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /test/mollie/partner_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class PartnerTest < Test::Unit::TestCase 5 | def setup 6 | stub_request(:get, 'https://api.mollie.com/v2/organizations/me/partner') 7 | .to_return(status: 200, body: read_fixture('organizations/partner.json'), headers: {}) 8 | end 9 | 10 | def test_class_type 11 | partner = Partner.current 12 | assert_equal Mollie::Partner, partner.class 13 | end 14 | 15 | def test_partner_type 16 | partner = Partner.current 17 | assert_equal 'signuplink', partner.type 18 | end 19 | 20 | def test_commision_partner 21 | partner = Partner.current 22 | assert partner.commission_partner? 23 | end 24 | 25 | def test_contract_signed_at 26 | partner = Partner.current 27 | assert_equal Time.parse('2018-03-20T13:13:37+00:00'), partner.contract_signed_at 28 | end 29 | 30 | def test_contract_update_available? 31 | partner = Partner.current 32 | assert partner.contract_update_available? 33 | end 34 | 35 | def test_signuplink 36 | partner = Partner.current 37 | assert_equal 'https://www.mollie.com/dashboard/signup/myCode?lang=en', partner.signuplink 38 | end 39 | 40 | def test_user_agent_tokens 41 | token = Partner.current.user_agent_tokens.first 42 | assert_equal 'unique-token', token.token 43 | assert_equal Time.parse('2018-03-20T13:13:37+00:00'), token.starts_at 44 | assert_nil nil, token.ends_at 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /test/mollie/payment/capture_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Payment 5 | class CaptureTest < Test::Unit::TestCase 6 | GET_CAPTURE = read_fixture('captures/get.json') 7 | LIST_CAPTURES = read_fixture('captures/list.json') 8 | 9 | PAYMENT_STUB = %({ "resource": "payment", "id": "tr_WDqYK6vllg" }).freeze 10 | SHIPMENT_STUB = %({ "resource": "shipment", "id": "shp_3wmsgCJN4U" }).freeze 11 | SETTLEMENT_STUB = %({ "resource": "settlement", "id": "stl_jDk30akdN" }).freeze 12 | 13 | def test_get_capture 14 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT') 15 | .to_return(status: 200, body: GET_CAPTURE, headers: {}) 16 | 17 | capture = Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 18 | assert_equal 'cpt_4qqhO89gsT', capture.id 19 | assert_equal 'live', capture.mode 20 | assert_equal BigDecimal('1027.99'), capture.amount.value 21 | assert_equal 'EUR', capture.amount.currency 22 | assert_equal BigDecimal('399'), capture.settlement_amount.value 23 | assert_equal 'EUR', capture.settlement_amount.currency 24 | assert_equal 'tr_WDqYK6vllg', capture.payment_id 25 | assert_equal 'shp_3wmsgCJN4U', capture.shipment_id 26 | assert_equal 'stl_jDk30akdN', capture.settlement_id 27 | assert_equal Time.parse('2018-08-02T09:29:56+00:00'), capture.created_at 28 | end 29 | 30 | def test_list_captures 31 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures') 32 | .to_return(status: 200, body: LIST_CAPTURES, headers: {}) 33 | 34 | captures = Payment::Capture.all(payment_id: 'tr_WDqYK6vllg') 35 | assert_equal 1, captures.size 36 | assert_equal 'cpt_4qqhO89gsT', captures.first.id 37 | assert_equal 'tr_WDqYK6vllg', captures.first.payment_id 38 | end 39 | 40 | def test_get_payment 41 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT') 42 | .to_return(status: 200, body: GET_CAPTURE, headers: {}) 43 | 44 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg') 45 | .to_return(status: 200, body: PAYMENT_STUB, headers: {}) 46 | 47 | capture = Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 48 | assert_equal 'cpt_4qqhO89gsT', capture.id 49 | assert_equal 'tr_WDqYK6vllg', capture.payment.id 50 | end 51 | 52 | def test_get_shipment 53 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT') 54 | .to_return(status: 200, body: GET_CAPTURE, headers: {}) 55 | 56 | stub_request(:get, 'https://api.mollie.com/v2/orders/ord_8wmqcHMN4U/shipments/shp_3wmsgCJN4U') 57 | .to_return(status: 200, body: SHIPMENT_STUB, headers: {}) 58 | 59 | capture = Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 60 | assert_equal 'cpt_4qqhO89gsT', capture.id 61 | assert_equal 'shp_3wmsgCJN4U', capture.shipment.id 62 | end 63 | 64 | def test_get_settlement 65 | stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/captures/cpt_4qqhO89gsT') 66 | .to_return(status: 200, body: GET_CAPTURE, headers: {}) 67 | 68 | stub_request(:get, 'https://api.mollie.com/v2/settlements/stl_jDk30akdN') 69 | .to_return(status: 200, body: SETTLEMENT_STUB, headers: {}) 70 | 71 | capture = Payment::Capture.get('cpt_4qqhO89gsT', payment_id: 'tr_WDqYK6vllg') 72 | assert_equal 'cpt_4qqhO89gsT', capture.id 73 | assert_equal 'stl_jDk30akdN', capture.settlement.id 74 | end 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /test/mollie/payment/chargeback_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Payment 5 | class ChargebackTest < Test::Unit::TestCase 6 | def test_kind_of_refund 7 | chargeback = Mollie::Payment::Chargeback.new({}) 8 | assert_kind_of Mollie::Chargeback, chargeback 9 | end 10 | 11 | def test_list_chargebacks 12 | stub_request(:get, 'https://api.mollie.com/v2/payments/pay-id/chargebacks') 13 | .to_return(status: 200, body: %({"_embedded" : {"chargebacks" : [{"id":"re-id"}]}}), headers: {}) 14 | 15 | chargebacks = Mollie::Payment::Chargeback.all(payment_id: 'pay-id') 16 | 17 | assert_equal 're-id', chargebacks.first.id 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/mollie/payment/refund_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Payment 5 | class RefundTest < Test::Unit::TestCase 6 | def test_kind_of_refund 7 | refund = Mollie::Payment::Refund.new({}) 8 | assert_kind_of Mollie::Refund, refund 9 | end 10 | 11 | def test_list_refunds 12 | stub_request(:get, 'https://api.mollie.com/v2/payments/pay-id/refunds') 13 | .to_return(status: 200, body: %({"_embedded" : { "refunds" : [{"id":"re-id"}]}}), headers: {}) 14 | 15 | refunds = Mollie::Payment::Refund.all(payment_id: 'pay-id') 16 | 17 | assert_equal 're-id', refunds.first.id 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/mollie/payment_link_test.rb: -------------------------------------------------------------------------------- 1 | require "helper" 2 | 3 | module Mollie 4 | class PaymentLinkTest < Test::Unit::TestCase 5 | CREATE_PAYMENT_LINK = read_fixture("payment_links/create.json") 6 | GET_PAYMENT_LINK = read_fixture("payment_links/get.json") 7 | UPDATE_PAYMENT_LINK = read_fixture("payment_links/update.json") 8 | LIST_PAYMENT_LINKS = read_fixture("payment_links/list.json") 9 | LIST_PAYMENT_LINK_PAYMENTS = read_fixture("payment_links/list-payments.json") 10 | 11 | def test_archived? 12 | assert PaymentLink.new(archived: true).archived? 13 | assert_false PaymentLink.new(archived: false).archived? 14 | end 15 | 16 | def test_create_payment 17 | minified_body = JSON.parse(CREATE_PAYMENT_LINK).to_json 18 | stub_request(:post, "https://api.mollie.com/v2/payment-links") 19 | .with(body: minified_body) 20 | .to_return(status: 201, body: GET_PAYMENT_LINK, headers: {}) 21 | 22 | payment_link = PaymentLink.create( 23 | description: "Bicycle tires", 24 | amount: {currency: "EUR", value: "24.95"} 25 | ) 26 | 27 | assert_kind_of PaymentLink, payment_link 28 | assert_equal "pl_4Y0eZitmBnQ6IDoMqZQKh", payment_link.id 29 | end 30 | 31 | def test_get_payment_link 32 | stub_request(:get, "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh") 33 | .to_return(status: 200, body: GET_PAYMENT_LINK, headers: {}) 34 | 35 | payment_link = PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh") 36 | 37 | assert_equal "pl_4Y0eZitmBnQ6IDoMqZQKh", payment_link.id 38 | assert_equal "test", payment_link.mode 39 | assert_equal "Bicycle tires", payment_link.description 40 | assert_false payment_link.archived 41 | assert_equal "pfl_QkEhN94Ba", payment_link.profile_id 42 | assert_equal 24.95, payment_link.amount.value 43 | assert_equal "EUR", payment_link.amount.currency 44 | assert_equal "https://webshop.example.org/payment-links/webhook", payment_link.webhook_url 45 | assert_equal "https://webshop.example.org/thanks", payment_link.redirect_url 46 | assert_equal Time.parse("2024-09-24T12:16:44+00:00"), payment_link.created_at 47 | assert_equal "https://paymentlink.mollie.com/payment/4Y0eZitmBnQ6IDoMqZQKh", payment_link.payment_link 48 | assert_nil payment_link.paid_at 49 | assert_nil payment_link.updated_at 50 | assert_nil payment_link.expires_at 51 | end 52 | 53 | def test_update_payment_link 54 | minified_body = JSON.parse(UPDATE_PAYMENT_LINK).to_json 55 | stub_request(:patch, 'https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh') 56 | .with(body: minified_body) 57 | .to_return(status: 200, body: GET_PAYMENT_LINK, headers: {}) 58 | 59 | payment_link = PaymentLink.update("pl_4Y0eZitmBnQ6IDoMqZQKh", JSON.parse(UPDATE_PAYMENT_LINK)) 60 | 61 | assert_kind_of PaymentLink, payment_link 62 | assert_equal "pl_4Y0eZitmBnQ6IDoMqZQKh", payment_link.id 63 | end 64 | 65 | def test_delete_payment_link 66 | stub_request(:delete, 'https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh') 67 | .to_return(status: 204, body: GET_PAYMENT_LINK, headers: {}) 68 | 69 | payment_link = PaymentLink.delete("pl_4Y0eZitmBnQ6IDoMqZQKh") 70 | assert_nil payment_link 71 | end 72 | 73 | def test_list_payment_links 74 | stub_request(:get, "https://api.mollie.com/v2/payment-links") 75 | .to_return(status: 200, body: LIST_PAYMENT_LINKS, headers: {}) 76 | 77 | payment_links = PaymentLink.all 78 | assert_equal 3, payment_links.size 79 | assert_equal "pl_one", payment_links[0].id 80 | assert_equal "pl_two", payment_links[1].id 81 | assert_equal "pl_three", payment_links[2].id 82 | end 83 | 84 | def test_list_payment_link_payments 85 | stub_request(:get, "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh") 86 | .to_return(status: 200, body: GET_PAYMENT_LINK, headers: {}) 87 | 88 | stub_request(:get, "https://api.mollie.com/v2/payment-links/pl_4Y0eZitmBnQ6IDoMqZQKh/payments") 89 | .to_return(status: 200, body: LIST_PAYMENT_LINK_PAYMENTS, headers: {}) 90 | 91 | payment_link = PaymentLink.get("pl_4Y0eZitmBnQ6IDoMqZQKh") 92 | payments = payment_link.payments 93 | 94 | assert_equal 3, payments.size 95 | assert_equal "tr_one", payments[0].id 96 | assert_equal "tr_two", payments[1].id 97 | assert_equal "tr_three", payments[2].id 98 | end 99 | end 100 | end 101 | -------------------------------------------------------------------------------- /test/mollie/permission_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class PermissionTest < Test::Unit::TestCase 5 | def test_setting_attributes 6 | attributes = { 7 | id: 'payments.read', 8 | description: 'View your payments', 9 | granted: true 10 | } 11 | 12 | permission = Permission.new(attributes) 13 | 14 | assert_equal 'payments.read', permission.id 15 | assert_equal 'View your payments', permission.description 16 | assert_equal true, permission.granted 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /test/mollie/settlement/chargeback_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Settlement 5 | class ChargebackTest < Test::Unit::TestCase 6 | def test_kind_of_chargeback 7 | chargeback = Mollie::Settlement::Chargeback.new({}) 8 | assert_kind_of Mollie::Chargeback, chargeback 9 | end 10 | 11 | def test_list_chargebacks 12 | stub_request(:get, 'https://api.mollie.com/v2/settlements/set-id/chargebacks') 13 | .to_return(status: 200, body: %({"_embedded" : { "chargebacks" : [{"id":"chg-id", "settlement_id":"set-id"}]}} ), headers: {}) 14 | 15 | chargebacks = Chargeback.all(settlement_id: 'set-id') 16 | assert_equal 'chg-id', chargebacks.first.id 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/mollie/settlement/payment_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Settlement 5 | class PaymentTest < Test::Unit::TestCase 6 | def test_kind_of_payment 7 | payment = Mollie::Settlement::Payment.new({}) 8 | assert_kind_of Mollie::Payment, payment 9 | end 10 | 11 | def test_list_payments 12 | stub_request(:get, 'https://api.mollie.com/v2/settlements/set-id/payments') 13 | .to_return(status: 200, body: %({"_embedded" : { "payments" : [{"id":"pay-id", "settlement_id":"set-id"}]}}), headers: {}) 14 | 15 | payments = Payment.all(settlement_id: 'set-id') 16 | 17 | assert_equal 'pay-id', payments.first.id 18 | assert_equal 'set-id', payments.first.settlement_id 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /test/mollie/settlement/refund_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class Settlement 5 | class RefundTest < Test::Unit::TestCase 6 | def test_kind_of_refund 7 | refund = Mollie::Settlement::Refund.new({}) 8 | assert_kind_of Mollie::Refund, refund 9 | end 10 | 11 | def test_list_refunds 12 | stub_request(:get, 'https://api.mollie.com/v2/settlements/set-id/refunds') 13 | .to_return(status: 200, body: %({"_embedded" : {"refunds" : [{"id":"re-id"}]}}), headers: {}) 14 | 15 | refunds = Mollie::Settlement::Refund.all(settlement_id: 'set-id') 16 | 17 | assert_equal 're-id', refunds.first.id 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/mollie/terminal_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class TerminalTest < Test::Unit::TestCase 5 | GET_TERMINAL = read_fixture('terminals/get.json') 6 | LIST_TERMINALS = read_fixture('terminals/list.json') 7 | 8 | def test_get_terminal 9 | stub_request(:get, "https://api.mollie.com/v2/terminals/term_7MgL4wea46qkRcoTZjWEH") 10 | .to_return(status: 200, body: GET_TERMINAL, headers: {}) 11 | 12 | terminal = Terminal.get("term_7MgL4wea46qkRcoTZjWEH") 13 | 14 | assert_equal "term_7MgL4wea46qkRcoTZjWEH", terminal.id 15 | assert_equal "pfl_QkEhN94Ba", terminal.profile_id 16 | assert_equal "active", terminal.status 17 | assert_equal "PAX", terminal.brand 18 | assert_equal "A920", terminal.model 19 | assert_equal "1234567890", terminal.serial_number 20 | assert_equal "EUR", terminal.currency 21 | assert_equal "Terminal #12345", terminal.description 22 | assert_equal Time.parse("2022-02-12T11:58:35.0Z"), terminal.created_at 23 | assert_equal Time.parse("2022-11-15T13:32:11+00:00"), terminal.updated_at 24 | assert_equal Time.parse("2022-02-12T12:13:35.0Z"), terminal.deactivated_at 25 | end 26 | 27 | def test_status_pending 28 | assert Terminal.new(status: Terminal::STATUS_PENDING).pending? 29 | assert !Terminal.new(status: "not-pending").pending? 30 | end 31 | 32 | def test_status_active 33 | assert Terminal.new(status: Terminal::STATUS_ACTIVE).active? 34 | assert !Terminal.new(status: "not-active").active? 35 | end 36 | 37 | def test_status_inactive 38 | assert Terminal.new(status: Terminal::STATUS_INACTIVE).inactive? 39 | assert !Terminal.new(status: "not-inactive").inactive? 40 | end 41 | 42 | def test_list_terminals 43 | stub_request(:get, "https://api.mollie.com/v2/terminals") 44 | .to_return(status: 200, body: LIST_TERMINALS, headers: {}) 45 | 46 | terminals = Terminal.all 47 | 48 | assert_equal 3, terminals.size 49 | assert_equal "terminal_one", terminals[0].id 50 | assert_equal "terminal_two", terminals[1].id 51 | assert_equal "terminal_three", terminals[2].id 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /test/mollie/util_test.rb: -------------------------------------------------------------------------------- 1 | require 'helper' 2 | 3 | module Mollie 4 | class UtilTest < Test::Unit::TestCase 5 | def test_extract_id 6 | links = { 7 | 'customer' => { 8 | 'href' => 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT', 9 | 'type' => 'application/hal+json' 10 | } 11 | } 12 | 13 | customer_id = Util.extract_id(links, 'customer') 14 | assert_equal 'cst_4qqhO89gsT', customer_id 15 | end 16 | 17 | def test_extract_id_missing_link 18 | links = { 19 | 'customer' => { 20 | 'href' => 'https://api.mollie.com/v2/customers/cst_4qqhO89gsT', 21 | 'type' => 'application/hal+json' 22 | } 23 | } 24 | 25 | customer_id = Util.extract_id(links, 'unknown-resource') 26 | assert_nil customer_id 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /test/run-test.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | # From https://github.com/test-unit/test-unit/blob/master/test/run-test.rb 4 | 5 | $KCODE = 'utf8' unless ''.respond_to?(:encoding) 6 | 7 | base_dir = File.expand_path(File.join(File.dirname(__FILE__), '..')) 8 | lib_dir = File.join(base_dir, 'lib') 9 | test_dir = File.join(base_dir, 'test') 10 | 11 | $LOAD_PATH.unshift(lib_dir) 12 | 13 | require 'test/unit' 14 | 15 | exit Test::Unit::AutoRunner.run(true, test_dir) 16 | --------------------------------------------------------------------------------