diff --git a/lib/mollie/client.rb b/lib/mollie/client.rb index 392e8ac..ce65b5a 100644 --- a/lib/mollie/client.rb +++ b/lib/mollie/client.rb @@ -126,6 +126,8 @@ def perform_http_call(http_method, api_method, id = nil, http_body = {}, query = case http_code when 200, 201 Util.nested_underscore_keys(JSON.parse(response.body)) + when 202 + JSON.parse(response.body) when 204 {} # No Content when 404 diff --git a/lib/mollie/payment.rb b/lib/mollie/payment.rb index 98bffd1..fda5a01 100644 --- a/lib/mollie/payment.rb +++ b/lib/mollie/payment.rb @@ -196,6 +196,10 @@ def refund!(options = {}) Payment::Refund.create(options) end + def release_authorization(options = {}) + Client.instance.perform_http_call("POST", "payments/#{id}", "release-authorization", {}, options) == {} + end + def refunds(options = {}) resources = (attributes['_embedded']['refunds'] if attributes['_embedded']) diff --git a/test/mollie/payment_test.rb b/test/mollie/payment_test.rb index 580f886..bf5079f 100644 --- a/test/mollie/payment_test.rb +++ b/test/mollie/payment_test.rb @@ -151,6 +151,22 @@ def test_create_payment_for_customer assert_equal 'cst_8wmqcHMN4U', payment.customer_id end + def test_release_authorization + stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg') + .to_return(status: 200, body: %( + { + "resource": "payment", + "id": "tr_WDqYK6vllg" + } + ), headers: {}) + + stub_request(:post, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg/release-authorization') + .to_return(status: 202, body: %({}), headers: {}) + + payment = Payment.get('tr_WDqYK6vllg') + assert payment.release_authorization + end + def test_refund! stub_request(:get, 'https://api.mollie.com/v2/payments/tr_WDqYK6vllg') .to_return(status: 200, body: %(