Skip to content

Commit

Permalink
1.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Yanakiev committed Apr 10, 2023
1 parent f295aef commit 43c1347
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 31 deletions.
12 changes: 10 additions & 2 deletions GenesisSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
56AFF29F28FD784F000C6720 /* ThreeDSV2Params.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56AFF29928FD784F000C6720 /* ThreeDSV2Params.swift */; };
56D38CFC2965B276007ECE0C /* ManagedRecurringParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56D38CFB2965B276007ECE0C /* ManagedRecurringParams.swift */; };
62D6D60C296FF70E00694F12 /* Recurring.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62D6D60B296FF70D00694F12 /* Recurring.swift */; };
62FAB49E29DAC77C0080ECAD /* PaymentSubtype.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62FAB49D29DAC77C0080ECAD /* PaymentSubtype.swift */; };
62FAB4A029DB0D550080ECAD /* BusinessAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 62FAB49F29DB0D550080ECAD /* BusinessAttributes.swift */; };
735425391F9F448100C78058 /* GenesisSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7354252F1F9F448100C78058 /* GenesisSwift.framework */; };
7354254C1F9F44F000C78058 /* GenesisXmlObjectProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7354254B1F9F44DE00C78058 /* GenesisXmlObjectProtocol.swift */; };
7354254D1F9F44F300C78058 /* DataProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7354254A1F9F44DE00C78058 /* DataProtocol.swift */; };
Expand Down Expand Up @@ -103,6 +105,8 @@
56AFF29928FD784F000C6720 /* ThreeDSV2Params.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ThreeDSV2Params.swift; sourceTree = "<group>"; };
56D38CFB2965B276007ECE0C /* ManagedRecurringParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManagedRecurringParams.swift; sourceTree = "<group>"; };
62D6D60B296FF70D00694F12 /* Recurring.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Recurring.swift; sourceTree = "<group>"; };
62FAB49D29DAC77C0080ECAD /* PaymentSubtype.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentSubtype.swift; sourceTree = "<group>"; };
62FAB49F29DB0D550080ECAD /* BusinessAttributes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BusinessAttributes.swift; sourceTree = "<group>"; };
7354252F1F9F448100C78058 /* GenesisSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = GenesisSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
735425331F9F448100C78058 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
735425381F9F448100C78058 /* GenesisSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GenesisSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -293,6 +297,7 @@
isa = PBXGroup;
children = (
56AFF29328FD784F000C6720 /* 3DSv2 */,
62FAB49F29DB0D550080ECAD /* BusinessAttributes.swift */,
2ED287482040517800B530B6 /* Credentials.swift */,
2D3908501FAD06F800CE5BCE /* Currency.swift */,
2D13FAAB1FB45D6900E0E529 /* GenesisConfiguration.swift */,
Expand All @@ -302,6 +307,7 @@
56D38CFB2965B276007ECE0C /* ManagedRecurringParams.swift */,
7354256F1F9F4E0700C78058 /* PaymentAddress.swift */,
735425711F9F4E2400C78058 /* PaymentRequest.swift */,
62FAB49D29DAC77C0080ECAD /* PaymentSubtype.swift */,
7354255F1F9F497B00C78058 /* PaymentTransactionType.swift */,
2E6B8F84205ABADA00444D4B /* Reconcile.swift */,
62D6D60B296FF70D00694F12 /* Recurring.swift */,
Expand Down Expand Up @@ -453,6 +459,7 @@
735425501F9F453500C78058 /* DynamicDescriptorParams.swift in Sources */,
735D00751F9F790C00994C17 /* IsoCountryCodes.swift in Sources */,
62D6D60C296FF70E00694F12 /* Recurring.swift in Sources */,
62FAB4A029DB0D550080ECAD /* BusinessAttributes.swift in Sources */,
56AFF29A28FD784F000C6720 /* RecurringParams.swift in Sources */,
7354255E1F9F493D00C78058 /* Extensions.swift in Sources */,
2E6B8F82205AACF000444D4B /* WPFResponse.swift in Sources */,
Expand All @@ -475,6 +482,7 @@
735425701F9F4E0800C78058 /* PaymentAddress.swift in Sources */,
2ED287492040517800B530B6 /* Credentials.swift in Sources */,
7354256C1F9F4DDB00C78058 /* RiskParams.swift in Sources */,
62FAB49E29DAC77C0080ECAD /* PaymentSubtype.swift in Sources */,
2D3908511FAD06F800CE5BCE /* Currency.swift in Sources */,
56D38CFC2965B276007ECE0C /* ManagedRecurringParams.swift in Sources */,
735425721F9F4E2500C78058 /* PaymentRequest.swift in Sources */,
Expand Down Expand Up @@ -643,7 +651,7 @@
INFOPLIST_FILE = "$(SRCROOT)/GenesisSwift/App/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.3.2;
MARKETING_VERSION = 1.3.3;
ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.GenesisSwift;
Expand Down Expand Up @@ -674,7 +682,7 @@
INFOPLIST_FILE = "$(SRCROOT)/GenesisSwift/App/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 1.3.2;
MARKETING_VERSION = 1.3.3;
OTHER_LDFLAGS = "";
PRODUCT_BUNDLE_IDENTIFIER = com.emerchantpay.GenesisSwift;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down
80 changes: 80 additions & 0 deletions GenesisSwift/Models/BusinessAttributes.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//
// BusinessAttributes.swift
// GenesisSwift
//
// Created by Georgi Yanakiev emerchantpay on 3.04.23.
// Copyright © 2023 eMerchantPay. All rights reserved.
//

import Foundation

public struct BusinessAttributes {

public let eventStartDate: Date?
public let eventEndDate: Date?
public let eventOrganizerId: String?
public let eventId: String?
public let dateOfOrder: Date?
public let deliveryDate: Date?
public let nameOfTheSupplier: String?

public init(eventStartDate: Date? = nil,
eventEndDate: Date? = nil,
eventOrganizerId: String? = nil,
eventId: String? = nil,
dateOfOrder: Date? = nil,
deliveryDate: Date? = nil,
nameOfTheSupplier: String? = nil) {

self.eventStartDate = eventStartDate
self.eventEndDate = eventEndDate
self.eventOrganizerId = eventOrganizerId
self.eventId = eventId
self.dateOfOrder = dateOfOrder
self.deliveryDate = deliveryDate
self.nameOfTheSupplier = nameOfTheSupplier
}

subscript(key: String) -> Any? {
switch key {
case EventStartDateKey: return eventStartDate
case EventEndDateKey: return eventEndDate
case EventOrganizerIdKey: return eventOrganizerId
case EventIdKey: return eventId
case DateOfOrderKey: return dateOfOrder
case DeliveryDateKey: return deliveryDate
case NameOfTheSupplierKey: return nameOfTheSupplier
default: return nil
}
}
}

//MARK: GenesisDescriptionProtocol
extension BusinessAttributes: GenesisDescriptionProtocol {
func description() -> String {
toXmlString()
}

}

// MARK: GenesisXmlObjectProtocol
extension BusinessAttributes: GenesisXmlObjectProtocol {
func propertyMap() -> [String : String] {
[EventStartDateKey: "event_start_date",
EventEndDateKey: "event_end_date",
EventOrganizerIdKey: "event_organizer_id",
EventIdKey: "event_id",
DateOfOrderKey: "date_of_order",
DeliveryDateKey: "delivery_date",
NameOfTheSupplierKey: "name_of_the_supplier"]
}

func toXmlString() -> String {
var xmlString = ""
for (key, value) in propertyMap() {
guard let varValue = self[key] else { continue }
xmlString += "<\(value)>" + String(describing: varValue) + "</\(value)>"
}
return xmlString
}
}
37 changes: 20 additions & 17 deletions GenesisSwift/Models/PaymentRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public final class PaymentRequest {
public var threeDSV2Params: ThreeDSV2Params?
public var recurringType: RecurringType?
public var recurringCategory: RecurringCategory?
public var paymentSubtype: PaymentSubtype?
public var paymentToken: String?
public var birthDate: Date?
public var documentId: String?
public var remoteIp: String?
public var businessAttributes: BusinessAttributes?
public var dynamicDescriptorParams: DynamicDescriptorParams?

public var additionalParameters: [String: String] = [:]

Expand All @@ -42,20 +49,6 @@ public final class PaymentRequest {
}
}

var merchantName: String? {
didSet {
assert(oldValue == nil, "Variable merchantName can be set only once!")
dynamicDescriptorParams = DynamicDescriptorParams(merchantName: merchantName, merchantCity: merchantCity)
}
}

var merchantCity: String? {
didSet {
assert(oldValue == nil, "Variable merchantCity can be set only once!")
dynamicDescriptorParams = DynamicDescriptorParams(merchantName: merchantName, merchantCity: merchantCity)
}
}

public var requires3DS: Bool {
// the request requires 3DS if any of its specified types require it
let types3DS: Set<TransactionName> = [.sale3d, .authorize3d, .initRecurringSale3d]
Expand All @@ -67,8 +60,6 @@ public final class PaymentRequest {
return false
}

private var dynamicDescriptorParams: DynamicDescriptorParams?

/// Default initialization
///
/// - Parameters:
Expand Down Expand Up @@ -126,6 +117,12 @@ public final class PaymentRequest {
case ConsumerId: return consumerId
case RecurringTypeKey: return recurringType
case RecurringCategoryKey: return recurringCategory
case PaymentSubtypeKey: return paymentSubtype
case PaymentTokenKey: return paymentToken
case BirthDateKey: return birthDate
case RemoteIpKey: return remoteIp
case DocumentIdKey: return documentId
case BusinessAttributesKey: return businessAttributes
default: return nil
}
}
Expand Down Expand Up @@ -159,7 +156,13 @@ extension PaymentRequest: GenesisXmlObjectProtocol {
ThreeDSV2ParamsKey: "threeds_v2_params",
DynamicDescriptorParamsKey: "dynamic_descriptor_params",
RecurringTypeKey: "recurring_type",
RecurringCategoryKey: "recurring_category"]
RecurringCategoryKey: "recurring_category",
BusinessAttributesKey: "business_attributes",
PaymentSubtypeKey: "payment_subtype",
PaymentTokenKey: "payment_token",
BirthDateKey: "birth_date",
RemoteIpKey: "remote_ip",
DocumentIdKey: "document_id"]
}

func toXmlString() -> String {
Expand Down
31 changes: 31 additions & 0 deletions GenesisSwift/Models/PaymentSubtype.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// PaymentSubtype.swift
// GenesisSwift
//
// Created by Georgi Yanakiev emerchantpay on 3.04.23.
// Copyright © 2023 eMerchantPay. All rights reserved.
//

public struct PaymentSubtype {

public enum TypeValues: String, CaseIterable {
case authorize
case sale
case initRecurringSale = "init_recurring_sale"
}

public let type: TypeValues

public init(type: TypeValues) {
self.type = type
}
}

// MARK: - GenesisDescriptionProtocol

extension PaymentSubtype: GenesisDescriptionProtocol, XMLConvertable {

func description() -> String {
type.rawValue
}
}
1 change: 1 addition & 0 deletions GenesisSwift/Models/PaymentTransactionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum TransactionName: String {
case containerStore = "container_store"
case neosurf
case klarnaAuthorize = "klarna_authorize"
case applePay = "apple_pay"
}

public final class PaymentTransactionType {
Expand Down
44 changes: 35 additions & 9 deletions GenesisSwift/Private/Models/DynamicDescriptorParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,44 @@

import Foundation

struct DynamicDescriptorParams {
let merchantName: String?
let merchantCity: String?
public struct DynamicDescriptorParams {
public let merchantName: String?
public let merchantCity: String?
public let subMerchantId: String?

var description: String {
var xmlString = ""
if (merchantName != nil) {
xmlString += "<merchant_name>" + merchantName! + "</merchant_name name>"
subscript(key: String) -> Any? {
switch key {
case MerchantNameKey: return merchantName
case MerchantCityKey: return merchantCity
case SubMerchantIdKey: return subMerchantId
default: return nil
}
if (merchantCity != nil) {
xmlString += "<merchant_city>" + merchantCity! + "</merchant_city>"
}
}

//MARK: GenesisDescriptionProtocol
extension DynamicDescriptorParams: GenesisDescriptionProtocol {
func description() -> String {
toXmlString()
}

}

// MARK: GenesisXmlObjectProtocol
extension DynamicDescriptorParams: GenesisXmlObjectProtocol {
func propertyMap() -> [String : String] {
[MerchantNameKey: "mechant_name",
MerchantCityKey: "merchant_city",
SubMerchantIdKey: "sub_merchant_id"]
}

func toXmlString() -> String {
var xmlString = ""
for (key, value) in propertyMap() {
guard let varValue = self[key] else { continue }
xmlString += "<\(value)>" + String(describing: varValue) + "</\(value)>"
}
return xmlString
}
}

21 changes: 21 additions & 0 deletions GenesisSwift/Validation/RequiredParameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@ let ManagedRecurringKey = "managedRecurring"
let RecurringTypeKey = "recurringType"
let RecurringCategoryKey = "recurringCategory"

let PaymentTokenKey = "paymentToken"
let PaymentSubtypeKey = "paymentSubtype"
let BirthDateKey = "birthDate"
let RemoteIpKey = "remoteIp"
let DocumentIdKey = "documentId"
let BusinessAttributesKey = "businessAttributes"
let EventStartDateKey = "eventStartDate"
let EventEndDateKey = "eventEndDate"
let EventOrganizerIdKey = "eventOrganizerId"
let EventIdKey = "eventId"
let DateOfOrderKey = "dateOfOrder"
let DeliveryDateKey = "deliveryDate"
let NameOfTheSupplierKey = "nameOfTheSupplier"
let MerchantNameKey = "merchantName"
let MerchantCityKey = "merchantCity"
let SubMerchantIdKey = "subMerchantId"

enum PropertyKeys {

// 3DSv2 parameters' keys
Expand Down Expand Up @@ -129,6 +146,10 @@ enum RequiredParameters {
requiredParameters.append(RecurringCategoryKey)
}

if [.applePay].contains(transactionName) {
requiredParameters.append(contentsOf: [PaymentTokenKey, PaymentSubtypeKey, BirthDateKey, RemoteIpKey, DocumentIdKey, BusinessAttributesKey])
}

return requiredParameters
}
}
16 changes: 13 additions & 3 deletions GenesisSwiftTests/DynamicDescriptorParamsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,30 @@ class DynamicDescriptorParamsTests: XCTestCase {
}

func testFullNames() {
sut = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: "fixed.city")
sut = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: "fixed.city", subMerchantId: nil)
XCTAssertEqual(sut.merchantName, "fixed.name")
XCTAssertEqual(sut.merchantCity, "fixed.city")
XCTAssertEqual(sut.subMerchantId, nil)
}

func testOnlyName() {
sut = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: nil)
sut = DynamicDescriptorParams(merchantName: "fixed.name", merchantCity: nil, subMerchantId: nil)
XCTAssertEqual(sut.merchantName, "fixed.name")
XCTAssertEqual(sut.merchantCity, nil)
XCTAssertEqual(sut.subMerchantId, nil)
}

func testOnlyCity() {
sut = DynamicDescriptorParams(merchantName: nil, merchantCity: "fixed.city")
sut = DynamicDescriptorParams(merchantName: nil, merchantCity: "fixed.city", subMerchantId: nil)
XCTAssertEqual(sut.merchantName, nil)
XCTAssertEqual(sut.merchantCity, "fixed.city")
XCTAssertEqual(sut.subMerchantId, nil)
}

func testOnlySubmerchantId() {
sut = DynamicDescriptorParams(merchantName: nil, merchantCity: nil, subMerchantId: "fixed.id")
XCTAssertEqual(sut.merchantName, nil)
XCTAssertEqual(sut.merchantCity, nil)
XCTAssertEqual(sut.subMerchantId, "fixed.id")
}
}
Loading

0 comments on commit 43c1347

Please sign in to comment.