Skip to content

Commit

Permalink
1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
emp-ivaylohadzhiev committed Oct 31, 2024
1 parent c3733af commit 183a5b5
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion GenesisSwift.podspec
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 6 additions & 2 deletions GenesisSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -98,6 +99,7 @@
2ED2D433206D10ED00C792C8 /* RequiredParametersValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequiredParametersValidator.swift; sourceTree = "<group>"; };
2EF574FC206BA0BD00C91DEA /* RequiredParameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequiredParameters.swift; sourceTree = "<group>"; };
2EF57500206BCEB200C91DEA /* ParametersRegex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParametersRegex.swift; sourceTree = "<group>"; };
56319FBA2CC8E71700F6F77D /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
56AFF29428FD784F000C6720 /* RecurringParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecurringParams.swift; sourceTree = "<group>"; };
56AFF29528FD784F000C6720 /* MerchantRiskParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MerchantRiskParams.swift; sourceTree = "<group>"; };
56AFF29628FD784F000C6720 /* CardHolderAccountParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardHolderAccountParams.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -264,6 +266,7 @@
735425761F9F4E7D00C78058 /* PaymentTransactionTypeTest.swift */,
2D13FB4D1FBD0AD500E0E529 /* XMLRespose.xml */,
2E6B8F73205812CE00444D4B /* StringTests.swift */,
56319FBA2CC8E71700F6F77D /* Utils.swift */,
);
path = GenesisSwiftTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "YES"
language = "en"
region = "US">
<Testables>
<TestableReference
skipped = "NO">
Expand Down
82 changes: 78 additions & 4 deletions GenesisSwift/Private/Models/DynamicDescriptorParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand All @@ -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) + "</\(value)>"
if let varValue = self[key] {
xmlString += "<\(value)>" + String(describing: varValue) + "</\(value)>"
}
}
return xmlString
}
Expand Down
13 changes: 13 additions & 0 deletions GenesisSwift/Validation/RequiredParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
67 changes: 44 additions & 23 deletions GenesisSwiftTests/DynamicDescriptorParamsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,65 @@ import XCTest
@testable import GenesisSwift

final class DynamicDescriptorParamsTests: XCTestCase {

private var sut: DynamicDescriptorParams!

override func tearDown() {
super.tearDown()
sut = nil
}
}

// MARK: - Tests

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)")
}
}
}
}
14 changes: 2 additions & 12 deletions GenesisSwiftTests/PaymentRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<endIndex])
}

func xmlValue(inTag tag: String, from xml: String) -> String? {
let startTag = "<\(tag)>"
let endTag = "</\(tag)>"
return valueBetween(start: startTag, end: endTag, in: xml)
Utils.xmlValue(inTag: tag, from: xml)
}
}
26 changes: 26 additions & 0 deletions GenesisSwiftTests/Utils.swift
Original file line number Diff line number Diff line change
@@ -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..<endIndex])
}

static func xmlValue(inTag tag: String, from xml: String) -> String? {
let startTag = "<\(tag)>"
let endTag = "</\(tag)>"
return valueBetween(start: startTag, end: endTag, in: xml)
}
}

0 comments on commit 183a5b5

Please sign in to comment.