diff --git a/GoCardless/GoCardless.csproj b/GoCardless/GoCardless.csproj index 45eaa32..3a4ca6c 100644 --- a/GoCardless/GoCardless.csproj +++ b/GoCardless/GoCardless.csproj @@ -2,7 +2,7 @@ GoCardless - 4.4.0 + 4.5.0 GoCardless Ltd Client for the GoCardless API - a powerful, simple solution for the collection of recurring bank-to-bank payments false @@ -11,7 +11,7 @@ GoCardless Ltd gocardless payments rest api direct debit https://github.com/gocardless/gocardless-dotnet/blob/master/LICENSE.txt - https://github.com/gocardless/gocardless-dotnet/releases/tag/v4.4.0 + https://github.com/gocardless/gocardless-dotnet/releases/tag/v4.5.0 netstandard1.6;netstandard2.0;net46 True true diff --git a/GoCardless/GoCardlessClient.Generated.cs b/GoCardless/GoCardlessClient.Generated.cs index cef7e0d..f3233eb 100644 --- a/GoCardless/GoCardlessClient.Generated.cs +++ b/GoCardless/GoCardlessClient.Generated.cs @@ -73,6 +73,11 @@ public partial class GoCardlessClient /// public MandatePdfService MandatePdfs => new MandatePdfService(this); + /// + ///A service for working with payer authorisation resources. + /// + public PayerAuthorisationService PayerAuthorisations => new PayerAuthorisationService(this); + /// ///A service for working with payment resources. /// diff --git a/GoCardless/GoCardlessClient.cs b/GoCardless/GoCardlessClient.cs index ee0a514..8dc2a14 100644 --- a/GoCardless/GoCardlessClient.cs +++ b/GoCardless/GoCardlessClient.cs @@ -252,9 +252,9 @@ private HttpRequestMessage BuildHttpRequestMessage(string method, string path var httpMethod = new HttpMethod(method); var requestMessage = new HttpRequestMessage(httpMethod, new Uri(_baseUrl, path)); - requestMessage.Headers.Add("User-Agent", "gocardless-dotnet/4.4.0"); + requestMessage.Headers.Add("User-Agent", "gocardless-dotnet/4.5.0"); requestMessage.Headers.Add("GoCardless-Version", "2015-07-06"); - requestMessage.Headers.Add("GoCardless-Client-Version", "4.4.0"); + requestMessage.Headers.Add("GoCardless-Client-Version", "4.5.0"); requestMessage.Headers.Add("GoCardless-Client-Library", "gocardless-dotnet"); requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", _accessToken); diff --git a/GoCardless/Resources/Event.cs b/GoCardless/Resources/Event.cs index 8d8ca5b..ab45c4a 100644 --- a/GoCardless/Resources/Event.cs +++ b/GoCardless/Resources/Event.cs @@ -376,7 +376,7 @@ public class EventLinks public string ParentEvent { get; set; } /// - /// ID of a Payer Authorisation. + /// ID of a [payer authorisation](#core-endpoints-payer-authorisations). /// [JsonProperty("payer_authorisation")] public string PayerAuthorisation { get; set; } diff --git a/GoCardless/Resources/PayerAuthorisation.cs b/GoCardless/Resources/PayerAuthorisation.cs new file mode 100644 index 0000000..534617e --- /dev/null +++ b/GoCardless/Resources/PayerAuthorisation.cs @@ -0,0 +1,506 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace GoCardless.Resources +{ + + /// + /// Represents a payer authorisation resource. + /// + /// Payer Authorisation resource acts as a wrapper for creating customer, + /// bank account and mandate details in a single request. + /// PayerAuthorisation API enables the integrators to build their own custom + /// payment pages. + /// + /// The process to use the Payer Authorisation API is as follows: + /// + /// 1. Create a Payer Authorisation, either empty or with already + /// available information + /// 2. Update the authorisation with additional information or fix any + /// mistakes + /// 3. Submit the authorisation, after the payer has reviewed their + /// information + /// 4. [coming soon] Redirect the payer to the verification mechanisms + /// from the response of the Submit request (this will be introduced as a + /// non-breaking change) + /// 5. Confirm the authorisation to indicate that the resources can be + /// created + /// + /// After the Payer Authorisation is confirmed, resources will eventually be + /// created as it's an asynchronous process. + /// + /// To retrieve the status and ID of the linked resources you can do one of + /// the following: + ///
    + ///
  1. Listen to payer_authorisation_completed webhook (recommended)
  2. + ///
  3. Poll the GET + /// endpoint
  4. + ///
  5. Poll the GET events API + /// https://api.gocardless.com/events?payer_authorisation={id}&action=completed + ///
  6. + ///
+ /// + ///

+ /// Note that the `create` and `update` endpoints behave differently than + /// other existing `create` and `update` endpoints. The Payer + /// Authorisation is still saved if incomplete data is provided. + /// We return the list of incomplete data in the `incomplete_fields` along + /// with the resources in the body of the response. + ///

+ /// The API is designed to be flexible and allows you to collect + /// information in multiple steps without storing any sensitive data in the + /// browser or in your servers. + ///

+ ///
+ public class PayerAuthorisation + { + /// + /// All details required for the creation of a + /// [Customer Bank Account](#core-endpoints-customer-bank-accounts). + /// + [JsonProperty("bank_account")] + public PayerAuthorisationBankAccount BankAccount { get; set; } + + /// + /// [Timestamp](#api-usage-time-zones--dates), recording when this Payer + /// Authorisation was created. + /// + [JsonProperty("created_at")] + public DateTimeOffset? CreatedAt { get; set; } + + /// + /// All details required for the creation of a + /// [Customer](#core-endpoints-customers). + /// + [JsonProperty("customer")] + public PayerAuthorisationCustomer Customer { get; set; } + + /// + /// Unique identifier, beginning with "PA". + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// An array of fields which are missing and is required to set up the + /// mandate. + /// + [JsonProperty("incomplete_fields")] + public List IncompleteFields { get; set; } + + /// + /// Resources linked to this PayerAuthorisation. + /// + [JsonProperty("links")] + public PayerAuthorisationLinks Links { get; set; } + + /// + /// All details required for the creation of a + /// [Mandate](#core-endpoints-mandates). + /// + [JsonProperty("mandate")] + public PayerAuthorisationMandate Mandate { get; set; } + + /// + /// One of: + /// - `created`: The PayerAuthorisation has been created, and not been + /// confirmed yet + /// - `submitted`: The payer information has been submitted + /// - `confirmed`: PayerAuthorisation is confirmed and resources are + /// ready to be created + /// - `completed`: The PayerAuthorisation has been completed and + /// customer, bank_account and mandate has been created + /// - `failed`: The PayerAuthorisation has failed and customer, + /// bank_account and mandate is not created + /// + [JsonProperty("status")] + public PayerAuthorisationStatus? Status { get; set; } + } + + /// + /// Represents a payer authorisation bank account resource. + /// + /// All details required for the creation of a + /// [Customer Bank Account](#core-endpoints-customer-bank-accounts). + /// + public class PayerAuthorisationBankAccount + { + /// + /// Name of the account holder, as known by the bank. Usually this is + /// the same as the name stored with the linked + /// [creditor](#core-endpoints-creditors). This field will be + /// transliterated, upcased and truncated to 18 characters. This field + /// is required unless the request includes a [customer bank account + /// token](#javascript-flow-customer-bank-account-tokens). + /// + [JsonProperty("account_holder_name")] + public string AccountHolderName { get; set; } + + /// + /// Bank account number - see [local + /// details](#appendix-local-bank-details) for more information. + /// Alternatively you can provide an `iban`. + /// + [JsonProperty("account_number")] + public string AccountNumber { get; set; } + + /// + /// Account number suffix (only for bank accounts denominated in NZD) - + /// see [local details](#local-bank-details-new-zealand) for more + /// information. + /// + [JsonProperty("account_number_suffix")] + public string AccountNumberSuffix { get; set; } + + /// + /// Bank account type. Required for USD-denominated bank accounts. Must + /// not be provided for bank accounts in other currencies. See [local + /// details](#local-bank-details-united-states) for more information. + /// + [JsonProperty("account_type")] + public PayerAuthorisationBankAccountAccountType? AccountType { get; set; } + + /// + /// Bank code - see [local details](#appendix-local-bank-details) for + /// more information. Alternatively you can provide an `iban`. + /// + [JsonProperty("bank_code")] + public string BankCode { get; set; } + + /// + /// Branch code - see [local details](#appendix-local-bank-details) for + /// more information. Alternatively you can provide an `iban`. + /// + [JsonProperty("branch_code")] + public string BranchCode { get; set; } + + /// + /// [ISO 3166-1 alpha-2 + /// code](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements). + /// Defaults to the country code of the `iban` if supplied, otherwise is + /// required. + /// + [JsonProperty("country_code")] + public string CountryCode { get; set; } + + /// + /// [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) + /// currency code. Currently "AUD", "CAD", "DKK", "EUR", "GBP", "NZD", + /// "SEK" and "USD" are supported. + /// + [JsonProperty("currency")] + public string Currency { get; set; } + + /// + /// International Bank Account Number. Alternatively you can provide + /// [local details](#appendix-local-bank-details). IBANs are not + /// accepted for Swedish bank accounts denominated in SEK - you must + /// supply [local details](#local-bank-details-sweden). + /// + [JsonProperty("iban")] + public string Iban { get; set; } + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with key + /// names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + } + + /// + /// Bank account type. Required for USD-denominated bank accounts. Must not be provided for bank + /// accounts in other currencies. See [local details](#local-bank-details-united-states) for + /// more information. + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PayerAuthorisationBankAccountAccountType { + + /// `account_type` with a value of "savings" + [EnumMember(Value = "savings")] + Savings, + /// `account_type` with a value of "checking" + [EnumMember(Value = "checking")] + Checking, + } + + /// + /// Represents a payer authorisation customer resource. + /// + /// All details required for the creation of a + /// [Customer](#core-endpoints-customers). + /// + public class PayerAuthorisationCustomer + { + /// + /// The first line of the customer's address. + /// + [JsonProperty("address_line1")] + public string AddressLine1 { get; set; } + + /// + /// The second line of the customer's address. + /// + [JsonProperty("address_line2")] + public string AddressLine2 { get; set; } + + /// + /// The third line of the customer's address. + /// + [JsonProperty("address_line3")] + public string AddressLine3 { get; set; } + + /// + /// The city of the customer's address. + /// + [JsonProperty("city")] + public string City { get; set; } + + /// + /// Customer's company name. Required unless a `given_name` and + /// `family_name` are provided. For Canadian customers, the use of a + /// `company_name` value will mean that any mandate created from this + /// customer will be considered to be a "Business PAD" (otherwise, any + /// mandate will be considered to be a "Personal PAD"). + /// + [JsonProperty("company_name")] + public string CompanyName { get; set; } + + /// + /// [ISO 3166-1 alpha-2 + /// code.](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) + /// + [JsonProperty("country_code")] + public string CountryCode { get; set; } + + /// + /// For Danish customers only. The civic/company number (CPR or CVR) of + /// the customer. Must be supplied if the customer's bank account is + /// denominated in Danish krone (DKK). + /// + [JsonProperty("danish_identity_number")] + public string DanishIdentityNumber { get; set; } + + /// + /// Customer's email address. Required in most cases, as this allows + /// GoCardless to send notifications to this customer. + /// + [JsonProperty("email")] + public string Email { get; set; } + + /// + /// Customer's surname. Required unless a `company_name` is provided. + /// + [JsonProperty("family_name")] + public string FamilyName { get; set; } + + /// + /// Customer's first name. Required unless a `company_name` is provided. + /// + [JsonProperty("given_name")] + public string GivenName { get; set; } + + /// + /// An [IETF Language Tag](https://tools.ietf.org/html/rfc5646), used + /// for both language + /// and regional variations of our product. + /// + /// + [JsonProperty("locale")] + public string Locale { get; set; } + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with key + /// names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + + /// + /// The customer's postal code. + /// + [JsonProperty("postal_code")] + public string PostalCode { get; set; } + + /// + /// The customer's address region, county or department. For US + /// customers a 2 letter + /// [ISO3166-2:US](https://en.wikipedia.org/wiki/ISO_3166-2:US) state + /// code is required (e.g. `CA` for California). + /// + [JsonProperty("region")] + public string Region { get; set; } + + /// + /// For Swedish customers only. The civic/company number (personnummer, + /// samordningsnummer, or organisationsnummer) of the customer. Must be + /// supplied if the customer's bank account is denominated in Swedish + /// krona (SEK). This field cannot be changed once it has been set. + /// + [JsonProperty("swedish_identity_number")] + public string SwedishIdentityNumber { get; set; } + } + + /// + /// An array of fields which are missing and is required to set up the + /// mandate. + /// + public class PayerAuthorisationIncompleteField + { + /// + /// The root resource. + /// + [JsonProperty("field")] + public string Field { get; set; } + + /// + /// A localised error message + /// + [JsonProperty("message")] + public string Message { get; set; } + + /// + /// The path to the field e.g. "/payer_authorisations/customer/city" + /// + [JsonProperty("request_pointer")] + public string RequestPointer { get; set; } + } + + /// + /// Represents a payer authorisation link resource. + /// + /// IDs of the created resources. Available after the Payer Authorisation is + /// completed. + /// + public class PayerAuthorisationLinks + { + /// + /// Unique identifier, beginning with "BA". + /// + [JsonProperty("bank_account")] + public string BankAccount { get; set; } + + /// + /// Unique identifier, beginning with "CU". + /// + [JsonProperty("customer")] + public string Customer { get; set; } + + /// + /// Unique identifier, beginning with "MD". Note that this prefix may + /// not apply to mandates created before 2016. + /// + [JsonProperty("mandate")] + public string Mandate { get; set; } + } + + /// + /// Represents a payer authorisation mandate resource. + /// + /// All details required for the creation of a + /// [Mandate](#core-endpoints-mandates). + /// + public class PayerAuthorisationMandate + { + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with key + /// names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + + /// + /// For ACH customers only. Required for ACH customers. A string + /// containing the IP address of the payer to whom the mandate belongs + /// (i.e. as a result of their completion of a mandate setup flow in + /// their browser). + /// + [JsonProperty("payer_ip_address")] + public string PayerIpAddress { get; set; } + + /// + /// Unique reference. Different schemes have different length and + /// [character set](#appendix-character-sets) requirements. GoCardless + /// will generate a unique reference satisfying the different scheme + /// requirements if this field is left blank. + /// + [JsonProperty("reference")] + public string Reference { get; set; } + + /// + /// A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + /// "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + /// + [JsonProperty("scheme")] + public PayerAuthorisationMandateScheme? Scheme { get; set; } + } + + /// + /// A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", "becs_nz", + /// "betalingsservice", "pad" and "sepa_core" are supported. + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PayerAuthorisationMandateScheme { + + /// `scheme` with a value of "ach" + [EnumMember(Value = "ach")] + Ach, + /// `scheme` with a value of "autogiro" + [EnumMember(Value = "autogiro")] + Autogiro, + /// `scheme` with a value of "bacs" + [EnumMember(Value = "bacs")] + Bacs, + /// `scheme` with a value of "becs" + [EnumMember(Value = "becs")] + Becs, + /// `scheme` with a value of "becs_nz" + [EnumMember(Value = "becs_nz")] + BecsNz, + /// `scheme` with a value of "betalingsservice" + [EnumMember(Value = "betalingsservice")] + Betalingsservice, + /// `scheme` with a value of "pad" + [EnumMember(Value = "pad")] + Pad, + /// `scheme` with a value of "sepa_core" + [EnumMember(Value = "sepa_core")] + SepaCore, + } + + /// + /// One of: + /// - `created`: The PayerAuthorisation has been created, and not been confirmed yet + /// - `submitted`: The payer information has been submitted + /// - `confirmed`: PayerAuthorisation is confirmed and resources are ready to be created + /// - `completed`: The PayerAuthorisation has been completed and customer, bank_account and + /// mandate has been created + /// - `failed`: The PayerAuthorisation has failed and customer, bank_account and mandate is not + /// created + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PayerAuthorisationStatus { + + /// `status` with a value of "created" + [EnumMember(Value = "created")] + Created, + /// `status` with a value of "submitted" + [EnumMember(Value = "submitted")] + Submitted, + /// `status` with a value of "confirmed" + [EnumMember(Value = "confirmed")] + Confirmed, + /// `status` with a value of "completed" + [EnumMember(Value = "completed")] + Completed, + /// `status` with a value of "failed" + [EnumMember(Value = "failed")] + Failed, + } + +} diff --git a/GoCardless/Services/EventService.cs b/GoCardless/Services/EventService.cs index 3b0baba..3a7a377 100644 --- a/GoCardless/Services/EventService.cs +++ b/GoCardless/Services/EventService.cs @@ -255,7 +255,7 @@ public enum EventInclude public string ParentEvent { get; set; } /// - /// ID of a Payer Authorisation. + /// ID of a [payer authorisation](#core-endpoints-payer-authorisations). /// [JsonProperty("payer_authorisation")] public string PayerAuthorisation { get; set; } diff --git a/GoCardless/Services/PayerAuthorisationService.cs b/GoCardless/Services/PayerAuthorisationService.cs new file mode 100644 index 0000000..4878f87 --- /dev/null +++ b/GoCardless/Services/PayerAuthorisationService.cs @@ -0,0 +1,933 @@ + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Threading; +using System.Threading.Tasks; +using GoCardless.Internals; +using GoCardless.Resources; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace GoCardless.Services +{ + /// + /// Service class for working with payer authorisation resources. + /// + /// Payer Authorisation resource acts as a wrapper for creating customer, + /// bank account and mandate details in a single request. + /// PayerAuthorisation API enables the integrators to build their own custom + /// payment pages. + /// + /// The process to use the Payer Authorisation API is as follows: + /// + /// 1. Create a Payer Authorisation, either empty or with already + /// available information + /// 2. Update the authorisation with additional information or fix any + /// mistakes + /// 3. Submit the authorisation, after the payer has reviewed their + /// information + /// 4. [coming soon] Redirect the payer to the verification mechanisms + /// from the response of the Submit request (this will be introduced as a + /// non-breaking change) + /// 5. Confirm the authorisation to indicate that the resources can be + /// created + /// + /// After the Payer Authorisation is confirmed, resources will eventually be + /// created as it's an asynchronous process. + /// + /// To retrieve the status and ID of the linked resources you can do one of + /// the following: + ///
    + ///
  1. Listen to payer_authorisation_completed webhook (recommended)
  2. + ///
  3. Poll the GET + /// endpoint
  4. + ///
  5. Poll the GET events API + /// https://api.gocardless.com/events?payer_authorisation={id}&action=completed + ///
  6. + ///
+ /// + ///

+ /// Note that the `create` and `update` endpoints behave differently than + /// other existing `create` and `update` endpoints. The Payer + /// Authorisation is still saved if incomplete data is provided. + /// We return the list of incomplete data in the `incomplete_fields` along + /// with the resources in the body of the response. + ///

+ /// The API is designed to be flexible and allows you to collect + /// information in multiple steps without storing any sensitive data in the + /// browser or in your servers. + ///

+ ///
+ + public class PayerAuthorisationService + { + private readonly GoCardlessClient _goCardlessClient; + + /// + /// Constructor. Users of this library should not call this. An instance of this + /// class can be accessed through an initialised GoCardlessClient. + /// + public PayerAuthorisationService(GoCardlessClient goCardlessClient) + { + _goCardlessClient = goCardlessClient; + } + + /// + /// Retrieves the details of a single existing Payer Authorisation. It + /// can be used for polling the status of a Payer Authorisation. + /// + /// Unique identifier, beginning with "PA". + /// An optional `PayerAuthorisationGetRequest` representing the query parameters for this get request. + /// An optional `RequestSettings` allowing you to configure the request + /// A single payer authorisation resource + public Task GetAsync(string identity, PayerAuthorisationGetRequest request = null, RequestSettings customiseRequestMessage = null) + { + request = request ?? new PayerAuthorisationGetRequest(); + if (identity == null) throw new ArgumentException(nameof(identity)); + + var urlParams = new List> + { + new KeyValuePair("identity", identity), + }; + + return _goCardlessClient.ExecuteAsync("GET", "/payer_authorisations/:identity", urlParams, request, null, null, customiseRequestMessage); + } + + /// + /// Creates a Payer Authorisation. The resource is saved to the database + /// even if incomplete. An empty array of incomplete_fields means that + /// the resource is valid. The ID of the resource is used for the other + /// actions. This endpoint has been designed this way so you do not need + /// to save any payer data on your servers or the browser while still + /// being able to implement a progressive solution, such as a multi-step + /// form. + /// + /// An optional `PayerAuthorisationCreateRequest` representing the body for this create request. + /// An optional `RequestSettings` allowing you to configure the request + /// A single payer authorisation resource + public Task CreateAsync(PayerAuthorisationCreateRequest request = null, RequestSettings customiseRequestMessage = null) + { + request = request ?? new PayerAuthorisationCreateRequest(); + + var urlParams = new List> + {}; + + return _goCardlessClient.ExecuteAsync("POST", "/payer_authorisations", urlParams, request, id => GetAsync(id, null, customiseRequestMessage), "payer_authorisations", customiseRequestMessage); + } + + /// + /// Updates a Payer Authorisation. Updates the Payer Authorisation with + /// the request data.Can be invoked as many times as needed. Only fields + /// present in the request will be modified. An empty array of + /// incomplete_fields means that the resource is valid. This endpoint + /// has been designed this way so you do not need to save any payer data + /// on your servers or the browser while still being able to implement a + /// progressive solution, such a multi-step form.

+ /// Note that in order to update the `metadata` attribute values it must + /// be sent completely as it overrides the previously existing values. + ///

+ ///
+ /// Unique identifier, beginning with "PA". + /// An optional `PayerAuthorisationUpdateRequest` representing the body for this update request. + /// An optional `RequestSettings` allowing you to configure the request + /// A single payer authorisation resource + public Task UpdateAsync(string identity, PayerAuthorisationUpdateRequest request = null, RequestSettings customiseRequestMessage = null) + { + request = request ?? new PayerAuthorisationUpdateRequest(); + if (identity == null) throw new ArgumentException(nameof(identity)); + + var urlParams = new List> + { + new KeyValuePair("identity", identity), + }; + + return _goCardlessClient.ExecuteAsync("PUT", "/payer_authorisations/:identity", urlParams, request, null, "payer_authorisations", customiseRequestMessage); + } + + /// + /// Submits all the data previously pushed to this PayerAuthorisation + /// for verification.This time, a 200 HTTP status is returned if the + /// resource is valid and a 422 error response in case of validation + /// errors. After it is successfully submitted, the Payer Authorisation + /// can no longer be edited. + /// + /// Unique identifier, beginning with "PA". + /// An optional `PayerAuthorisationSubmitRequest` representing the body for this submit request. + /// An optional `RequestSettings` allowing you to configure the request + /// A single payer authorisation resource + public Task SubmitAsync(string identity, PayerAuthorisationSubmitRequest request = null, RequestSettings customiseRequestMessage = null) + { + request = request ?? new PayerAuthorisationSubmitRequest(); + if (identity == null) throw new ArgumentException(nameof(identity)); + + var urlParams = new List> + { + new KeyValuePair("identity", identity), + }; + + return _goCardlessClient.ExecuteAsync("POST", "/payer_authorisations/:identity/actions/submit", urlParams, request, null, "data", customiseRequestMessage); + } + + /// + /// Confirms the Payer Authorisation, indicating that the resources are + /// ready to be created. + /// A Payer Authorisation cannot be confirmed if it hasn't been + /// submitted yet. + /// + ///

+ /// The main use of the confirm endpoint is to enable integrators to + /// acknowledge the end of the setup process. + /// They might want to make the payers go through some other steps + /// after they go through our flow or make them go through the necessary + /// verification mechanism(upcomming feature). + ///

+ ///
+ /// Unique identifier, beginning with "PA". + /// An optional `PayerAuthorisationConfirmRequest` representing the body for this confirm request. + /// An optional `RequestSettings` allowing you to configure the request + /// A single payer authorisation resource + public Task ConfirmAsync(string identity, PayerAuthorisationConfirmRequest request = null, RequestSettings customiseRequestMessage = null) + { + request = request ?? new PayerAuthorisationConfirmRequest(); + if (identity == null) throw new ArgumentException(nameof(identity)); + + var urlParams = new List> + { + new KeyValuePair("identity", identity), + }; + + return _goCardlessClient.ExecuteAsync("POST", "/payer_authorisations/:identity/actions/confirm", urlParams, request, null, "data", customiseRequestMessage); + } + } + + + /// + /// Retrieves the details of a single existing Payer Authorisation. It can + /// be used for polling the status of a Payer Authorisation. + /// + public class PayerAuthorisationGetRequest + { + } + + + /// + /// Creates a Payer Authorisation. The resource is saved to the database + /// even if incomplete. An empty array of incomplete_fields means that the + /// resource is valid. The ID of the resource is used for the other actions. + /// This endpoint has been designed this way so you do not need to save any + /// payer data on your servers or the browser while still being able to + /// implement a progressive solution, such as a multi-step form. + /// + public class PayerAuthorisationCreateRequest : IHasIdempotencyKey + { + + /// + /// All details required for the creation of a + /// [Customer Bank Account](#core-endpoints-customer-bank-accounts). + /// + [JsonProperty("bank_account")] + public PayerAuthorisationBankAccount BankAccount { get; set; } + /// + /// All details required for the creation of a + /// [Customer Bank Account](#core-endpoints-customer-bank-accounts). + /// + public class PayerAuthorisationBankAccount + { + + /// + /// Name of the account holder, as known by the bank. Usually this + /// is the same as the name stored with the linked + /// [creditor](#core-endpoints-creditors). This field will be + /// transliterated, upcased and truncated to 18 characters. This + /// field is required unless the request includes a [customer bank + /// account token](#javascript-flow-customer-bank-account-tokens). + /// + [JsonProperty("account_holder_name")] + public string AccountHolderName { get; set; } + + /// + /// Bank account number - see [local + /// details](#appendix-local-bank-details) for more information. + /// Alternatively you can provide an `iban`. + /// + [JsonProperty("account_number")] + public string AccountNumber { get; set; } + + /// + /// Account number suffix (only for bank accounts denominated in + /// NZD) - see [local details](#local-bank-details-new-zealand) for + /// more information. + /// + [JsonProperty("account_number_suffix")] + public string AccountNumberSuffix { get; set; } + + /// + /// Bank account type. Required for USD-denominated bank accounts. + /// Must not be provided for bank accounts in other currencies. See + /// [local details](#local-bank-details-united-states) for more + /// information. + /// + [JsonProperty("account_type")] + public PayerAuthorisationAccountType? AccountType { get; set; } + /// + /// Bank account type. Required for USD-denominated bank accounts. Must + /// not be provided for bank accounts in other currencies. See [local + /// details](#local-bank-details-united-states) for more information. + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PayerAuthorisationAccountType + { + + /// `account_type` with a value of "savings" + [EnumMember(Value = "savings")] + Savings, + /// `account_type` with a value of "checking" + [EnumMember(Value = "checking")] + Checking, + } + + /// + /// Bank code - see [local details](#appendix-local-bank-details) + /// for more information. Alternatively you can provide an `iban`. + /// + [JsonProperty("bank_code")] + public string BankCode { get; set; } + + /// + /// Branch code - see [local details](#appendix-local-bank-details) + /// for more information. Alternatively you can provide an `iban`. + /// + [JsonProperty("branch_code")] + public string BranchCode { get; set; } + + /// + /// [ISO 3166-1 alpha-2 + /// code](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements). + /// Defaults to the country code of the `iban` if supplied, + /// otherwise is required. + /// + [JsonProperty("country_code")] + public string CountryCode { get; set; } + + /// + /// [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) + /// currency code. Currently "AUD", "CAD", "DKK", "EUR", "GBP", + /// "NZD", "SEK" and "USD" are supported. + /// + [JsonProperty("currency")] + public string Currency { get; set; } + + /// + /// International Bank Account Number. Alternatively you can provide + /// [local details](#appendix-local-bank-details). IBANs are not + /// accepted for Swedish bank accounts denominated in SEK - you must + /// supply [local details](#local-bank-details-sweden). + /// + [JsonProperty("iban")] + public string Iban { get; set; } + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with + /// key names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + } + + /// + /// All details required for the creation of a + /// [Customer](#core-endpoints-customers). + /// + [JsonProperty("customer")] + public PayerAuthorisationCustomer Customer { get; set; } + /// + /// All details required for the creation of a + /// [Customer](#core-endpoints-customers). + /// + public class PayerAuthorisationCustomer + { + + /// + /// The first line of the customer's address. + /// + [JsonProperty("address_line1")] + public string AddressLine1 { get; set; } + + /// + /// The second line of the customer's address. + /// + [JsonProperty("address_line2")] + public string AddressLine2 { get; set; } + + /// + /// The third line of the customer's address. + /// + [JsonProperty("address_line3")] + public string AddressLine3 { get; set; } + + /// + /// The city of the customer's address. + /// + [JsonProperty("city")] + public string City { get; set; } + + /// + /// Customer's company name. Required unless a `given_name` and + /// `family_name` are provided. For Canadian customers, the use of a + /// `company_name` value will mean that any mandate created from + /// this customer will be considered to be a "Business PAD" + /// (otherwise, any mandate will be considered to be a "Personal + /// PAD"). + /// + [JsonProperty("company_name")] + public string CompanyName { get; set; } + + /// + /// [ISO 3166-1 alpha-2 + /// code.](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) + /// + [JsonProperty("country_code")] + public string CountryCode { get; set; } + + /// + /// For Danish customers only. The civic/company number (CPR or CVR) + /// of the customer. Must be supplied if the customer's bank account + /// is denominated in Danish krone (DKK). + /// + [JsonProperty("danish_identity_number")] + public string DanishIdentityNumber { get; set; } + + /// + /// Customer's email address. Required in most cases, as this allows + /// GoCardless to send notifications to this customer. + /// + [JsonProperty("email")] + public string Email { get; set; } + + /// + /// Customer's surname. Required unless a `company_name` is + /// provided. + /// + [JsonProperty("family_name")] + public string FamilyName { get; set; } + + /// + /// Customer's first name. Required unless a `company_name` is + /// provided. + /// + [JsonProperty("given_name")] + public string GivenName { get; set; } + + /// + /// An [IETF Language Tag](https://tools.ietf.org/html/rfc5646), + /// used for both language + /// and regional variations of our product. + /// + /// + [JsonProperty("locale")] + public string Locale { get; set; } + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with + /// key names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + + /// + /// The customer's postal code. + /// + [JsonProperty("postal_code")] + public string PostalCode { get; set; } + + /// + /// The customer's address region, county or department. For US + /// customers a 2 letter + /// [ISO3166-2:US](https://en.wikipedia.org/wiki/ISO_3166-2:US) + /// state code is required (e.g. `CA` for California). + /// + [JsonProperty("region")] + public string Region { get; set; } + + /// + /// For Swedish customers only. The civic/company number + /// (personnummer, samordningsnummer, or organisationsnummer) of the + /// customer. Must be supplied if the customer's bank account is + /// denominated in Swedish krona (SEK). This field cannot be changed + /// once it has been set. + /// + [JsonProperty("swedish_identity_number")] + public string SwedishIdentityNumber { get; set; } + } + + /// + /// All details required for the creation of a + /// [Mandate](#core-endpoints-mandates). + /// + [JsonProperty("mandate")] + public PayerAuthorisationMandate Mandate { get; set; } + /// + /// All details required for the creation of a + /// [Mandate](#core-endpoints-mandates). + /// + public class PayerAuthorisationMandate + { + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with + /// key names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + + /// + /// For ACH customers only. Required for ACH customers. A string + /// containing the IP address of the payer to whom the mandate + /// belongs (i.e. as a result of their completion of a mandate setup + /// flow in their browser). + /// + [JsonProperty("payer_ip_address")] + public string PayerIpAddress { get; set; } + + /// + /// Unique reference. Different schemes have different length and + /// [character set](#appendix-character-sets) requirements. + /// GoCardless will generate a unique reference satisfying the + /// different scheme requirements if this field is left blank. + /// + [JsonProperty("reference")] + public string Reference { get; set; } + + /// + /// A Direct Debit scheme. Currently "ach", "autogiro", "bacs", + /// "becs", "becs_nz", "betalingsservice", "pad" and "sepa_core" are + /// supported. + /// + [JsonProperty("scheme")] + public PayerAuthorisationScheme? Scheme { get; set; } + /// + /// A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + /// "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PayerAuthorisationScheme + { + + /// `scheme` with a value of "ach" + [EnumMember(Value = "ach")] + Ach, + /// `scheme` with a value of "autogiro" + [EnumMember(Value = "autogiro")] + Autogiro, + /// `scheme` with a value of "bacs" + [EnumMember(Value = "bacs")] + Bacs, + /// `scheme` with a value of "becs" + [EnumMember(Value = "becs")] + Becs, + /// `scheme` with a value of "becs_nz" + [EnumMember(Value = "becs_nz")] + BecsNz, + /// `scheme` with a value of "betalingsservice" + [EnumMember(Value = "betalingsservice")] + Betalingsservice, + /// `scheme` with a value of "pad" + [EnumMember(Value = "pad")] + Pad, + /// `scheme` with a value of "sepa_core" + [EnumMember(Value = "sepa_core")] + SepaCore, + } + } + + /// + /// A unique key to ensure that this request only succeeds once, allowing you to safely retry request errors such as network failures. + /// Any requests, where supported, to create a resource with a key that has previously been used will not succeed. + /// See: https://developer.gocardless.com/api-reference/#making-requests-idempotency-keys + /// + [JsonIgnore] + public string IdempotencyKey { get; set; } + } + + + /// + /// Updates a Payer Authorisation. Updates the Payer Authorisation with the + /// request data.Can be invoked as many times as needed. Only fields present + /// in the request will be modified. An empty array of incomplete_fields + /// means that the resource is valid. This endpoint has been designed this + /// way so you do not need to save any payer data on your servers or the + /// browser while still being able to implement a progressive solution, such + /// a multi-step form.

Note that in order to update the + /// `metadata` attribute values it must be sent completely as it overrides + /// the previously existing values.

+ ///
+ public class PayerAuthorisationUpdateRequest + { + + /// + /// All details required for the creation of a + /// [Customer Bank Account](#core-endpoints-customer-bank-accounts). + /// + [JsonProperty("bank_account")] + public PayerAuthorisationBankAccount BankAccount { get; set; } + /// + /// All details required for the creation of a + /// [Customer Bank Account](#core-endpoints-customer-bank-accounts). + /// + public class PayerAuthorisationBankAccount + { + + /// + /// Name of the account holder, as known by the bank. Usually this + /// is the same as the name stored with the linked + /// [creditor](#core-endpoints-creditors). This field will be + /// transliterated, upcased and truncated to 18 characters. This + /// field is required unless the request includes a [customer bank + /// account token](#javascript-flow-customer-bank-account-tokens). + /// + [JsonProperty("account_holder_name")] + public string AccountHolderName { get; set; } + + /// + /// Bank account number - see [local + /// details](#appendix-local-bank-details) for more information. + /// Alternatively you can provide an `iban`. + /// + [JsonProperty("account_number")] + public string AccountNumber { get; set; } + + /// + /// Account number suffix (only for bank accounts denominated in + /// NZD) - see [local details](#local-bank-details-new-zealand) for + /// more information. + /// + [JsonProperty("account_number_suffix")] + public string AccountNumberSuffix { get; set; } + + /// + /// Bank account type. Required for USD-denominated bank accounts. + /// Must not be provided for bank accounts in other currencies. See + /// [local details](#local-bank-details-united-states) for more + /// information. + /// + [JsonProperty("account_type")] + public PayerAuthorisationAccountType? AccountType { get; set; } + /// + /// Bank account type. Required for USD-denominated bank accounts. Must + /// not be provided for bank accounts in other currencies. See [local + /// details](#local-bank-details-united-states) for more information. + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PayerAuthorisationAccountType + { + + /// `account_type` with a value of "savings" + [EnumMember(Value = "savings")] + Savings, + /// `account_type` with a value of "checking" + [EnumMember(Value = "checking")] + Checking, + } + + /// + /// Bank code - see [local details](#appendix-local-bank-details) + /// for more information. Alternatively you can provide an `iban`. + /// + [JsonProperty("bank_code")] + public string BankCode { get; set; } + + /// + /// Branch code - see [local details](#appendix-local-bank-details) + /// for more information. Alternatively you can provide an `iban`. + /// + [JsonProperty("branch_code")] + public string BranchCode { get; set; } + + /// + /// [ISO 3166-1 alpha-2 + /// code](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements). + /// Defaults to the country code of the `iban` if supplied, + /// otherwise is required. + /// + [JsonProperty("country_code")] + public string CountryCode { get; set; } + + /// + /// [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) + /// currency code. Currently "AUD", "CAD", "DKK", "EUR", "GBP", + /// "NZD", "SEK" and "USD" are supported. + /// + [JsonProperty("currency")] + public string Currency { get; set; } + + /// + /// International Bank Account Number. Alternatively you can provide + /// [local details](#appendix-local-bank-details). IBANs are not + /// accepted for Swedish bank accounts denominated in SEK - you must + /// supply [local details](#local-bank-details-sweden). + /// + [JsonProperty("iban")] + public string Iban { get; set; } + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with + /// key names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + } + + /// + /// All details required for the creation of a + /// [Customer](#core-endpoints-customers). + /// + [JsonProperty("customer")] + public PayerAuthorisationCustomer Customer { get; set; } + /// + /// All details required for the creation of a + /// [Customer](#core-endpoints-customers). + /// + public class PayerAuthorisationCustomer + { + + /// + /// The first line of the customer's address. + /// + [JsonProperty("address_line1")] + public string AddressLine1 { get; set; } + + /// + /// The second line of the customer's address. + /// + [JsonProperty("address_line2")] + public string AddressLine2 { get; set; } + + /// + /// The third line of the customer's address. + /// + [JsonProperty("address_line3")] + public string AddressLine3 { get; set; } + + /// + /// The city of the customer's address. + /// + [JsonProperty("city")] + public string City { get; set; } + + /// + /// Customer's company name. Required unless a `given_name` and + /// `family_name` are provided. For Canadian customers, the use of a + /// `company_name` value will mean that any mandate created from + /// this customer will be considered to be a "Business PAD" + /// (otherwise, any mandate will be considered to be a "Personal + /// PAD"). + /// + [JsonProperty("company_name")] + public string CompanyName { get; set; } + + /// + /// [ISO 3166-1 alpha-2 + /// code.](http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements) + /// + [JsonProperty("country_code")] + public string CountryCode { get; set; } + + /// + /// For Danish customers only. The civic/company number (CPR or CVR) + /// of the customer. Must be supplied if the customer's bank account + /// is denominated in Danish krone (DKK). + /// + [JsonProperty("danish_identity_number")] + public string DanishIdentityNumber { get; set; } + + /// + /// Customer's email address. Required in most cases, as this allows + /// GoCardless to send notifications to this customer. + /// + [JsonProperty("email")] + public string Email { get; set; } + + /// + /// Customer's surname. Required unless a `company_name` is + /// provided. + /// + [JsonProperty("family_name")] + public string FamilyName { get; set; } + + /// + /// Customer's first name. Required unless a `company_name` is + /// provided. + /// + [JsonProperty("given_name")] + public string GivenName { get; set; } + + /// + /// An [IETF Language Tag](https://tools.ietf.org/html/rfc5646), + /// used for both language + /// and regional variations of our product. + /// + /// + [JsonProperty("locale")] + public string Locale { get; set; } + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with + /// key names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + + /// + /// The customer's postal code. + /// + [JsonProperty("postal_code")] + public string PostalCode { get; set; } + + /// + /// The customer's address region, county or department. For US + /// customers a 2 letter + /// [ISO3166-2:US](https://en.wikipedia.org/wiki/ISO_3166-2:US) + /// state code is required (e.g. `CA` for California). + /// + [JsonProperty("region")] + public string Region { get; set; } + + /// + /// For Swedish customers only. The civic/company number + /// (personnummer, samordningsnummer, or organisationsnummer) of the + /// customer. Must be supplied if the customer's bank account is + /// denominated in Swedish krona (SEK). This field cannot be changed + /// once it has been set. + /// + [JsonProperty("swedish_identity_number")] + public string SwedishIdentityNumber { get; set; } + } + + /// + /// All details required for the creation of a + /// [Mandate](#core-endpoints-mandates). + /// + [JsonProperty("mandate")] + public PayerAuthorisationMandate Mandate { get; set; } + /// + /// All details required for the creation of a + /// [Mandate](#core-endpoints-mandates). + /// + public class PayerAuthorisationMandate + { + + /// + /// Key-value store of custom data. Up to 3 keys are permitted, with + /// key names up to 50 characters and values up to 500 characters. + /// + [JsonProperty("metadata")] + public IDictionary Metadata { get; set; } + + /// + /// For ACH customers only. Required for ACH customers. A string + /// containing the IP address of the payer to whom the mandate + /// belongs (i.e. as a result of their completion of a mandate setup + /// flow in their browser). + /// + [JsonProperty("payer_ip_address")] + public string PayerIpAddress { get; set; } + + /// + /// Unique reference. Different schemes have different length and + /// [character set](#appendix-character-sets) requirements. + /// GoCardless will generate a unique reference satisfying the + /// different scheme requirements if this field is left blank. + /// + [JsonProperty("reference")] + public string Reference { get; set; } + + /// + /// A Direct Debit scheme. Currently "ach", "autogiro", "bacs", + /// "becs", "becs_nz", "betalingsservice", "pad" and "sepa_core" are + /// supported. + /// + [JsonProperty("scheme")] + public PayerAuthorisationScheme? Scheme { get; set; } + /// + /// A Direct Debit scheme. Currently "ach", "autogiro", "bacs", "becs", + /// "becs_nz", "betalingsservice", "pad" and "sepa_core" are supported. + /// + [JsonConverter(typeof(StringEnumConverter))] + public enum PayerAuthorisationScheme + { + + /// `scheme` with a value of "ach" + [EnumMember(Value = "ach")] + Ach, + /// `scheme` with a value of "autogiro" + [EnumMember(Value = "autogiro")] + Autogiro, + /// `scheme` with a value of "bacs" + [EnumMember(Value = "bacs")] + Bacs, + /// `scheme` with a value of "becs" + [EnumMember(Value = "becs")] + Becs, + /// `scheme` with a value of "becs_nz" + [EnumMember(Value = "becs_nz")] + BecsNz, + /// `scheme` with a value of "betalingsservice" + [EnumMember(Value = "betalingsservice")] + Betalingsservice, + /// `scheme` with a value of "pad" + [EnumMember(Value = "pad")] + Pad, + /// `scheme` with a value of "sepa_core" + [EnumMember(Value = "sepa_core")] + SepaCore, + } + } + } + + + /// + /// Submits all the data previously pushed to this PayerAuthorisation for + /// verification.This time, a 200 HTTP status is returned if the resource is + /// valid and a 422 error response in case of validation errors. After it is + /// successfully submitted, the Payer Authorisation can no longer be edited. + /// + public class PayerAuthorisationSubmitRequest + { + } + + + /// + /// Confirms the Payer Authorisation, indicating that the resources are + /// ready to be created. + /// A Payer Authorisation cannot be confirmed if it hasn't been submitted + /// yet. + /// + ///

+ /// The main use of the confirm endpoint is to enable integrators to + /// acknowledge the end of the setup process. + /// They might want to make the payers go through some other steps after + /// they go through our flow or make them go through the necessary + /// verification mechanism(upcomming feature). + ///

+ ///
+ public class PayerAuthorisationConfirmRequest + { + } + + /// + /// An API response for a request returning a single payer authorisation. + /// + public class PayerAuthorisationResponse : ApiResponse + { + /// + /// The payer authorisation from the response. + /// + [JsonProperty("payer_authorisations")] + public PayerAuthorisation PayerAuthorisation { get; private set; } + } +} diff --git a/README.md b/README.md index d19b50e..4694709 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ For full details of the GoCardless API, see the [API docs](https://developer.goc To install `GoCardless`, run the following command in the [Package Manager Console](https://docs.microsoft.com/en-us/nuget/tools/package-manager-console) -`Install-Package GoCardless -Version 4.4.0` +`Install-Package GoCardless -Version 4.5.0` ## Usage