Skip to content

Commit

Permalink
Apply SwiftFormat and rename some stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
hyp3rflow committed Feb 10, 2023
1 parent 9c91d43 commit 81f0ec2
Show file tree
Hide file tree
Showing 63 changed files with 1,057 additions and 1,297 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### Xcode ###
build
.build
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcworkspace/contents.xcworkspacedata
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: dc94aab5cf45a14d04fee8f93c0c0613b8dbcd1a

COCOAPODS: 1.10.1
COCOAPODS: 1.11.3
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
}
},
{
"package": "RxBus",
"repositoryURL": "https://github.com/ridi/RxBus-swift.git",
"package": "RxBusForPort",
"repositoryURL": "https://github.com/iamport/RxBus-Swift",
"state": {
"branch": null,
"revision": "b154da5fffb4c5d0d17b7f46e9cd38f382e298e4",
"version": "1.3.2"
"revision": "24458425acf1da825a8e7587231052cef90c3a6b",
"version": "1.3.5"
}
},
{
Expand All @@ -28,6 +28,15 @@
"version": "6.2.0"
}
},
{
"package": "SwiftFormat",
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat",
"state": {
"branch": null,
"revision": "ae4d0b672cd7094ae513097c617951a5ac714418",
"version": "0.50.8"
}
},
{
"package": "Then",
"repositoryURL": "https://github.com/devxoul/Then.git",
Expand Down
4 changes: 2 additions & 2 deletions Example/iamport-ios/View/PaymentResultViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import RxSwift
class PaymentResultViewController: UIViewController, UIGestureRecognizerDelegate {

// 결과 전달 받을 RxSubject
let impResponseRelay = BehaviorRelay<IamPortResponse?>(value: nil)
let impResponseRelay = BehaviorRelay<IamportResponse?>(value: nil)
var disposeBag = DisposeBag()

override func viewDidLoad() {
Expand Down Expand Up @@ -53,7 +53,7 @@ class PaymentResultViewController: UIViewController, UIGestureRecognizerDelegate
// imp_success, success 해당 값을 맹신할 수 없습니다.
// 뱅크페이 실시간 계좌이체는 해당 값이 전달되지 않는 케이스가 있습니다.
// 결과 콜백을 받으면, Iamport REST API 등을 통해 "실제 결제 여부" 를 체크하셔야 합니다.
private func isSuccess(_ iamportResponse: IamPortResponse) -> Bool {
private func isSuccess(_ iamportResponse: IamportResponse) -> Bool {
iamportResponse.imp_success ?? false || iamportResponse.success ?? false
}

Expand Down
6 changes: 3 additions & 3 deletions Example/iamport-ios/View/PaymentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ class PaymentViewController: UIViewController, WKNavigationDelegate {
}

let userCode = viewModel.order.userCode // iamport 에서 부여받은 가맹점 식별코드
if let request = viewModel.createPaymentData() {
dump(request)
if let payment = viewModel.createPaymentData() {
dump(payment)


// #case1 use for UIViewController
// WebViewContorller 용 닫기버튼 생성(PG "uplus(구 토스페이먼츠)" 는 자체취소 버튼이 없는 것으로 보임)
Iamport.shared.useNaviButton(enable: true)

Iamport.shared.payment(viewController: self,
userCode: userCode.value, iamPortRequest: request) { iamPortResponse in
userCode: userCode.value, payment: payment) { iamPortResponse in
viewModel.iamportCallback(iamPortResponse)
}

Expand Down
6 changes: 3 additions & 3 deletions Example/iamport-ios/View/PaymentWebViewModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ class PaymentWebViewModeViewController: UIViewController, WKNavigationDelegate {
}

let userCode = viewModel.order.userCode // iamport 에서 부여받은 가맹점 식별코드
if let request = viewModel.createPaymentData() {
dump(request)
if let payment = viewModel.createPaymentData() {
dump(payment)

//WebView 사용
Iamport.shared.paymentWebView(webViewMode: wkWebView, userCode: userCode.value, iamPortRequest: request) { [weak self] iamPortResponse in
Iamport.shared.paymentWebView(webViewMode: wkWebView, userCode: userCode.value, payment: payment) { [weak self] iamPortResponse in
viewModel.iamportCallback(iamPortResponse)
self?.presentationMode?.wrappedValue.dismiss()
}
Expand Down
18 changes: 9 additions & 9 deletions Example/iamport-ios/View/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
// 아임포트 SDK 본인인증 요청
func requestCertification() {
let userCode = "iamport" // 다날
let request = createCertificationData()
dump(request)
let certification = createCertificationData()
dump(certification)

guard let navController = navigationController else {
print("navigationController 를 찾을 수 없습니다")
return
}

Iamport.shared.certification(navController: navController, userCode: userCode, iamPortCertification: request) { [weak self] iamPortResponse in
Iamport.shared.certification(navController: navController, userCode: userCode, certification: certification) { [weak self] iamPortResponse in
self?.paymentCallback(iamPortResponse)
}

Expand Down Expand Up @@ -106,7 +106,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
} else {
}
Iamport.shared.paymentWebView(webViewMode: wkWebView,
userCode: userCode, iamPortRequest: request) { [weak self] iamPortResponse in
userCode: userCode, payment: request) { [weak self] iamPortResponse in
self?.paymentCallback(iamPortResponse)
}

Expand All @@ -132,11 +132,11 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
}

// 아임포트 결제 데이터 생성
func createPaymentData() -> IamPortRequest {
func createPaymentData() -> IamportPayment {
let display = CardQuota()
display.card_quota = []

return IamPortRequest(
return IamportPayment(
pg: PG.html5_inicis.makePgRawName(pgId: ""),
merchant_uid: "muid_ios_\(Int(Date().timeIntervalSince1970))",
amount: "1000").then {
Expand All @@ -149,8 +149,8 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
}

// 아임포트 본인인증 데이터 생성
func createCertificationData() -> IamPortCertification {
IamPortCertification(merchant_uid: "muid_ios_\(Int(Date().timeIntervalSince1970))").then {
func createCertificationData() -> IamportCertification {
IamportCertification(merchant_uid: "muid_ios_\(Int(Date().timeIntervalSince1970))").then {
$0.min_age = 19
$0.name = "김빙봉"
$0.phone = "010-1234-5678"
Expand All @@ -160,7 +160,7 @@ class ViewController: UIViewController, UIGestureRecognizerDelegate {
}

// 결제 완료 후 콜백 함수 (예시)
func paymentCallback(_ response: IamPortResponse?) {
func paymentCallback(_ response: IamportResponse?) {
print("------------------------------------------")
print("결과 왔습니다~~")
print("Iamport Payment response: \(response)")
Expand Down
14 changes: 7 additions & 7 deletions Example/iamport-ios/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class ViewModel: ObservableObject, Then {
@Published var isCert: Bool = false
@Published var showResult: Bool = false
@Published var CardDirectCode: String = ""
var iamPortResponse: IamPortResponse?
var iamPortResponse: IamportResponse?

init() {
order = Order().then { order in
Expand Down Expand Up @@ -91,10 +91,10 @@ public class ViewModel: ObservableObject, Then {
}

// 아임포트 결제 데이터 생성
func createPaymentData() -> IamPortRequest? {
func createPaymentData() -> IamportPayment? {
let payMethod = order.payMethod.value

let req = IamPortRequest(
let req = IamportPayment(
pg: order.pg.value,
merchant_uid: order.merchantUid.value,
amount: order.price.value).then {
Expand Down Expand Up @@ -144,7 +144,7 @@ public class ViewModel: ObservableObject, Then {


// 결제 완료 후 콜백 함수 (예시)
func iamportCallback(_ response: IamPortResponse?) {
func iamportCallback(_ response: IamportResponse?) {
print("------------------------------------------")
print("결과 왔습니다~~")
if let res = response {
Expand All @@ -163,8 +163,8 @@ public class ViewModel: ObservableObject, Then {
}

// 아임포트 본인인증 데이터 생성
func createCertificationData() -> IamPortCertification {
IamPortCertification(merchant_uid: cert.merchantUid.value).then {
func createCertificationData() -> IamportCertification {
IamportCertification(merchant_uid: cert.merchantUid.value).then {
$0.min_age = Int(cert.minAge.value)
$0.name = cert.name.value
$0.phone = cert.phone.value
Expand Down Expand Up @@ -219,4 +219,4 @@ public class ViewModel: ObservableObject, Then {

//

}
}
11 changes: 10 additions & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"package": "RxBus",
"repositoryURL": "https://github.com/ridi/RxBus-swift",
"repositoryURL": "https://github.com/iamport/RxBus-Swift",
"state": {
"branch": null,
"revision": "b154da5fffb4c5d0d17b7f46e9cd38f382e298e4",
Expand All @@ -28,6 +28,15 @@
"version": "6.2.0"
}
},
{
"package": "SwiftFormat",
"repositoryURL": "https://github.com/nicklockwood/SwiftFormat",
"state": {
"branch": null,
"revision": "ae4d0b672cd7094ae513097c617951a5ac714418",
"version": "0.50.8"
}
},
{
"package": "Then",
"repositoryURL": "https://github.com/devxoul/Then.git",
Expand Down
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let package = Package(
.package(name: "RxBusForPort", url: "https://github.com/iamport/RxBus-Swift", .upToNextMinor(from: "1.3.0")),
.package(url: "https://github.com/Alamofire/Alamofire.git", .upToNextMajor(from: "5.4.0")),
.package(url: "https://github.com/devxoul/Then.git", .upToNextMajor(from: "2.7.0")),
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.50.4")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
41 changes: 19 additions & 22 deletions Sources/iamport-ios/Assets/iamportcdn.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,50 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<!-- 현재 콜백은 불필요 할 듯 onPageFinished 쓰니까..! -->
<script type="text/javascript">
console.log("Wait cdn-iamport-sdk...");

const iosHandler = window.webkit.messageHandlers
const handlers = window.webkit.messageHandlers;
document.addEventListener('DOMContentLoaded', () => {
console.log("Load finish cdn-iamport-sdk...");
iosHandler.startWorkingSdk.postMessage("")
handlers.startWorkingSdk.postMessage("");
});

function dLog(log) {
<!-- console.log(log)-->
iosHandler.debugConsoleLog.postMessage(log)
handlers.debugConsoleLog.postMessage(log);
}

function callback(response) {
dLog(response)
iosHandler.customCallback.postMessage(JSON.stringify(response))
dLog(response);
handlers.customCallback.postMessage(JSON.stringify(response));
}

function init(userCode) {
dLog("init userCode :: " + dLog)
dLog("init userCode :: " + dLog);
IMP.init(userCode);
}

function agency(userCode, tierCode) {
dLog("agency userCode :: " + dLog + ", tierCode :: " + tierCode)
dLog("agency userCode :: " + dLog + ", tierCode :: " + tierCode);
IMP.agency(userCode, tierCode);
}

function requestPay(impRequest) {
dLog("requestPay :: " + impRequest)
IMP.request_pay(JSON.parse(impRequest), callback);
function requestPay(request) {
dLog("requestPay :: " + request);
IMP.request_pay(JSON.parse(request), callback);;
}

function requestPayWithCustomData(impRequest, customData) {
var data = JSON.parse(impRequest)
function requestPayWithCustomData(request, customData) {
var data = JSON.parse(request);

var decodeCustom = decodeURIComponent(escape(window.atob(customData)))
dLog(decodeCustom)
var decodeCustom = decodeURIComponent(escape(window.atob(customData)));
dLog(decodeCustom);

try {
data.custom_data = JSON.parse(decodeCustom)
data.custom_data = JSON.parse(decodeCustom);
} catch (error) {
dLog(error.message)
data.custom_data = decodeCustom
dLog(error.message);
data.custom_data = decodeCustom;
}

IMP.request_pay(data, callback);
Expand All @@ -61,7 +59,6 @@
}

</script>
<script defer type="text/javascript" src="https://code.jquery.com/jquery-latest.min.js"></script>
<script defer type="text/javascript" src="https://cdn.iamport.kr/js/iamport.payment-1.2.0.js"></script>
<script defer type="text/javascript" src="https://cdn.iamport.kr/v1/iamport.js"></script>
</body>
</html>
</html>
2 changes: 1 addition & 1 deletion Sources/iamport-ios/Classes/Data/Approve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class ApproveData: Codable {
var merchantUid: String
var success: Bool
var reason: String?
}
}
5 changes: 2 additions & 3 deletions Sources/iamport-ios/Classes/Data/BankPayResultCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ enum BankPayResultCode: String, CaseIterable {
case FAIL_CERT_MODULE_INIT

static func from(_ s: String) -> BankPayResultCode? {
for value in self.allCases {
if (s == value.code) {
for value in allCases {
if s == value.code {
return value
}
}
Expand Down Expand Up @@ -54,5 +54,4 @@ enum BankPayResultCode: String, CaseIterable {
return "인증모듈 초기화 오류"
}
}

}
16 changes: 7 additions & 9 deletions Sources/iamport-ios/Classes/Data/CHAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,31 @@ struct CHAI {
static let CHANNEL = "mobile"
}


public enum CHAI_MODE: String, CaseIterable, Codable {

case prod
case staging
case dev

var url: String {
switch self {
case .prod:
return CONST.CHAI_SERVICE_URL
return Constant.CHAI_SERVICE_URL
case .staging:
return CONST.CHAI_SERVICE_STAGING_URL
return Constant.CHAI_SERVICE_STAGING_URL
case .dev:
return CONST.CHAI_SERVICE_DEV_URL
return Constant.CHAI_SERVICE_DEV_URL
}
}

static func getChaiUrl(mode: String) -> String {
for value in self.allCases {
if (mode == value.rawValue) {
dlog("Found CHAI mode => [\(mode)]")
for value in allCases {
if mode == value.rawValue {
debug_log("Found CHAI mode => [\(mode)]")
return value.url
}
}

print("Not found CHAI mode => [\(mode)]")
return prod.url // default
}
}
}
Loading

0 comments on commit 81f0ec2

Please sign in to comment.