콘텐츠 상세, 콘텐츠 구매
- pg 테스트 계정의 경우 캔이 아닌 원으로 표시되도록 하고 콘텐츠 구매시 바로 결제 후 구매 되도록 수정
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// CanPaymentTempViewModel.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 5/20/24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Combine
|
||||
|
||||
import Bootpay
|
||||
|
||||
enum TempPaymentMethod: String {
|
||||
case card = "카드"
|
||||
case bank = "계좌이체"
|
||||
case phone = "휴대폰"
|
||||
}
|
||||
|
||||
final class CanPaymentTempViewModel: ObservableObject {
|
||||
|
||||
private let repository = CanPaymentTempRepository()
|
||||
private var subscription = Set<AnyCancellable>()
|
||||
|
||||
@Published var isTermsAgree = false
|
||||
@Published var errorMessage = ""
|
||||
@Published var isShowPopup = false
|
||||
@Published var isLoading = false
|
||||
|
||||
@Published var isShowPaymentView = false
|
||||
@Published var paymentMethod: TempPaymentMethod? = nil
|
||||
|
||||
let payload = Payload()
|
||||
|
||||
func chargeCan(can: Int, paymentGateway: PaymentGateway, onSuccess: @escaping () -> Void) {
|
||||
isLoading = true
|
||||
repository.chargeCan(request: CanChargeTempRequest(can: can, price: can * 110, paymentGateway: paymentGateway))
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<CanChargeResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
let bootUser = BootUser()
|
||||
bootUser.userId = "\(UserDefaults.int(forKey: .userId))"
|
||||
bootUser.username = UserDefaults.string(forKey: .nickname)
|
||||
|
||||
payload.applicationId = BOOTPAY_APP_ID
|
||||
payload.pg = "세틀뱅크"
|
||||
payload.orderId = "\(data.chargeId)"
|
||||
payload.method = paymentMethod!.rawValue
|
||||
payload.user = bootUser
|
||||
|
||||
onSuccess()
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func verifyPayment(_ data: [String: Any], onSuccess: @escaping () -> Void) {
|
||||
isLoading = true
|
||||
|
||||
let _data = data["data"] as? [String: Any]
|
||||
|
||||
if let data = _data {
|
||||
let receiptId = data["receipt_id"] as! String
|
||||
let orderId = data["order_id"] as! String
|
||||
|
||||
repository.pgVerify(receiptId: receiptId, orderId: orderId)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
|
||||
|
||||
if decoded.success {
|
||||
onSuccess()
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
} else {
|
||||
isLoading = false
|
||||
errorMessage = "본인인증 중 오류가 발생했습니다."
|
||||
isShowPopup = true
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user