Browse Source

auto refund post api complete

pull/1/head
shishir sapkota 6 years ago
parent
commit
42ac46643f
  1. 8
      GME Remit.xcodeproj/project.pbxproj
  2. 2
      GMERemittance/AppDelegate.swift
  3. 47
      GMERemittance/Model/AutoRefund.swift
  4. 109
      GMERemittance/Module/Auto refund/AutoRefundsViewController.swift
  5. 6
      GMERemittance/Module/Auto refund/autoRefund.storyboard
  6. 68
      GMERemittance/Module/Auto refund/autoRefundService.swift
  7. 6
      GMERemittance/Utility/AppConstants.swift
  8. 2
      Pods/Pods.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist

8
GME Remit.xcodeproj/project.pbxproj

@ -83,6 +83,8 @@
04CAEC2D1FEBAEB400C819D4 /* KYCViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04CAEC2C1FEBAEB400C819D4 /* KYCViewModel.swift */; }; 04CAEC2D1FEBAEB400C819D4 /* KYCViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04CAEC2C1FEBAEB400C819D4 /* KYCViewModel.swift */; };
04CD5395208F0765008F0971 /* UploadImageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04CD5394208F0765008F0971 /* UploadImageViewModel.swift */; }; 04CD5395208F0765008F0971 /* UploadImageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04CD5394208F0765008F0971 /* UploadImageViewModel.swift */; };
04CDC57E20809DCE0081BE50 /* Reward.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04CDC57D20809DCE0081BE50 /* Reward.swift */; }; 04CDC57E20809DCE0081BE50 /* Reward.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04CDC57D20809DCE0081BE50 /* Reward.swift */; };
04DC27EC21A51E29003714F5 /* AutoRefund.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DC27EB21A51E29003714F5 /* AutoRefund.swift */; };
04DC27EE21A51E83003714F5 /* autoRefundService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DC27ED21A51E83003714F5 /* autoRefundService.swift */; };
04DD3AC02004A6980021A366 /* ForgetPasswordDOBViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DD3ABF2004A6980021A366 /* ForgetPasswordDOBViewController.swift */; }; 04DD3AC02004A6980021A366 /* ForgetPasswordDOBViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04DD3ABF2004A6980021A366 /* ForgetPasswordDOBViewController.swift */; };
04E1032C2007A88600AE24A2 /* ScrollableProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E1032B2007A88600AE24A2 /* ScrollableProtocol.swift */; }; 04E1032C2007A88600AE24A2 /* ScrollableProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04E1032B2007A88600AE24A2 /* ScrollableProtocol.swift */; };
04EA4DB12026CD0E00BF6BED /* TrackTransfer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04EA4DB02026CD0E00BF6BED /* TrackTransfer.storyboard */; }; 04EA4DB12026CD0E00BF6BED /* TrackTransfer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 04EA4DB02026CD0E00BF6BED /* TrackTransfer.storyboard */; };
@ -623,6 +625,8 @@
04CAEC2C1FEBAEB400C819D4 /* KYCViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KYCViewModel.swift; sourceTree = "<group>"; }; 04CAEC2C1FEBAEB400C819D4 /* KYCViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KYCViewModel.swift; sourceTree = "<group>"; };
04CD5394208F0765008F0971 /* UploadImageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadImageViewModel.swift; sourceTree = "<group>"; }; 04CD5394208F0765008F0971 /* UploadImageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadImageViewModel.swift; sourceTree = "<group>"; };
04CDC57D20809DCE0081BE50 /* Reward.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reward.swift; sourceTree = "<group>"; }; 04CDC57D20809DCE0081BE50 /* Reward.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Reward.swift; sourceTree = "<group>"; };
04DC27EB21A51E29003714F5 /* AutoRefund.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoRefund.swift; sourceTree = "<group>"; };
04DC27ED21A51E83003714F5 /* autoRefundService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = autoRefundService.swift; sourceTree = "<group>"; };
04DD3ABF2004A6980021A366 /* ForgetPasswordDOBViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForgetPasswordDOBViewController.swift; sourceTree = "<group>"; }; 04DD3ABF2004A6980021A366 /* ForgetPasswordDOBViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ForgetPasswordDOBViewController.swift; sourceTree = "<group>"; };
04E1032B2007A88600AE24A2 /* ScrollableProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollableProtocol.swift; sourceTree = "<group>"; }; 04E1032B2007A88600AE24A2 /* ScrollableProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollableProtocol.swift; sourceTree = "<group>"; };
04EA4DB02026CD0E00BF6BED /* TrackTransfer.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = TrackTransfer.storyboard; sourceTree = "<group>"; }; 04EA4DB02026CD0E00BF6BED /* TrackTransfer.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = TrackTransfer.storyboard; sourceTree = "<group>"; };
@ -1169,6 +1173,7 @@
children = ( children = (
045976B121A3D8F30001E92A /* AutoRefundsViewController.swift */, 045976B121A3D8F30001E92A /* AutoRefundsViewController.swift */,
045976B321A3D90A0001E92A /* autoRefund.storyboard */, 045976B321A3D90A0001E92A /* autoRefund.storyboard */,
04DC27ED21A51E83003714F5 /* autoRefundService.swift */,
); );
path = "Auto refund"; path = "Auto refund";
sourceTree = "<group>"; sourceTree = "<group>";
@ -3189,6 +3194,7 @@
D97785AB215DD23400754079 /* TransactionModel.swift */, D97785AB215DD23400754079 /* TransactionModel.swift */,
D9DC108321639E56008F3C51 /* SuccessMessage.swift */, D9DC108321639E56008F3C51 /* SuccessMessage.swift */,
D96BD1202164828D00DFE7D8 /* WalletStatement.swift */, D96BD1202164828D00DFE7D8 /* WalletStatement.swift */,
04DC27EB21A51E29003714F5 /* AutoRefund.swift */,
); );
path = Model; path = Model;
sourceTree = "<group>"; sourceTree = "<group>";
@ -4530,6 +4536,7 @@
D937037121490C3800D93077 /* KycForm2ModuleInterface.swift in Sources */, D937037121490C3800D93077 /* KycForm2ModuleInterface.swift in Sources */,
D946719521426DFB003924DB /* LoginModuleInterface.swift in Sources */, D946719521426DFB003924DB /* LoginModuleInterface.swift in Sources */,
D96BD1262164875800DFE7D8 /* WalletStatementTableViewCell.swift in Sources */, D96BD1262164875800DFE7D8 /* WalletStatementTableViewCell.swift in Sources */,
04DC27EC21A51E29003714F5 /* AutoRefund.swift in Sources */,
D96BD11A216479E200DFE7D8 /* WalletStatementPresenter.swift in Sources */, D96BD11A216479E200DFE7D8 /* WalletStatementPresenter.swift in Sources */,
A255A907206A14220002905D /* SSBadgeButton.swift in Sources */, A255A907206A14220002905D /* SSBadgeButton.swift in Sources */,
D922D9232134DCF000D43053 /* EditReciepientWireframe.swift in Sources */, D922D9232134DCF000D43053 /* EditReciepientWireframe.swift in Sources */,
@ -4627,6 +4634,7 @@
D922D98D21351AAE00D43053 /* SendMoneyExchangeRateViewInterface.swift in Sources */, D922D98D21351AAE00D43053 /* SendMoneyExchangeRateViewInterface.swift in Sources */,
9F2E45A2204E8A3F00D0B28C /* CalendarViewController.swift in Sources */, 9F2E45A2204E8A3F00D0B28C /* CalendarViewController.swift in Sources */,
D90A9D66213696E400A96E45 /* BankPickerViewController.swift in Sources */, D90A9D66213696E400A96E45 /* BankPickerViewController.swift in Sources */,
04DC27EE21A51E83003714F5 /* autoRefundService.swift in Sources */,
0428DC6A204910F9008355D7 /* WalletTransactionListViewController.swift in Sources */, 0428DC6A204910F9008355D7 /* WalletTransactionListViewController.swift in Sources */,
049E61A51FF0AE9D00817C76 /* UrlManager.swift in Sources */, 049E61A51FF0AE9D00817C76 /* UrlManager.swift in Sources */,
D9AFE856215C7166005F3A25 /* HomeCollectionTableViewCell.swift in Sources */, D9AFE856215C7166005F3A25 /* HomeCollectionTableViewCell.swift in Sources */,

2
GMERemittance/AppDelegate.swift

@ -19,7 +19,7 @@ import AlamofireNetworkActivityLogger
import IQKeyboardManagerSwift import IQKeyboardManagerSwift
import LGSideMenuController import LGSideMenuController
let server: Server = .live
let server: Server = .stagging
@UIApplicationMain @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate { class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {

47
GMERemittance/Model/AutoRefund.swift

@ -0,0 +1,47 @@
//
// AutoRefund.swift
// GME Remit
//
// Created by Mac on 11/21/18.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
import ObjectMapper
class AutoRefund: Mappable {
var currentBalance: String?
var minAmount: String?
var chargeAmount: String?
required init?(map: Map) {
}
func mapping(map: Map) {
chargeAmount <- map["RefundCharge"]
minAmount <- map["MinimumAmount"]
currentBalance <- map["CurrentBalance"]
}
}
class AutoRefundContainer: Mappable {
var errorCode: String?
var message: String?
var id: String?
var data: AutoRefund?
required init?(map: Map) {
}
func mapping(map: Map) {
errorCode <- map["ErrorCode"]
message <- map["Msg"]
id <- map["Id"]
data <- map["Data"]
}
}

109
GMERemittance/Module/Auto refund/AutoRefundsViewController.swift

@ -12,6 +12,19 @@ class AutoRefundsViewController: UIViewController {
@IBOutlet weak var backgroundView: UIView! @IBOutlet weak var backgroundView: UIView!
@IBOutlet weak var countryBackgroundView: UIView! @IBOutlet weak var countryBackgroundView: UIView!
@IBOutlet weak var availableBalanceLabel: UILabel!
@IBOutlet weak var refundChargeLabel: UILabel!
@IBOutlet weak var amountTextfield: UITextField!
var autorefund: AutoRefund? {
didSet {
let availableBalance = (autorefund?.currentBalance ?? "0") + "(KRW)"
let refundCharge = (autorefund?.minAmount ?? "10,000") + "(KRW)"
self.availableBalanceLabel.text = availableBalance
self.refundChargeLabel.text = refundCharge
}
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
setup() setup()
@ -30,80 +43,64 @@ class AutoRefundsViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
self.navigationItem.title = "Auto Refund " self.navigationItem.title = "Auto Refund "
fetchInfo()
} }
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
import Alamofire
protocol FetchAutoRefundInfo: ApiServiceType {
func fetchAutoRefundInfo(username: String?, success: @escaping (AutoRefund) -> (), failure: @escaping (Error) -> ())
}
private func fetchInfo() {
self.showProgressHud()
let username = Utility.getMyUserName() ?? ""
self.fetchAutoRefundInfo(username: username, success: { (autorefund) in
extension FetchAutoRefundInfo {
func fetchAutoRefundInfo(username: String?, success: @escaping (AutoRefund) -> (), failure: @escaping (Error) -> ()) {
let url = baseUrl + "refund/\(username)"
auth.request(method: .post, url: url, params: nil, encoding: URLEncoding.default, success: { (response: AutoRefundContainer) in
if let model = response.data {
success(model)
}else {
let error = NSError.init(domain: "FetchAutoRefundInfo", code: 0, userInfo: [NSLocalizedDescriptionKey : "Could not parse json"])
}
self.autorefund = autorefund
self.hideProgressHud()
}) { (error) in }) { (error) in
failure(error)
self.hideProgressHud()
self.show(error: error.localizedDescription)
} }
} }
}
@IBAction func refund(_ sender: Any) {
let amount = self.amountTextfield.text!
let minAmnt = self.autorefund?.minAmount ?? "0"
if amount.isEmpty {self.show(error: "add refund amount"); return}
if !isValidRefundable(amount: amount) {
self.show(error: "refund amount should be greator than \(minAmnt) KRW")
return
}
let chargeAmt = self.autorefund?.chargeAmount ?? ""
import ObjectMapper
let userName = Utility.getMyUserName()
let id = Utility.getMyId()
class AutoRefund: Mappable {
var username: String?
var amount: String?
var chargeAmount: String?
self.showProgressHud()
self.refund(amount: amount, userName: userName, chargeAmount: chargeAmt, userId: id, success: { (message) in
self.hideProgressHud()
print(message)
}) { (error) in
self.hideProgressHud()
self.show(error: error.localizedDescription)
}
required init?(map: Map) {
}
private func isValidRefundable(amount: String) -> Bool {
let minRefundAmount = self.autorefund?.minAmount ?? "0"
guard let amt = Double(amount), let minRefundAmt = Double(minRefundAmount) else {return false}
let result = amt >= minRefundAmt
return result
} }
func mapping(map: Map) {
username <- map["Username"]
amount <- map["Amount"]
chargeAmount <- map["ChargeAmount"]
func show(error: String) {
self.alert(message: error)
} }
} }
extension AutoRefundsViewController: FetchAutoRefundInfo {
}
class AutoRefundContainer: Mappable {
var errorCode: String?
var message: String?
var id: String?
var data: AutoRefund?
required init?(map: Map) {
}
extension AutoRefundsViewController: RefundService {
func mapping(map: Map) {
errorCode <- map["ErrorCode"]
message <- map["Msg"]
id <- map["Id"]
data <- map["Data"]
}
} }

6
GMERemittance/Module/Auto refund/autoRefund.storyboard

@ -51,6 +51,9 @@
<integer key="value" value="25"/> <integer key="value" value="25"/>
</userDefinedRuntimeAttribute> </userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes> </userDefinedRuntimeAttributes>
<connections>
<action selector="refund:" destination="Ce0-gZ-wGC" eventType="touchUpInside" id="vir-2J-17S"/>
</connections>
</button> </button>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="5no-cI-xf0"> <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="50" translatesAutoresizingMaskIntoConstraints="NO" id="5no-cI-xf0">
<rect key="frame" x="10" y="30" width="394" height="186.33333333333334"/> <rect key="frame" x="10" y="30" width="394" height="186.33333333333334"/>
@ -229,8 +232,11 @@
<viewLayoutGuide key="safeArea" id="ggt-18-hOm"/> <viewLayoutGuide key="safeArea" id="ggt-18-hOm"/>
</view> </view>
<connections> <connections>
<outlet property="amountTextfield" destination="ArH-OD-ene" id="iTb-Qr-lL7"/>
<outlet property="availableBalanceLabel" destination="Neh-19-adB" id="Xid-iK-Z2d"/>
<outlet property="backgroundView" destination="ZWG-NA-5Ws" id="DAY-P3-fbk"/> <outlet property="backgroundView" destination="ZWG-NA-5Ws" id="DAY-P3-fbk"/>
<outlet property="countryBackgroundView" destination="UE2-ls-4MK" id="FQX-JO-Q5I"/> <outlet property="countryBackgroundView" destination="UE2-ls-4MK" id="FQX-JO-Q5I"/>
<outlet property="refundChargeLabel" destination="eby-hG-WLU" id="IYd-9d-vjc"/>
</connections> </connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Yjd-qR-1Db" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="Yjd-qR-1Db" userLabel="First Responder" sceneMemberID="firstResponder"/>

68
GMERemittance/Module/Auto refund/autoRefundService.swift

@ -0,0 +1,68 @@
//
// autoRefundService.swift
// GME Remit
//
// Created by Mac on 11/21/18.
// Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
//
import Foundation
import Alamofire
protocol FetchAutoRefundInfo: ApiServiceType {
func fetchAutoRefundInfo(username: String, success: @escaping (AutoRefund) -> (), failure: @escaping (Error) -> ())
}
extension FetchAutoRefundInfo {
func fetchAutoRefundInfo(username: String, success: @escaping (AutoRefund) -> (), failure: @escaping (Error) -> ()) {
let url = baseUrl + "refund/\(username)"
auth.request(method: .get, url: url, params: nil, encoding: URLEncoding.default, success: { (response: AutoRefundContainer) in
if let model = response.data {
success(model)
}else {
let error = NSError.init(domain: "FetchAutoRefundInfo", code: 0, userInfo: [NSLocalizedDescriptionKey : "Could not parse json"])
}
}) { (error) in
failure(error)
}
}
}
protocol RefundService: ApiServiceType {
func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (String) -> (), failure: @escaping (Error) -> ())
}
extension RefundService {
func refund(amount: String, userName: String, chargeAmount: String, userId: String, success: @escaping (String) -> (), failure: @escaping (Error) -> ()) {
let url = baseUrl + "refund/proceed"
let params = [
"Username": userName,
"Amount": amount,
"ChargeAmount": chargeAmount,
"UserId": userId
]
auth.request(method: .post, url: url, params: params, success: { (response: SuccessMessageContainer) in
if (response.errorCode ?? "") == "1" {
let error = NSError.init(domain: "Network", code: 0, userInfo: [NSLocalizedDescriptionKey : response.message ?? ""])
failure(error)
}else {
success(response.data?.message ?? "")
}
}) { (error) in
failure(error)
}
}
}
//{
// "Username":"demo.gme@gmeremit.com",
// "Amount":"11000",
// "ChargeAmount":"1000",
// "UserId":"39442"
//}

6
GMERemittance/Utility/AppConstants.swift

@ -70,6 +70,12 @@ class Utility {
return myUsername return myUsername
} }
static func getMyId() -> String {
let defaults = UserDefaults.standard
let myId = defaults.string(forKey: UserKeys.senderId) ?? ""
return myId
}
static func isValidEmail(email: String) -> Bool { static func isValidEmail(email: String) -> Bool {
let emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}" let emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegex) let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegex)

2
Pods/Pods.xcodeproj/xcuserdata/mac.xcuserdatad/xcschemes/xcschememanagement.plist

@ -17,7 +17,7 @@
<key>AlamofireNetworkActivityLogger.xcscheme</key> <key>AlamofireNetworkActivityLogger.xcscheme</key>
<dict> <dict>
<key>orderHint</key> <key>orderHint</key>
<integer>8</integer>
<integer>9</integer>
</dict> </dict>
<key>BRYXBanner.xcscheme</key> <key>BRYXBanner.xcscheme</key>
<dict> <dict>

Loading…
Cancel
Save