Skip to content

Commit

Permalink
- Fixed delete() method missing comma.
Browse files Browse the repository at this point in the history
- Fixed create/all() by setting id to nil instead of 0.
- Renamed refunds accessor to payments_refunds for consistency.
  • Loading branch information
Rick Wong committed Mar 14, 2014
1 parent d4331cc commit 8cfcabd
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
11 changes: 11 additions & 0 deletions README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ Retrieving a payment.
end
```

### Refunding payments ###

The API also supports refunding payments. Note that there is no confirmation and that all refunds are immediate and
definitive. Refunds are only supported for iDEAL, credit card and Bank Transfer payments. Other types of payments cannot
be refunded through our API at the moment.

```ruby
payment = mollie.payments.get payment.id
refund = mollie.payments_refunds.with(payment).create
```

## Examples ##

The examples require [Sinatra](http://rubygems.org/gems/sinatra) so you will need to install that gem first. Afterwards simply run:
Expand Down
2 changes: 1 addition & 1 deletion examples/5-payments-history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
$response.body = "Your API key has #{payments.totalCount} payments, last #{payments.count}:<br>"

payments.each { |payment|
$response.body << "&euro; #{payment.amount}, status: #{CGI.escapeHTML payment.status}<br>"
$response.body << "&euro; #{payment.amount}, status: #{CGI.escapeHTML payment.status} (#{CGI.escapeHTML payment.id})<br>"
}
rescue Mollie::API::Exception => e
$response.body << "API call failed: " << (CGI.escapeHTML e.message)
Expand Down
4 changes: 2 additions & 2 deletions examples/7-refund-payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
#
# Refund the payment.
#
refund = mollie.refunds.with(payment).create
refund = mollie.payments_refunds.with(payment).create

$response.body << "The payment #{payment.id} is now refunded.<br>"

#
# Retrieve refunds on a payment.
#
refunds = mollie.refunds.with(payment).all
refunds = mollie.payments_refunds.with(payment).all

refunds.each { |refund|
$response.body << '<br> Refund date: ' << (CGI.escapeHTML refund.refundedDatetime)
Expand Down
10 changes: 5 additions & 5 deletions lib/Mollie/API/Client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class Client
API_ENDPOINT = "https://api.mollie.nl"
API_VERSION = "v1"

attr_reader :payments, :issuers, :methods, :refunds
attr_reader :payments, :issuers, :methods, :payments_refunds

def initialize ()
@payments = Mollie::API::Resource::Payments.new self
@issuers = Mollie::API::Resource::Issuers.new self
@methods = Mollie::API::Resource::Methods.new self
@refunds = Mollie::API::Resource::Payments::Refunds.new self
@payments = Mollie::API::Resource::Payments.new self
@issuers = Mollie::API::Resource::Issuers.new self
@methods = Mollie::API::Resource::Methods.new self
@payments_refunds = Mollie::API::Resource::Payments::Refunds.new self

@api_endpoint = API_ENDPOINT
@api_key = ""
Expand Down
23 changes: 16 additions & 7 deletions lib/Mollie/API/Resource/Base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,40 @@ def getResourceName ()
end

def create (data = {})
request("POST", 0, data) { |response| newResourceObject(response) }
request("POST", nil, data) { |response|
newResourceObject response
}
end

def get (id)
request("GET", id) { |response| newResourceObject(response) }
request("GET", id, {}) { |response|
newResourceObject response
}
end

def update (id, data = {})
request("POST", id, data) { |response| newResourceObject(response) }
request("POST", id, data) { |response|
newResourceObject response
}
end

def delete (id)
request("DELETE" id)
request "DELETE", id, {}
end

def all ()
request("GET") { |response| Mollie::API::Object::List.new response, getResourceObject }
request("GET", nil, {}) { |response|
Mollie::API::Object::List.new response, getResourceObject
}
end

def newResourceObject(response)
def newResourceObject (response)
getResourceObject.new response
end

def request(method, id = 0, data = {})
def request (method, id = 0, data = {})
response = @client.performHttpCall method, getResourceName, id, data

yield(response) if block_given?
end
end
Expand Down

0 comments on commit 8cfcabd

Please sign in to comment.