diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 790df2a4b..aa7e05fd4 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f80865bcd..e4aac361d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - uses: actions/setup-go@v4 with: diff --git a/.github/workflows/models.yml b/.github/workflows/models.yml index d13e6ac35..a9cd6a82e 100644 --- a/.github/workflows/models.yml +++ b/.github/workflows/models.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest name: Generate Models steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 - uses: actions/setup-go@v4 with: go-version: 1.18 diff --git a/Makefile b/Makefile index 06ce05147..764ca1d3c 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ openapi-generator-cli:=java -jar $(openapi-generator-jar) goimports:=$(shell go env GOPATH)/bin/goimports generator:=go -services:=balancecontrol balanceplatform acswebhook configurationwebhook reportwebhook transferwebhook binlookup checkout legalentity management managementwebhook payments payout posterminalmanagement recurring storedvalue transfers +services:=balancecontrol balanceplatform acswebhook configurationwebhook reportwebhook transferwebhook binlookup checkout legalentity management managementwebhook payments payout posterminalmanagement recurring storedvalue transfers dataprotection output:=src templates:=templates/custom @@ -56,6 +56,8 @@ management: hasRestServiceError=true managementwebhook: spec=ManagementNotificationService-v1 posterminalmanagement: spec=TfmAPIService-v1 posterminalmanagement: serviceName=PosTerminalManagementApi +dataprotection: spec=DataProtectionService-v1 +dataprotection: serviceName=DataProtection # Generate a full client (models and service classes) $(services): schema $(openapi-generator-jar) $(goimports) diff --git a/Readme.md b/Readme.md index 780a2f06a..be133da0d 100644 --- a/Readme.md +++ b/Readme.md @@ -11,25 +11,24 @@ This is the officially supported golang library for using Adyen's APIs. The Library supports all APIs under the following services: | API | Description | Service constructor | Supported version | -|------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|-------------------| +|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------|-------------------| | [Checkout API](https://docs.adyen.com/api-explorer/Checkout/70/overview) | Our latest integration for accepting online payments. | client.Checkout() | **v70** | | [Payouts API](https://docs.adyen.com/api-explorer/Payout/68/overview) | Endpoints for sending funds to your customers. | client.Payout() | **v68** | | [Recurring API](https://docs.adyen.com/api-explorer/Recurring/68/overview) | Endpoints for managing saved payment details. | client.Recurring() | **v68** | | [BIN lookup API](https://docs.adyen.com/api-explorer/BinLookup/54/overview) | The BIN Lookup API provides endpoints for retrieving information based on a given BIN. | client.BinLookup() | **v54** | | [POS Terminal Management API](https://docs.adyen.com/api-explorer/postfmapi/1/overview) | Endpoints for managing your point-of-sale payment terminals. | client.PosTerminalManagement() | **v1** | | [Management API](https://docs.adyen.com/api-explorer/Management/1/overview) | Configure and manage your Adyen company and merchant accounts, stores, and payment terminals. | client.Management() | **v1** | +| [Data Protection API](https://docs.adyen.com/development-resources/data-protection-api) | Adyen Data Protection API provides a way for you to process [Subject Erasure Requests](https://gdpr-info.eu/art-17-gdpr/) as mandated in GDPR. | client.DataProtection() | **v1** | | [Balance Control API](https://docs.adyen.com/api-explorer/BalanceControl/1/overview) | The Balance Control API lets you transfer funds between merchant accounts that belong to the same legal entity and are under the same company account. | client.BalanceControl() | **v1** | | [Legal Entity Management API](https://docs.adyen.com/api-explorer/legalentity/3/overview) | Manage legal entities that contain information required for verification. | client.LegalEntity() | **v3** | | [Configuration API](https://docs.adyen.com/api-explorer/balanceplatform/2/overview) | The Configuration API enables you to create a platform where you can onboard your users as account holders and create balance accounts, cards, and business accounts. | client.BalancePlatform() | **v2** | | [Transfers API](https://docs.adyen.com/api-explorer/transfers/3/overview) | The Transfers API provides endpoints that can be used to get information about all your transactions, move funds within your balance platform or send funds from your balance platform to a transfer instrument. | client.Transfers() | **v3** | -| [Payments API](https://docs.adyen.com/api-explorer/Payment/68/overview) | Our classic integration for online payments. | client.Payments() | **v68** | -| [Account API](https://docs.adyen.com/api-explorer/Account/6/overview) | This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsAccount() | **v6** | -| [Fund API](https://docs.adyen.com/api-explorer/Fund/6/overview) | This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsFund() | **v6** | -| [Hosted onboarding API](https://docs.adyen.com/api-explorer/Hop/6/overview) | This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsHostedOnboardingPage() | **v6** | -| [Notification Configuration API](https://docs.adyen.com/api-explorer/NotificationConfiguration/6/overview) | This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsNotificationConfiguration() | **v6** | -| [Platforms Notifications Webhooks](https://docs.adyen.com/api-explorer/Notification/6/overview) | | *Models only* | **v6** | | [Stored Value API](https://docs.adyen.com/payment-methods/gift-cards/stored-value-api) | Manage both online and point-of-sale gift cards and other stored-value cards. | client.StoredValue() | **v46** | -| [Webhooks](https://docs.adyen.com/api-explorer/Webhooks/1/overview) | Adyen uses webhooks to send notifications about payment status updates, newly available reports, and other events that can be subscribed to. For more information, refer to our [documentation](https://docs.adyen.com/development-resources/webhooks). | *Models only* | **v1** | +| [Payments API](https://docs.adyen.com/api-explorer/Payment/68/overview) | Our classic integration for online payments. | client.Payments() | **v68** | +| [Account API](https://docs.adyen.com/api-explorer/Account/6/overview) | **Deprecated:** This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsAccount() | **v6** | +| [Fund API](https://docs.adyen.com/api-explorer/Fund/6/overview) | **Deprecated:** This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsFund() | **v6** | +| [Hosted onboarding API](https://docs.adyen.com/api-explorer/Hop/6/overview) | **Deprecated:** This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsHostedOnboardingPage() | **v6** | +| [Notification Configuration API](https://docs.adyen.com/api-explorer/NotificationConfiguration/6/overview) | **Deprecated:** This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | client.PlatformsNotificationConfiguration() | **v6** | For more information, refer to our [documentation](https://docs.adyen.com/) or the [API Explorer](https://docs.adyen.com/api-explorer/). @@ -37,13 +36,15 @@ For more information, refer to our [documentation](https://docs.adyen.com/) or t The library supports all webhooks under the following model directories: -| Webhooks | Description | Package | Supported Version | -|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------|-------------------| -| [Authentication Webhooks](https://docs.adyen.com/api-explorer/acs-webhook/1/overview) | Adyen sends this webhook when the process of cardholder authentication is finalized, whether it is completed successfully, fails, or expires. | [acswebhook](src/acswebhook) | **v1** | -| [Configuration Webhooks](https://docs.adyen.com/api-explorer/balanceplatform-webhooks/1/overview) | You can use these webhooks to build your implementation. For example, you can use this information to update internal statuses when the status of a capability is changed. | [configurationwebhook](src/configurationwebhook) | **v1** | -| [Transfer Webhooks](https://docs.adyen.com/api-explorer/transfer-webhooks/3/overview) | You can use these webhooks to build your implementation. For example, you can use this information to update balances in your own dashboards or to keep track of incoming funds. | [transferwebhook](src/transferwebhook) | **v3** | -| [Report Webhooks](https://docs.adyen.com/api-explorer/report-webhooks/1/overview) | You can download reports programmatically by making an HTTP GET request, or manually from your Balance Platform Customer Area | [reportwebhook](src/reportwebhook) | **v1** | -| [Management Webhooks](https://docs.adyen.com/api-explorer/ManagementNotification/1/overview) | Adyen uses webhooks to inform your system about events that happen with your Adyen company and merchant accounts, stores, payment terminals, and payment methods when using Management API. | [managementwebhook](src/managementwebhook) | **v1** | +| Webhooks | Description | Package | Supported Version | +|---------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------|-------------------| +| [Payment Webhooks](https://docs.adyen.com/api-explorer/Webhooks/1/overview) | Adyen uses webhooks to send notifications about payment status updates, newly available reports, and other events that can be subscribed to. For more information, refer to our [documentation](https://docs.adyen.com/development-resources/webhooks). | [webhook](src/webhook) | **v1** | +| [Authentication Webhooks](https://docs.adyen.com/api-explorer/acs-webhook/1/overview) | Adyen sends this webhook when the process of cardholder authentication is finalized, whether it is completed successfully, fails, or expires. | [acswebhook](src/acswebhook) | **v1** | +| [Configuration Webhooks](https://docs.adyen.com/api-explorer/balanceplatform-webhooks/1/overview) | You can use these webhooks to build your implementation. For example, you can use this information to update internal statuses when the status of a capability is changed. | [configurationwebhook](src/configurationwebhook) | **v1** | +| [Transfer Webhooks](https://docs.adyen.com/api-explorer/transfer-webhooks/3/overview) | You can use these webhooks to build your implementation. For example, you can use this information to update balances in your own dashboards or to keep track of incoming funds. | [transferwebhook](src/transferwebhook) | **v3** | +| [Report Webhooks](https://docs.adyen.com/api-explorer/report-webhooks/1/overview) | You can download reports programmatically by making an HTTP GET request, or manually from your Balance Platform Customer Area | [reportwebhook](src/reportwebhook) | **v1** | +| [Management Webhooks](https://docs.adyen.com/api-explorer/ManagementNotification/1/overview) | Adyen uses webhooks to inform your system about events that happen with your Adyen company and merchant accounts, stores, payment terminals, and payment methods when using Management API. | [managementwebhook](src/managementwebhook) | **v1** | +| [Platforms Notifications Webhooks](https://docs.adyen.com/api-explorer/Notification/6/overview) | **Deprecated:** This API is used for the classic integration. If you are just starting your implementation, refer to our [new integration guide](https://docs.adyen.com/marketplaces-and-platforms) instead. | [platformsnotificationevents](src/platformsnotificationevents) | **v6** | ## Prerequisites diff --git a/src/adyen/api.go b/src/adyen/api.go index 234860c8b..019fe50b4 100644 --- a/src/adyen/api.go +++ b/src/adyen/api.go @@ -8,6 +8,7 @@ package adyen import ( "fmt" + "github.com/adyen/adyen-go-api-library/v7/src/dataprotection" "net/http" "github.com/adyen/adyen-go-api-library/v7/src/balancecontrol" @@ -53,6 +54,8 @@ const ( LegalEntityEntityLive = "https://kyc-live.adyen.com/lem" PosTerminalManagementEndpointTest = "https://postfmapi-test.adyen.com/postfmapi/terminal" PosTerminalManagementEndpointLive = "https://postfmapi-live.adyen.com/postfmapi/terminal" + DataProtectionEndpointTest = "https://ca-test.adyen.com/ca/services/DataProtectionService" + DataProtectionEndpointLive = "https://ca-live.adyen.com/ca/services/DataProtectionService" ) // also update LibVersion in src/common/configuration.go when a version is updated and a major lib version is released @@ -74,6 +77,7 @@ const ( ManagementAPIVersion = "v1" LegalEntityAPIVersion = "v3" PosTerminalManagementAPIVersion = "v1" + DataProtectionAPIVersion = "v1" ) // APIClient Manages access to Adyen API services. @@ -102,6 +106,7 @@ type APIClient struct { transfers *transfers.APIClient management *management.APIClient legalEntity *legalentity.APIClient + dataProtection *dataprotection.GeneralApi } // NewClient creates a new API client. Requires Config object. @@ -368,6 +373,18 @@ func (c *APIClient) PlatformsNotificationConfiguration() *platformsnotificationc return c.platformsNotificationConfiguration } +func (c *APIClient) DataProtection() *dataprotection.GeneralApi { + if c.dataProtection == nil { + c.dataProtection = &dataprotection.GeneralApi{ + Client: c.client, + BasePath: func() string { + return fmt.Sprintf("%s/%s", c.client.Cfg.DataProtectionEndpoint, DataProtectionAPIVersion) + }, + } + } + return c.dataProtection +} + /* SetEnvironment This defines the payment environment for live or test @@ -392,6 +409,7 @@ func (c *APIClient) SetEnvironment(env common.Environment, liveEndpointURLPrefix c.client.Cfg.ManagementEndpoint = ManagementEndpointLive c.client.Cfg.LegalEntityEndpoint = LegalEntityEntityLive c.client.Cfg.PosTerminalManagementEndpoint = PosTerminalManagementEndpointLive + c.client.Cfg.DataProtectionEndpoint = DataProtectionEndpointLive } else { c.client.Cfg.Environment = env c.client.Cfg.Endpoint = EndpointTest @@ -404,6 +422,7 @@ func (c *APIClient) SetEnvironment(env common.Environment, liveEndpointURLPrefix c.client.Cfg.ManagementEndpoint = ManagementEndpointTest c.client.Cfg.LegalEntityEndpoint = LegalEntityEntityTest c.client.Cfg.PosTerminalManagementEndpoint = PosTerminalManagementEndpointTest + c.client.Cfg.DataProtectionEndpoint = DataProtectionEndpointTest } c.client.Cfg.CheckoutEndpoint += "/" + CheckoutAPIVersion diff --git a/src/common/configuration.go b/src/common/configuration.go index b46482e81..dc7f58046 100644 --- a/src/common/configuration.go +++ b/src/common/configuration.go @@ -51,7 +51,7 @@ const ( const ( LibName = "adyen-go-api-library" - LibVersion = "7.2.0" + LibVersion = "7.3.0" ) // Config stores the configuration of the API client @@ -71,6 +71,7 @@ type Config struct { LegalEntityEndpoint string `json:"legalEntityEndpoint,omitempty"` TransfersEndpoint string `json:"transfersEndpoint,omitempty"` PosTerminalManagementEndpoint string `json:"posTerminalManagementEndpoint,omitempty"` + DataProtectionEndpoint string `json:"dataProtectionEndpoint,omitempty"` //Checkout Specific CheckoutEndpoint string `json:"checkoutEndpoint,omitempty"` diff --git a/src/dataprotection/.openapi-generator-ignore b/src/dataprotection/.openapi-generator-ignore new file mode 100644 index 000000000..2f7402806 --- /dev/null +++ b/src/dataprotection/.openapi-generator-ignore @@ -0,0 +1,4 @@ +# OpenAPI Generator Ignore + +# Single class service does not need an "index" to group multiple tags +client.go \ No newline at end of file diff --git a/src/dataprotection/api_general.go b/src/dataprotection/api_general.go new file mode 100644 index 000000000..6a14e60cb --- /dev/null +++ b/src/dataprotection/api_general.go @@ -0,0 +1,67 @@ +/* +Adyen Data Protection API + +API version: 1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dataprotection + +import ( + "context" + "net/http" + "net/url" + + "github.com/adyen/adyen-go-api-library/v7/src/common" +) + +// GeneralApi service +type GeneralApi common.Service + +// All parameters accepted by GeneralApi.RequestSubjectErasure +type GeneralApiRequestSubjectErasureInput struct { + subjectErasureByPspReferenceRequest *SubjectErasureByPspReferenceRequest +} + +func (r GeneralApiRequestSubjectErasureInput) SubjectErasureByPspReferenceRequest(subjectErasureByPspReferenceRequest SubjectErasureByPspReferenceRequest) GeneralApiRequestSubjectErasureInput { + r.subjectErasureByPspReferenceRequest = &subjectErasureByPspReferenceRequest + return r +} + +/* +Prepare a request for RequestSubjectErasure + +@return GeneralApiRequestSubjectErasureInput +*/ +func (a *GeneralApi) RequestSubjectErasureInput() GeneralApiRequestSubjectErasureInput { + return GeneralApiRequestSubjectErasureInput{} +} + +/* +RequestSubjectErasure Submit a Subject Erasure Request. + +Sends the PSP reference containing the shopper data that should be deleted. + +@param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). +@param r GeneralApiRequestSubjectErasureInput - Request parameters, see RequestSubjectErasureInput +@return SubjectErasureResponse, *http.Response, error +*/ +func (a *GeneralApi) RequestSubjectErasure(ctx context.Context, r GeneralApiRequestSubjectErasureInput) (SubjectErasureResponse, *http.Response, error) { + res := &SubjectErasureResponse{} + path := "/requestSubjectErasure" + queryParams := url.Values{} + headerParams := make(map[string]string) + httpRes, err := common.SendAPIRequest( + ctx, + a.Client, + r.subjectErasureByPspReferenceRequest, + res, + http.MethodPost, + a.BasePath()+path, + queryParams, + headerParams, + ) + + return *res, httpRes, err +} diff --git a/src/dataprotection/model_service_error.go b/src/dataprotection/model_service_error.go new file mode 100644 index 000000000..0c8d394b6 --- /dev/null +++ b/src/dataprotection/model_service_error.go @@ -0,0 +1,273 @@ +/* +Adyen Data Protection API + +API version: 1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dataprotection + +import ( + "encoding/json" + + "github.com/adyen/adyen-go-api-library/v7/src/common" +) + +// checks if the ServiceError type satisfies the MappedNullable interface at compile time +var _ common.MappedNullable = &ServiceError{} + +// ServiceError struct for ServiceError +type ServiceError struct { + // The error code mapped to the error message. + ErrorCode *string `json:"errorCode,omitempty"` + // The category of the error. + ErrorType *string `json:"errorType,omitempty"` + // A short explanation of the issue. + Message *string `json:"message,omitempty"` + // The PSP reference of the payment. + PspReference *string `json:"pspReference,omitempty"` + // The HTTP response status. + Status *int32 `json:"status,omitempty"` +} + +// NewServiceError instantiates a new ServiceError object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewServiceError() *ServiceError { + this := ServiceError{} + return &this +} + +// NewServiceErrorWithDefaults instantiates a new ServiceError object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewServiceErrorWithDefaults() *ServiceError { + this := ServiceError{} + return &this +} + +// GetErrorCode returns the ErrorCode field value if set, zero value otherwise. +func (o *ServiceError) GetErrorCode() string { + if o == nil || common.IsNil(o.ErrorCode) { + var ret string + return ret + } + return *o.ErrorCode +} + +// GetErrorCodeOk returns a tuple with the ErrorCode field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServiceError) GetErrorCodeOk() (*string, bool) { + if o == nil || common.IsNil(o.ErrorCode) { + return nil, false + } + return o.ErrorCode, true +} + +// HasErrorCode returns a boolean if a field has been set. +func (o *ServiceError) HasErrorCode() bool { + if o != nil && !common.IsNil(o.ErrorCode) { + return true + } + + return false +} + +// SetErrorCode gets a reference to the given string and assigns it to the ErrorCode field. +func (o *ServiceError) SetErrorCode(v string) { + o.ErrorCode = &v +} + +// GetErrorType returns the ErrorType field value if set, zero value otherwise. +func (o *ServiceError) GetErrorType() string { + if o == nil || common.IsNil(o.ErrorType) { + var ret string + return ret + } + return *o.ErrorType +} + +// GetErrorTypeOk returns a tuple with the ErrorType field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServiceError) GetErrorTypeOk() (*string, bool) { + if o == nil || common.IsNil(o.ErrorType) { + return nil, false + } + return o.ErrorType, true +} + +// HasErrorType returns a boolean if a field has been set. +func (o *ServiceError) HasErrorType() bool { + if o != nil && !common.IsNil(o.ErrorType) { + return true + } + + return false +} + +// SetErrorType gets a reference to the given string and assigns it to the ErrorType field. +func (o *ServiceError) SetErrorType(v string) { + o.ErrorType = &v +} + +// GetMessage returns the Message field value if set, zero value otherwise. +func (o *ServiceError) GetMessage() string { + if o == nil || common.IsNil(o.Message) { + var ret string + return ret + } + return *o.Message +} + +// GetMessageOk returns a tuple with the Message field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServiceError) GetMessageOk() (*string, bool) { + if o == nil || common.IsNil(o.Message) { + return nil, false + } + return o.Message, true +} + +// HasMessage returns a boolean if a field has been set. +func (o *ServiceError) HasMessage() bool { + if o != nil && !common.IsNil(o.Message) { + return true + } + + return false +} + +// SetMessage gets a reference to the given string and assigns it to the Message field. +func (o *ServiceError) SetMessage(v string) { + o.Message = &v +} + +// GetPspReference returns the PspReference field value if set, zero value otherwise. +func (o *ServiceError) GetPspReference() string { + if o == nil || common.IsNil(o.PspReference) { + var ret string + return ret + } + return *o.PspReference +} + +// GetPspReferenceOk returns a tuple with the PspReference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServiceError) GetPspReferenceOk() (*string, bool) { + if o == nil || common.IsNil(o.PspReference) { + return nil, false + } + return o.PspReference, true +} + +// HasPspReference returns a boolean if a field has been set. +func (o *ServiceError) HasPspReference() bool { + if o != nil && !common.IsNil(o.PspReference) { + return true + } + + return false +} + +// SetPspReference gets a reference to the given string and assigns it to the PspReference field. +func (o *ServiceError) SetPspReference(v string) { + o.PspReference = &v +} + +// GetStatus returns the Status field value if set, zero value otherwise. +func (o *ServiceError) GetStatus() int32 { + if o == nil || common.IsNil(o.Status) { + var ret int32 + return ret + } + return *o.Status +} + +// GetStatusOk returns a tuple with the Status field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ServiceError) GetStatusOk() (*int32, bool) { + if o == nil || common.IsNil(o.Status) { + return nil, false + } + return o.Status, true +} + +// HasStatus returns a boolean if a field has been set. +func (o *ServiceError) HasStatus() bool { + if o != nil && !common.IsNil(o.Status) { + return true + } + + return false +} + +// SetStatus gets a reference to the given int32 and assigns it to the Status field. +func (o *ServiceError) SetStatus(v int32) { + o.Status = &v +} + +func (o ServiceError) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o ServiceError) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !common.IsNil(o.ErrorCode) { + toSerialize["errorCode"] = o.ErrorCode + } + if !common.IsNil(o.ErrorType) { + toSerialize["errorType"] = o.ErrorType + } + if !common.IsNil(o.Message) { + toSerialize["message"] = o.Message + } + if !common.IsNil(o.PspReference) { + toSerialize["pspReference"] = o.PspReference + } + if !common.IsNil(o.Status) { + toSerialize["status"] = o.Status + } + return toSerialize, nil +} + +type NullableServiceError struct { + value *ServiceError + isSet bool +} + +func (v NullableServiceError) Get() *ServiceError { + return v.value +} + +func (v *NullableServiceError) Set(val *ServiceError) { + v.value = val + v.isSet = true +} + +func (v NullableServiceError) IsSet() bool { + return v.isSet +} + +func (v *NullableServiceError) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableServiceError(val *ServiceError) *NullableServiceError { + return &NullableServiceError{value: val, isSet: true} +} + +func (v NullableServiceError) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableServiceError) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/src/dataprotection/model_subject_erasure_by_psp_reference_request.go b/src/dataprotection/model_subject_erasure_by_psp_reference_request.go new file mode 100644 index 000000000..acd4771b0 --- /dev/null +++ b/src/dataprotection/model_subject_erasure_by_psp_reference_request.go @@ -0,0 +1,199 @@ +/* +Adyen Data Protection API + +API version: 1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dataprotection + +import ( + "encoding/json" + + "github.com/adyen/adyen-go-api-library/v7/src/common" +) + +// checks if the SubjectErasureByPspReferenceRequest type satisfies the MappedNullable interface at compile time +var _ common.MappedNullable = &SubjectErasureByPspReferenceRequest{} + +// SubjectErasureByPspReferenceRequest struct for SubjectErasureByPspReferenceRequest +type SubjectErasureByPspReferenceRequest struct { + // Set this to **true** if you want to delete shopper-related data, even if the shopper has an existing recurring transaction. This only deletes the shopper-related data for the specific payment, but does not cancel the existing recurring transaction. + ForceErasure *bool `json:"forceErasure,omitempty"` + // Your merchant account + MerchantAccount *string `json:"merchantAccount,omitempty"` + // The PSP reference of the payment. We will delete all shopper-related data for this payment. + PspReference *string `json:"pspReference,omitempty"` +} + +// NewSubjectErasureByPspReferenceRequest instantiates a new SubjectErasureByPspReferenceRequest object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewSubjectErasureByPspReferenceRequest() *SubjectErasureByPspReferenceRequest { + this := SubjectErasureByPspReferenceRequest{} + return &this +} + +// NewSubjectErasureByPspReferenceRequestWithDefaults instantiates a new SubjectErasureByPspReferenceRequest object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewSubjectErasureByPspReferenceRequestWithDefaults() *SubjectErasureByPspReferenceRequest { + this := SubjectErasureByPspReferenceRequest{} + return &this +} + +// GetForceErasure returns the ForceErasure field value if set, zero value otherwise. +func (o *SubjectErasureByPspReferenceRequest) GetForceErasure() bool { + if o == nil || common.IsNil(o.ForceErasure) { + var ret bool + return ret + } + return *o.ForceErasure +} + +// GetForceErasureOk returns a tuple with the ForceErasure field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SubjectErasureByPspReferenceRequest) GetForceErasureOk() (*bool, bool) { + if o == nil || common.IsNil(o.ForceErasure) { + return nil, false + } + return o.ForceErasure, true +} + +// HasForceErasure returns a boolean if a field has been set. +func (o *SubjectErasureByPspReferenceRequest) HasForceErasure() bool { + if o != nil && !common.IsNil(o.ForceErasure) { + return true + } + + return false +} + +// SetForceErasure gets a reference to the given bool and assigns it to the ForceErasure field. +func (o *SubjectErasureByPspReferenceRequest) SetForceErasure(v bool) { + o.ForceErasure = &v +} + +// GetMerchantAccount returns the MerchantAccount field value if set, zero value otherwise. +func (o *SubjectErasureByPspReferenceRequest) GetMerchantAccount() string { + if o == nil || common.IsNil(o.MerchantAccount) { + var ret string + return ret + } + return *o.MerchantAccount +} + +// GetMerchantAccountOk returns a tuple with the MerchantAccount field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SubjectErasureByPspReferenceRequest) GetMerchantAccountOk() (*string, bool) { + if o == nil || common.IsNil(o.MerchantAccount) { + return nil, false + } + return o.MerchantAccount, true +} + +// HasMerchantAccount returns a boolean if a field has been set. +func (o *SubjectErasureByPspReferenceRequest) HasMerchantAccount() bool { + if o != nil && !common.IsNil(o.MerchantAccount) { + return true + } + + return false +} + +// SetMerchantAccount gets a reference to the given string and assigns it to the MerchantAccount field. +func (o *SubjectErasureByPspReferenceRequest) SetMerchantAccount(v string) { + o.MerchantAccount = &v +} + +// GetPspReference returns the PspReference field value if set, zero value otherwise. +func (o *SubjectErasureByPspReferenceRequest) GetPspReference() string { + if o == nil || common.IsNil(o.PspReference) { + var ret string + return ret + } + return *o.PspReference +} + +// GetPspReferenceOk returns a tuple with the PspReference field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SubjectErasureByPspReferenceRequest) GetPspReferenceOk() (*string, bool) { + if o == nil || common.IsNil(o.PspReference) { + return nil, false + } + return o.PspReference, true +} + +// HasPspReference returns a boolean if a field has been set. +func (o *SubjectErasureByPspReferenceRequest) HasPspReference() bool { + if o != nil && !common.IsNil(o.PspReference) { + return true + } + + return false +} + +// SetPspReference gets a reference to the given string and assigns it to the PspReference field. +func (o *SubjectErasureByPspReferenceRequest) SetPspReference(v string) { + o.PspReference = &v +} + +func (o SubjectErasureByPspReferenceRequest) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o SubjectErasureByPspReferenceRequest) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !common.IsNil(o.ForceErasure) { + toSerialize["forceErasure"] = o.ForceErasure + } + if !common.IsNil(o.MerchantAccount) { + toSerialize["merchantAccount"] = o.MerchantAccount + } + if !common.IsNil(o.PspReference) { + toSerialize["pspReference"] = o.PspReference + } + return toSerialize, nil +} + +type NullableSubjectErasureByPspReferenceRequest struct { + value *SubjectErasureByPspReferenceRequest + isSet bool +} + +func (v NullableSubjectErasureByPspReferenceRequest) Get() *SubjectErasureByPspReferenceRequest { + return v.value +} + +func (v *NullableSubjectErasureByPspReferenceRequest) Set(val *SubjectErasureByPspReferenceRequest) { + v.value = val + v.isSet = true +} + +func (v NullableSubjectErasureByPspReferenceRequest) IsSet() bool { + return v.isSet +} + +func (v *NullableSubjectErasureByPspReferenceRequest) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSubjectErasureByPspReferenceRequest(val *SubjectErasureByPspReferenceRequest) *NullableSubjectErasureByPspReferenceRequest { + return &NullableSubjectErasureByPspReferenceRequest{value: val, isSet: true} +} + +func (v NullableSubjectErasureByPspReferenceRequest) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSubjectErasureByPspReferenceRequest) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/src/dataprotection/model_subject_erasure_response.go b/src/dataprotection/model_subject_erasure_response.go new file mode 100644 index 000000000..59378ef91 --- /dev/null +++ b/src/dataprotection/model_subject_erasure_response.go @@ -0,0 +1,135 @@ +/* +Adyen Data Protection API + +API version: 1 +*/ + +// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT. + +package dataprotection + +import ( + "encoding/json" + + "github.com/adyen/adyen-go-api-library/v7/src/common" +) + +// checks if the SubjectErasureResponse type satisfies the MappedNullable interface at compile time +var _ common.MappedNullable = &SubjectErasureResponse{} + +// SubjectErasureResponse struct for SubjectErasureResponse +type SubjectErasureResponse struct { + // The result of this operation. + Result *string `json:"result,omitempty"` +} + +// NewSubjectErasureResponse instantiates a new SubjectErasureResponse object +// This constructor will assign default values to properties that have it defined, +// and makes sure properties required by API are set, but the set of arguments +// will change when the set of required properties is changed +func NewSubjectErasureResponse() *SubjectErasureResponse { + this := SubjectErasureResponse{} + return &this +} + +// NewSubjectErasureResponseWithDefaults instantiates a new SubjectErasureResponse object +// This constructor will only assign default values to properties that have it defined, +// but it doesn't guarantee that properties required by API are set +func NewSubjectErasureResponseWithDefaults() *SubjectErasureResponse { + this := SubjectErasureResponse{} + return &this +} + +// GetResult returns the Result field value if set, zero value otherwise. +func (o *SubjectErasureResponse) GetResult() string { + if o == nil || common.IsNil(o.Result) { + var ret string + return ret + } + return *o.Result +} + +// GetResultOk returns a tuple with the Result field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *SubjectErasureResponse) GetResultOk() (*string, bool) { + if o == nil || common.IsNil(o.Result) { + return nil, false + } + return o.Result, true +} + +// HasResult returns a boolean if a field has been set. +func (o *SubjectErasureResponse) HasResult() bool { + if o != nil && !common.IsNil(o.Result) { + return true + } + + return false +} + +// SetResult gets a reference to the given string and assigns it to the Result field. +func (o *SubjectErasureResponse) SetResult(v string) { + o.Result = &v +} + +func (o SubjectErasureResponse) MarshalJSON() ([]byte, error) { + toSerialize, err := o.ToMap() + if err != nil { + return []byte{}, err + } + return json.Marshal(toSerialize) +} + +func (o SubjectErasureResponse) ToMap() (map[string]interface{}, error) { + toSerialize := map[string]interface{}{} + if !common.IsNil(o.Result) { + toSerialize["result"] = o.Result + } + return toSerialize, nil +} + +type NullableSubjectErasureResponse struct { + value *SubjectErasureResponse + isSet bool +} + +func (v NullableSubjectErasureResponse) Get() *SubjectErasureResponse { + return v.value +} + +func (v *NullableSubjectErasureResponse) Set(val *SubjectErasureResponse) { + v.value = val + v.isSet = true +} + +func (v NullableSubjectErasureResponse) IsSet() bool { + return v.isSet +} + +func (v *NullableSubjectErasureResponse) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableSubjectErasureResponse(val *SubjectErasureResponse) *NullableSubjectErasureResponse { + return &NullableSubjectErasureResponse{value: val, isSet: true} +} + +func (v NullableSubjectErasureResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableSubjectErasureResponse) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} + +func (o *SubjectErasureResponse) isValidResult() bool { + var allowedEnumValues = []string{"ACTIVE_RECURRING_TOKEN_EXISTS", "ALREADY_PROCESSED", "PAYMENT_NOT_FOUND", "SUCCESS"} + for _, allowed := range allowedEnumValues { + if o.GetResult() == allowed { + return true + } + } + return false +} diff --git a/tests/data_protection_test.go b/tests/data_protection_test.go new file mode 100644 index 000000000..730cd6f44 --- /dev/null +++ b/tests/data_protection_test.go @@ -0,0 +1,93 @@ +package tests + +import ( + "bytes" + "context" + "errors" + "github.com/adyen/adyen-go-api-library/v7/src/adyen" + "github.com/adyen/adyen-go-api-library/v7/src/common" + "github.com/adyen/adyen-go-api-library/v7/src/dataprotection" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "io" + "io/ioutil" + "net/http" + "net/http/httptest" + "os" + "testing" +) + +func TestDataProtection(t *testing.T) { + client := adyen.NewClient(&common.Config{ + ApiKey: "YOUR_ADYEN_API_KEY", + Environment: "TEST", + Debug: "true" == os.Getenv("DEBUG"), + }) + + mux := http.NewServeMux() + mux.HandleFunc("/requestSubjectErasure", func(w http.ResponseWriter, r *http.Request) { + require.Equal(t, "POST", r.Method) + w.Header().Set("Content-Type", "application/json") + body, _ := ioutil.ReadAll(r.Body) + if bytes.Contains(body, []byte("invalidMerchant")) { + w.WriteHeader(http.StatusUnprocessableEntity) + io.WriteString(w, `{ + "status": 422, + "errorCode": "901", + "message": "Invalid Merchant Account", + "errorType": "validation" + }`) + return + } + io.WriteString(w, `{ "result": "SUCCESS" }`) + }) + + mockServer := httptest.NewServer(mux) + defer mockServer.Close() + client.DataProtection().BasePath = func() string { return mockServer.URL } + service := client.DataProtection() + + t.Run("Configuration", func(t *testing.T) { + testClient := adyen.NewClient(&common.Config{ + Environment: common.TestEnv, + }) + assert.Equal(t, "https://ca-test.adyen.com/ca/services/DataProtectionService/v1", testClient.DataProtection().BasePath()) + liveClient := adyen.NewClient(&common.Config{ + Environment: common.LiveEnv, + }) + assert.Equal(t, "https://ca-live.adyen.com/ca/services/DataProtectionService/v1", liveClient.DataProtection().BasePath()) + }) + + t.Run("Submit a Subject Erasure Request", func(t *testing.T) { + req := service.RequestSubjectErasureInput().SubjectErasureByPspReferenceRequest(dataprotection.SubjectErasureByPspReferenceRequest{ + ForceErasure: common.PtrBool(true), + MerchantAccount: common.PtrString("string"), + PspReference: common.PtrString("string"), + }) + res, httpRes, err := service.RequestSubjectErasure(context.Background(), req) + + require.NotNil(t, res) + assert.Equal(t, 200, httpRes.StatusCode) + require.NoError(t, err) + assert.Equal(t, "SUCCESS", res.GetResult()) + }) + + t.Run("Invalid Merchant Account", func(t *testing.T) { + req := service.RequestSubjectErasureInput().SubjectErasureByPspReferenceRequest(dataprotection.SubjectErasureByPspReferenceRequest{ + ForceErasure: common.PtrBool(false), + MerchantAccount: common.PtrString("invalidMerchant"), + PspReference: common.PtrString("string"), + }) + res, httpRes, err := service.RequestSubjectErasure(context.Background(), req) + + assert.Nil(t, res.Result) + assert.Equal(t, 422, httpRes.StatusCode) + require.Error(t, err) + var apiError common.APIError + errors.As(err, &apiError) + assert.Equal(t, float64(422), apiError.Status) + assert.Equal(t, "901", apiError.Code) + assert.Equal(t, "Invalid Merchant Account", apiError.Message) + assert.Equal(t, "validation", apiError.Type) + }) +}