Skip to content
Closed
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
8 changes: 0 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
source 'https://rubygems.org'
gemspec

# We support both pre-1.x and post-1.x Faraday versions, but to ensure compatibility we
# pin this gem against each in separate runs of CI, using the FARADAY_VERSION env var. For
# more details on the values, see .github/workflows/tests.yml in the gocardless-pro-ruby
# repository.
if ENV.key?("FARADAY_VERSION")
gem 'faraday', "~> #{ENV["FARADAY_VERSION"]}"
end
50 changes: 50 additions & 0 deletions lib/gocardless_pro/resources/creditor_bank_account_validate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# This client is automatically generated from a template and JSON schema definition.
# See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
#

require 'uri'

module GoCardlessPro
# A module containing classes for each of the resources in the GC Api
module Resources
# Represents an instance of a creditor_bank_account_validate resource returned from the API

# Creditor Bank Accounts hold the bank details of a
# [creditor](#core-endpoints-creditors). These are the bank accounts which
# your [payouts](#core-endpoints-payouts) will be sent to.
#
# When all locale details and Iban are supplied validates creditor bank
# details without creating a creditor bank account and also provdes bank
# details such as name and icon url. When partial details are are provided
# the endpoint will only provide bank details such as name and icon url but
# will not be able to determine if the provided details are valid.
#
# <p class="restricted-notice"><strong>Restricted</strong>: This API is not
# available for partner integrations.</p>
class CreditorBankAccountValidate
attr_reader :bank_name, :icon_url, :invalid_reasons, :is_valid

# Initialize a creditor_bank_account_validate resource instance
# @param object [Hash] an object returned from the API
def initialize(object, response = nil)
@object = object

@bank_name = object['bank_name']
@icon_url = object['icon_url']
@invalid_reasons = object['invalid_reasons']
@is_valid = object['is_valid']
@response = response
end

def api_response
ApiResponse.new(@response)
end

# Provides the creditor_bank_account_validate resource as a hash of all its readable attributes
def to_h
@object
end
end
end
end
4 changes: 4 additions & 0 deletions lib/gocardless_pro/resources/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def mandate
@links['mandate']
end

def mandate_request
@links['mandate_request']
end

def mandate_request_mandate
@links['mandate_request_mandate']
end
Expand Down
3 changes: 2 additions & 1 deletion lib/gocardless_pro/resources/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Resources
# the state of a payment changes.
class Payment
attr_reader :amount, :amount_refunded, :charge_date, :created_at, :currency, :description, :faster_ach, :fx, :id,
:metadata, :reference, :retry_if_possible, :status
:metadata, :reference, :retry_if_possible, :scheme, :status

# Initialize a payment resource instance
# @param object [Hash] an object returned from the API
Expand All @@ -39,6 +39,7 @@ def initialize(object, response = nil)
@metadata = object['metadata']
@reference = object['reference']
@retry_if_possible = object['retry_if_possible']
@scheme = object['scheme']
@status = object['status']
@response = response
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require_relative './base_service'

# encoding: utf-8
#
# This client is automatically generated from a template and JSON schema definition.
# See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
#

module GoCardlessPro
module Services
# Service for making requests to the CreditorBankAccountValidate endpoints
class CreditorBankAccountValidatesService < BaseService
# Validate bank details without creating a creditor bank account
# Example URL: /creditor_bank_accounts/validate
# @param options [Hash] parameters as a hash, under a params key.
def validate(options = {})
path = '/creditor_bank_accounts/validate'

params = options.delete(:params) || {}
options[:params] = {}
options[:params]['data'] = params

options[:retry_failures] = false

response = make_request(:post, path, options)

return if response.body.nil?

Resources::CreditorBankAccountValidate.new(unenvelope_body(response.body), response)
end

private

# Unenvelope the response of the body using the service's `envelope_key`
#
# @param body [Hash]
def unenvelope_body(body)
body[envelope_key] || body['data']
end

# return the key which API responses will envelope data under
def envelope_key
'creditor_bank_accounts'
end
end
end
end
6 changes: 6 additions & 0 deletions lib/gocardless_pro/services/scenario_simulators_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ class ScenarioSimulatorsService < BaseService
# `failed`. The billing request must be in the `pending` state, with all
# actions completed except for `bank_authorisation`. Only billing requests
# with a `payment_request` are supported.</li>
# <li>`billing_request_fulfilled_and_payment_confirmed_to_failed`:
# Authorises the billing request, fulfils it, moves the associated payment
# to `confirmed` and then moves it to `failed`. The billing request must
# be in the `pending` state, with all actions completed except for
# `bank_authorisation`. Only billing requests with a `payment_request` are
# supported.</li>
# <li>`billing_request_fulfilled_and_payment_paid_out`: Authorises the
# billing request, fulfils it, and moves the associated payment to
# `paid_out`. The billing request must be in the `pending` state, with all
Expand Down
68 changes: 68 additions & 0 deletions spec/resources/creditor_bank_account_validate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require 'spec_helper'

describe GoCardlessPro::Resources::CreditorBankAccountValidate do
let(:client) do
GoCardlessPro::Client.new(
access_token: 'SECRET_TOKEN'
)
end

let(:response_headers) { { 'Content-Type' => 'application/json' } }

describe '#validate' do
subject(:post_response) { client.creditor_bank_account_validates.validate }

let(:resource_id) { 'ABC123' }

let!(:stub) do
# /creditor_bank_accounts/validate
stub_url = '/creditor_bank_accounts/validate'.gsub(':identity', resource_id)
stub_request(:post, /.*api.gocardless.com#{stub_url}/).to_return(
body: {
'creditor_bank_accounts' => {

'bank_name' => 'bank_name-input',
'icon_url' => 'icon_url-input',
'invalid_reasons' => 'invalid_reasons-input',
'is_valid' => 'is_valid-input'
}
}.to_json,

headers: response_headers
)
end

it 'wraps the response and calls the right endpoint' do
expect(post_response).to be_a(GoCardlessPro::Resources::CreditorBankAccountValidate)

expect(stub).to have_been_requested
end

context 'when the request needs a body and custom header' do
subject(:post_response) { client.creditor_bank_account_validates.validate(body, headers) }

let(:resource_id) { 'ABC123' }

let!(:stub) do
# /creditor_bank_accounts/validate
stub_url = '/creditor_bank_accounts/validate'.gsub(':identity', resource_id)
stub_request(:post, /.*api.gocardless.com#{stub_url}/)
.with(
body: { foo: 'bar' },
headers: { 'Foo' => 'Bar' }
).to_return(
body: {
'creditor_bank_accounts' => {

'bank_name' => 'bank_name-input',
'icon_url' => 'icon_url-input',
'invalid_reasons' => 'invalid_reasons-input',
'is_valid' => 'is_valid-input'
}
}.to_json,
headers: response_headers
)
end
end
end
end
17 changes: 17 additions & 0 deletions spec/resources/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
end
Expand All @@ -51,6 +52,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}
Expand All @@ -74,6 +76,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}

Expand Down Expand Up @@ -130,6 +133,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
end
Expand Down Expand Up @@ -176,6 +180,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down Expand Up @@ -213,6 +218,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}],
meta: {
Expand Down Expand Up @@ -253,6 +259,8 @@

expect(get_list_response.records.first.retry_if_possible).to eq('retry_if_possible-input')

expect(get_list_response.records.first.scheme).to eq('scheme-input')

expect(get_list_response.records.first.status).to eq('status-input')
end

Expand Down Expand Up @@ -284,6 +292,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}],
meta: {
Expand Down Expand Up @@ -313,6 +322,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}],
meta: {
Expand Down Expand Up @@ -358,6 +368,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down Expand Up @@ -397,6 +408,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down Expand Up @@ -458,6 +470,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down Expand Up @@ -497,6 +510,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down Expand Up @@ -542,6 +556,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down Expand Up @@ -576,6 +591,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down Expand Up @@ -621,6 +637,7 @@
'metadata' => 'metadata-input',
'reference' => 'reference-input',
'retry_if_possible' => 'retry_if_possible-input',
'scheme' => 'scheme-input',
'status' => 'status-input'
}
}.to_json,
Expand Down
Loading
Loading