gocardless_pro 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gocardless_pro.rb +3 -0
  3. data/lib/gocardless_pro/client.rb +6 -1
  4. data/lib/gocardless_pro/resources/bank_details_lookup.rb +1 -1
  5. data/lib/gocardless_pro/resources/creditor.rb +3 -4
  6. data/lib/gocardless_pro/resources/creditor_bank_account.rb +5 -6
  7. data/lib/gocardless_pro/resources/customer.rb +0 -1
  8. data/lib/gocardless_pro/resources/customer_bank_account.rb +5 -6
  9. data/lib/gocardless_pro/resources/mandate.rb +2 -3
  10. data/lib/gocardless_pro/resources/payment.rb +2 -3
  11. data/lib/gocardless_pro/resources/payout_item.rb +81 -0
  12. data/lib/gocardless_pro/resources/redirect_flow.rb +16 -21
  13. data/lib/gocardless_pro/resources/refund.rb +3 -3
  14. data/lib/gocardless_pro/resources/subscription.rb +34 -50
  15. data/lib/gocardless_pro/services/bank_details_lookups_service.rb +14 -10
  16. data/lib/gocardless_pro/services/creditor_bank_accounts_service.rb +4 -4
  17. data/lib/gocardless_pro/services/customer_bank_accounts_service.rb +6 -10
  18. data/lib/gocardless_pro/services/mandate_pdfs_service.rb +3 -4
  19. data/lib/gocardless_pro/services/mandates_service.rb +2 -3
  20. data/lib/gocardless_pro/services/payments_service.rb +5 -8
  21. data/lib/gocardless_pro/services/payout_items_service.rb +68 -0
  22. data/lib/gocardless_pro/services/redirect_flows_service.rb +5 -6
  23. data/lib/gocardless_pro/services/refunds_service.rb +8 -11
  24. data/lib/gocardless_pro/services/subscriptions_service.rb +18 -2
  25. data/lib/gocardless_pro/version.rb +1 -1
  26. data/spec/resources/payout_item_spec.rb +96 -0
  27. data/spec/services/payout_items_service_spec.rb +212 -0
  28. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8695d142ee02b15a42c2ddbd7565ce06a067fa8f
4
- data.tar.gz: 4c0927aad319de86206bdcc71952a47e4a0f1c88
3
+ metadata.gz: eb3944b3517a68c3d3a825fdd00ebd3e9951c130
4
+ data.tar.gz: 24cab2d00dc28ceda2fdaa2d9e0c10d71c57ab09
5
5
  SHA512:
6
- metadata.gz: 91d51533cc01b11109feaba8810bd9b63bd84dc3f4b9fa083d180cac83961acb27026f448c10f32eeb08505745140f9fec010c42cc99762651218f856c85f67c
7
- data.tar.gz: 000cec55d848d73509a7bcb60e398036fafb41417c183440d5563c8eee312ab0e076dc728c435e1a387f30c2e473fb6c492dc6bf83ca7b6ee4192cc40d7c18ca
6
+ metadata.gz: 8e6c180d2bf3d244a3f99c8f767852e7af34626aa09721a79a7c087e62cf1fdfef58efb3e5bef3f55b1077c140bbb1395f8917ec999e57dcfe95ce72994cac71
7
+ data.tar.gz: 3111e978bff8ffc020f35696f02ed12d418ca43bf1b38b87c9271cc1e0eb74071f73228bf65c4b48b5ccb44e51ebd9cd944c99352e715b4301d08fd898ef241d
@@ -67,6 +67,9 @@ require_relative 'gocardless_pro/services/payments_service'
67
67
  require_relative 'gocardless_pro/resources/payout'
68
68
  require_relative 'gocardless_pro/services/payouts_service'
69
69
 
70
+ require_relative 'gocardless_pro/resources/payout_item'
71
+ require_relative 'gocardless_pro/services/payout_items_service'
72
+
70
73
  require_relative 'gocardless_pro/resources/redirect_flow'
71
74
  require_relative 'gocardless_pro/services/redirect_flows_service'
72
75
 
@@ -53,6 +53,11 @@ module GoCardlessPro
53
53
  @payouts ||= Services::PayoutsService.new(@api_service)
54
54
  end
55
55
 
56
+ # Access to the service for payout_item to make API calls
57
+ def payout_items
58
+ @payout_items ||= Services::PayoutItemsService.new(@api_service)
59
+ end
60
+
56
61
  # Access to the service for redirect_flow to make API calls
57
62
  def redirect_flows
58
63
  @redirect_flows ||= Services::RedirectFlowsService.new(@api_service)
@@ -118,7 +123,7 @@ module GoCardlessPro
118
123
  'User-Agent' => user_agent.to_s,
119
124
  'Content-Type' => 'application/json',
120
125
  'GoCardless-Client-Library' => 'gocardless-pro-ruby',
121
- 'GoCardless-Client-Version' => '2.3.0',
126
+ 'GoCardless-Client-Version' => '2.4.0',
122
127
  },
123
128
  }
124
129
  end
@@ -12,7 +12,7 @@ module GoCardlessPro
12
12
  module Resources
13
13
  # Represents an instance of a bank_details_lookup resource returned from the API
14
14
 
15
- # Look up the name and reachability of a bank.
15
+ # Look up the name and reachability of a bank account.
16
16
  class BankDetailsLookup
17
17
  attr_reader :available_debit_schemes
18
18
  attr_reader :bank_name
@@ -17,10 +17,9 @@ module GoCardlessPro
17
17
  # organisation will have a single "creditor", but the API also supports
18
18
  # collecting payments on behalf of others.
19
19
  #
20
- # Please get in touch
21
- # if you wish to use this endpoint. Currently, for Anti Money Laundering
22
- # reasons, any creditors you add must be directly related to your
23
- # organisation.
20
+ # Please get in touch if you wish to use this endpoint. Currently, for Anti
21
+ # Money Laundering reasons, any creditors you add must be directly related
22
+ # to your organisation.
24
23
  class Creditor
25
24
  attr_reader :address_line1
26
25
  attr_reader :address_line2
@@ -16,12 +16,11 @@ module GoCardlessPro
16
16
  # [creditor](#core-endpoints-creditors). These are the bank accounts which
17
17
  # your [payouts](#core-endpoints-payouts) will be sent to.
18
18
  #
19
- # Note
20
- # that creditor bank accounts must be unique, and so you will encounter a
21
- # `bank_account_exists` error if you try to create a duplicate bank account.
22
- # You may wish to handle this by updating the existing record instead, the
23
- # ID of which will be provided as `links[creditor_bank_account]` in the
24
- # error response.
19
+ # Note that creditor bank accounts must be unique, and so you will encounter
20
+ # a `bank_account_exists` error if you try to create a duplicate bank
21
+ # account. You may wish to handle this by updating the existing record
22
+ # instead, the ID of which will be provided as
23
+ # `links[creditor_bank_account]` in the error response.
25
24
  class CreditorBankAccount
26
25
  attr_reader :account_holder_name
27
26
  attr_reader :account_number_ending
@@ -17,7 +17,6 @@ module GoCardlessPro
17
17
  # accounts](#core-endpoints-customer-bank-accounts), which in turn can have
18
18
  # several Direct Debit [mandates](#core-endpoints-mandates).
19
19
  #
20
- #
21
20
  # Note: the `swedish_identity_number` field may only be supplied for Swedish
22
21
  # customers, and must be supplied if you intend to set up an Autogiro
23
22
  # mandate with the customer.
@@ -17,12 +17,11 @@ module GoCardlessPro
17
17
  # [customer](#core-endpoints-customers), and may be linked to several Direct
18
18
  # Debit [mandates](#core-endpoints-mandates).
19
19
  #
20
- # Note that
21
- # customer bank accounts must be unique, and so you will encounter a
22
- # `bank_account_exists` error if you try to create a duplicate bank account.
23
- # You may wish to handle this by updating the existing record instead, the
24
- # ID of which will be provided as `links[customer_bank_account]` in the
25
- # error response.
20
+ # Note that customer bank accounts must be unique, and so you will encounter
21
+ # a `bank_account_exists` error if you try to create a duplicate bank
22
+ # account. You may wish to handle this by updating the existing record
23
+ # instead, the ID of which will be provided as
24
+ # `links[customer_bank_account]` in the error response.
26
25
  class CustomerBankAccount
27
26
  attr_reader :account_holder_name
28
27
  attr_reader :account_number_ending
@@ -15,9 +15,8 @@ module GoCardlessPro
15
15
  # Mandates represent the Direct Debit mandate with a
16
16
  # [customer](#core-endpoints-customers).
17
17
  #
18
- # GoCardless will notify
19
- # you via a [webhook](#appendix-webhooks) whenever the status of a mandate
20
- # changes.
18
+ # GoCardless will notify you via a [webhook](#appendix-webhooks) whenever
19
+ # the status of a mandate changes.
21
20
  class Mandate
22
21
  attr_reader :created_at
23
22
  attr_reader :id
@@ -17,9 +17,8 @@ module GoCardlessPro
17
17
  # [creditor](#core-endpoints-creditors), taken against a Direct Debit
18
18
  # [mandate](#core-endpoints-mandates).
19
19
  #
20
- # GoCardless will notify
21
- # you via a [webhook](#appendix-webhooks) whenever the state of a payment
22
- # changes.
20
+ # GoCardless will notify you via a [webhook](#appendix-webhooks) whenever
21
+ # the state of a payment changes.
23
22
  class Payment
24
23
  attr_reader :amount
25
24
  attr_reader :amount_refunded
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+
3
+ #
4
+ # This client is automatically generated from a template and JSON schema definition.
5
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
6
+ #
7
+
8
+ require 'uri'
9
+
10
+ module GoCardlessPro
11
+ # A module containing classes for each of the resources in the GC Api
12
+ module Resources
13
+ # Represents an instance of a payout_item resource returned from the API
14
+
15
+ # When we collect a payment on your behalf, we add the money you've
16
+ # collected to your
17
+ # GoCardless balance, minus any fees paid. Periodically (usually every
18
+ # working day),
19
+ # we take any positive balance in your GoCardless account, and pay it out to
20
+ # your
21
+ # nominated bank account.
22
+ #
23
+ # Other actions in your GoCardless account can also affect your balance. For
24
+ # example,
25
+ # if a customer charges back a payment, we'll deduct the payment's amount
26
+ # from your
27
+ # balance, but add any fees you paid for that payment back to your balance.
28
+ #
29
+ # The Payout Items API allows you to view, on a per-payout basis, the credit
30
+ # and debit
31
+ # items that make up that payout's amount.
32
+ #
33
+ # <p class="beta-notice"><strong>Beta</strong>: The Payout Items API is in
34
+ # beta, and is
35
+ # subject to <a href="#overview-backwards-compatibility">backwards
36
+ # incompatible changes</a>
37
+ # with 30 days notice. Before making any breaking changes, we will contact
38
+ # all integrators
39
+ # who have used the API.</p>
40
+ #
41
+ class PayoutItem
42
+ attr_reader :amount
43
+ attr_reader :type
44
+
45
+ # Initialize a payout_item resource instance
46
+ # @param object [Hash] an object returned from the API
47
+ def initialize(object, response = nil)
48
+ @object = object
49
+
50
+ @amount = object['amount']
51
+ @links = object['links']
52
+ @type = object['type']
53
+ @response = response
54
+ end
55
+
56
+ def api_response
57
+ ApiResponse.new(@response)
58
+ end
59
+
60
+ # Return the links that the resource has
61
+ def links
62
+ @payout_item_links ||= Links.new(@links)
63
+ end
64
+
65
+ # Provides the payout_item resource as a hash of all its readable attributes
66
+ def to_h
67
+ @object
68
+ end
69
+
70
+ class Links
71
+ def initialize(links)
72
+ @links = links || {}
73
+ end
74
+
75
+ def payment
76
+ @links['payment']
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -20,35 +20,30 @@ module GoCardlessPro
20
20
  #
21
21
  # The overall flow is:
22
22
  #
23
- # 1. You
24
- # [create](#redirect-flows-create-a-redirect-flow) a redirect flow for your
25
- # customer, and redirect them to the returned redirect url, e.g.
23
+ # 1. You [create](#redirect-flows-create-a-redirect-flow) a redirect flow
24
+ # for your customer, and redirect them to the returned redirect url, e.g.
26
25
  # `https://pay.gocardless.com/flow/RE123`.
27
26
  #
28
- # 2. Your customer
29
- # supplies their name, email, address, and bank account details, and submits
30
- # the form. This securely stores their details, and redirects them back to
31
- # your `success_redirect_url` with `redirect_flow_id=RE123` in the
32
- # querystring.
27
+ # 2. Your customer supplies their name, email, address, and bank account
28
+ # details, and submits the form. This securely stores their details, and
29
+ # redirects them back to your `success_redirect_url` with
30
+ # `redirect_flow_id=RE123` in the querystring.
33
31
  #
34
- # 3. You
35
- # [complete](#redirect-flows-complete-a-redirect-flow) the redirect flow,
36
- # which creates a [customer](#core-endpoints-customers), [customer bank
37
- # account](#core-endpoints-customer-bank-accounts), and
32
+ # 3. You [complete](#redirect-flows-complete-a-redirect-flow) the redirect
33
+ # flow, which creates a [customer](#core-endpoints-customers), [customer
34
+ # bank account](#core-endpoints-customer-bank-accounts), and
38
35
  # [mandate](#core-endpoints-mandates), and returns the ID of the mandate.
39
36
  # You may wish to create a [subscription](#core-endpoints-subscriptions) or
40
37
  # [payment](#core-endpoints-payments) at this point.
41
38
  #
42
- # Once you
43
- # have [completed](#redirect-flows-complete-a-redirect-flow) the redirect
44
- # flow via the API, you should display a confirmation page to your customer,
45
- # confirming that their Direct Debit has been set up. You can build your own
46
- # page, or redirect to the one we provide in the `confirmation_url`
47
- # attribute of the redirect flow.
39
+ # Once you have [completed](#redirect-flows-complete-a-redirect-flow) the
40
+ # redirect flow via the API, you should display a confirmation page to your
41
+ # customer, confirming that their Direct Debit has been set up. You can
42
+ # build your own page, or redirect to the one we provide in the
43
+ # `confirmation_url` attribute of the redirect flow.
48
44
  #
49
- # Redirect flows expire 30
50
- # minutes after they are first created. You cannot complete an expired
51
- # redirect flow.
45
+ # Redirect flows expire 30 minutes after they are first created. You cannot
46
+ # complete an expired redirect flow.
52
47
  class RedirectFlow
53
48
  attr_reader :confirmation_url
54
49
  attr_reader :created_at
@@ -16,9 +16,9 @@ module GoCardlessPro
16
16
  # [payment](#core-endpoints-payments) back to the
17
17
  # [customer](#core-endpoints-customers).
18
18
  #
19
- # GoCardless will notify
20
- # you via a [webhook](#appendix-webhooks) whenever a refund is created, and
21
- # will update the `amount_refunded` property of the payment.
19
+ # GoCardless will notify you via a [webhook](#appendix-webhooks) whenever a
20
+ # refund is created, and will update the `amount_refunded` property of the
21
+ # payment.
22
22
  class Refund
23
23
  attr_reader :amount
24
24
  attr_reader :created_at
@@ -17,70 +17,54 @@ module GoCardlessPro
17
17
  #
18
18
  # ### Recurrence Rules
19
19
  #
20
- # The following
21
- # rules apply when specifying recurrence:
20
+ # The following rules apply when specifying recurrence:
22
21
  #
23
- # - The first payment
24
- # must be charged within 1 year.
25
- # - When neither `month` nor
26
- # `day_of_month` are present, the subscription will recur from the
27
- # `start_date` based on the `interval_unit`.
28
- # - If `month` or
29
- # `day_of_month` are present, the recurrence rules will be applied from the
30
- # `start_date`, and the following validations apply:
22
+ # - The first payment must be charged within 1 year.
23
+ # - When neither `month` nor `day_of_month` are present, the subscription
24
+ # will recur from the `start_date` based on the `interval_unit`.
25
+ # - If `month` or `day_of_month` are present, the recurrence rules will be
26
+ # applied from the `start_date`, and the following validations apply:
31
27
  #
32
- # |
33
- # interval_unit | month |
28
+ # | interval_unit | month |
34
29
  # day_of_month |
35
- # | :-------------- |
36
- # :--------------------------------------------- |
30
+ # | :-------------- | :--------------------------------------------- |
37
31
  # :-------------------------------------- |
38
- # | yearly |
39
- # optional (required if `day_of_month` provided) | optional (required if
40
- # `month` provided) |
41
- # | monthly | invalid
42
- # | required |
43
- # |
44
- # weekly | invalid | invalid
45
- # |
32
+ # | yearly | optional (required if `day_of_month` provided) |
33
+ # optional (required if `month` provided) |
34
+ # | monthly | invalid |
35
+ # required |
36
+ # | weekly | invalid |
37
+ # invalid |
46
38
  #
47
39
  # Examples:
48
40
  #
49
- # |
50
- # interval_unit | interval | month | day_of_month | valid?
51
- # |
52
- # | :-------------- | :--------- |
53
- # :------ | :------------- |
41
+ # | interval_unit | interval | month | day_of_month | valid?
42
+ # |
43
+ # | :-------------- | :--------- | :------ | :------------- |
54
44
  # :------------------------------------------------- |
55
- # | yearly
56
- # | 1 | january | -1 | valid
57
- # |
58
- # | yearly | 1 | march |
59
- # | invalid - missing `day_of_month` |
60
- # |
61
- # monthly | 6 | | 12 | valid
62
- # |
63
- # | monthly | 6 |
64
- # august | 12 | invalid - `month` must be blank
65
- # |
66
- # | weekly | 2 | | |
67
- # valid |
68
- # | weekly
69
- # | 2 | october | 10 | invalid - `month` and
70
- # `day_of_month` must be blank |
45
+ # | yearly | 1 | january | -1 | valid
46
+ # |
47
+ # | yearly | 1 | march | | invalid -
48
+ # missing `day_of_month` |
49
+ # | monthly | 6 | | 12 | valid
50
+ # |
51
+ # | monthly | 6 | august | 12 | invalid -
52
+ # `month` must be blank |
53
+ # | weekly | 2 | | | valid
54
+ # |
55
+ # | weekly | 2 | october | 10 | invalid -
56
+ # `month` and `day_of_month` must be blank |
71
57
  #
72
58
  # ### Rolling dates
73
59
  #
74
- #
75
60
  # When a charge date falls on a non-business day, one of two things will
76
61
  # happen:
77
62
  #
78
- # - if the recurrence rule specified `-1` as the
79
- # `day_of_month`, the charge date will be rolled __backwards__ to the
80
- # previous business day (i.e., the last working day of the month).
81
- # -
82
- # otherwise the charge date will be rolled __forwards__ to the next business
83
- # day.
63
+ # - if the recurrence rule specified `-1` as the `day_of_month`, the charge
64
+ # date will be rolled __backwards__ to the previous business day (i.e., the
65
+ # last working day of the month).
66
+ # - otherwise the charge date will be rolled __forwards__ to the next
67
+ # business day.
84
68
  #
85
69
  class Subscription
86
70
  attr_reader :amount
@@ -11,19 +11,23 @@ module GoCardlessPro
11
11
  module Services
12
12
  # Service for making requests to the BankDetailsLookup endpoints
13
13
  class BankDetailsLookupsService < BaseService
14
- # Performs a bank details lookup.
15
- #
16
- # As part of the lookup a modulus check and
14
+ # Performs a bank details lookup. As part of the lookup, a modulus check and
17
15
  # reachability check are performed.
18
16
  #
19
- # Bank account details may be supplied
20
- # using [local details](#appendix-local-bank-details) or an IBAN.
17
+ # If your request returns an [error](#api-usage-errors) or the
18
+ # `available_debit_schemes`
19
+ # attribute is an empty array, you will not be able to collect payments from the
20
+ # specified bank account. GoCardless may be able to collect payments from an
21
+ # account
22
+ # even if no `bic` is returned.
23
+ #
24
+ # Bank account details may be supplied using [local
25
+ # details](#appendix-local-bank-details) or an IBAN.
21
26
  #
22
- # _Note:_
23
- # Usage of this endpoint is monitored. If your organisation relies on GoCardless
24
- # for
25
- # modulus or reachability checking but not for payment collection, please
26
- # get in touch.
27
+ # _Note:_ Usage of this endpoint is monitored. If your organisation relies on
28
+ # GoCardless for
29
+ # modulus or reachability checking but not for payment collection, please get in
30
+ # touch.
27
31
  # Example URL: /bank_details_lookups
28
32
  # @param options [Hash] parameters as a hash, under a params key.
29
33
  def create(options = {})
@@ -88,11 +88,11 @@ module GoCardlessPro
88
88
  # Immediately disables the bank account, no money can be paid out to a disabled
89
89
  # account.
90
90
  #
91
- # This will return a `disable_failed` error if the bank account
92
- # has already been disabled.
91
+ # This will return a `disable_failed` error if the bank account has already been
92
+ # disabled.
93
93
  #
94
- # A disabled bank account can be re-enabled by
95
- # creating a new bank account resource with the same details.
94
+ # A disabled bank account can be re-enabled by creating a new bank account
95
+ # resource with the same details.
96
96
  # Example URL: /creditor_bank_accounts/:identity/actions/disable
97
97
  #
98
98
  # @param identity # Unique identifier, beginning with "BA".
@@ -13,17 +13,14 @@ module GoCardlessPro
13
13
  class CustomerBankAccountsService < BaseService
14
14
  # Creates a new customer bank account object.
15
15
  #
16
- # There are three different
17
- # ways to supply bank account details:
16
+ # There are three different ways to supply bank account details:
18
17
  #
19
- # - [Local
20
- # details](#appendix-local-bank-details)
18
+ # - [Local details](#appendix-local-bank-details)
21
19
  #
22
20
  # - IBAN
23
21
  #
24
- # - [Customer Bank
25
- # Account Tokens](#javascript-flow-create-a-customer-bank-account-token)
26
- #
22
+ # - [Customer Bank Account
23
+ # Tokens](#javascript-flow-create-a-customer-bank-account-token)
27
24
  #
28
25
  # For more information on the different fields required in each country, see
29
26
  # [local bank details](#appendix-local-bank-details).
@@ -124,12 +121,11 @@ module GoCardlessPro
124
121
 
125
122
  # Immediately cancels all associated mandates and cancellable payments.
126
123
  #
127
- #
128
124
  # This will return a `disable_failed` error if the bank account has already been
129
125
  # disabled.
130
126
  #
131
- # A disabled bank account can be re-enabled by creating a new
132
- # bank account resource with the same details.
127
+ # A disabled bank account can be re-enabled by creating a new bank account
128
+ # resource with the same details.
133
129
  # Example URL: /customer_bank_accounts/:identity/actions/disable
134
130
  #
135
131
  # @param identity # Unique identifier, beginning with "BA".
@@ -13,10 +13,9 @@ module GoCardlessPro
13
13
  class MandatePdfsService < BaseService
14
14
  # Generates a PDF mandate and returns its temporary URL.
15
15
  #
16
- # Customer and bank
17
- # account details can be left blank (for a blank mandate), provided manually, or
18
- # inferred from the ID of an existing [mandate](#core-endpoints-mandates).
19
- #
16
+ # Customer and bank account details can be left blank (for a blank mandate),
17
+ # provided manually, or inferred from the ID of an existing
18
+ # [mandate](#core-endpoints-mandates).
20
19
  #
21
20
  # To generate a PDF mandate in a foreign language, set your `Accept-Language`
22
21
  # header to the relevant [ISO
@@ -110,8 +110,8 @@ module GoCardlessPro
110
110
  # metadata supplied to this endpoint will be stored on the mandate cancellation
111
111
  # event it causes.
112
112
  #
113
- # This will fail with a `cancellation_failed` error if the
114
- # mandate is already cancelled.
113
+ # This will fail with a `cancellation_failed` error if the mandate is already
114
+ # cancelled.
115
115
  # Example URL: /mandates/:identity/actions/cancel
116
116
  #
117
117
  # @param identity # Unique identifier, beginning with "MD".
@@ -148,7 +148,6 @@ module GoCardlessPro
148
148
  # `failed` webhook up to two working days later. Any metadata supplied to this
149
149
  # endpoint will be stored on the `resubmission_requested` event it causes.
150
150
  #
151
- #
152
151
  # This will fail with a `mandate_not_inactive` error if the mandate is already
153
152
  # being submitted, or is active.
154
153
  #
@@ -13,8 +13,7 @@ module GoCardlessPro
13
13
  class PaymentsService < BaseService
14
14
  # <a name="mandate_is_inactive"></a>Creates a new payment object.
15
15
  #
16
- # This
17
- # fails with a `mandate_is_inactive` error if the linked
16
+ # This fails with a `mandate_is_inactive` error if the linked
18
17
  # [mandate](#core-endpoints-mandates) is cancelled or has failed. Payments can
19
18
  # be created against mandates with status of: `pending_customer_approval`,
20
19
  # `pending_submission`, `submitted`, and `active`.
@@ -116,8 +115,8 @@ module GoCardlessPro
116
115
  # metadata supplied to this endpoint will be stored on the payment cancellation
117
116
  # event it causes.
118
117
  #
119
- # This will fail with a `cancellation_failed` error unless
120
- # the payment's status is `pending_submission`.
118
+ # This will fail with a `cancellation_failed` error unless the payment's status
119
+ # is `pending_submission`.
121
120
  # Example URL: /payments/:identity/actions/cancel
122
121
  #
123
122
  # @param identity # Unique identifier, beginning with "PM".
@@ -154,11 +153,9 @@ module GoCardlessPro
154
153
  # event. Any metadata supplied to this endpoint will be stored against the
155
154
  # payment submission event it causes.
156
155
  #
157
- # This will return a `retry_failed`
158
- # error if the payment has not failed.
156
+ # This will return a `retry_failed` error if the payment has not failed.
159
157
  #
160
- # Payments can be retried up to 3
161
- # times.
158
+ # Payments can be retried up to 3 times.
162
159
  # Example URL: /payments/:identity/actions/retry
163
160
  #
164
161
  # @param identity # Unique identifier, beginning with "PM".
@@ -0,0 +1,68 @@
1
+ require_relative './base_service'
2
+ require 'uri'
3
+
4
+ # encoding: utf-8
5
+ #
6
+ # This client is automatically generated from a template and JSON schema definition.
7
+ # See https://github.com/gocardless/gocardless-pro-ruby#contributing before editing.
8
+ #
9
+
10
+ module GoCardlessPro
11
+ module Services
12
+ # Service for making requests to the PayoutItem endpoints
13
+ class PayoutItemsService < BaseService
14
+ # Returns a [cursor-paginated](#api-usage-cursor-pagination) list of items in
15
+ # the payout.
16
+ #
17
+ # Example URL: /payout_items
18
+ # @param options [Hash] parameters as a hash, under a params key.
19
+ def list(options = {})
20
+ path = '/payout_items'
21
+
22
+ options[:retry_failures] = true
23
+
24
+ response = make_request(:get, path, options)
25
+
26
+ ListResponse.new(
27
+ response: response,
28
+ unenveloped_body: unenvelope_body(response.body),
29
+ resource_class: Resources::PayoutItem
30
+ )
31
+ end
32
+
33
+ # Get a lazily enumerated list of all the items returned. This is simmilar to the `list` method but will paginate for you automatically.
34
+ #
35
+ # @param options [Hash] parameters as a hash. If the request is a GET, these will be converted to query parameters.
36
+ # Otherwise they will be the body of the request.
37
+ def all(options = {})
38
+ Paginator.new(
39
+ service: self,
40
+ options: options
41
+ ).enumerator
42
+ end
43
+
44
+ private
45
+
46
+ # Unenvelope the response of the body using the service's `envelope_key`
47
+ #
48
+ # @param body [Hash]
49
+ def unenvelope_body(body)
50
+ body[envelope_key] || body['data']
51
+ end
52
+
53
+ # return the key which API responses will envelope data under
54
+ def envelope_key
55
+ 'payout_items'
56
+ end
57
+
58
+ # take a URL with placeholder params and substitute them out for the actual value
59
+ # @param url [String] the URL with placeholders in
60
+ # @param param_map [Hash] a hash of placeholders and their actual values (which will be escaped)
61
+ def sub_url(url, param_map)
62
+ param_map.reduce(url) do |new_url, (param, value)|
63
+ new_url.gsub(":#{param}", URI.escape(value))
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -62,12 +62,11 @@ module GoCardlessPro
62
62
  # [mandate](#core-endpoints-mandates) using the details supplied by your
63
63
  # customer and returns the ID of the created mandate.
64
64
  #
65
- # This will return a
66
- # `redirect_flow_incomplete` error if your customer has not yet been redirected
67
- # back to your site, and a `redirect_flow_already_completed` error if your
68
- # integration has already completed this flow. It will return a `bad_request`
69
- # error if the `session_token` differs to the one supplied when the redirect
70
- # flow was created.
65
+ # This will return a `redirect_flow_incomplete` error if your customer has not
66
+ # yet been redirected back to your site, and a `redirect_flow_already_completed`
67
+ # error if your integration has already completed this flow. It will return a
68
+ # `bad_request` error if the `session_token` differs to the one supplied when
69
+ # the redirect flow was created.
71
70
  # Example URL: /redirect_flows/:identity/actions/complete
72
71
  #
73
72
  # @param identity # Unique identifier, beginning with "RE".
@@ -13,22 +13,19 @@ module GoCardlessPro
13
13
  class RefundsService < BaseService
14
14
  # Creates a new refund object.
15
15
  #
16
- # This fails with:<a
17
- # name="refund_payment_invalid_state"></a><a
16
+ # This fails with:<a name="refund_payment_invalid_state"></a><a
18
17
  # name="total_amount_confirmation_invalid"></a><a
19
18
  # name="number_of_refunds_exceeded"></a>
20
19
  #
21
- # - `refund_payment_invalid_state`
22
- # error if the linked [payment](#core-endpoints-payments) isn't either
23
- # `confirmed` or `paid_out`.
20
+ # - `refund_payment_invalid_state` error if the linked
21
+ # [payment](#core-endpoints-payments) isn't either `confirmed` or `paid_out`.
24
22
  #
25
- # - `total_amount_confirmation_invalid` if the
26
- # confirmation amount doesn't match the total amount refunded for the payment.
27
- # This safeguard is there to prevent two processes from creating refunds without
28
- # awareness of each other.
23
+ # - `total_amount_confirmation_invalid` if the confirmation amount doesn't match
24
+ # the total amount refunded for the payment. This safeguard is there to prevent
25
+ # two processes from creating refunds without awareness of each other.
29
26
  #
30
- # - `number_of_refunds_exceeded` if five or more
31
- # refunds have already been created against the payment.
27
+ # - `number_of_refunds_exceeded` if five or more refunds have already been
28
+ # created against the payment.
32
29
  #
33
30
  # Example URL: /refunds
34
31
  # @param options [Hash] parameters as a hash, under a params key.
@@ -86,6 +86,22 @@ module GoCardlessPro
86
86
  end
87
87
 
88
88
  # Updates a subscription object.
89
+ #
90
+ # This fails with:
91
+ #
92
+ # - `validation_failed` if invalid data is provided when attempting to update a
93
+ # subscription.
94
+ #
95
+ # - `subscription_not_active` if the subscription is no longer active.
96
+ #
97
+ # - `subscription_already_ended` if the subscription has taken all payments.
98
+ #
99
+ # - `mandate_payments_require_approval` if the amount is being changed and the
100
+ # mandate requires approval.
101
+ #
102
+ # - `exceeded_max_amendments` error if the amount is being changed and the
103
+ # subscription amount has already been changed 10 times.
104
+ #
89
105
  # Example URL: /subscriptions/:identity
90
106
  #
91
107
  # @param identity # Unique identifier, beginning with "SB".
@@ -110,8 +126,8 @@ module GoCardlessPro
110
126
  # Any metadata supplied to this endpoint will be stored on the payment
111
127
  # cancellation event it causes.
112
128
  #
113
- # This will fail with a cancellation_failed
114
- # error if the subscription is already cancelled or finished.
129
+ # This will fail with a cancellation_failed error if the subscription is already
130
+ # cancelled or finished.
115
131
  # Example URL: /subscriptions/:identity/actions/cancel
116
132
  #
117
133
  # @param identity # Unique identifier, beginning with "SB".
@@ -4,5 +4,5 @@ end
4
4
 
5
5
  module GoCardlessPro
6
6
  # Current version of the GC gem
7
- VERSION = '2.3.0'.freeze
7
+ VERSION = '2.4.0'.freeze
8
8
  end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Resources::PayoutItem do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: 'SECRET_TOKEN'
7
+ )
8
+ end
9
+
10
+ let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
+
12
+ describe '#list' do
13
+ describe 'with no filters' do
14
+ subject(:get_list_response) { client.payout_items.list }
15
+
16
+ before do
17
+ stub_request(:get, %r{.*api.gocardless.com/payout_items}).to_return(
18
+ body: {
19
+ 'payout_items' => [{
20
+
21
+ 'amount' => 'amount-input',
22
+ 'links' => 'links-input',
23
+ 'type' => 'type-input',
24
+ }],
25
+ meta: {
26
+ cursors: {
27
+ before: nil,
28
+ after: 'ABC123',
29
+ },
30
+ },
31
+ }.to_json,
32
+ headers: response_headers
33
+ )
34
+ end
35
+
36
+ it 'wraps each item in the resource class' do
37
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::PayoutItem)
38
+
39
+ expect(get_list_response.records.first.amount).to eq('amount-input')
40
+
41
+ expect(get_list_response.records.first.type).to eq('type-input')
42
+ end
43
+
44
+ it 'exposes the cursors for before and after' do
45
+ expect(get_list_response.before).to eq(nil)
46
+ expect(get_list_response.after).to eq('ABC123')
47
+ end
48
+
49
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
50
+ end
51
+ end
52
+
53
+ describe '#all' do
54
+ let!(:first_response_stub) do
55
+ stub_request(:get, %r{.*api.gocardless.com/payout_items$}).to_return(
56
+ body: {
57
+ 'payout_items' => [{
58
+
59
+ 'amount' => 'amount-input',
60
+ 'links' => 'links-input',
61
+ 'type' => 'type-input',
62
+ }],
63
+ meta: {
64
+ cursors: { after: 'AB345' },
65
+ limit: 1,
66
+ },
67
+ }.to_json,
68
+ headers: response_headers
69
+ )
70
+ end
71
+
72
+ let!(:second_response_stub) do
73
+ stub_request(:get, %r{.*api.gocardless.com/payout_items\?after=AB345}).to_return(
74
+ body: {
75
+ 'payout_items' => [{
76
+
77
+ 'amount' => 'amount-input',
78
+ 'links' => 'links-input',
79
+ 'type' => 'type-input',
80
+ }],
81
+ meta: {
82
+ limit: 2,
83
+ cursors: {},
84
+ },
85
+ }.to_json,
86
+ headers: response_headers
87
+ )
88
+ end
89
+
90
+ it 'automatically makes the extra requests' do
91
+ expect(client.payout_items.all.to_a.length).to eq(2)
92
+ expect(first_response_stub).to have_been_requested
93
+ expect(second_response_stub).to have_been_requested
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,212 @@
1
+ require 'spec_helper'
2
+
3
+ describe GoCardlessPro::Services::PayoutItemsService do
4
+ let(:client) do
5
+ GoCardlessPro::Client.new(
6
+ access_token: 'SECRET_TOKEN'
7
+ )
8
+ end
9
+
10
+ let(:response_headers) { { 'Content-Type' => 'application/json' } }
11
+
12
+ describe '#list' do
13
+ describe 'with no filters' do
14
+ subject(:get_list_response) { client.payout_items.list }
15
+
16
+ let(:body) do
17
+ {
18
+ 'payout_items' => [{
19
+
20
+ 'amount' => 'amount-input',
21
+ 'links' => 'links-input',
22
+ 'type' => 'type-input',
23
+ }],
24
+ meta: {
25
+ cursors: {
26
+ before: nil,
27
+ after: 'ABC123',
28
+ },
29
+ },
30
+ }.to_json
31
+ end
32
+
33
+ before do
34
+ stub_request(:get, %r{.*api.gocardless.com/payout_items}).to_return(
35
+ body: body,
36
+ headers: response_headers
37
+ )
38
+ end
39
+
40
+ it 'wraps each item in the resource class' do
41
+ expect(get_list_response.records.map(&:class).uniq.first).to eq(GoCardlessPro::Resources::PayoutItem)
42
+
43
+ expect(get_list_response.records.first.amount).to eq('amount-input')
44
+
45
+ expect(get_list_response.records.first.type).to eq('type-input')
46
+ end
47
+
48
+ it 'exposes the cursors for before and after' do
49
+ expect(get_list_response.before).to eq(nil)
50
+ expect(get_list_response.after).to eq('ABC123')
51
+ end
52
+
53
+ specify { expect(get_list_response.api_response.headers).to eql('content-type' => 'application/json') }
54
+
55
+ describe 'retry behaviour' do
56
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
57
+
58
+ it 'retries timeouts' do
59
+ stub = stub_request(:get, %r{.*api.gocardless.com/payout_items}).
60
+ to_timeout.then.to_return(status: 200, headers: response_headers, body: body)
61
+
62
+ get_list_response
63
+ expect(stub).to have_been_requested.twice
64
+ end
65
+
66
+ it 'retries 5XX errors' do
67
+ stub = stub_request(:get, %r{.*api.gocardless.com/payout_items}).
68
+ to_return(status: 502,
69
+ headers: { 'Content-Type' => 'text/html' },
70
+ body: '<html><body>Response from Cloudflare</body></html>').
71
+ then.to_return(status: 200, headers: response_headers, body: body)
72
+
73
+ get_list_response
74
+ expect(stub).to have_been_requested.twice
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#all' do
81
+ let!(:first_response_stub) do
82
+ stub_request(:get, %r{.*api.gocardless.com/payout_items$}).to_return(
83
+ body: {
84
+ 'payout_items' => [{
85
+
86
+ 'amount' => 'amount-input',
87
+ 'links' => 'links-input',
88
+ 'type' => 'type-input',
89
+ }],
90
+ meta: {
91
+ cursors: { after: 'AB345' },
92
+ limit: 1,
93
+ },
94
+ }.to_json,
95
+ headers: response_headers
96
+ )
97
+ end
98
+
99
+ let!(:second_response_stub) do
100
+ stub_request(:get, %r{.*api.gocardless.com/payout_items\?after=AB345}).to_return(
101
+ body: {
102
+ 'payout_items' => [{
103
+
104
+ 'amount' => 'amount-input',
105
+ 'links' => 'links-input',
106
+ 'type' => 'type-input',
107
+ }],
108
+ meta: {
109
+ limit: 2,
110
+ cursors: {},
111
+ },
112
+ }.to_json,
113
+ headers: response_headers
114
+ )
115
+ end
116
+
117
+ it 'automatically makes the extra requests' do
118
+ expect(client.payout_items.all.to_a.length).to eq(2)
119
+ expect(first_response_stub).to have_been_requested
120
+ expect(second_response_stub).to have_been_requested
121
+ end
122
+
123
+ describe 'retry behaviour' do
124
+ before { allow_any_instance_of(GoCardlessPro::Request).to receive(:sleep) }
125
+
126
+ it 'retries timeouts' do
127
+ first_response_stub = stub_request(:get, %r{.*api.gocardless.com/payout_items$}).to_return(
128
+ body: {
129
+ 'payout_items' => [{
130
+
131
+ 'amount' => 'amount-input',
132
+ 'links' => 'links-input',
133
+ 'type' => 'type-input',
134
+ }],
135
+ meta: {
136
+ cursors: { after: 'AB345' },
137
+ limit: 1,
138
+ },
139
+ }.to_json,
140
+ headers: response_headers
141
+ )
142
+
143
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/payout_items\?after=AB345}).
144
+ to_timeout.then.
145
+ to_return(
146
+ body: {
147
+ 'payout_items' => [{
148
+
149
+ 'amount' => 'amount-input',
150
+ 'links' => 'links-input',
151
+ 'type' => 'type-input',
152
+ }],
153
+ meta: {
154
+ limit: 2,
155
+ cursors: {},
156
+ },
157
+ }.to_json,
158
+ headers: response_headers
159
+ )
160
+
161
+ client.payout_items.all.to_a
162
+
163
+ expect(first_response_stub).to have_been_requested
164
+ expect(second_response_stub).to have_been_requested.twice
165
+ end
166
+
167
+ it 'retries 5XX errors' do
168
+ first_response_stub = stub_request(:get, %r{.*api.gocardless.com/payout_items$}).to_return(
169
+ body: {
170
+ 'payout_items' => [{
171
+
172
+ 'amount' => 'amount-input',
173
+ 'links' => 'links-input',
174
+ 'type' => 'type-input',
175
+ }],
176
+ meta: {
177
+ cursors: { after: 'AB345' },
178
+ limit: 1,
179
+ },
180
+ }.to_json,
181
+ headers: response_headers
182
+ )
183
+
184
+ second_response_stub = stub_request(:get, %r{.*api.gocardless.com/payout_items\?after=AB345}).
185
+ to_return(
186
+ status: 502,
187
+ body: '<html><body>Response from Cloudflare</body></html>',
188
+ headers: { 'Content-Type' => 'text/html' }
189
+ ).then.to_return(
190
+ body: {
191
+ 'payout_items' => [{
192
+
193
+ 'amount' => 'amount-input',
194
+ 'links' => 'links-input',
195
+ 'type' => 'type-input',
196
+ }],
197
+ meta: {
198
+ limit: 2,
199
+ cursors: {},
200
+ },
201
+ }.to_json,
202
+ headers: response_headers
203
+ )
204
+
205
+ client.payout_items.all.to_a
206
+
207
+ expect(first_response_stub).to have_been_requested
208
+ expect(second_response_stub).to have_been_requested.twice
209
+ end
210
+ end
211
+ end
212
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gocardless_pro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-18 00:00:00.000000000 Z
11
+ date: 2017-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -126,6 +126,7 @@ files:
126
126
  - lib/gocardless_pro/resources/mandate_pdf.rb
127
127
  - lib/gocardless_pro/resources/payment.rb
128
128
  - lib/gocardless_pro/resources/payout.rb
129
+ - lib/gocardless_pro/resources/payout_item.rb
129
130
  - lib/gocardless_pro/resources/redirect_flow.rb
130
131
  - lib/gocardless_pro/resources/refund.rb
131
132
  - lib/gocardless_pro/resources/subscription.rb
@@ -140,6 +141,7 @@ files:
140
141
  - lib/gocardless_pro/services/mandate_pdfs_service.rb
141
142
  - lib/gocardless_pro/services/mandates_service.rb
142
143
  - lib/gocardless_pro/services/payments_service.rb
144
+ - lib/gocardless_pro/services/payout_items_service.rb
143
145
  - lib/gocardless_pro/services/payouts_service.rb
144
146
  - lib/gocardless_pro/services/redirect_flows_service.rb
145
147
  - lib/gocardless_pro/services/refunds_service.rb
@@ -159,6 +161,7 @@ files:
159
161
  - spec/resources/mandate_pdf_spec.rb
160
162
  - spec/resources/mandate_spec.rb
161
163
  - spec/resources/payment_spec.rb
164
+ - spec/resources/payout_item_spec.rb
162
165
  - spec/resources/payout_spec.rb
163
166
  - spec/resources/redirect_flow_spec.rb
164
167
  - spec/resources/refund_spec.rb
@@ -173,6 +176,7 @@ files:
173
176
  - spec/services/mandate_pdfs_service_spec.rb
174
177
  - spec/services/mandates_service_spec.rb
175
178
  - spec/services/payments_service_spec.rb
179
+ - spec/services/payout_items_service_spec.rb
176
180
  - spec/services/payouts_service_spec.rb
177
181
  - spec/services/redirect_flows_service_spec.rb
178
182
  - spec/services/refunds_service_spec.rb
@@ -217,6 +221,7 @@ test_files:
217
221
  - spec/resources/mandate_pdf_spec.rb
218
222
  - spec/resources/mandate_spec.rb
219
223
  - spec/resources/payment_spec.rb
224
+ - spec/resources/payout_item_spec.rb
220
225
  - spec/resources/payout_spec.rb
221
226
  - spec/resources/redirect_flow_spec.rb
222
227
  - spec/resources/refund_spec.rb
@@ -231,6 +236,7 @@ test_files:
231
236
  - spec/services/mandate_pdfs_service_spec.rb
232
237
  - spec/services/mandates_service_spec.rb
233
238
  - spec/services/payments_service_spec.rb
239
+ - spec/services/payout_items_service_spec.rb
234
240
  - spec/services/payouts_service_spec.rb
235
241
  - spec/services/redirect_flows_service_spec.rb
236
242
  - spec/services/refunds_service_spec.rb