Skip to content

Commit

Permalink
1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
emp-ivaylohadzhiev committed Jul 29, 2024
1 parent 2555170 commit c3733af
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.5.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -564,6 +565,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 1.5.1;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -597,7 +599,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.inapppayments;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -629,7 +631,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.inapppayments;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ private extension HomeTableViewController {
}

@IBAction func privacyPolicyButtonPressed() {
openURLString(urlString: "https://www.genesissupport247.com/privacy-policy/")
openURLString("https://www.genesissupport247.com/privacy-policy/")
}

@IBAction func termsAndConditionsButtonPressed() {
openURLString(urlString: "https://www.genesissupport247.com/terms-conditions/")
openURLString("https://www.genesissupport247.com/terms-conditions/")
}

func openURLString(urlString: String) {
func openURLString(_ urlString: String) {
if let url = URL(string: urlString), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ extension TransactionDetailsViewController: GenesisDelegate {
}

func genesisDidEndWithSuccess(userInfo: [AnyHashable: Any]) {
let uniqueId = userInfo[GenesisInfoKeys.uniqueId]!
presentAlertWithTitle("Success", andMessage: "Success transaction: \(uniqueId)")
if let uniqueId = userInfo[GenesisInfoKeys.uniqueId] {
presentAlertWithTitle("Success", andMessage: "Success transaction: \(uniqueId)")
}
}

func genesisDidEndWithFailure(userInfo: [AnyHashable: Any], errorCode: GenesisError) {
Expand Down
55 changes: 39 additions & 16 deletions GenesisSwift Example/iOS Example/Sources/Model/InputData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,11 @@ public final class InputData: NSObject {
value: Date().dateBySubstracting(2, from: .year)!.iso8601Date,
regex: Regex.date)
private(set) lazy var recurringType = PickerData(title: Titles.recurringType.rawValue,
value: RecurringType.TypeValues.initial.rawValue,
items: RecurringType.TypeValues.allCases
.map { EnumPickerItem($0.rawValue) })
value: RecurringTypePickerValues.notAvailable.rawValue,
items: RecurringTypePickerValues.allCases.map { EnumPickerItem($0.rawValue) })
private(set) lazy var recurringCategory = PickerData(title: Titles.recurringCategory.rawValue,
value: RecurringCategory.CategoryValues.subscription.rawValue,
items: RecurringCategory.CategoryValues.allCases
.map { EnumPickerItem($0.rawValue) })
value: RecurringCategoryPickerValues.notAvailable.rawValue,
items: RecurringCategoryPickerValues.allCases.map { EnumPickerItem($0.rawValue) })

private var defaultObjects: [ObjectDataProtocol] {
var all: [ObjectDataProtocol] = [transactionId, amount, currency, usage, customerEmail, customerPhone,
Expand Down Expand Up @@ -405,6 +403,29 @@ extension InputData {
case automatic
case manual
}

enum RecurringTypePickerValues: String, CaseIterable {
case notAvailable = "N/A"
case initial
case managed
case subsequent

var recurringType: RecurringType? {
guard let type = RecurringType.TypeValues(rawValue: rawValue) else { return nil }
return RecurringType(type: type)
}
}

enum RecurringCategoryPickerValues: String, CaseIterable {
case notAvailable = "N/A"
case subscription
case standingOrder = "standing_order"

var recurringCategory: RecurringCategory? {
guard let category = RecurringCategory.CategoryValues(rawValue: rawValue) else { return nil }
return RecurringCategory(category: category)
}
}
}

private extension InputData {
Expand Down Expand Up @@ -525,13 +546,19 @@ extension InputData {
}

var recurringTypeValue: RecurringType? {
let recurringType = RecurringType(type: RecurringType.TypeValues(rawValue: recurringType.value) ?? .initial)

return [.authorize, .authorize3d, .sale, .sale3d].contains(transactionName) ? recurringType : nil
if [.authorize, .authorize3d, .sale, .sale3d].contains(transactionName) {
return RecurringTypePickerValues(rawValue: recurringType.value)?.recurringType
} else {
return nil
}
}

var recurringCategoryValue: RecurringCategory {
RecurringCategory(category: RecurringCategory.CategoryValues(rawValue: recurringCategory.value) ?? .subscription)
var recurringCategoryValue: RecurringCategory? {
if [.initRecurringSale, .initRecurringSale3d].contains(transactionName) {
return RecurringCategoryPickerValues(rawValue: recurringCategory.value)?.recurringCategory
} else {
return nil
}
}

var lifetimeValue: Int {
Expand Down Expand Up @@ -568,8 +595,8 @@ extension InputData {
transactionTypes: [paymentTransactionType],
notificationUrl: notificationUrl.value)
paymentRequest.usage = usage.value

paymentRequest.lifetime = lifetimeValue
paymentRequest.recurringCategory = recurringCategoryValue

if let payLaterValue, payLaterValue {
paymentRequest.payLater = payLaterValue
Expand All @@ -580,10 +607,6 @@ extension InputData {
paymentRequest.threeDSV2Params = threeDSParams
}

if paymentRequest.requiresRecurringCategory {
paymentRequest.recurringCategory = recurringCategoryValue
}

if paymentRequest.requiresPaymentSubtype {
paymentRequest.paymentSubtype = paymentSubtypeValue
}
Expand Down
28 changes: 22 additions & 6 deletions GenesisSwift Example/iOS Example/Tests/InputDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,38 @@ extension InputDataTests {
XCTAssertTrue(data.supportsRecurringType)
var request = data.createPaymentRequest()
for type in request.transactionTypes {
XCTAssertNotNil(type.recurringType)
XCTAssertNil(type.recurringType) // not set explicitly
}
data.recurringType.value = InputData.RecurringTypePickerValues.initial.rawValue
request = data.createPaymentRequest()
for type in request.transactionTypes {
XCTAssertNotNil(type.recurringType) // set explicitly
}

data = InputData(transactionName: .sale3d)
XCTAssertTrue(data.supportsRecurringType)
request = data.createPaymentRequest()
for type in request.transactionTypes {
XCTAssertNotNil(type.recurringType)
XCTAssertNil(type.recurringType) // not set explicitly
}
data.recurringType.value = InputData.RecurringTypePickerValues.subsequent.rawValue
request = data.createPaymentRequest()
for type in request.transactionTypes {
XCTAssertNotNil(type.recurringType) // set explicitly
}

data = InputData(transactionName: .authorize)
XCTAssertTrue(data.supportsRecurringType)
request = data.createPaymentRequest()
for type in request.transactionTypes {
XCTAssertNotNil(type.recurringType)
XCTAssertNil(type.recurringType) // not set explicitly
}

data = InputData(transactionName: .authorize3d)
XCTAssertTrue(data.supportsRecurringType)
request = data.createPaymentRequest()
for type in request.transactionTypes {
XCTAssertNotNil(type.recurringType)
XCTAssertNil(type.recurringType) // not set explicitly
}

data = InputData(transactionName: .initRecurringSale)
Expand Down Expand Up @@ -147,12 +157,18 @@ extension InputDataTests {
var data = InputData(transactionName: .initRecurringSale)
XCTAssertTrue(data.supportsRecurringCategory)
var request = data.createPaymentRequest()
XCTAssertNotNil(request.recurringCategory)
XCTAssertNil(request.recurringCategory) // not set explicitly
data.recurringCategory.value = InputData.RecurringCategoryPickerValues.subscription.rawValue
request = data.createPaymentRequest()
XCTAssertNotNil(request.recurringCategory) // set explicitly

data = InputData(transactionName: .initRecurringSale3d)
XCTAssertTrue(data.supportsRecurringCategory)
request = data.createPaymentRequest()
XCTAssertNotNil(request.recurringCategory)
XCTAssertNil(request.recurringCategory) // not set explicitly
data.recurringCategory.value = InputData.RecurringCategoryPickerValues.standingOrder.rawValue
request = data.createPaymentRequest()
XCTAssertNotNil(request.recurringCategory) // set explicitly

data = InputData(transactionName: .sale)
XCTAssertFalse(data.supportsRecurringCategory)
Expand Down
25 changes: 24 additions & 1 deletion GenesisSwift Example/iOS Example/Tests/PickerDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ import XCTest
@testable import GenesisSwift

class PickerDataTests: XCTestCase {

private var sut: PickerData!

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

// MARK: - Tests

extension PickerDataTests {

func testPickerData() {
let item1 = IsoCountryInfo(name: "item1.name", numeric: "item1.numeric", alpha2: "item1.alpha2", alpha3: "item1.alpha3",
calling: "item1.calling", currency: "item1.currency", continent: "item1.continent")
Expand All @@ -28,4 +37,18 @@ class PickerDataTests: XCTestCase {
XCTAssertEqual(sut.items[1].pickerTitle, item2.name.rawValue)
XCTAssertEqual(sut.items[1].pickerValue, item2.name.rawValue)
}

func testRecurringParamsConversion() {

XCTAssertNil(InputData.RecurringTypePickerValues.notAvailable.recurringType)
XCTAssertEqual(InputData.RecurringTypePickerValues.initial.recurringType?.type, RecurringType.TypeValues.initial)
XCTAssertEqual(InputData.RecurringTypePickerValues.managed.recurringType?.type, RecurringType.TypeValues.managed)
XCTAssertEqual(InputData.RecurringTypePickerValues.subsequent.recurringType?.type, RecurringType.TypeValues.subsequent)

XCTAssertNil(InputData.RecurringCategoryPickerValues.notAvailable.recurringCategory)
XCTAssertEqual(InputData.RecurringCategoryPickerValues.standingOrder.recurringCategory?.category,
RecurringCategory.CategoryValues.standingOrder)
XCTAssertEqual(InputData.RecurringCategoryPickerValues.subscription.recurringCategory?.category,
RecurringCategory.CategoryValues.subscription)
}
}
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.0"
s.version = "1.5.1"
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
6 changes: 3 additions & 3 deletions GenesisSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -669,7 +669,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
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 +707,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.5.0;
MARKETING_VERSION = 1.5.1;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++14";
OTHER_LDFLAGS = "";
Expand Down
2 changes: 1 addition & 1 deletion GenesisSwift/Models/KlarnaItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension KlarnaItem: ValidateInputDataProtocol {
public func isValidData() throws {
let requiredParameters = RequiredParameters.requiredParametersForKlarnaItem()
let validator = RequiredParametersValidator(withRequiredParameters: requiredParameters)
try validator.isValidKlarnaItem(item: self)
try validator.validateKlarnaItem(self)
}
}

Expand Down
3 changes: 1 addition & 2 deletions GenesisSwift/Models/PaymentAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ extension PaymentAddress: ValidateInputDataProtocol {
public func isValidData() throws {
let requiredParameters = RequiredParameters.requiredParametersForAddress()
let validator = RequiredParametersValidator(withRequiredParameters: requiredParameters)

try validator.isValidAddress(address: self)
try validator.validateAddress(self)
}
}

Expand Down
14 changes: 7 additions & 7 deletions GenesisSwift/Models/PaymentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public final class PaymentRequest {
}

public var requiresRecurringType: Bool {
// the request requires RecurringType if any of its specified types require it
let requiredTypes: Set<TransactionName> = [.sale, .sale3d, .authorize, .authorize3d]
return isParameterRequired(for: requiredTypes)
// .sale, .sale3d, .authorize & .authorize3d may contain a recurring type parameter, but it is not required
// retain for backward compatibility and future requirements' changes
false
}

public var requiresRecurringCategory: Bool {
// the request requires RecurringCategory if any of its specified types require it
let requiredTypes: Set<TransactionName> = [.initRecurringSale, .initRecurringSale3d]
return isParameterRequired(for: requiredTypes)
// .initRecurringSale & .initRecurringSale3d may contain a recurring category parameter, but it is not required
// retain for backward compatibility and future requirements' changes
false
}

public var requiresPaymentSubtype: Bool {
Expand Down Expand Up @@ -263,7 +263,7 @@ extension PaymentRequest: ValidateInputDataProtocol {
let requiredParameters = RequiredParameters.requiredParametersForRequest(paymentRequest: self)
let validator = RequiredParametersValidator(withRequiredParameters: requiredParameters)

try validator.isValidRequest(request: self)
try validator.validateRequest(self)
}
}

Expand Down
5 changes: 2 additions & 3 deletions GenesisSwift/Models/PaymentTransactionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,9 @@ public final class PaymentTransactionType {
extension PaymentTransactionType: ValidateInputDataProtocol {

public func isValidData() throws {
let requiredParameters = RequiredParameters.requiredParametersForTransactionType(transactionType: self)
let requiredParameters = RequiredParameters.requiredParametersForTransactionType(self)
let validator = RequiredParametersValidator(withRequiredParameters: requiredParameters)

try validator.isValidTransactionType(transactionType: self)
try validator.validateTransactionType(self)
}
}

Expand Down
3 changes: 1 addition & 2 deletions GenesisSwift/Models/Reminder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ extension Reminder: ValidateInputDataProtocol {
public func isValidData() throws {
let requiredParamters = RequiredParameters.requiredParametersForReminder()
let validator = RequiredParametersValidator(withRequiredParameters: requiredParamters)

try validator.isValidReminder(reminder: self)
try validator.validateReminder(self)
}
}
18 changes: 7 additions & 11 deletions GenesisSwift/Protocols/String+Conversion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ import Foundation
public extension String {

func explicitConvertionToDecimal() -> Decimal? {
struct StaticFormatter {
static let formatter: NumberFormatter = {
let tmpFormatter = NumberFormatter()
tmpFormatter.generatesDecimalNumbers = true
tmpFormatter.numberStyle = NumberFormatter.Style.decimal
return tmpFormatter
enum StaticFormatter {
static let decimalFormatter: NumberFormatter = {
let formatter = NumberFormatter()
formatter.generatesDecimalNumbers = true
formatter.numberStyle = .decimal
return formatter
}()
}

if let decimalNumber = StaticFormatter.formatter.number(from: self) as? Decimal {
return decimalNumber
}

return nil
return StaticFormatter.decimalFormatter.number(from: self) as? Decimal
}
}
Loading

0 comments on commit c3733af

Please sign in to comment.