Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "List all payment methods" API #150

Merged
merged 1 commit into from
Jun 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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