From 5c72285f6a12c919c9971424622ba3a1485de57d Mon Sep 17 00:00:00 2001 From: Andrii Vysotskyi Date: Wed, 10 Apr 2024 11:13:06 +0200 Subject: [PATCH] fix(POM-360): enableThreeDS2 parameter encoding (#261) --- Scripts/Sourcery.sh | 2 +- .../Generated/Sourcery+Generated.swift | 38 ++++++++++++++++++- .../POAssignCustomerTokenRequest.swift | 14 +++---- .../POInvoiceAuthorizationRequest.swift | 9 ++--- Templates/Auto.stencil | 2 + Templates/AutoCodingKeys.stencil | 12 ++++++ Templates/AutoCompletion.stencil | 5 +-- .../Integration/CardsServiceTests.swift | 2 +- .../CustomerTokensServiceTests.swift | 2 +- ...GatewayConfigurationsRepositoryTests.swift | 2 +- 10 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 Templates/Auto.stencil create mode 100644 Templates/AutoCodingKeys.stencil diff --git a/Scripts/Sourcery.sh b/Scripts/Sourcery.sh index d944ccdf1..49ac84238 100755 --- a/Scripts/Sourcery.sh +++ b/Scripts/Sourcery.sh @@ -8,6 +8,6 @@ export PATH="/opt/homebrew/bin:$PATH" # Run sourcery sourcery \ --sources $PROJECT_DIR/Sources/$TARGET_NAME/Sources \ - --templates $PROJECT_DIR/Templates/AutoCompletion.stencil \ + --templates $PROJECT_DIR/Templates \ --parseDocumentation \ --output $PROJECT_DIR/Sources/$TARGET_NAME/Sources/Generated/Sourcery+Generated.swift diff --git a/Sources/ProcessOut/Sources/Generated/Sourcery+Generated.swift b/Sources/ProcessOut/Sources/Generated/Sourcery+Generated.swift index 8d42209d6..33501717c 100644 --- a/Sources/ProcessOut/Sources/Generated/Sourcery+Generated.swift +++ b/Sources/ProcessOut/Sources/Generated/Sourcery+Generated.swift @@ -1,10 +1,44 @@ -// Generated using Sourcery 2.1.7 — https://github.com/krzysztofzablocki/Sourcery +// Generated using Sourcery 2.2.2 — https://github.com/krzysztofzablocki/Sourcery // DO NOT EDIT import Foundation import UIKit -// swiftlint:disable all +// MARK: - AutoCodingKeys + +extension POAssignCustomerTokenRequest { + + enum CodingKeys: String, CodingKey { + case source + case preferredScheme + case verify + case invoiceId + case enableThreeDS2 = "enable_three_d_s_2" + case thirdPartySdkVersion + case metadata + } +} + +extension POInvoiceAuthorizationRequest { + + enum CodingKeys: String, CodingKey { + case source + case incremental + case enableThreeDS2 = "enable_three_d_s_2" + case preferredScheme + case thirdPartySdkVersion + case invoiceDetailIds + case overrideMacBlocking + case initialSchemeTransactionId + case autoCaptureAt + case captureAmount + case authorizeOnly + case allowFallbackToSale + case metadata + } +} + +// MARK: - AutoCompletion extension POCardsService { diff --git a/Sources/ProcessOut/Sources/Repositories/CustomerTokens/Requests/POAssignCustomerTokenRequest.swift b/Sources/ProcessOut/Sources/Repositories/CustomerTokens/Requests/POAssignCustomerTokenRequest.swift index 68193ea8d..521235778 100644 --- a/Sources/ProcessOut/Sources/Repositories/CustomerTokens/Requests/POAssignCustomerTokenRequest.swift +++ b/Sources/ProcessOut/Sources/Repositories/CustomerTokens/Requests/POAssignCustomerTokenRequest.swift @@ -8,15 +8,13 @@ import Foundation /// Request to use to assign new source to existing customer token and potentially verify it. -public struct POAssignCustomerTokenRequest: Encodable { +public struct POAssignCustomerTokenRequest: Encodable { // sourcery: AutoCodingKeys /// Id of the customer who token belongs to. - @POImmutableExcludedCodable - public var customerId: String + public let customerId: String // sourcery:coding: skip /// Tokens that belong to the customer. - @POImmutableExcludedCodable - public var tokenId: String + public let tokenId: String // sourcery:coding: skip /// Payment source to associate with token. The source can be a card, an APM or a gateway request. For the source /// to be valid, you must not have used it for any previous payment or to create any other customer tokens. @@ -34,7 +32,7 @@ public struct POAssignCustomerTokenRequest: Encodable { public let invoiceId: String? /// Boolean value indicating whether 3DS2 is enabled. Default value is `true`. - public let enableThreeDS2: Bool + public let enableThreeDS2: Bool // sourcery:coding: key="enable_three_d_s_2" /// Can be used for a 3DS2 request to indicate which third party SDK is used for the call. public let thirdPartySdkVersion: String? @@ -54,8 +52,8 @@ public struct POAssignCustomerTokenRequest: Encodable { thirdPartySdkVersion: String? = nil, metadata: [String: String]? = nil ) { - self._customerId = .init(value: customerId) - self._tokenId = .init(value: tokenId) + self.customerId = customerId + self.tokenId = tokenId self.source = source self.preferredScheme = preferredScheme self.verify = verify diff --git a/Sources/ProcessOut/Sources/Repositories/Invoices/Requests/POInvoiceAuthorizationRequest.swift b/Sources/ProcessOut/Sources/Repositories/Invoices/Requests/POInvoiceAuthorizationRequest.swift index eac1144d7..7edf0d645 100644 --- a/Sources/ProcessOut/Sources/Repositories/Invoices/Requests/POInvoiceAuthorizationRequest.swift +++ b/Sources/ProcessOut/Sources/Repositories/Invoices/Requests/POInvoiceAuthorizationRequest.swift @@ -7,11 +7,10 @@ import Foundation -public struct POInvoiceAuthorizationRequest: Encodable { +public struct POInvoiceAuthorizationRequest: Encodable { // sourcery: AutoCodingKeys /// Invoice identifier to to perform authorization for. - @POImmutableExcludedCodable - public var invoiceId: String + public let invoiceId: String // sourcery:coding: skip /// Payment source to use for authorization. public let source: String @@ -20,7 +19,7 @@ public struct POInvoiceAuthorizationRequest: Encodable { public let incremental: Bool /// Boolean value indicating whether 3DS2 is enabled. Default value is `true`. - public let enableThreeDS2: Bool + public let enableThreeDS2: Bool // sourcery:coding: key="enable_three_d_s_2" /// Card scheme or co-scheme that should get priority if it is available. public let preferredScheme: String? @@ -75,7 +74,7 @@ public struct POInvoiceAuthorizationRequest: Encodable { allowFallbackToSale: Bool = false, metadata: [String: String]? = nil ) { - self._invoiceId = .init(value: invoiceId) + self.invoiceId = invoiceId self.source = source self.incremental = incremental self.enableThreeDS2 = enableThreeDS2 diff --git a/Templates/Auto.stencil b/Templates/Auto.stencil new file mode 100644 index 000000000..f7d21f384 --- /dev/null +++ b/Templates/Auto.stencil @@ -0,0 +1,2 @@ +import Foundation +import UIKit diff --git a/Templates/AutoCodingKeys.stencil b/Templates/AutoCodingKeys.stencil new file mode 100644 index 000000000..7dcb7c513 --- /dev/null +++ b/Templates/AutoCodingKeys.stencil @@ -0,0 +1,12 @@ +// MARK: - AutoCodingKeys +{% for type in types.all|annotated:"AutoCodingKeys" %} + +extension {{ type.name }} { + + enum CodingKeys: String, CodingKey { + {% for variable in type.instanceVariables where not variable.annotations.coding.skip %} + case {{ variable.name }}{% if variable.annotations.coding.key %} = "{{ variable.annotations.coding.key }}"{% endif %} + {% endfor %} + } +} +{% endfor %} \ No newline at end of file diff --git a/Templates/AutoCompletion.stencil b/Templates/AutoCompletion.stencil index 24d16bdef..60ed581d5 100644 --- a/Templates/AutoCompletion.stencil +++ b/Templates/AutoCompletion.stencil @@ -1,7 +1,4 @@ -import Foundation -import UIKit - -// swiftlint:disable all +// MARK: - AutoCompletion {% for type in types.implementing.POAutoCompletion|protocol %} extension {{ type.name }} { diff --git a/Tests/ProcessOutTests/Sources/Integration/CardsServiceTests.swift b/Tests/ProcessOutTests/Sources/Integration/CardsServiceTests.swift index a9d9de4a7..116cd82de 100644 --- a/Tests/ProcessOutTests/Sources/Integration/CardsServiceTests.swift +++ b/Tests/ProcessOutTests/Sources/Integration/CardsServiceTests.swift @@ -9,7 +9,7 @@ import Foundation import XCTest @testable import ProcessOut -@MainActor final class CardsServiceTests: XCTestCase { +final class CardsServiceTests: XCTestCase { override func setUp() { super.setUp() diff --git a/Tests/ProcessOutTests/Sources/Integration/CustomerTokensServiceTests.swift b/Tests/ProcessOutTests/Sources/Integration/CustomerTokensServiceTests.swift index 9eb763f56..366995cfb 100644 --- a/Tests/ProcessOutTests/Sources/Integration/CustomerTokensServiceTests.swift +++ b/Tests/ProcessOutTests/Sources/Integration/CustomerTokensServiceTests.swift @@ -8,7 +8,7 @@ import XCTest @_spi(PO) @testable import ProcessOut -@MainActor final class CustomerTokensServiceTests: XCTestCase { +final class CustomerTokensServiceTests: XCTestCase { override func setUp() { super.setUp() diff --git a/Tests/ProcessOutTests/Sources/Integration/GatewayConfigurationsRepositoryTests.swift b/Tests/ProcessOutTests/Sources/Integration/GatewayConfigurationsRepositoryTests.swift index d988f77c4..3bb418ada 100644 --- a/Tests/ProcessOutTests/Sources/Integration/GatewayConfigurationsRepositoryTests.swift +++ b/Tests/ProcessOutTests/Sources/Integration/GatewayConfigurationsRepositoryTests.swift @@ -9,7 +9,7 @@ import Foundation import XCTest @testable import ProcessOut -@MainActor final class GatewayConfigurationsRepositoryTests: XCTestCase { +final class GatewayConfigurationsRepositoryTests: XCTestCase { override func setUp() { super.setUp()