Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webview mode 결제요청 방식 변경 #45

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ target 'iamport-ios_Example' do
# cocoapods 사용시 enable
# cocoapods 사용시 enable
# pod 'iamport-ios', :path => '../' # local
# pod 'iamport-ios', '~> 1.4.1' # remote
# pod 'iamport-ios', '~> 1.4.2' # remote
# cocoapods 사용시 enable
# cocoapods 사용시 enable

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ it, simply add the following line to your Podfile:

- cocoapods 이용시 (RxSwift 5.x 사용)
```ruby
pod 'iamport-ios', '~> 1.4.1'
pod 'iamport-ios', '~> 1.4.2'
```


Expand Down
43 changes: 43 additions & 0 deletions Sources/PrivacyInfo.xcprivacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyTracking</key>
<false/>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryDiskSpace</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>E174.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategorySystemBootTime</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>35F9.1</string>
</array>
</dict>
</array>
</dict>
</plist>
55 changes: 34 additions & 21 deletions Sources/iamport-ios/Classes/Presentation/IamportWebViewMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -355,24 +355,19 @@ extension IamportWebViewMode: WKScriptMessageHandler {
case .START_WORKING_SDK:
print("JS SDK 통한 결제 시작 요청")

guard let pay = request else {
guard let request = request else {
print(".START_WORKING_SDK payment 를 찾을 수 없음")
return
}
debug_dump(pay)
debug_dump(request)

let encoder = JSONEncoder()
initSDK(userCode: request.userCode, tierCode: request.tierCode)

initSDK(userCode: pay.userCode, tierCode: pay.tierCode)

switch pay.payload {
case let .payment(payload):
let jsonData = try? encoder.encode(payload)
requestPay(payloadJsonData: jsonData)

case let .certification(payload):
let jsonData = try? encoder.encode(payload)
requestCertification(payloadJsonData: jsonData)
switch request.payload {
case let .payment(payment):
requestPay(payment: payment)
case let .certification(certification):
requestCertification(certification: certification)
}

case .RECEIVED:
Expand Down Expand Up @@ -408,20 +403,38 @@ extension IamportWebViewMode: WKScriptMessageHandler {
evaluateJavaScript(method: jsInitMethod)
}

private func requestPay(payloadJsonData: Data?) {
guard let json = payloadJsonData, let request = String(data: json, encoding: .utf8)?.replacingOccurrences(of: "'", with: "\\'") else {
print("Failed to encode payload for `requestPay`")
private func requestPay(payment: IamportPayment) {
guard let requestJsonData = try? JSONEncoder().encode(payment) else {
print("requestPay :: payment 데이터를 JSONEncoder encode 할 수 없습니다.")
return
}
debug_log("payment request : '\(request)'")
evaluateJavaScript(method: "requestPay('\(request)');")

guard let requestPayload = String(data: requestJsonData, encoding: .utf8)?.replacingOccurrences(of: "'", with: "\\'")
else {
print("requestPayWithCustomData :: requestJsonData 을 String 화 할 수 없습니다.")
return
}

if let encodedCustomData = payment.custom_data?.getBase64Encode() {
debug_log("requestPayWithCustomData request : '\(requestPayload)', encodedCustomData : '\(encodedCustomData)'")
evaluateJavaScript(method: "requestPayWithCustomData('\(requestPayload)', '\(encodedCustomData)');")
} else {
debug_log("requestPay request : '\(requestPayload)'")
evaluateJavaScript(method: "requestPay('\(requestPayload)');")
}
}

private func requestCertification(payloadJsonData: Data?) {
guard let json = payloadJsonData, let request = String(data: json, encoding: .utf8)?.replacingOccurrences(of: "'", with: "\\'") else {
print("Failed to encode payload for `requestCertification`")
private func requestCertification(certification: IamportCertification) {
guard let certificationJsonData = try? JSONEncoder().encode(certification) else {
print("requestCertification :: certification 데이터를 JSONEncoder encode 할 수 없습니다.")
return
}

guard let request = String(data: certificationJsonData, encoding: .utf8)?.replacingOccurrences(of: "'", with: "\\'") else {
print("requestCertification :: certificationJsonData를 String으로 변환할 수 없습니다.")
return
}

debug_log("certification request : '\(request)'")
evaluateJavaScript(method: "certification('\(request)');")
}
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.1'
s.version = '1.4.2'
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