Skip to content
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ customer = client.v2.customers.create(email: 'customer@example.com', name: 'Jon
payment_methods = client.v2.payment_methods.list(customer: 'customer_id')
client.v2.payment_methods.cancel('payment_method_id')
mandate = client.v2.payment_methods.mandate_document('payment_method_id')
installments = client.v2.payment_methods.installments('payment_method_id', amount: 1000, currency: 'CLP')
# => { available_installments: [3, 6, 12] }
# Mexican direct debit mandates are sent as multipart. Nested fields are sent in
# bracket notation and consent documents accept a path or an IO.
payment_method = client.v2.payment_methods.create(
Expand Down
1 change: 1 addition & 0 deletions lib/fintoc/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class RefreshIntentInProgressError < FintocError; end
class RejectedRefreshIntentError < FintocError; end
class SenderBlockedAccountError < FintocError; end
class AmountOutOfRangeError < FintocError; end
class ChargeProcessingFeeNotAllowedError < FintocError; end
class CountryNotSupportedError < FintocError; end
class DirectDebitSuspendedError < FintocError; end
class FileTooLargeError < FintocError; end
Expand Down
5 changes: 5 additions & 0 deletions lib/fintoc/v2/managers/payment_methods_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def mandate_document(payment_method_id)
@client.get(version: :v2).call("payment_methods/#{payment_method_id}/mandate_document")
end

def installments(payment_method_id, amount:, currency:)
@client.get(version: :v2)
.call("payment_methods/#{payment_method_id}/installments", amount:, currency:)
end

private

def flatten_form(fields, prefix = nil)
Expand Down
3 changes: 2 additions & 1 deletion spec/lib/fintoc/base_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,8 @@ def expect_error(klass, status:, code:)
'credit_already_simulated' => 'CreditAlreadySimulatedError',
'transfer_not_cancellable' => 'TransferNotCancellableError',
'usdt_collection_already_open' => 'UsdtCollectionAlreadyOpenError',
'payment_method_canceled' => 'PaymentMethodCanceledError'
'payment_method_canceled' => 'PaymentMethodCanceledError',
'charge_processing_fee_not_allowed' => 'ChargeProcessingFeeNotAllowedError'
}.each do |code, klass|
it "resolves the #{code} error" do
expect(client.send(:error_class, code)).to eq(Fintoc::Errors.const_get(klass))
Expand Down
36 changes: 36 additions & 0 deletions spec/lib/fintoc/v2/managers/payment_methods_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@

expect(manager.list(payment_options: { amount: 1000 })).to contain_exactly(a_kind_of(Fintoc::V2::PaymentMethod))
end

it 'sends the off_session payment option in bracket notation' do
stub_request(:get, "#{collection_url}?payment_options%5Boff_session%5D=true")
.to_return(body: [payload].to_json, headers: headers)

expect(manager.list(payment_options: { off_session: true }))
.to contain_exactly(a_kind_of(Fintoc::V2::PaymentMethod))
end
end

describe '#get' do
Expand Down Expand Up @@ -120,4 +128,32 @@
expect(manager.mandate_document(payload[:id])).to eq(response)
end
end

describe '#installments' do
let(:response) { { available_installments: [3, 6, 12] } }

before do
stub_request(:get, "#{resource_url}/installments")
.with(query: { amount: '1000', currency: 'CLP' })
.to_return(body: response.to_json, headers: headers)
end

it 'returns the available installments for the amount' do
expect(manager.installments(payload[:id], amount: 1000, currency: 'CLP')).to eq(response)
end

it 'raises the API error when the card is not available for installments' do
stub_request(:get, "#{resource_url}/installments")
.with(query: { amount: '1000', currency: 'CLP' })
.to_return(
status: 422,
body: { error: { type: 'invalid_request_error', code: 'invalid_payment_method_state',
message: 'Payment method is not available for installments' } }.to_json,
headers: headers
)

expect { manager.installments(payload[:id], amount: 1000, currency: 'CLP') }
.to raise_error(Fintoc::Errors::InvalidPaymentMethodStateError)
end
end
end
Loading