From 183a5b54ee214f7fd45309702bc5f738ad911bc7 Mon Sep 17 00:00:00 2001 From: "Ivaylo Hadzhiev (emerchantpay)" Date: Thu, 31 Oct 2024 22:49:56 +0200 Subject: [PATCH] 1.5.2 --- .../project.pbxproj | 4 +- GenesisSwift.podspec | 2 +- GenesisSwift.xcodeproj/project.pbxproj | 8 +- .../xcschemes/GenesisSwiftTests.xcscheme | 4 +- .../Models/DynamicDescriptorParams.swift | 82 ++++++++++++++++++- .../Validation/RequiredParameters.swift | 13 +++ .../DynamicDescriptorParamsTests.swift | 67 +++++++++------ GenesisSwiftTests/PaymentRequestTests.swift | 14 +--- GenesisSwiftTests/Utils.swift | 26 ++++++ 9 files changed, 175 insertions(+), 45 deletions(-) create mode 100644 GenesisSwiftTests/Utils.swift diff --git a/GenesisSwift Example/GenesisSwift Example.xcodeproj/project.pbxproj b/GenesisSwift Example/GenesisSwift Example.xcodeproj/project.pbxproj index 9bf97d6..15621ad 100644 --- a/GenesisSwift Example/GenesisSwift Example.xcodeproj/project.pbxproj +++ b/GenesisSwift Example/GenesisSwift Example.xcodeproj/project.pbxproj @@ -599,7 +599,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.inapppayments; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -631,7 +631,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.inapppayments; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/GenesisSwift.podspec b/GenesisSwift.podspec index c9e9040..e1a760c 100755 --- a/GenesisSwift.podspec +++ b/GenesisSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "GenesisSwift" - s.version = "1.5.1" + s.version = "1.5.2" s.summary = "iOS Genesis Payment Gateway" s.description = "The iOS Genesis Payment Gateway Swift SDK." s.homepage = "https://github.com/GenesisGateway/ios_sdk.git" diff --git a/GenesisSwift.xcodeproj/project.pbxproj b/GenesisSwift.xcodeproj/project.pbxproj index 3cec8ab..24a258b 100644 --- a/GenesisSwift.xcodeproj/project.pbxproj +++ b/GenesisSwift.xcodeproj/project.pbxproj @@ -30,6 +30,7 @@ 2ED2D434206D10ED00C792C8 /* RequiredParametersValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2ED2D433206D10ED00C792C8 /* RequiredParametersValidator.swift */; }; 2EF574FD206BA0BD00C91DEA /* RequiredParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EF574FC206BA0BD00C91DEA /* RequiredParameters.swift */; }; 2EF57501206BCEB200C91DEA /* ParametersRegex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EF57500206BCEB200C91DEA /* ParametersRegex.swift */; }; + 56319FBB2CC8E71700F6F77D /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56319FBA2CC8E71700F6F77D /* Utils.swift */; }; 56AFF29A28FD784F000C6720 /* RecurringParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFF29428FD784F000C6720 /* RecurringParams.swift */; }; 56AFF29B28FD784F000C6720 /* MerchantRiskParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFF29528FD784F000C6720 /* MerchantRiskParams.swift */; }; 56AFF29C28FD784F000C6720 /* CardHolderAccountParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFF29628FD784F000C6720 /* CardHolderAccountParams.swift */; }; @@ -98,6 +99,7 @@ 2ED2D433206D10ED00C792C8 /* RequiredParametersValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequiredParametersValidator.swift; sourceTree = ""; }; 2EF574FC206BA0BD00C91DEA /* RequiredParameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequiredParameters.swift; sourceTree = ""; }; 2EF57500206BCEB200C91DEA /* ParametersRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersRegex.swift; sourceTree = ""; }; + 56319FBA2CC8E71700F6F77D /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 56AFF29428FD784F000C6720 /* RecurringParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecurringParams.swift; sourceTree = ""; }; 56AFF29528FD784F000C6720 /* MerchantRiskParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MerchantRiskParams.swift; sourceTree = ""; }; 56AFF29628FD784F000C6720 /* CardHolderAccountParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardHolderAccountParams.swift; sourceTree = ""; }; @@ -264,6 +266,7 @@ 735425761F9F4E7D00C78058 /* PaymentTransactionTypeTest.swift */, 2D13FB4D1FBD0AD500E0E529 /* XMLRespose.xml */, 2E6B8F73205812CE00444D4B /* StringTests.swift */, + 56319FBA2CC8E71700F6F77D /* Utils.swift */, ); path = GenesisSwiftTests; sourceTree = ""; @@ -508,6 +511,7 @@ 7354257D1F9F4E7D00C78058 /* PaymentTransactionTypeTest.swift in Sources */, 2D13FA9A1FB24F2500E0E529 /* CurrencyTest.swift in Sources */, 2E6B8F74205812CE00444D4B /* StringTests.swift in Sources */, + 56319FBB2CC8E71700F6F77D /* Utils.swift in Sources */, 2ED2874B2040573F00B530B6 /* CredentialsTest.swift in Sources */, 2E9D2C4A204833240009FD06 /* GenesisTest.swift in Sources */, 7354257C1F9F4E7D00C78058 /* PaymentAddressTests.swift in Sources */, @@ -669,7 +673,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++14"; ONLY_ACTIVE_ARCH = NO; @@ -707,7 +711,7 @@ "@executable_path/Frameworks", "@loader_path/Frameworks", ); - MARKETING_VERSION = 1.5.1; + MARKETING_VERSION = 1.5.2; MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++14"; OTHER_LDFLAGS = ""; diff --git a/GenesisSwift.xcodeproj/xcshareddata/xcschemes/GenesisSwiftTests.xcscheme b/GenesisSwift.xcodeproj/xcshareddata/xcschemes/GenesisSwiftTests.xcscheme index 4a0a165..4e97d6f 100644 --- a/GenesisSwift.xcodeproj/xcshareddata/xcschemes/GenesisSwiftTests.xcscheme +++ b/GenesisSwift.xcodeproj/xcshareddata/xcschemes/GenesisSwiftTests.xcscheme @@ -10,7 +10,9 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + language = "en" + region = "US"> diff --git a/GenesisSwift/Private/Models/DynamicDescriptorParams.swift b/GenesisSwift/Private/Models/DynamicDescriptorParams.swift index bd502d8..906d8cb 100644 --- a/GenesisSwift/Private/Models/DynamicDescriptorParams.swift +++ b/GenesisSwift/Private/Models/DynamicDescriptorParams.swift @@ -8,13 +8,73 @@ import Foundation public struct DynamicDescriptorParams { public let merchantName: String? public let merchantCity: String? + public let merchantCountry: String? + public let merchantState: String? + public let merchantZipCode: String? + public let merchantAddress: String? + public let merchantUrl: String? + public let merchantPhone: String? + public let merchantServiceCity: String? + public let merchantServiceCountry: String? + public let merchantServiceState: String? + public let merchantServiceZipCode: String? + public let merchantServicePhone: String? public let subMerchantId: String? + public let merchantGeoCoordinates: String? + public let merchantServiceGeoCoordinates: String? + + public init(merchantName: String? = nil, + merchantCity: String? = nil, + merchantCountry: String? = nil, + merchantState: String? = nil, + merchantZipCode: String? = nil, + merchantAddress: String? = nil, + merchantUrl: String? = nil, + merchantPhone: String? = nil, + merchantServiceCity: String? = nil, + merchantServiceCountry: String? = nil, + merchantServiceState: String? = nil, + merchantServiceZipCode: String? = nil, + merchantServicePhone: String? = nil, + subMerchantId: String? = nil, + merchantGeoCoordinates: String? = nil, + merchantServiceGeoCoordinates: String? = nil) { + self.merchantName = merchantName + self.merchantCity = merchantCity + self.merchantCountry = merchantCountry + self.merchantState = merchantState + self.merchantZipCode = merchantZipCode + self.merchantAddress = merchantAddress + self.merchantUrl = merchantUrl + self.merchantPhone = merchantPhone + self.merchantServiceCity = merchantServiceCity + self.merchantServiceCountry = merchantServiceCountry + self.merchantServiceState = merchantServiceState + self.merchantServiceZipCode = merchantServiceZipCode + self.merchantServicePhone = merchantServicePhone + self.subMerchantId = subMerchantId + self.merchantGeoCoordinates = merchantGeoCoordinates + self.merchantServiceGeoCoordinates = merchantServiceGeoCoordinates + } subscript(key: String) -> Any? { switch key { case PropertyKeys.MerchantNameKey: return merchantName case PropertyKeys.MerchantCityKey: return merchantCity + case PropertyKeys.MerchantCountryKey: return merchantCountry + case PropertyKeys.MerchantStateKey: return merchantState + case PropertyKeys.MerchantZipCodeKey: return merchantZipCode + case PropertyKeys.MerchantAddressKey: return merchantAddress + case PropertyKeys.MerchantUrlKey: return merchantUrl + case PropertyKeys.MerchantPhoneKey: return merchantPhone + case PropertyKeys.MerchantServiceCityKey: return merchantServiceCity + case PropertyKeys.MerchantServiceCountryKey: return merchantServiceCountry + case PropertyKeys.MerchantServiceStateKey: return merchantServiceState + case PropertyKeys.MerchantServiceZipCodeKey: return merchantServiceZipCode + case PropertyKeys.MerchantServicePhoneKey: return merchantServicePhone case PropertyKeys.SubMerchantIdKey: return subMerchantId + case PropertyKeys.MerchantGeoCoordinatesKeys: return merchantGeoCoordinates + case PropertyKeys.MerchantServiceGeoCoordinatesKey: return merchantServiceGeoCoordinates default: return nil } } @@ -30,16 +90,30 @@ extension DynamicDescriptorParams: GenesisDescriptionProtocol { // MARK: - GenesisXmlObjectProtocol extension DynamicDescriptorParams: GenesisXmlObjectProtocol { func propertyMap() -> [String: String] { - [PropertyKeys.MerchantNameKey: "mechant_name", + [PropertyKeys.MerchantNameKey: "merchant_name", PropertyKeys.MerchantCityKey: "merchant_city", - PropertyKeys.SubMerchantIdKey: "sub_merchant_id"] + PropertyKeys.MerchantCountryKey: "merchant_country", + PropertyKeys.MerchantStateKey: "merchant_state", + PropertyKeys.MerchantZipCodeKey: "merchant_zip_code", + PropertyKeys.MerchantAddressKey: "merchant_address", + PropertyKeys.MerchantUrlKey: "merchant_url", + PropertyKeys.MerchantPhoneKey: "merchant_phone", + PropertyKeys.MerchantServiceCityKey: "merchant_service_city", + PropertyKeys.MerchantServiceCountryKey: "merchant_service_country", + PropertyKeys.MerchantServiceStateKey: "merchant_service_state", + PropertyKeys.MerchantServiceZipCodeKey: "merchant_service_zip_code", + PropertyKeys.MerchantServicePhoneKey: "merchant_service_phone", + PropertyKeys.SubMerchantIdKey: "sub_merchant_id", + PropertyKeys.MerchantGeoCoordinatesKeys: "merchant_geo_coordinates", + PropertyKeys.MerchantServiceGeoCoordinatesKey: "merchant_service_geo_coordinates"] } func toXmlString() -> String { var xmlString = "" for (key, value) in propertyMap() { - guard let varValue = self[key] else { continue } - xmlString += "<\(value)>" + String(describing: varValue) + "" + if let varValue = self[key] { + xmlString += "<\(value)>" + String(describing: varValue) + "" + } } return xmlString } diff --git a/GenesisSwift/Validation/RequiredParameters.swift b/GenesisSwift/Validation/RequiredParameters.swift index 2c074e1..d44fe93 100644 --- a/GenesisSwift/Validation/RequiredParameters.swift +++ b/GenesisSwift/Validation/RequiredParameters.swift @@ -71,7 +71,20 @@ enum PropertyKeys { static let NameOfTheSupplierKey = "nameOfTheSupplier" static let MerchantNameKey = "merchantName" static let MerchantCityKey = "merchantCity" + static let MerchantCountryKey = "merchantCountry" + static let MerchantStateKey = "merchantState" + static let MerchantZipCodeKey = "merchantZipCode" + static let MerchantAddressKey = "merchantAddress" + static let MerchantUrlKey = "merchantUrl" + static let MerchantPhoneKey = "merchantPhone" + static let MerchantServiceCityKey = "merchantServiceCity" + static let MerchantServiceCountryKey = "merchantServiceCountry" + static let MerchantServiceStateKey = "merchantServiceState" + static let MerchantServiceZipCodeKey = "merchantServiceZipCode" + static let MerchantServicePhoneKey = "merchantServicePhone" static let SubMerchantIdKey = "subMerchantId" + static let MerchantGeoCoordinatesKeys = "merchantGeoCoordinates" + static let MerchantServiceGeoCoordinatesKey = "merchantServiceGeoCoordinates" static let RemindersKey = "reminders" static let ChannelKey = "channel" static let AfterKey = "after" diff --git a/GenesisSwiftTests/DynamicDescriptorParamsTests.swift b/GenesisSwiftTests/DynamicDescriptorParamsTests.swift index 7bbc91d..9dfcbf8 100644 --- a/GenesisSwiftTests/DynamicDescriptorParamsTests.swift +++ b/GenesisSwiftTests/DynamicDescriptorParamsTests.swift @@ -7,13 +7,6 @@ import XCTest @testable import GenesisSwift final class DynamicDescriptorParamsTests: XCTestCase { - - private var sut: DynamicDescriptorParams! - - override func tearDown() { - super.tearDown() - sut = nil - } } // MARK: - Tests @@ -21,30 +14,58 @@ final class DynamicDescriptorParamsTests: XCTestCase { extension DynamicDescriptorParamsTests { func testFullNames() { - sut = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: "fixed.city", subMerchantId: nil) - XCTAssertEqual(sut.merchantName, "fixed.name") - XCTAssertEqual(sut.merchantCity, "fixed.city") - XCTAssertNil(sut.subMerchantId) + let params = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: "fixed.city", subMerchantId: nil) + XCTAssertEqual(params.merchantName, "fixed.name") + XCTAssertEqual(params.merchantCity, "fixed.city") + XCTAssertNil(params.subMerchantId) } func testOnlyName() { - sut = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: nil, subMerchantId: nil) - XCTAssertEqual(sut.merchantName, "fixed.name") - XCTAssertNil(sut.merchantCity) - XCTAssertNil(sut.subMerchantId) + let params = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: nil, subMerchantId: nil) + XCTAssertEqual(params.merchantName, "fixed.name") + XCTAssertNil(params.merchantCity) + XCTAssertNil(params.subMerchantId) } func testOnlyCity() { - sut = DynamicDescriptorParams(merchantName: nil, merchantCity: "fixed.city", subMerchantId: nil) - XCTAssertNil(sut.merchantName) - XCTAssertEqual(sut.merchantCity, "fixed.city") - XCTAssertNil(sut.subMerchantId) + let params = DynamicDescriptorParams(merchantName: nil, merchantCity: "fixed.city", subMerchantId: nil) + XCTAssertNil(params.merchantName) + XCTAssertEqual(params.merchantCity, "fixed.city") + XCTAssertNil(params.subMerchantId) } func testOnlySubmerchantId() { - sut = DynamicDescriptorParams(merchantName: nil, merchantCity: nil, subMerchantId: "fixed.id") - XCTAssertNil(sut.merchantName) - XCTAssertNil(sut.merchantCity) - XCTAssertEqual(sut.subMerchantId, "fixed.id") + let params = DynamicDescriptorParams(merchantName: nil, merchantCity: nil, subMerchantId: "fixed.id") + XCTAssertNil(params.merchantName) + XCTAssertNil(params.merchantCity) + XCTAssertEqual(params.subMerchantId, "fixed.id") + } + + func testAllParameters() { + let params = DynamicDescriptorParams(merchantName: "John Doe", + merchantCity: "Dallas", + merchantCountry: "US", + merchantState: "TX", + merchantZipCode: "1024", + merchantAddress: "High Str. 1", + merchantUrl: "https://google.com", + merchantPhone: "1-555-01234", + merchantServiceCity: "Austin", + merchantServiceCountry: "US", + merchantServiceState: "TX", + merchantServiceZipCode: "1023", + merchantServicePhone: "1-555-12345", + subMerchantId: "12345", + merchantGeoCoordinates: "40.73061,-73.93524", + merchantServiceGeoCoordinates: "40.73061,-73.93524") + let xml = params.description() + + for (key, tagValue) in params.propertyMap() { + if let paramValue = params[key] as? String { + XCTAssertEqual(paramValue, Utils.xmlValue(inTag: tagValue, from: xml)) + } else { + XCTFail("Missing dynamic param value for tag: \(tagValue)") + } + } } } diff --git a/GenesisSwiftTests/PaymentRequestTests.swift b/GenesisSwiftTests/PaymentRequestTests.swift index 4e00109..c92d4f5 100644 --- a/GenesisSwiftTests/PaymentRequestTests.swift +++ b/GenesisSwiftTests/PaymentRequestTests.swift @@ -644,21 +644,11 @@ private extension PaymentRequestTests { let start = "Wrong value for " let end = "required parameter" - guard let params = valueBetween(start: start, end: end, in: errorMessage), !params.isEmpty else { return [] } + guard let params = Utils.valueBetween(start: start, end: end, in: errorMessage), !params.isEmpty else { return [] } return params.components(separatedBy: ", ").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) } } - func valueBetween(start: String, end: String, in text: String) -> String? { - guard let startIndex = text.range(of: start, options: .caseInsensitive)?.upperBound else { return nil } - guard let endIndex = text.range(of: end, options: .caseInsensitive)?.lowerBound else { return nil } - guard startIndex < endIndex else { return nil } - - return String(text[startIndex.. String? { - let startTag = "<\(tag)>" - let endTag = "" - return valueBetween(start: startTag, end: endTag, in: xml) + Utils.xmlValue(inTag: tag, from: xml) } } diff --git a/GenesisSwiftTests/Utils.swift b/GenesisSwiftTests/Utils.swift new file mode 100644 index 0000000..d0563c0 --- /dev/null +++ b/GenesisSwiftTests/Utils.swift @@ -0,0 +1,26 @@ +// +// Utils.swift +// GenesisSwiftTests +// +// Created by Ivaylo Hadzhiev on 23.10.24. +// Copyright © 2024 eMerchantPay. All rights reserved. +// + +import Foundation + +enum Utils { + + static func valueBetween(start: String, end: String, in text: String) -> String? { + guard let startIndex = text.range(of: start, options: .caseInsensitive)?.upperBound else { return nil } + guard let endIndex = text.range(of: end, options: .caseInsensitive)?.lowerBound else { return nil } + guard startIndex < endIndex else { return nil } + + return String(text[startIndex.. String? { + let startTag = "<\(tag)>" + let endTag = "" + return valueBetween(start: startTag, end: endTag, in: xml) + } +}