iOS 환경에서 포트원 V2 결제 시스템에 연동하기 위한 SDK입니다.
- iOS 14.0 이상
- Swift 6.0 이상
- Xcode 15.0 이상
- Xcode에서 프로젝트를 열고 File > Add Package Dependencies를 선택합니다.
- 패키지 URL에 다음을 입력합니다:
https://github.com/portone-io/ios-sdk.git
- 버전 규칙을 선택하고 Add Package를 클릭합니다.
Package.swift
파일에 다음 의존성을 추가합니다:
dependencies: [
.package(url: "https://github.com/portone-io/ios-sdk.git", from: "<버전>")
]
앱의 Info.plist
에 다음 설정을 추가해야 합니다.
자세한 내용은 SwiftExample/SwiftExample/Info.plist 또는 UIKitExample/UIKitExample/Info.plist에서 확인할 수 있습니다.
-
URL Scheme 등록 (결제 완료 후 앱으로 돌아오기 위함)
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>your-app-scheme</string> </array> </dict> </array>
-
외부 결제 앱 스킴 등록 (한국 결제 앱 연동을 위함)
<key>LSApplicationQueriesSchemes</key> <array> <string>kakaotalk</string> <string>naverpay</string> <string>ispmobile</string> <string>shinhan-sr-ansimclick</string> <!-- ... --> </array>
SDK는 SwiftUI와 UIKit 모두를 지원합니다:
- SwiftUI 예제: SwiftExample/SwiftExample/ContentView.swift
- UIKit 예제: UIKitExample/UIKitExample/ViewController.swift
import SwiftUI
import PortOneSdk
struct PaymentView: View {
@State private var showPaymentSheet = false
var body: some View {
Button("결제하기") {
showPaymentSheet = true
}
.sheet(isPresented: $showPaymentSheet) {
let paymentId = UUID().uuidString.replacingOccurrences(of: "-", with: "")
PaymentWebView(
data: [
"storeId": "your-store-id",
"channelKey": "your-channel-key",
"paymentId": paymentId,
"orderName": "주문명",
"totalAmount": 1000,
"currency": "KRW",
"payMethod": "CARD",
"appScheme": "your-app-scheme://"
],
onCompletion: { result in
switch result {
case .success(let payment):
print("결제 성공: \(payment)")
case .failure(let error):
print("결제 실패: \(error)")
}
showPaymentSheet = false
}
)
}
}
}
import SwiftUI
import PortOneSdk
struct BillingKeyView: View {
@State private var showIssueBillingKeySheet = false
var body: some View {
Button("빌링키 발급") {
showIssueBillingKeySheet = true
}
.sheet(isPresented: $showIssueBillingKeySheet) {
IssueBillingKeyWebView(
data: [
"storeId": "your-store-id",
"channelKey": "your-channel-key",
"issueName": "빌링키 발급 테스트",
"billingKeyMethod": "CARD",
"appScheme": "your-app-scheme://"
],
onCompletion: { result in
switch result {
case .success(let billingKey):
print("빌링키 발급 성공: \(billingKey)")
case .failure(let error):
print("빌링키 발급 실패: \(error)")
}
showIssueBillingKeySheet = false
}
)
}
}
}
import SwiftUI
import PortOneSdk
struct IdentityVerificationView: View {
@State private var showIdentityVerificationSheet = false
var body: some View {
Button("본인인증") {
showIdentityVerificationSheet = true
}
.sheet(isPresented: $showIdentityVerificationSheet) {
let identityVerificationId = UUID().uuidString.replacingOccurrences(of: "-", with: "")
IdentityVerificationWebView(
data: [
"storeId": "your-store-id",
"channelKey": "your-channel-key",
"identityVerificationId": identityVerificationId
],
onCompletion: { result in
switch result {
case .success(let verification):
print("본인인증 성공: \(verification)")
case .failure(let error):
print("본인인증 실패: \(error)")
}
showIdentityVerificationSheet = false
}
)
}
}
}
import UIKit
import PortOneSdk
class PaymentViewController: UIViewController {
@IBAction func paymentButtonTapped(_ sender: UIButton) {
let paymentId = UUID().uuidString.replacingOccurrences(of: "-", with: "")
let paymentViewController = PaymentViewController(
data: [
"storeId": "your-store-id",
"channelKey": "your-channel-key",
"paymentId": paymentId,
"orderName": "주문명",
"totalAmount": 1000,
"currency": "KRW",
"payMethod": "CARD",
"appScheme": "your-app-scheme://"
],
onCompletion: { [weak self] result in
DispatchQueue.main.async {
self?.dismiss(animated: true) {
switch result {
case .success(let payment):
print("결제 성공: \(payment)")
case .failure(let error):
print("결제 실패: \(error)")
}
}
}
}
)
present(paymentViewController, animated: true)
}
}
import UIKit
import PortOneSdk
class BillingKeyViewController: UIViewController {
@IBAction func billingKeyButtonTapped(_ sender: UIButton) {
let billingKeyViewController = IssueBillingKeyViewController(
data: [
"storeId": "your-store-id",
"channelKey": "your-channel-key",
"issueName": "빌링키 발급 테스트",
"billingKeyMethod": "CARD",
"appScheme": "your-app-scheme://"
],
onCompletion: { [weak self] result in
DispatchQueue.main.async {
self?.dismiss(animated: true) {
switch result {
case .success(let billingKey):
print("빌링키 발급 성공: \(billingKey)")
case .failure(let error):
print("빌링키 발급 실패: \(error)")
}
}
}
}
)
present(billingKeyViewController, animated: true)
}
}
import UIKit
import PortOneSdk
class IdentityViewController: UIViewController {
@IBAction func identityVerificationButtonTapped(_ sender: UIButton) {
let identityVerificationId = UUID().uuidString.replacingOccurrences(of: "-", with: "")
let identityVerificationViewController = IdentityVerificationViewController(
data: [
"storeId": "your-store-id",
"channelKey": "your-channel-key",
"identityVerificationId": identityVerificationId
],
onCompletion: { [weak self] result in
DispatchQueue.main.async {
self?.dismiss(animated: true) {
switch result {
case .success(let verification):
print("본인인증 성공: \(verification)")
case .failure(let error):
print("본인인증 실패: \(error)")
}
}
}
}
)
present(identityVerificationViewController, animated: true)
}
}
결제, 빌링키 발급, 본인인증의 상세 파라미터는 포트원 개발자 문서를 참조하세요.
단, redirectUrl
파라미터의 경우 결제 결과를 받아오기 위해 SDK가 자동 입력하므로 무시됩니다.
SwiftExample
디렉토리에서 SwiftUI 기반 SDK 사용 예제를 확인할 수 있습니다:
cd SwiftExample
open SwiftExample.xcodeproj
UIKitExample
디렉토리에서 UIKit 기반 SDK 사용 예제를 확인할 수 있습니다:
cd UIKitExample
open UIKitExample.xcodeproj
예제를 실행하기 전에 각 프로젝트의 소스 파일에서 실제 storeId
와 channelKey
로 변경해야 합니다.
이 프로젝트는 Apache License 2.0과 MIT License의 듀얼 라이선스로 제공됩니다. 자세한 내용은 LICENSE-APACHE와 LICENSE-MIT 파일을 참조하세요.