diff --git a/Gemfile b/Gemfile index df630a9..851fabc 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/lib/gocardless_pro/resources/creditor_bank_account_validate.rb b/lib/gocardless_pro/resources/creditor_bank_account_validate.rb new file mode 100644 index 0000000..243a361 --- /dev/null +++ b/lib/gocardless_pro/resources/creditor_bank_account_validate.rb @@ -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. + # + #

Restricted: This API is not + # available for partner integrations.

+ 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 diff --git a/lib/gocardless_pro/resources/event.rb b/lib/gocardless_pro/resources/event.rb index fb543c6..fb556b3 100644 --- a/lib/gocardless_pro/resources/event.rb +++ b/lib/gocardless_pro/resources/event.rb @@ -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 diff --git a/lib/gocardless_pro/resources/payment.rb b/lib/gocardless_pro/resources/payment.rb index 56a82cd..2cf595d 100644 --- a/lib/gocardless_pro/resources/payment.rb +++ b/lib/gocardless_pro/resources/payment.rb @@ -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 @@ -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 diff --git a/lib/gocardless_pro/services/creditor_bank_account_validates_service.rb b/lib/gocardless_pro/services/creditor_bank_account_validates_service.rb new file mode 100644 index 0000000..4604fe1 --- /dev/null +++ b/lib/gocardless_pro/services/creditor_bank_account_validates_service.rb @@ -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 diff --git a/lib/gocardless_pro/services/scenario_simulators_service.rb b/lib/gocardless_pro/services/scenario_simulators_service.rb index 0b7e946..abe9802 100644 --- a/lib/gocardless_pro/services/scenario_simulators_service.rb +++ b/lib/gocardless_pro/services/scenario_simulators_service.rb @@ -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. + #
  • `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.
  • #
  • `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 diff --git a/spec/resources/creditor_bank_account_validate_spec.rb b/spec/resources/creditor_bank_account_validate_spec.rb new file mode 100644 index 0000000..f5f6be8 --- /dev/null +++ b/spec/resources/creditor_bank_account_validate_spec.rb @@ -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 diff --git a/spec/resources/payment_spec.rb b/spec/resources/payment_spec.rb index 4dbdfac..c005c17 100644 --- a/spec/resources/payment_spec.rb +++ b/spec/resources/payment_spec.rb @@ -28,6 +28,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } end @@ -51,6 +52,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } } @@ -74,6 +76,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } @@ -130,6 +133,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } end @@ -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, @@ -213,6 +218,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -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 @@ -284,6 +292,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -313,6 +322,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/spec/services/creditor_bank_account_validates_service_spec.rb b/spec/services/creditor_bank_account_validates_service_spec.rb new file mode 100644 index 0000000..4dff1b5 --- /dev/null +++ b/spec/services/creditor_bank_account_validates_service_spec.rb @@ -0,0 +1,79 @@ +require 'spec_helper' + +describe GoCardlessPro::Services::CreditorBankAccountValidatesService 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 + + describe 'retry behaviour' do + it "doesn't retry errors" do + stub_url = '/creditor_bank_accounts/validate'.gsub(':identity', resource_id) + stub = stub_request(:post, /.*api.gocardless.com#{stub_url}/) + .to_timeout + + expect { post_response }.to raise_error(Faraday::ConnectionFailed) + expect(stub).to have_been_requested + end + 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 diff --git a/spec/services/payments_service_spec.rb b/spec/services/payments_service_spec.rb index c0a6908..689852c 100644 --- a/spec/services/payments_service_spec.rb +++ b/spec/services/payments_service_spec.rb @@ -28,6 +28,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } end @@ -51,6 +52,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } } @@ -74,6 +76,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } @@ -153,6 +156,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } end @@ -199,6 +203,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, @@ -251,6 +256,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -296,6 +302,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 @@ -350,6 +358,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -379,6 +388,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -417,6 +427,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -446,6 +457,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -480,6 +492,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -512,6 +525,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' }], meta: { @@ -557,6 +571,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, @@ -596,6 +611,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, @@ -712,6 +728,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, @@ -776,6 +793,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, @@ -832,6 +850,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, @@ -866,6 +885,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, @@ -922,6 +942,7 @@ 'metadata' => 'metadata-input', 'reference' => 'reference-input', 'retry_if_possible' => 'retry_if_possible-input', + 'scheme' => 'scheme-input', 'status' => 'status-input' } }.to_json, diff --git a/tmp-push-files-checkout b/tmp-push-files-checkout new file mode 160000 index 0000000..d7e823b --- /dev/null +++ b/tmp-push-files-checkout @@ -0,0 +1 @@ +Subproject commit d7e823b84342f016df7c023bc9b82aa99b2e502a