Skip to content

Commit

Permalink
Template changes (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
gc-robot-readwrite-sso and gocardless-robot authored Nov 22, 2023
1 parent 6c185c8 commit e0157e1
Show file tree
Hide file tree
Showing 12 changed files with 302 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/gocardless_pro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ module GoCardlessPro
require_relative 'gocardless_pro/resources/tax_rate'
require_relative 'gocardless_pro/services/tax_rates_service'

require_relative 'gocardless_pro/resources/transferred_mandate'
require_relative 'gocardless_pro/services/transferred_mandates_service'

require_relative 'gocardless_pro/resources/verification_detail'
require_relative 'gocardless_pro/services/verification_details_service'

Expand Down
7 changes: 6 additions & 1 deletion lib/gocardless_pro/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ def tax_rates
@tax_rates ||= Services::TaxRatesService.new(@api_service)
end

# Access to the service for transferred_mandate to make API calls
def transferred_mandates
@transferred_mandates ||= Services::TransferredMandatesService.new(@api_service)
end

# Access to the service for verification_detail to make API calls
def verification_details
@verification_details ||= Services::VerificationDetailsService.new(@api_service)
Expand Down Expand Up @@ -213,7 +218,7 @@ def default_options
'User-Agent' => "#{user_agent}",
'Content-Type' => 'application/json',
'GoCardless-Client-Library' => 'gocardless-pro-ruby',
'GoCardless-Client-Version' => '2.50.0',
'GoCardless-Client-Version' => '2.51.0',
},
}
end
Expand Down
2 changes: 2 additions & 0 deletions lib/gocardless_pro/resources/billing_request_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class BillingRequestFlow
attr_reader :authorisation_url
attr_reader :auto_fulfil
attr_reader :created_at
attr_reader :customer_details_captured
attr_reader :exit_uri
attr_reader :expires_at
attr_reader :id
Expand All @@ -39,6 +40,7 @@ def initialize(object, response = nil)
@authorisation_url = object['authorisation_url']
@auto_fulfil = object['auto_fulfil']
@created_at = object['created_at']
@customer_details_captured = object['customer_details_captured']
@exit_uri = object['exit_uri']
@expires_at = object['expires_at']
@id = object['id']
Expand Down
16 changes: 15 additions & 1 deletion lib/gocardless_pro/resources/billing_request_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ module GoCardlessPro
module Resources
# Represents an instance of a billing_request_template resource returned from the API

# Billing Request Templates
# Billing Request Templates are reusable templates that result in
# numerous Billing Requests with similar attributes. They provide
# a no-code solution for generating various types of multi-user payment
# links.
#
# Each template includes a reusable URL that can be embedded in a website
# or shared with customers via email. Every time the URL is opened,
# it generates a new Billing Request.
#
# Billing Request Templates overcome the key limitation of the Billing
# Request:
# a Billing Request cannot be shared among multiple users because it is
# intended
# for single-use and is designed to cater to the unique needs of individual
# customers.
class BillingRequestTemplate
attr_reader :authorisation_url
attr_reader :created_at
Expand Down
60 changes: 60 additions & 0 deletions lib/gocardless_pro/resources/transferred_mandate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# 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 transferred_mandate resource returned from the API

# Mandates that have been transferred using Current Account Switch Service
class TransferredMandate
attr_reader :encrypted_data
attr_reader :key
attr_reader :kid

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

@encrypted_data = object['encrypted_data']
@key = object['key']
@kid = object['kid']
@links = object['links']
@response = response
end

def api_response
ApiResponse.new(@response)
end

# Return the links that the resource has
def links
@transferred_mandate_links ||= Links.new(@links)
end

# Provides the transferred_mandate resource as a hash of all its readable attributes
def to_h
@object
end

class Links
def initialize(links)
@links = links || {}
end

def customer_bank_account
@links['customer_bank_account']
end

def mandate
@links['mandate']
end
end
end
end
end
4 changes: 4 additions & 0 deletions lib/gocardless_pro/services/billing_requests_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ def collect_customer_details(identity, options = {})
# the bank account is valid for the billing request scheme before creating
# and attaching it.
#
# If the scheme is PayTo and the pay_id is available, this can be included in
# the payload along with the
# country_code.
#
# _ACH scheme_ For compliance reasons, an extra validation step is done using
# a third-party provider to make sure the customer's bank account can accept
# Direct Debit. If a bank account is discovered to be closed or invalid, the
Expand Down
48 changes: 48 additions & 0 deletions lib/gocardless_pro/services/transferred_mandates_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 TransferredMandate endpoints
class TransferredMandatesService < BaseService
# Returns encrypted bank details for the transferred mandate
# Example URL: /transferred_mandate/:identity
#
# @param identity # Unique identifier, beginning with "MD". Note that this prefix may not
# apply to mandates created before 2016.
# @param options [Hash] parameters as a hash, under a params key.
def transferred_mandates(identity, options = {})
path = sub_url('/transferred_mandate/:identity', {
'identity' => identity,
})

options[:retry_failures] = false

response = make_request(:get, path, options)

return if response.body.nil?

Resources::TransferredMandate.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
'transferred_mandate'
end
end
end
end
2 changes: 1 addition & 1 deletion lib/gocardless_pro/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module GoCardlessPro

module GoCardlessPro
# Current version of the GC gem
VERSION = '2.50.0'
VERSION = '2.51.0'
end
6 changes: 6 additions & 0 deletions spec/resources/billing_request_flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand All @@ -44,6 +45,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand All @@ -70,6 +72,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down Expand Up @@ -129,6 +132,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down Expand Up @@ -190,6 +194,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down Expand Up @@ -238,6 +243,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down
70 changes: 70 additions & 0 deletions spec/resources/transferred_mandate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'spec_helper'

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

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

describe '#transferred_mandates' do
subject(:get_response) { client.transferred_mandates.transferred_mandates(resource_id) }

let(:resource_id) { 'ABC123' }

let!(:stub) do
# /transferred_mandate/%v
stub_url = '/transferred_mandate/:identity'.gsub(':identity', resource_id)
stub_request(:get, /.*api.gocardless.com#{stub_url}/).to_return(
body: {
'transferred_mandate' => {

'encrypted_data' => 'encrypted_data-input',
'key' => 'key-input',
'kid' => 'kid-input',
'links' => 'links-input',
},
}.to_json,

headers: response_headers
)
end

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

expect(stub).to have_been_requested
end

context 'when the request needs a body and custom header' do
let(:body) { { foo: 'bar' } }
let(:headers) { { 'Foo' => 'Bar' } }
subject(:get_response) { client.transferred_mandates.transferred_mandates(resource_id, body, headers) }

let(:resource_id) { 'ABC123' }

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

'encrypted_data' => 'encrypted_data-input',
'key' => 'key-input',
'kid' => 'kid-input',
'links' => 'links-input',
},
}.to_json,
headers: response_headers
)
end
end
end
end
6 changes: 6 additions & 0 deletions spec/services/billing_request_flows_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand All @@ -44,6 +45,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand All @@ -70,6 +72,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down Expand Up @@ -152,6 +155,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down Expand Up @@ -213,6 +217,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down Expand Up @@ -272,6 +277,7 @@
'authorisation_url' => 'authorisation_url-input',
'auto_fulfil' => 'auto_fulfil-input',
'created_at' => 'created_at-input',
'customer_details_captured' => 'customer_details_captured-input',
'exit_uri' => 'exit_uri-input',
'expires_at' => 'expires_at-input',
'id' => 'id-input',
Expand Down
Loading

0 comments on commit e0157e1

Please sign in to comment.