You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.1 KiB
66 lines
2.1 KiB
//
|
|
// RenewIDService.swift
|
|
// GME Remit
|
|
//
|
|
// Created by Swift Tech on 30/09/2021.
|
|
//Copyright © 2021 Gobal Money Express Co. Ltd. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
class RenewIDService: RenewIDServiceType {
|
|
func saveKycInfo(
|
|
with model: PictureInfoModel,
|
|
success: @escaping (String) -> Void,
|
|
failure: @escaping (Error) -> Void
|
|
) {
|
|
APIRouter.submitRenewID
|
|
.requestMultipart(
|
|
images: getImageParams(model: model),
|
|
needsAuthorization: true,
|
|
success: { (response: KYCResponseContainer) in
|
|
if (response.errorCode ?? "") == "1" {
|
|
let error = NSError(
|
|
domain: "Network",
|
|
code: 0,
|
|
userInfo: [NSLocalizedDescriptionKey : response.message ?? ""]
|
|
)
|
|
failure(error)
|
|
} else {
|
|
guard let message = response.message else {
|
|
return
|
|
}
|
|
success(message)
|
|
}
|
|
},
|
|
failure: failure)
|
|
}
|
|
|
|
private func getCompressedImage(base64: String) -> Data? {
|
|
guard let imageData = Data(base64Encoded: base64) else { return nil }
|
|
return UIImage(data: imageData)?.jpegData(compressionQuality: 0.6)
|
|
}
|
|
|
|
private func getImageParams(model: PictureInfoModel) -> [String: Data] {
|
|
var images: [String: Data] = [:]
|
|
|
|
// frontIDPicture
|
|
if let image = model.frontIDPicture {
|
|
if let data = getCompressedImage(base64: image) {
|
|
print("frontIdPic:\(data)")
|
|
images["idFront"] = data
|
|
}
|
|
}
|
|
|
|
// backIDPicture
|
|
if let image = model.backIDPicture {
|
|
if let data = getCompressedImage(base64: image) {
|
|
print("backIDPicture:\(data)")
|
|
images["idBack"] = data
|
|
}
|
|
}
|
|
|
|
return images
|
|
}
|
|
}
|