From 3580ce08312c06782f82e71af96ea0ef5622c5de Mon Sep 17 00:00:00 2001 From: Justin Case Date: Sun, 10 May 2020 21:59:55 +0200 Subject: [PATCH] Settlement: add `captures` helper method --- examples/settlements/list-captures.rb | 1 + lib/mollie.rb | 1 + lib/mollie/settlement.rb | 4 ++++ lib/mollie/settlement/capture.rb | 6 ++++++ test/mollie/settlement_test.rb | 11 +++++++++++ 5 files changed, 23 insertions(+) create mode 100644 examples/settlements/list-captures.rb create mode 100644 lib/mollie/settlement/capture.rb diff --git a/examples/settlements/list-captures.rb b/examples/settlements/list-captures.rb new file mode 100644 index 0000000..965c929 --- /dev/null +++ b/examples/settlements/list-captures.rb @@ -0,0 +1 @@ +captures = Mollie::Settlement::Capture.all(settlement_id: 'stl_jDk30akdN') diff --git a/lib/mollie.rb b/lib/mollie.rb index 6334ff7..f521c6f 100644 --- a/lib/mollie.rb +++ b/lib/mollie.rb @@ -38,6 +38,7 @@ module Mollie require 'mollie/payment/capture' require 'mollie/payment/chargeback' require 'mollie/payment/refund' +require 'mollie/settlement/capture' require 'mollie/settlement/chargeback' require 'mollie/settlement/payment' require 'mollie/settlement/refund' diff --git a/lib/mollie/settlement.rb b/lib/mollie/settlement.rb index c548a16..e3409be 100644 --- a/lib/mollie/settlement.rb +++ b/lib/mollie/settlement.rb @@ -77,6 +77,10 @@ def chargebacks(options = {}) Settlement::Chargeback.all(options.merge(settlement_id: id)) end + def captures(options = {}) + Settlement::Capture.all(options.merge(settlement_id: id)) + end + def invoice(options = {}) return if invoice_id.nil? Invoice.get(invoice_id, options) diff --git a/lib/mollie/settlement/capture.rb b/lib/mollie/settlement/capture.rb new file mode 100644 index 0000000..9940550 --- /dev/null +++ b/lib/mollie/settlement/capture.rb @@ -0,0 +1,6 @@ +module Mollie + class Settlement + class Capture < Mollie::Payment::Capture + end + end +end diff --git a/test/mollie/settlement_test.rb b/test/mollie/settlement_test.rb index e8e4ad6..9a27d4d 100644 --- a/test/mollie/settlement_test.rb +++ b/test/mollie/settlement_test.rb @@ -224,6 +224,17 @@ def test_list_chargebacks assert_equal 'chb-id', chargebacks.first.id end + def test_list_captures + stub_request(:get, 'https://api.mollie.com/v2/settlements/stl-id/captures') + .to_return(status: 200, body: %( + { "_embedded" : {"captures" : [{ "id": "cpt-id", "settlement_id": "stl-id" }]}} + ), headers: {}) + + captures = Settlement.new(id: 'stl-id').captures + assert_equal Settlement::Capture, captures.klass + assert_equal 'cpt-id', captures.first.id + end + def test_get_invoice stub_request(:get, 'https://api.mollie.com/v2/settlements/stl_jDk30akdN') .to_return(