Skip to content

Commit

Permalink
Merge pull request #132 in MI/yandex-checkout-payments-swift from rel…
Browse files Browse the repository at this point in the history
…ease/3.5.0 to master

* commit '92e72fc6e1baf7832801d5c449252abdb7348e94':
  [MOC-509] Handle TMX errors as new session_id
  • Loading branch information
AutoMergeBot authored and AutoMergeBot committed May 1, 2020
2 parents 6151a41 + 92e72fc commit 686b9cb
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 64 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Changelog

### 3.4.0
### 3.5.0

1. Исправили проблему с работой TMX.
1. Исправили возможные проблемы с получением токена.

### 3.3.0

Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PODS:
- Reveal-SDK (24)
- SwiftLint (0.34.0)
- When (4.0.0)
- YandexCheckoutPayments (3.4.0):
- YandexCheckoutPayments (3.5.0):
- FunctionalSwift (~> 1.1.0)
- When (~> 4.0.0)
- YandexCheckoutPaymentsApi (~> 1.8.0)
Expand Down Expand Up @@ -63,7 +63,7 @@ SPEC CHECKSUMS:
Reveal-SDK: 5d7e56b8f018c0a88b3a2c10bf68d598bbd3b071
SwiftLint: 79d48a17c6565dc286c37efb8322c7b450f95c67
When: 4ffc88d535a094ad4bd5eaf2fd187de747e716d1
YandexCheckoutPayments: a70c8878b072e3dc6988b7d9aa5b0ce766229a16
YandexCheckoutPayments: fe888ebd8523848ca83fc51dca10d399e0c163f1
YandexCheckoutPaymentsApi: fbe102bbfbab08a83da1a428a37f3d4b4bc1c28e
YandexCheckoutShowcaseApi: 44382163176b3a53692fa1c3b85c0c8d0a82b7e6
YandexCheckoutWalletApi: 5d2774cd1216ee0ce47d6412184008b37caeaeac
Expand Down
2 changes: 1 addition & 1 deletion YandexCheckoutPayments.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'YandexCheckoutPayments'
s.version = '3.4.0'
s.version = '3.5.0'
s.homepage = 'https://github.com/yandex-money/yandex-checkout-payments-swift'
s.license = {
:type => "MIT",
Expand Down
45 changes: 32 additions & 13 deletions YandexCheckoutPayments.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

/* Begin PBXBuildFile section */
301D747F20B5D7E60000E394 /* PassKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 301D747E20B5D7E60000E394 /* PassKit.framework */; };
3031D7972420EF57002D0EED /* TMXProfiling.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D7932420EEEF002D0EED /* TMXProfiling.framework */; };
3031D7982420EF57002D0EED /* TMXProfiling.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D7932420EEEF002D0EED /* TMXProfiling.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3031D79B2420EF79002D0EED /* TMXProfilingConnections.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D79A2420EF79002D0EED /* TMXProfilingConnections.framework */; };
3031D79C2420EF79002D0EED /* TMXProfilingConnections.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D79A2420EF79002D0EED /* TMXProfilingConnections.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
303FD05A21B92EC900CE82B4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 303FD05D21B92EC900CE82B4 /* InfoPlist.strings */; };
303FD05B21B92EC900CE82B4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 303FD05D21B92EC900CE82B4 /* InfoPlist.strings */; };
305DF8D2245C2754009CAE58 /* TMXProfiling.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D7932420EEEF002D0EED /* TMXProfiling.framework */; };
305DF8D3245C2754009CAE58 /* TMXProfiling.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D7932420EEEF002D0EED /* TMXProfiling.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
305DF8FE245C2FCD009CAE58 /* TMXProfilingConnections.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D79A2420EF79002D0EED /* TMXProfilingConnections.framework */; };
305DF8FF245C2FCD009CAE58 /* TMXProfilingConnections.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3031D79A2420EF79002D0EED /* TMXProfilingConnections.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3089EF4923846F6300CB7319 /* SwitcherSavePaymentMethodViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3089EF4823846F6300CB7319 /* SwitcherSavePaymentMethodViewModel.swift */; };
3089EF4B23846F6C00CB7319 /* StrictSavePaymentMethodViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3089EF4A23846F6C00CB7319 /* StrictSavePaymentMethodViewModel.swift */; };
3089EF4D23846F7400CB7319 /* SavePaymentMethodViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3089EF4C23846F7400CB7319 /* SavePaymentMethodViewModel.swift */; };
Expand Down Expand Up @@ -656,14 +656,14 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
3031D7992420EF57002D0EED /* Embed Frameworks */ = {
305DF8D4245C2754009CAE58 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
3031D7982420EF57002D0EED /* TMXProfiling.framework in Embed Frameworks */,
3031D79C2420EF79002D0EED /* TMXProfilingConnections.framework in Embed Frameworks */,
305DF8D3245C2754009CAE58 /* TMXProfiling.framework in Embed Frameworks */,
305DF8FF245C2FCD009CAE58 /* TMXProfilingConnections.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1174,9 +1174,9 @@
buildActionMask = 2147483647;
files = (
E011A09D20725BC200B786B5 /* MessageUI.framework in Frameworks */,
3031D7972420EF57002D0EED /* TMXProfiling.framework in Frameworks */,
305DF8D2245C2754009CAE58 /* TMXProfiling.framework in Frameworks */,
E07E0C1B20246E86000DEF25 /* libz.tbd in Frameworks */,
3031D79B2420EF79002D0EED /* TMXProfilingConnections.framework in Frameworks */,
305DF8FE245C2FCD009CAE58 /* TMXProfilingConnections.framework in Frameworks */,
C6949D5CB8A33018E3B4A224 /* Pods_YandexCheckoutPaymentsExamplePods.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -3075,7 +3075,8 @@
E06532921FF13B5800831588 /* Frameworks */,
E06532931FF13B5800831588 /* Resources */,
9C543C2339037E1990ABEA7F /* [CP] Embed Pods Frameworks */,
3031D7992420EF57002D0EED /* Embed Frameworks */,
305DF8D4245C2754009CAE58 /* Embed Frameworks */,
305DF8D1245C269B009CAE58 /* strip_framework.sh */,
);
buildRules = (
);
Expand Down Expand Up @@ -3190,6 +3191,24 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
305DF8D1245C269B009CAE58 /* strip_framework.sh */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = strip_framework.sh;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "#!/bin/sh\n\n# Created by Samin Pour on 18/6/18.\n# Copyright © 2018 ThreatMetrix. All rights reserved.\n#\n# ThreatMetrix iOS SDK contains multiple architectures, armv7, armv7s, arm64, x86_64. The arm\n# architectures are for devices, x86_64 is for simulators. When preparing application for publishing\n# Xcode removes simulator architectures from your application, but due to a bug / design flaw it\n# doesn't strip these slices from dynamic frameworks.\n#\n# If these architectures are not removed Apple will reject the binary.\n# http://www.openradar.me/radar?id=6409498411401216#ag9zfm9wZW5yYWRhci1ocmRyFAsSB0NvbW1lbnQYgICAuO-k9QgM\n# Possible error messages in Xcode are\n# 1. “iTunes Store Operation Failed: Unsupported Architectures. The executable YourApp contains unsupported architectures '[(x86_64, i386)]'”\n# 2. “LC_ENCRYPTION_INFO”\n# 3. “Invalid Segment Alignment”\n# 4. “The binary is invalid.”\n# Removing simulator slices will resolve these issues.\n#\n# This script automatically strips unused architectures from ThreatMetrix framework, to use it please\n# add a new \"Run Script Phase\" to the build phase and add the content of this file there.\n#\n# IMPORTANT NOTE: Please make sure to add this script after \"Embed Frameworks\" / \"Copy File(s)\" phase\n\n\nAPP_PATH=\"${TARGET_BUILD_DIR}/${WRAPPER_NAME}\"\n\nfind \"$APP_PATH\" -name 'TMX*.framework' -type d | while read -r FRAMEWORK; do\n FRAMEWORK_EXECUTABLE_NAME=$(defaults read \"$FRAMEWORK/Info.plist\" CFBundleExecutable)\n FRAMEWORK_EXECUTABLE_PATH=\"$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME\"\n\n EXTRACTED_ARCHS=()\n\n for ARCH in $ARCHS; do\n lipo -extract \"$ARCH\" \"$FRAMEWORK_EXECUTABLE_PATH\" -o \"$FRAMEWORK_EXECUTABLE_PATH-$ARCH\"\n EXTRACTED_ARCHS+=(\"$FRAMEWORK_EXECUTABLE_PATH-$ARCH\")\n done\n\n lipo -o \"$FRAMEWORK_EXECUTABLE_PATH-merged\" -create \"${EXTRACTED_ARCHS[@]}\"\n rm \"${EXTRACTED_ARCHS[@]}\"\n\n rm \"$FRAMEWORK_EXECUTABLE_PATH\"\n mv \"$FRAMEWORK_EXECUTABLE_PATH-merged\" \"$FRAMEWORK_EXECUTABLE_PATH\"\n\ndone\n";
};
30B58B7421B6B62E004BC42E /* Run Swiftlint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down Expand Up @@ -4244,7 +4263,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = ./YandexCheckoutPayments/Public/Resources/Entitlements/YandexCheckoutPaymentsExamplePods.entitlements;
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_TEAM = 2752592HU5;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -4316,7 +4335,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = ./YandexCheckoutPayments/Public/Resources/Entitlements/YandexCheckoutPaymentsExamplePods.debug.entitlements;
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_TEAM = 2752592HU5;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -4345,7 +4364,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = ./YandexCheckoutPayments/Public/Resources/Entitlements/YandexCheckoutPaymentsExamplePods.inhouse.entitlements;
CURRENT_PROJECT_VERSION = 16;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_TEAM = 2752592HU5;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,58 +96,24 @@ class ThreatMetrixService {
}

private static func handleProfilingResult(_ result: [AnyHashable: Any]?) {
var sessionId: String?
var error: ProfileError?

defer {
if let sessionId = sessionId {
ThreatMetrixService.currentProfilingCallback?(.right(sessionId))
} else {
ThreatMetrixService.currentProfilingCallback?(.left(error ?? ProfileError.internalError))
}
ThreatMetrixService.currentProfilingCallback = nil
}
let profilingResult: String

guard let parameters = result else {
error = .internalError
let status = TMXStatusCode.init -<< (result?[TMXProfileStatus] as? Int)
if status == .notYet, currentProfilingCallback != nil {
TMXProfiling.sharedInstance()?.profileDevice { result in
ThreatMetrixService.profileHandler = nil
handleProfilingResult(result)
}
return
}

if let parametersSessionId = parameters[TMXSessionID] as? String {
sessionId = parametersSessionId
if let sessionId = result?[TMXSessionID] as? String, status == .ok {
profilingResult = sessionId
} else {
guard let statusRawValue = parameters[TMXProfileStatus] as? NSNumber,
let status = TMXStatusCode(rawValue: statusRawValue.intValue) else {
error = .internalError
return
}

switch status {
case .ok:
sessionId = parameters[TMXSessionID] as? String

case .internalError:
error = .internalError

case .connectionError,
.hostNotFoundError,
.networkTimeoutError,
.partialProfile,
.profilingTimeoutError: //partialProfile called when not all api requests were made, because of bad connection
error = .connectionFail

case .interruptedError:
error = .interrupted

case .hostVerificationError,
.invalidOrgID,
.notConfigured,
.invalidParameter,
.certificateMismatch,
.notYet:
error = .invalidConfiguration
}
profilingResult = (status ?? .internalError).thmErrorCode
}
currentProfilingCallback?(.right(profilingResult))
currentProfilingCallback = nil
}

/// Cancel current profiling
Expand All @@ -168,3 +134,40 @@ extension ThreatMetrixService {
case interrupted
}
}

extension TMXStatusCode {
var thmErrorCode: String {
switch self {
case .notYet:
return "TMX_NOT_YET"
case .ok:
return "TMX_OK"
case .connectionError:
return "TMX_CONNECTION_ERROR"
case .hostNotFoundError:
return "TMX_HOST_NOT_FOUND_ERROR"
case .networkTimeoutError:
return "TMX_NETWORK_TIMEOUT_ERROR"
case .hostVerificationError:
return "TMX_HOST_VERIFICATION_ERROR"
case .internalError:
return "TMX_INTERNAL_ERROR"
case .interruptedError:
return "TMX_INTERRUPTED_ERROR"
case .partialProfile:
return "TMX_PARTIAL_PROFILE"
case .invalidOrgID:
return "TMX_INVALID_ORG_ID"
case .notConfigured:
return "TMX_NOT_CONFIGURED"
case .certificateMismatch:
return "TMX_CERTIFICATE_MISMATCH"
case .invalidParameter:
return "TMX_INVALID_PARAMETER"
case .profilingTimeoutError:
return "TMX_PROFILING_TIMEOUT_ERROR"
default:
return "UNKNOWN_ERROR_CODE_\(self.rawValue)"
}
}
}

0 comments on commit 686b9cb

Please sign in to comment.