Skip to content

Commit

Permalink
Merge pull request #150 from mollie/GH-149
Browse files Browse the repository at this point in the history
Add "List all payment methods" API
  • Loading branch information
justincase authored Jun 13, 2021
2 parents 9d8eebc + 457b853 commit c7508e9
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/mollie/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class Method < Base
:pricing,
:status

def self.all_available(options = {})
response = Client.instance.perform_http_call("GET", "methods", "all", {}, options)
Mollie::List.new(response, Mollie::Method)
end

def minimum_amount=(minimum_amount)
@minimum_amount = Mollie::Amount.new(minimum_amount)
end
Expand Down
92 changes: 92 additions & 0 deletions test/fixtures/methods/all.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"count": 3,
"_embedded": {
"methods": [
{
"resource": "method",
"id": "ideal",
"description": "iDEAL",
"minimumAmount": {
"value": "0.01",
"currency": "EUR"
},
"maximumAmount": {
"value": "50000.00",
"currency": "EUR"
},
"image": {
"size1x": "https://www.mollie.com/external/icons/payment-methods/ideal.png",
"size2x": "https://www.mollie.com/external/icons/payment-methods/ideal%402x.png",
"svg": "https://www.mollie.com/external/icons/payment-methods/ideal.svg"
},
"status": "pending-boarding",
"_links": {
"self": {
"href": "https://api.mollie.com/v2/methods/ideal",
"type": "application/hal+json"
}
}
},
{
"resource": "method",
"id": "creditcard",
"description": "Credit card",
"minimumAmount": {
"value": "0.01",
"currency": "EUR"
},
"maximumAmount": {
"value": "2000.00",
"currency": "EUR"
},
"image": {
"size1x": "https://www.mollie.com/external/icons/payment-methods/creditcard.png",
"size2x": "https://www.mollie.com/external/icons/payment-methods/creditcard%402x.png",
"svg": "https://www.mollie.com/external/icons/payment-methods/creditcard.svg"
},
"status": "pending-boarding",
"_links": {
"self": {
"href": "https://api.mollie.com/v2/methods/creditcard",
"type": "application/hal+json"
}
}
},
{
"resource": "method",
"id": "bancontact",
"description": "Bancontact",
"minimumAmount": {
"value": "0.02",
"currency": "EUR"
},
"maximumAmount": {
"value": "50000.00",
"currency": "EUR"
},
"image": {
"size1x": "https://www.mollie.com/external/icons/payment-methods/bancontact.png",
"size2x": "https://www.mollie.com/external/icons/payment-methods/bancontact%402x.png",
"svg": "https://www.mollie.com/external/icons/payment-methods/bancontact.svg"
},
"status": null,
"_links": {
"self": {
"href": "https://api.mollie.com/v2/methods/bancontact",
"type": "application/hal+json"
}
}
}
]
},
"_links": {
"documentation": {
"href": "https://docs.mollie.com/reference/v2/methods-api/list-all-methods",
"type": "text/html"
},
"self": {
"href": "https://api.mollie.com/v2/methods/all",
"type": "application/hal+json"
}
}
}
11 changes: 11 additions & 0 deletions test/mollie/method_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def test_setting_attributes
assert_equal 'https://www.mollie.com/external/icons/payment-methods/creditcard.svg', method.image['svg']
end

def test_all_available
stub_request(:get, 'https://api.mollie.com/v2/methods/all')
.to_return(status: 200, body: read_fixture('methods/all.json'), headers: {})

available_methods = Method.all_available
assert_equal 3, available_methods.size

ideal_method = available_methods.first
assert_equal "pending-boarding", ideal_method.status
end

def test_pricing
stub_request(:get, 'https://api.mollie.com/v2/methods/creditcard?include=pricing')
.to_return(status: 200, body: read_fixture('methods/get-includes-pricing.json'), headers: {})
Expand Down

0 comments on commit c7508e9

Please sign in to comment.