Skip to content

Commit

Permalink
Merge pull request #110 from Mangopay/feature/MPSDK-231-get-refunds-f…
Browse files Browse the repository at this point in the history
…or-payin-endpoint-v4

Implemented Get Refunds for a PayIn endpoint on V4
  • Loading branch information
mickaelpois authored Mar 19, 2018
2 parents 0ad8864 + 469c45e commit 3148124
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/mangopay/api/api_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class << self
create_direct_debit_web_pay_in: %w[POST payins/directdebit/web],
create_direct_debit_direct_pay_in: %w[POST payins/directdebit/direct],
get_pay_in: %w[GET %(payins/#{_param1})],
get_payins_refunds: %w[GET %(payins/#{_param1}/refunds)],

get_extended_card_view: %w[GET %(payins/card/web/#{_param1}/extended)],

Expand Down
22 changes: 22 additions & 0 deletions lib/mangopay/api/service/refunds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ def of_pay_out(id)
parse_results results
end

# Retrieves pages of refund entities belonging to a certain pay-in.
# Allows configuration of paging and sorting parameters by yielding
# a filtering object to a provided block. When no filters are specified,
# will retrieve the first page of 10 newest results.
#
# Allowed +FilterRequest+ params:
# * page
# * per_page
# * sort_field and sort_direction
# * status
# * result_code
#
# @param +id+ [String] ID of the pay-in whose refunds to retrieve
# @return [Array] the requested Refund entity objects
def of_pay_in(id)
uri = provide_uri(:get_payins_refunds, id)
filter_request = nil
yield filter_request = FilterRequest.new if block_given?
results = HttpClient.get(uri, filter_request)
parse_results results
end

private

# Parses a JSON-originating hash into the corresponding
Expand Down
36 changes: 36 additions & 0 deletions spec/mangopay/refunds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,40 @@
end
end
end

describe '.of_pay_in' do

context "given an existing entity's ID" do
id = CARD_WEB_PAY_IN_PERSISTED.id

context 'not having specified filters' do
results = MangoApi::Refunds.of_pay_in id

it 'retrieves list with default parameters' do
expect(results).to be_kind_of Array
results.each do |result|
expect(result).to be_kind_of MangoModel::Refund
expect(result.id).not_to be_nil
end
end
end

context 'having specified filters' do
results = MangoApi::Refunds.of_pay_in id do |filter|
filter.page = 1
filter.per_page = 3
filter.status = MangoModel::TransactionStatus::CREATED
end

it 'retrieves list with specified parameters' do
expect(results).to be_kind_of Array
results.each do |result|
expect(result).to be_kind_of MangoModel::Refund
expect(result.id).not_to be_nil
expect(result.status).to be MangoModel::TransactionStatus::CREATED
end
end
end
end
end
end

0 comments on commit 3148124

Please sign in to comment.