Skip to content

Commit

Permalink
Merge pull request #52 from iamport/feat/update-support-pgs
Browse files Browse the repository at this point in the history
V1 IOS SDK 스마트로 v2, 나이스 v2, 하이픈, 웰컴페이먼츠 지원 추가
  • Loading branch information
youjmen authored Nov 23, 2024
2 parents d2d34cc + a95966d commit cfa5ca2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 51 deletions.
5 changes: 4 additions & 1 deletion Example/iamport-ios/Model/Order.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ class Order: ObservableObject, Then {
var userCode = PubData()
var payMethod = PubData()
var pg = PubData()
var orderName = PubData()
var price = PubData()
var name = PubData()
var appScheme = PubData()
var merchantUid = PubData()
var digital = PubData()
var cardCode = PubData()
var buyerName = PubData()
var buyerTel = PubData()
var buyerEmail = PubData()
var buyerAddr = PubData()
}
6 changes: 3 additions & 3 deletions Example/iamport-ios/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import SwiftUI
class Utils {

enum SampleUserCode: String, CaseIterable {
case imp96304110
case iamport
case imp19424728
case imp10391932
Expand All @@ -24,6 +23,7 @@ class Utils {
case imp02690184
case imp89347847
case imp67688738
case imp58026550

var name: String {
switch self {
Expand Down Expand Up @@ -53,8 +53,8 @@ class Utils {
return "tosspayments(신모듈) 테스트"
case .imp67688738:
return "KSNET 테스트"
case .imp96304110:
return "빙봉"
case .imp58026550:
return "PortOne Internal Test(Do Not Use)"
}
}
}
Expand Down
19 changes: 14 additions & 5 deletions Example/iamport-ios/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ struct ContentView: View {
}.padding()
}
}

Section(header: Text("구매자")) {
ForEach(viewModel.customerInfos, id: \.0) {
getNaviCustomerInfoView($0.0, $0.1.value)
}
}
}

HStack(spacing: 30) {
Expand All @@ -60,7 +66,7 @@ struct ContentView: View {
buttonPaymentWebViewMode()
}.padding()

}.navigationBarTitle(Text("아임포트로 결제~~"), displayMode: .inline)
}.navigationBarTitle(Text("포트원 V1 IOS 결제 테스트"), displayMode: .inline)
}.tabItem {
Image(systemName: "list.dash")
Text("결제")
Expand Down Expand Up @@ -99,7 +105,7 @@ struct ContentView: View {
}

}.actionSheet(isPresented: $viewModel.showResult) {
ActionSheet(title: Text("결제 결과 도착~"),
ActionSheet(title: Text("결제 결과:"),
message: Text("\(String(describing: viewModel.iamportResponse))"),
buttons: [.default(Text("닫기"))])
}
Expand Down Expand Up @@ -130,14 +136,19 @@ struct ContentView: View {
listItem(title, value)
}
}

private func getNaviCustomerInfoView(_ title: String, _ value: String) -> some View {
NavigationLink(destination: OrderInfoView(infos: $viewModel.customerInfos)) {
listItem(title, value)
}
}


// 웹뷰모드
private func buttonPaymentWebViewMode() -> some View {
ZStack {
Button(action: {
buttonTag = 1
viewModel.updateMerchantUid()
}) {
NavigationLink(destination: paymentWebViewMode, tag: 1, selection: $buttonTag) {
Text("웹뷰모드 결제")
Expand All @@ -152,7 +163,6 @@ struct ContentView: View {
ZStack {
Button(action: {
viewModel.isPayment = true
viewModel.updateMerchantUid()
}) {
Text("결제하기")
.font(.headline)
Expand All @@ -173,7 +183,6 @@ struct ContentView: View {
ZStack {
Button(action: {
viewModel.isCert = true
viewModel.updateMerchantUid()
}) {
Text("본인인증")
.font(.headline)
Expand Down
58 changes: 17 additions & 41 deletions Example/iamport-ios/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ViewModel: ObservableObject, Then {
@Published var iamportInfos: Array<(ItemType, PubData)> = []
@Published var orderInfos: Array<(String, PubData)> = []
@Published var certInfos: Array<(String, PubData)> = []
@Published var customerInfos: Array<(String, PubData)> = []

@Published var isDigital = false
@Published var isCardDirect = false
Expand All @@ -52,8 +53,7 @@ public class ViewModel: ObservableObject, Then {
order = Order().then { order in
order.userCode.value = Utils.SampleUserCode.iamport.rawValue
order.price.value = "1000"
order.orderName.value = "주문할건데요?"
order.name.value = "박포트"
order.name.value = "테스트 결제"
order.pg.value = PG.html5_inicis.rawValue
order.appScheme.value = "iamport"
}
Expand All @@ -62,8 +62,6 @@ public class ViewModel: ObservableObject, Then {
cert.userCode.value = Utils.SampleUserCode.iamport.rawValue
}

updateMerchantUid()

// pub data init
iamportInfos = [
(.UserCode, order.userCode),
Expand All @@ -73,9 +71,8 @@ public class ViewModel: ObservableObject, Then {
]

orderInfos = [
("주문명", order.orderName),
("주문명", order.name),
("가격", order.price),
("이름", order.name),
("주문번호", order.merchantUid),
]

Expand All @@ -87,6 +84,13 @@ public class ViewModel: ObservableObject, Then {
("(선택)최소나이", cert.minAge),
]

customerInfos = [
("구매자 이름", order.buyerName),
("구매자 연락처", order.buyerTel),
("구매자 이메일", order.buyerEmail),
("구매자 주소", order.buyerAddr),
]

updatePayMethodList(pg: order.pg.value)
}

Expand All @@ -99,8 +103,12 @@ public class ViewModel: ObservableObject, Then {
merchant_uid: order.merchantUid.value,
amount: order.price.value).then {
$0.pay_method = payMethod
$0.name = order.orderName.value
$0.buyer_name = order.name.value
$0.name = order.name.value
$0.buyer_name = order.buyerName.value
$0.buyer_tel = order.buyerTel.value
$0.buyer_email = order.buyerEmail.value
$0.buyer_addr = order.buyerAddr.value

if (payMethod == PayMethod.phone.rawValue) {
$0.digital = order.digital.flag
} else if (payMethod == PayMethod.vbank.rawValue) {
Expand All @@ -115,33 +123,6 @@ public class ViewModel: ObservableObject, Then {
if (isCardDirect) {
$0.card = Card(direct: CardDirect(code: order.cardCode.value))
}
$0.custom_data = """
{
"employees": {
"employee": [
{
"id": "1",
"firstName": "Tom",
"lastName": "Cruise",
"photo": "https://jsonformatter.org/img/tom-cruise.jpg",
"cuppingnote": "[\\"\\",\\"\\",\\"\\",\\"\\",\\"\\",\\"\\",\\"\\"]"
},
{
"id": "2",
"firstName": "Maria",
"lastName": "Sharapova",
"photo": "https://jsonformatter.org/img/Maria-Sharapova.jpg"
},
{
"id": "3",
"firstName": "Robert",
"lastName": "Downey Jr.",
"photo": "https://jsonformatter.org/img/Robert-Downey-Jr.jpg"
}
]
}
}
"""
}

return req
Expand Down Expand Up @@ -181,12 +162,7 @@ public class ViewModel: ObservableObject, Then {
setPayMethodList(pg: pg)
initPayMethod()
}

func updateMerchantUid() {
order.merchantUid.value = UUID().uuidString
cert.merchantUid.value = UUID().uuidString
}


private func initPayMethod() {
order.payMethod.value = payMethodList[0].rawValue
}
Expand Down
13 changes: 13 additions & 0 deletions Sources/iamport-ios/Classes/Data/PG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public enum PG: String, CaseIterable, Codable {
case smartro
case tosspayments
case ksnet
case nice_v2
case smartro_v2
case welcome
case hyphen


public var name: String {
switch self {
Expand Down Expand Up @@ -89,6 +94,14 @@ public enum PG: String, CaseIterable, Codable {
return "토스페이"
case .smartro:
return "스마트로"
case .nice_v2:
return "나이스 V2(신모듈)"
case .smartro_v2:
return "스마트로 V2(신모듈)"
case .welcome:
return "웰컴페이먼츠"
case .hyphen:
return "하이픈 바로계좌결제"
}
}

Expand Down
2 changes: 1 addition & 1 deletion iamport-ios.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'iamport-ios'
s.version = '1.4.6'
s.version = '1.4.7'
s.summary = 'iamport-ios will help develop for your iOS App payments'

# This description is used to generate tags and improve search results.
Expand Down

0 comments on commit cfa5ca2

Please sign in to comment.