-
Notifications
You must be signed in to change notification settings - Fork 0
/
KhaltiPaymentControllerViewModel.swift
70 lines (48 loc) · 1.82 KB
/
KhaltiPaymentControllerViewModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//
// KhaltiPaymentControllerViewModel.swift
// KhaltiCheckout
//
// Created by Mac on 6/11/24.
//
import Foundation
class KhaltiPaymentControllerViewModel {
var khalti:Khalti?
let service = KhaltiAPIService()
let monitor = NetworkMonitor.shared
init(khalti:Khalti? = nil) {
self.khalti = khalti
}
func getPaymentDetail(onCompletion: @escaping ((PaymentDetailModel)->()), onError: @escaping ((String)->())){
let baseUrl = getBaseUrl()
let url = baseUrl.appendUrl(url: Url.PAYMENT_DETAIL)
if let pIdx = khalti?.config.pIdx {
var params = [String:String]()
params["pidx"] = pIdx
service.fetchDetail(url:url,params: params, onCompletion: {[weak self](response) in
onCompletion(response)
}, onError: {(error) in
onError(error)
})
}
}
func verifyPaymentStatus(onCompletion:@escaping((PaymentLoadModel)->()),onError: @escaping ((String)->())){
let baseUrl = getBaseUrl()
let url = baseUrl.appendUrl(url: Url.LOOKUP_SDK)
if let pIdx = khalti?.config.pIdx {
var params = [String:String]()
params["pidx"] = pIdx
service.fetchPaymentStatus(url:url,params: params, onCompletion: {(response) in
onCompletion(response)
}, onError: {(error) in
onError(error)
})
}
}
private func isNetworkReachable(){
}
private func getBaseUrl() ->Url{
let isProd = khalti?.config.isProd() ?? false
let baseUrl = isProd ? Url.BASE_KHALTI_URL_PROD: Url.BASE_KHALTI_URL_STAGING
return baseUrl
}
}