mollie-api-ruby 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00c764099a49ead8514278cfa6db983f644c35f0
4
- data.tar.gz: 04224d5226ac3b33340225fb2a4126f0f058ff8e
3
+ metadata.gz: 1814d5f5f87cb8fe85890e2a1b7381045e5483a6
4
+ data.tar.gz: 25c77c32cda7f816ab3a67f6d0c7cb1804c7ee81
5
5
  SHA512:
6
- metadata.gz: e1f1fb6c5e98c36fec4de50dcb300e45529373c62b11bae41ed2c2febf9e54e529dc3ab85dfadf7d2224e2c999b5b634b895cfad50e8cc2c57f2ba11fa97ca47
7
- data.tar.gz: c7fe28ba206cdea937e4e1d2300dd10501c7738d3cebc6058433a877d12c4cdc6e96d6e711e9cb843b517e5a7b33d477b4a431603c8c48133addbe966451c5da
6
+ metadata.gz: e356234410dbd7ddfce3878af51ea8d1e5599a2e46772e7bcb5c30d3b7c6dd33ef7bef7673a9e792eb607d370e913182676501208f04b3a385be3f424c612f4a
7
+ data.tar.gz: 57429e86b3b93ba8409ab5f5dc6a1175f9a0b02965d54e78773be744b59303953b04c36f4a00c7ae85d40cd1ebae988da628589f4a02584372c397c5b878a722
data/README.mdown CHANGED
@@ -67,6 +67,17 @@ Retrieving a payment.
67
67
  end
68
68
  ```
69
69
 
70
+ ### Refunding payments ###
71
+
72
+ The API also supports refunding payments. Note that there is no confirmation and that all refunds are immediate and
73
+ definitive. Refunds are only supported for iDEAL, credit card and Bank Transfer payments. Other types of payments cannot
74
+ be refunded through our API at the moment.
75
+
76
+ ```ruby
77
+ payment = mollie.payments.get payment.id
78
+ refund = mollie.payments_refunds.with(payment).create
79
+ ```
80
+
70
81
  ## Examples ##
71
82
 
72
83
  The examples require [Sinatra](http://rubygems.org/gems/sinatra) so you will need to install that gem first. Afterwards simply run:
@@ -86,6 +97,7 @@ Contact: [www.mollie.nl](http://www.mollie.nl) — info@mollie.nl — +31 20-612
86
97
  + [More information about iDEAL via Mollie](https://www.mollie.nl/betaaldiensten/ideal/)
87
98
  + [More information about Creditcard via Mollie](https://www.mollie.nl/betaaldiensten/creditcard/)
88
99
  + [More information about Mister Cash via Mollie](https://www.mollie.nl/betaaldiensten/mistercash/)
100
+ + [More information about Bank transfer via Mollie](https://www.mollie.nl/betaaldiensten/overboeking/)
89
101
  + [More information about PayPal via Mollie](https://www.mollie.nl/betaaldiensten/paypal/)
90
102
  + [More information about paysafecard via Mollie](https://www.mollie.nl/betaaldiensten/paysafecard/)
91
103
 
@@ -10,7 +10,7 @@ begin
10
10
  # See: https://www.mollie.nl/beheer/account/profielen/
11
11
  #
12
12
  mollie = Mollie::API::Client.new
13
- mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
13
+ mollie.setApiKey "test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp"
14
14
 
15
15
  #
16
16
  # Generate a unique order id for this example. It is important to include this unique attribute
@@ -10,7 +10,7 @@ begin
10
10
  # See: https://www.mollie.nl/beheer/account/profielen/
11
11
  #
12
12
  mollie = Mollie::API::Client.new
13
- mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
13
+ mollie.setApiKey "test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp"
14
14
 
15
15
  #
16
16
  # Retrieve the payment's current state.
@@ -10,7 +10,7 @@ begin
10
10
  # See: https://www.mollie.nl/beheer/account/profielen/
11
11
  #
12
12
  mollie = Mollie::API::Client.new
13
- mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
13
+ mollie.setApiKey "test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp"
14
14
 
15
15
  #
16
16
  # First, let the customer pick the bank in a simple HTML form. This step is actually optional.
@@ -10,7 +10,7 @@ begin
10
10
  # See: https://www.mollie.nl/beheer/account/profielen/
11
11
  #
12
12
  mollie = Mollie::API::Client.new
13
- mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
13
+ mollie.setApiKey "test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp"
14
14
 
15
15
  #
16
16
  # Get the all payments for this API key ordered by newest.
@@ -20,7 +20,7 @@ begin
20
20
  $response.body = "Your API key has #{payments.totalCount} payments, last #{payments.count}:<br>"
21
21
 
22
22
  payments.each { |payment|
23
- $response.body << "&euro; #{payment.amount}, status: #{CGI.escapeHTML payment.status}<br>"
23
+ $response.body << "&euro; #{payment.amount}, status: #{CGI.escapeHTML payment.status} (#{CGI.escapeHTML payment.id})<br>"
24
24
  }
25
25
  rescue Mollie::API::Exception => e
26
26
  $response.body << "API call failed: " << (CGI.escapeHTML e.message)
@@ -10,7 +10,7 @@ begin
10
10
  # See: https://www.mollie.nl/beheer/account/profielen/
11
11
  #
12
12
  mollie = Mollie::API::Client.new
13
- mollie.setApiKey "test_dHar4XY7LxsDOtmnkVtjNVWXLSlXsM"
13
+ mollie.setApiKey "test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp"
14
14
 
15
15
  #
16
16
  # Get the all the activated methods for this API key.
@@ -0,0 +1,40 @@
1
+ #
2
+ # Example 7 - How to refund a payment programmatically.
3
+ #
4
+ require File.expand_path "../lib/Mollie/API/Client", __dir__
5
+
6
+ begin
7
+ #
8
+ # Initialize the Mollie API library with your API key.
9
+ #
10
+ # See: https://www.mollie.nl/beheer/account/profielen/
11
+ #
12
+ mollie = Mollie::API::Client.new
13
+ mollie.setApiKey "test_bt7vvByF6jTcBR4dLuW66eNnHYNIJp"
14
+
15
+ #
16
+ # Retrieve the payment you want to refund from the API.
17
+ #
18
+ payment = mollie.payments.get "tr_dO6CPyCfoK"
19
+
20
+ #
21
+ # Refund the payment.
22
+ #
23
+ refund = mollie.payments_refunds.with(payment).create
24
+
25
+ $response.body << "The payment #{payment.id} is now refunded.<br>"
26
+
27
+ #
28
+ # Retrieve refunds on a payment.
29
+ #
30
+ refunds = mollie.payments_refunds.with(payment).all
31
+
32
+ refunds.each { |refund|
33
+ $response.body << '<br> Refund date: ' << (CGI.escapeHTML refund.refundedDatetime)
34
+ $response.body << '<br> Refunded: &euro; ' << (CGI.escapeHTML refund.amountRefunded)
35
+ $response.body << '<br> Remaining: &euro; ' << (CGI.escapeHTML refund.amountRemaining)
36
+ $response.body << '<br>'
37
+ }
38
+ rescue Mollie::API::Exception => e
39
+ $response.body << "API call failed: " << (CGI.escapeHTML e.message)
40
+ end
data/examples/app.rb CHANGED
@@ -9,7 +9,8 @@ examples = [
9
9
  '3-return-page',
10
10
  '4-ideal-payment',
11
11
  '5-payments-history',
12
- '6-list-activated-methods'
12
+ '6-list-activated-methods',
13
+ '7-refund-payment'
13
14
  ]
14
15
 
15
16
  get "/" do
@@ -4,27 +4,30 @@ require "rest_client"
4
4
  ["Exception",
5
5
  "Resource/Base",
6
6
  "Resource/Payments",
7
+ "Resource/Payments/Refunds",
7
8
  "Resource/Issuers",
8
9
  "Resource/Methods",
9
10
  "Object/Base",
10
11
  "Object/List",
11
12
  "Object/Payment",
13
+ "Object/Payment/Refund",
12
14
  "Object/Issuer",
13
15
  "Object/Method"].each {|file| require File.expand_path file, __dir__ }
14
16
 
15
17
  module Mollie
16
18
  module API
17
19
  class Client
18
- CLIENT_VERSION = "1.0.1"
20
+ CLIENT_VERSION = "1.1.0"
19
21
  API_ENDPOINT = "https://api.mollie.nl"
20
22
  API_VERSION = "v1"
21
23
 
22
- attr_reader :payments, :issuers, :methods
24
+ attr_reader :payments, :issuers, :methods, :payments_refunds
23
25
 
24
26
  def initialize ()
25
- @payments = Mollie::API::Resource::Payments.new self
26
- @issuers = Mollie::API::Resource::Issuers.new self
27
- @methods = Mollie::API::Resource::Methods.new self
27
+ @payments = Mollie::API::Resource::Payments.new self
28
+ @issuers = Mollie::API::Resource::Issuers.new self
29
+ @methods = Mollie::API::Resource::Methods.new self
30
+ @payments_refunds = Mollie::API::Resource::Payments::Refunds.new self
28
31
 
29
32
  @api_endpoint = API_ENDPOINT
30
33
  @api_key = ""
@@ -88,7 +91,12 @@ module Mollie
88
91
  raise e if response[:error].nil?
89
92
  end
90
93
 
91
- raise Mollie::API::Exception.new response[:error][:message] unless response[:error].nil?
94
+ unless response[:error].nil?
95
+ exception = Mollie::API::Exception.new response[:error][:message]
96
+ exception.field = response[:error][:field] unless response[:error][:field].nil?
97
+ raise exception
98
+ end
99
+
92
100
  response
93
101
  end
94
102
 
@@ -1,6 +1,9 @@
1
1
  module Mollie
2
2
  module API
3
3
  class Exception < StandardError
4
+ @field = nil
5
+
6
+ attr_accessor :field
4
7
  end
5
8
  end
6
9
  end
@@ -2,11 +2,12 @@ module Mollie
2
2
  module API
3
3
  module Object
4
4
  class Method < Base
5
- IDEAL = "ideal"
6
- CREDITCARD = "creditcard"
7
- MISTERCASH = "mistercash"
8
- PAYPAL = "paypal"
9
- PAYSAFECARD = "paysafecard"
5
+ IDEAL = "ideal"
6
+ CREDITCARD = "creditcard"
7
+ MISTERCASH = "mistercash"
8
+ BANKTRANSFER = "banktransfer"
9
+ PAYPAL = "paypal"
10
+ PAYSAFECARD = "paysafecard"
10
11
 
11
12
  attr_accessor :id,
12
13
  :description,
@@ -23,4 +24,4 @@ module Mollie
23
24
  end
24
25
  end
25
26
  end
26
- end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Mollie
2
+ module API
3
+ module Object
4
+ class Payment
5
+ class Refund < Base
6
+ attr_accessor :id,
7
+ :amountRefunded,
8
+ :amountRemaining,
9
+ :payment,
10
+ :refundedDatetime
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -11,27 +11,41 @@ module Mollie
11
11
  end
12
12
 
13
13
  def create (data = {})
14
- response = @client.performHttpCall "POST", getResourceName, nil, data
15
- getResourceObject.new response
14
+ request("POST", nil, data) { |response|
15
+ newResourceObject response
16
+ }
16
17
  end
17
18
 
18
19
  def get (id)
19
- response = @client.performHttpCall "GET", getResourceName, id || 0
20
- getResourceObject.new response
20
+ request("GET", id, {}) { |response|
21
+ newResourceObject response
22
+ }
21
23
  end
22
24
 
23
25
  def update (id, data = {})
24
- response = @client.performHttpCall "POST", getResourceName, id || 0, data
25
- getResourceObject.new response
26
+ request("POST", id, data) { |response|
27
+ newResourceObject response
28
+ }
26
29
  end
27
30
 
28
31
  def delete (id)
29
- @client.performHttpCall "DELETE", getResourceName, id || 0
32
+ request "DELETE", id, {}
30
33
  end
31
34
 
32
35
  def all ()
33
- response = @client.performHttpCall "GET", getResourceName
34
- Mollie::API::Object::List.new response, getResourceObject
36
+ request("GET", nil, {}) { |response|
37
+ Mollie::API::Object::List.new response, getResourceObject
38
+ }
39
+ end
40
+
41
+ def newResourceObject (response)
42
+ getResourceObject.new response
43
+ end
44
+
45
+ def request (method, id = 0, data = {})
46
+ response = @client.performHttpCall method, getResourceName, id, data
47
+
48
+ yield(response) if block_given?
35
49
  end
36
50
  end
37
51
  end
@@ -0,0 +1,27 @@
1
+ require 'open-uri'
2
+
3
+ module Mollie
4
+ module API
5
+ module Resource
6
+ class Payments
7
+ class Refunds < Base
8
+ @payment_id = nil
9
+
10
+ def getResourceObject ()
11
+ Mollie::API::Object::Payment::Refund
12
+ end
13
+
14
+ def getResourceName ()
15
+ payment_id = URI::encode(@payment_id)
16
+ "payments/#{payment_id}/refunds"
17
+ end
18
+
19
+ def with (payment)
20
+ @payment_id = payment.id
21
+ self
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mollie-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Wong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-24 00:00:00.000000000 Z
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -55,6 +55,7 @@ files:
55
55
  - examples/4-ideal-payment.rb
56
56
  - examples/5-payments-history.rb
57
57
  - examples/6-list-activated-methods.rb
58
+ - examples/7-refund-payment.rb
58
59
  - examples/app.rb
59
60
  - examples/orders/.gitignore
60
61
  - lib/Mollie/API/Client.rb
@@ -64,10 +65,12 @@ files:
64
65
  - lib/Mollie/API/Object/List.rb
65
66
  - lib/Mollie/API/Object/Method.rb
66
67
  - lib/Mollie/API/Object/Payment.rb
68
+ - lib/Mollie/API/Object/Payment/Refund.rb
67
69
  - lib/Mollie/API/Resource/Base.rb
68
70
  - lib/Mollie/API/Resource/Issuers.rb
69
71
  - lib/Mollie/API/Resource/Methods.rb
70
72
  - lib/Mollie/API/Resource/Payments.rb
73
+ - lib/Mollie/API/Resource/Payments/Refunds.rb
71
74
  - lib/Mollie/API/cacert.pem
72
75
  - mollie.gemspec
73
76
  homepage: https://github.com/mollie/mollie-api-ruby