Skip to content

iamport/iamport-ios

Repository files navigation

๐ŸŒฑ I'mport iOS SDK ๐ŸŒฑ

iamport-ios

CI Status Version License Platform

์„ค๋ช…

iOS ๋„ค์ดํ‹ฐ๋ธŒ ์•ฑ์—์„œ ๊ฒฐ์ œ ๊ฐœ๋ฐœ์„ ๊ฐ„ํŽธํ•˜๊ฒŒ ๋„์™€์ฃผ๋Š” ์•„์ž„ํฌํŠธ SDK ์ž…๋‹ˆ๋‹ค.

  • CHAI ๊ฐ„ํŽธ๊ฒฐ์ œ๋Š” Native ์—ฐ๋™๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์—ฌ๋Ÿฌ PG ๋“ค์„ WebView ๊ธฐ๋ฐ˜์œผ๋กœ ๊ฒฐ์ œ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์ถ”ํ›„ ์ˆœ์ฐจ์ ์œผ๋กœ ํƒ€ ๊ฐ„ํŽธ๊ฒฐ์ œ๋“ค๋„ ๋„ค์ดํ‹ฐ๋ธŒ ์—ฐ๋™ ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.



iOS plist ์„ค์ •๋ฐฉ๋ฒ•

iOS ์„ค์ • ํŽผ์ณ๋ณด๊ธฐ

iOS ์„ค์ •ํ•˜๊ธฐ

iOS์—์„œ ์•„์ž„ํฌํŠธ ๊ฒฐ์ œ์—ฐ๋™ ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜ 3๊ฐ€์ง€ ํ•ญ๋ชฉ์„ ์„ค์ •ํ•ด์ฃผ์…”์•ผ ํ•ฉ๋‹ˆ๋‹ค.

1. App Scheme ๋“ฑ๋ก

์™ธ๋ถ€ ๊ฒฐ์ œ ์•ฑ(์˜ˆ) ํŽ˜์ด์ฝ”, ์‹ ํ•œ ํŒ ํŽ˜์ด)์—์„œ ๊ฒฐ์ œ ํ›„ ๋Œ์•„์˜ฌ ๋•Œ ์‚ฌ์šฉํ•  URL identifier๋ฅผ ์„ค์ •ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

  1. [ํ”„๋กœ์ ํŠธ ํด๋”]/ios/[ํ”„๋กœ์ ํŠธ ์ด๋ฆ„]/Info.plist ํŒŒ์ผ์„ ์—ฐ ํ›„ URL types์†์„ฑ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
  2. item 0๋ฅผ ํ™•์žฅํ•˜์—ฌ URL schemes๋ฅผ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
  3. item 0์— App Scheme์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

2. ์™ธ๋ถ€ ์•ฑ ๋ฆฌ์ŠคํŠธ ๋“ฑ๋ก

3rd party์•ฑ(์˜ˆ) ๊ฐ„ํŽธ๊ฒฐ์ œ ์•ฑ)์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋„๋ก ์™ธ๋ถ€ ์•ฑ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋“ฑ๋กํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

  1. [ํ”„๋กœ์ ํŠธ ํด๋”]/ios/[ํ”„๋กœ์ ํŠธ ์ด๋ฆ„]/Info.plist ํŒŒ์ผ์„ ์˜คํ”ˆํ•ฉ๋‹ˆ๋‹ค.
  2. LSApplicationQueriesSchemes ์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ์•„๋ž˜์— ์™ธ๋ถ€ ์•ฑ ๋ฆฌ์ŠคํŠธ๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>kftc-bankpay</string> <!-- ๊ณ„์ขŒ์ด์ฒด -->
  <string>ispmobile</string> <!-- ISP๋ชจ๋ฐ”์ผ -->
  <string>itms-apps</string> <!-- ์•ฑ์Šคํ† ์–ด -->
  <string>hdcardappcardansimclick</string> <!-- ํ˜„๋Œ€์นด๋“œ-์•ฑ์นด๋“œ -->
  <string>smhyundaiansimclick</string> <!-- ํ˜„๋Œ€์นด๋“œ-๊ณต์ธ์ธ์ฆ์„œ -->
  <string>shinhan-sr-ansimclick</string> <!-- ์‹ ํ•œ์นด๋“œ-์•ฑ์นด๋“œ -->
  <string>smshinhanansimclick</string> <!-- ์‹ ํ•œ์นด๋“œ-๊ณต์ธ์ธ์ฆ์„œ -->
  <string>kb-acp</string> <!-- ๊ตญ๋ฏผ์นด๋“œ-์•ฑ์นด๋“œ -->
	<string>kb-auth</string> <!-- ๊ตญ๋ฏผ -->
	<string>kb-screen</string> <!-- ๊ตญ๋ฏผ -->
	<string>kbbank</string> <!-- ๊ตญ๋ฏผ -->
	<string>liivbank</string> <!-- Liiv ๊ตญ๋ฏผ -->
	<string>newliiv</string> <!-- ๊ตญ๋ฏผ -->
  <string>mpocket.online.ansimclick</string> <!-- ์‚ผ์„ฑ์นด๋“œ-์•ฑ์นด๋“œ -->
  <string>ansimclickscard</string> <!-- ์‚ผ์„ฑ์นด๋“œ-์˜จ๋ผ์ธ๊ฒฐ์ œ -->
  <string>ansimclickipcollect</string> <!-- ์‚ผ์„ฑ์นด๋“œ-์˜จ๋ผ์ธ๊ฒฐ์ œ -->
  <string>vguardstart</string> <!-- ์‚ผ์„ฑ์นด๋“œ-๋ฐฑ์‹  -->
  <string>samsungpay</string> <!-- ์‚ผ์„ฑ์นด๋“œ-์‚ผ์„ฑํŽ˜์ด -->
  <string>scardcertiapp</string> <!-- ์‚ผ์„ฑ์นด๋“œ-๊ณต์ธ์ธ์ฆ์„œ -->
  <string>lottesmartpay</string> <!-- ๋กฏ๋ฐ์นด๋“œ-๋ชจ๋ฐ”์ผ๊ฒฐ์ œ -->
  <string>lotteappcard</string> <!-- ๋กฏ๋ฐ์นด๋“œ-์•ฑ์นด๋“œ -->
  <string>cloudpay</string> <!-- ํ•˜๋‚˜์นด๋“œ-์•ฑ์นด๋“œ -->
  <string>nhappcardansimclick</string> <!-- ๋†ํ˜‘์นด๋“œ-์•ฑ์นด๋“œ -->
  <string>nonghyupcardansimclick</string> <!-- ๋†ํ˜‘์นด๋“œ-๊ณต์ธ์ธ์ฆ์„œ -->
  <string>citispay</string> <!-- ์”จํ‹ฐ์นด๋“œ-์•ฑ์นด๋“œ -->
  <string>citicardappkr</string> <!-- ์”จํ‹ฐ์นด๋“œ-๊ณต์ธ์ธ์ฆ์„œ -->
  <string>citimobileapp</string> <!-- ์”จํ‹ฐ์นด๋“œ-๊ฐ„ํŽธ๊ฒฐ์ œ -->
  <string>kakaotalk</string> <!-- ์นด์นด์˜คํ†ก -->
  <string>payco</string> <!-- ํŽ˜์ด์ฝ” -->
  <string>lpayapp</string> <!-- (๊ตฌ)๋กฏ๋ฐ LํŽ˜์ด -->
  <string>hanamopmoasign</string> <!-- ํ•˜๋‚˜์นด๋“œ ๊ณต์ธ์ธ์ฆ์•ฑ -->
  <string>wooripay</string> <!-- (๊ตฌ) ์šฐ๋ฆฌํŽ˜์ด -->
  <string>nhallonepayansimclick</string> <!-- NH ์˜ฌ์›ํŽ˜์ด -->
  <string>hanawalletmembers</string> <!-- ํ•˜๋‚˜์นด๋“œ(ํ•˜๋‚˜๋ฉค๋ฒ„์Šค ์›”๋ ›) -->
  <string>chaipayment</string> <!-- ์ฐจ์ด -->
  <string>hyundaicardappcardid</string>  <!-- ํ˜„๋Œ€์นด๋“œ -->
  <string>com.wooricard.wcard</string>  <!-- ์šฐ๋ฆฌwonํŽ˜์ด -->
  <string>lmslpay</string>  <!-- ๋กฏ๋ฐ LํŽ˜์ด -->
  <string>lguthepay-xpay</string>  <!-- ํŽ˜์ด๋‚˜์šฐ -->
  <string>supertoss</string>   <!-- ํ† ์Šค -->
  <string>newsmartpib</string>   <!-- ์šฐ๋ฆฌWON๋ฑ…ํ‚น -->
</array>

3. App Transport Security ์„ค์ •

  1. [ํ”„๋กœ์ ํŠธ ํด๋”]/ios/[ํ”„๋กœ์ ํŠธ ์ด๋ฆ„]/Info.plist ํŒŒ์ผ์„ ์˜คํ”ˆํ•ฉ๋‹ˆ๋‹ค.
  2. App Transport Security ์†์„ฑ์„ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
  3. ํ•˜๋ถ€ ์†์„ฑ์— Allow Arbitrary Loads in Web Content,Allow Arbitrary Loads ์†์„ฑ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ๊ฐ๊ฐ์˜ ๊ฐ’(value)์„ YES๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoadsInWebContent</key>
  <true/>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

iamport-ios is available through CocoaPods. To install it, simply add the following line to your Podfile:

[์ตœ์‹ ๋ฒ„์ „ ํ™•์ธ]

  • cocoapods ์ด์šฉ์‹œ (RxSwift 5.x ์‚ฌ์šฉ)
pod 'iamport-ios', '~> 1.4.1'
  • Swift Package Manager ์ด์šฉ์‹œ (RxSwift 6.x ์‚ฌ์šฉ)
iamport-ios 1.1.0 ๋ถ€ํ„ฐ ์ง€์›

Usage

  • UINavigationController ์‚ฌ์šฉ์˜ ๊ฒฝ์šฐ.
    storyboard ์˜ root view controller ์—์„œ Xcode ์ƒ๋‹จ -> Editor -> Embed in -> Navigation Controller.
  • UIViewController, WKWebView ์ง€์›.
  // ๊ฒฐ์ œ ์š”์ฒญ ๋ฐ์ดํ„ฐ ๊ตฌ์„ฑ 
  let payment = IamportPayment(
                pg: PG.html5_inicis.getPgSting(pgId: ""), // PG ์‚ฌ
                merchant_uid: "mid_123456",                   // ์ฃผ๋ฌธ๋ฒˆํ˜ธ                
                amount: "1000").then {                        // ๊ฐ€๊ฒฉ
                  $0.pay_method = "card"                      // ๊ฒฐ์ œ์ˆ˜๋‹จ
                  $0.name = "์ƒ˜ํ”Œ ๋จธ์ฒœํŠธ์—์„œ ์ฃผ๋ฌธ~"                // ์ฃผ๋ฌธ๋ช…
                  $0.buyer_name = "๋…๊ณ ๋…"                     
                  $0.app_scheme = "iamport"                   // ๊ฒฐ์ œ ํ›„ ์•ฑ์œผ๋กœ ๋ณต๊ท€ ์œ„ํ•œ app scheme
              }

  // I'mport SDK ์— ๊ฒฐ์ œ ์š”์ฒญ
  // case1 : UINavigationController ์‚ฌ์šฉ
  Iamport.shared.payment(navController: navigationController, // ๋„ค๋น„๊ฒŒ์ด์…˜ ์ปจํŠธ๋กค๋Ÿฌ
                         userCode: userCode, // ๋จธ์ฒœํŠธ ์œ ์ € ์‹๋ณ„ ์ฝ”๋“œ
                         payment: payment) // ๊ฒฐ์ œ ์š”์ฒญ ๋ฐ์ดํ„ฐ
                         { [weak self] iamportResponse in
                            // ๊ฒฐ์ œ ์ข…๋ฃŒ ์ฝœ๋ฐฑ
                         }

  // case2 : UIViewController ์‚ฌ์šฉ
  Iamport.shared.payment(viewController: viewController, /* ์ดํ•˜๋™์ผ.. */)

  // case3 : WebView ๋ฅผ ๋ฐ”๋กœ ๋„˜๊ฒจ ๊ฒฐ์ œ๋ฅผ ์›ํ•˜๋ฉด, ์•„๋ž˜ [Optional ๊ตฌํ˜„์‚ฌํ•ญ WebView Mode ์™€ MobileWeb Mode] ์ฐธ์กฐํ•˜์„ธ์š”.
  
  Iamport.shared.close() // sdk ์ข…๋ฃŒ ์›ํ• ์‹œ ํ˜ธ์ถœ
  // AppDelegate.swift ์„ค์ •
  func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
      Iamport.shared.receivedURL(url)
      return true
  }

Optional ๊ตฌํ˜„์‚ฌํ•ญ WebView Mode ์™€ MobileWeb Mode

ํŽผ์ณ๋ณด๊ธฐ

๋ณธ sdk ์—์„œ๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ๊ฒฐ์ œ์—ฐ๋™์˜ ํŽธ์˜๋ฅผ ์ œ๊ณตํ•˜๊ณ ์ž
Iamport.payment ๋ฅผ ํ†ตํ•ด ๊ฒฐ์ œ ์š”์ฒญ์‹œ ์ƒˆ๋กœ์šด UIViewController ๊ฐ€ ์—ด๋ฆฌ๊ณ ,
๋‚ด๋ถ€์ ์œผ๋กœ WebView ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์ „๋‹ฌํ•ด์ฃผ์‹  parameters ๋ฅผ ํ†ตํ•ด ๊ฒฐ์ œ์ฐฝ์„ ์—ด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ์š”์ฒญ์— ๋”ฐ๋ผ ๊ฐœ๋ฐœ์˜ ์ž์œ ๋„๋ฅผ ๋“œ๋ฆฌ๊ธฐ ์œ„ํ•ด WebView Mode, MobileWeb Mode ๋‘๊ฐ€์ง€๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ( <= 1.0.0-dev08 )

1. WebView Mode

์„ค๋ช… : ๊ฒฐ์ œํŽ˜์ด์ง€๋ฅผ ์ง์ ‘ ์ƒ์„ฑํ•˜์‹œ๊ณ  iamport-sdk ์— WKWebView ๋ฅผ ๋„˜๊ฒจ ๊ฒฐ์ œ๋ฅผ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
ex) ์ง์ ‘ ๊ฒฐ์ œํŽ˜์ด์ง€๋ฅผ ๊พธ๋ฏธ๊ธฐ ์›ํ•˜๋Š” ๋ถ„.

  • ๋ฐ˜์˜๋ฐฉ๋ฒ• : ๊ธฐ์กด ์œ„์˜ [Usage] ์‚ฌํ•ญ ๊ณผ ๊ฐ™์ด iamport-sdk ์„ธํŒ…์„ ํ•ฉ๋‹ˆ๋‹ค.
    Iamport.shared.paymentWebView ํ˜ธ์ถœ ํŒŒ๋ผ๋ฏธํ„ฐ ์ค‘ webview ์— WKWebView ๋ฅผ ๋„ฃ์–ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๊ทธ ์™ธ๋Š” ๊ธฐ์กด์˜ ๋™์ž‘๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

PaymentWebViewModeView.swift ์ฐธ์กฐ

Iamport.shared.paymentWebView(webViewMode: wkWebView, /*์ดํ•˜ ๋™์ผ*/)

2. MobileWeb Mode

  • ์„ค๋ช… : ์•„์ž„ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” Mobile ์›นํŽ˜์ด์ง€๊ฐ€ load ๋œ webview ๋ฅผ ๋„˜๊ฒจ ๊ฒฐ์ œ ์ง„ํ–‰์„ ์„œํฌํŠธ ํ•ฉ๋‹ˆ๋‹ค.
    ex) ์ด๋ฏธ ์›น์‚ฌ์ดํŠธ์—์„œ ์•„์ž„ํฌํŠธ js sdk ๋ฅผ ์ด์šฉํ•˜๊ณ  ์žˆ๊ณ , ๋ณธ์ธ ์„œ๋น„์Šค๋ฅผ app ์œผ๋กœ๋งŒ ๊ฐ์‹ธ์„œ ์ถœ์‹œ ํ•˜๊ณ ์ž ํ•˜์‹œ๋Š” ๋ถ„.

  • ๋ฐ˜์˜๋ฐฉ๋ฒ• Step1 : ios ์•ฑ์—์„œ ๊ธฐ์กด ์œ„์˜ [Usage] ์‚ฌํ•ญ ๊ณผ ๊ฐ™์ด iamport-sdk ์„ธํŒ…์„ ํ•ฉ๋‹ˆ๋‹ค.
    ์ถ”๊ฐ€๋กœ Iamport.shared.pluginMobileWebSupporter(webview) ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ webview ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.
    ์‹ค์ œ ๊ฒฐ์ œ ์ง„ํ–‰์€ ๊ณ ๊ฐ๋‹˜์˜ ์›น์‚ฌ์ดํŠธ ๋‚ด์—์„œ ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.

mobileweb.html ์ฐธ์กฐ (์˜ˆ์‹œ์ด๋ฉฐ ์‹ค์ œ๋กœ๋Š” ๊ณ ๊ฐ๋‹˜์˜ Front-End ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.)
PaymentMobileWebMode.swift ์ฐธ์กฐ

Iamport.shared.pluginMobileWebSupporter(mobileWebMode: wkWebView)
  • ๋ฐ˜์˜๋ฐฉ๋ฒ• Step2 : ๊ธฐ์กด js sdk ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์›น ํ”„๋ก ํŠธ์—”๋“œ(html) ์˜
    IMP.request_pay, IMP.certification ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ณณ ์œ„์—์„œ, ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

  • ์ „๋‹ฌํ•˜๋Š” ๋ฐ์ดํ„ฐ ํ˜•์‹

// 1. `IMP.request_pay`๋ฅผ ํ†ตํ•œ ๊ฒฐ์ œ์˜ ๊ฒฝ์šฐ
const params = {
    userCode: userCode, // ๊ฐ€๋งน์  ์‹๋ณ„์ฝ”๋“œ
    payment: payment,   // ๊ฒฐ์ œ ๋ฐ์ดํ„ฐ
};

// 2. `IMP.certification`๋ฅผ ํ†ตํ•œ ๋ณธ์ธ์ธ์ฆ์˜ ๊ฒฝ์šฐ
const params = {
    userCode: userCode,           // ๊ฐ€๋งน์  ์‹๋ณ„์ฝ”๋“œ
    certification: certification, // ๋ณธ์ธ์ธ์ฆ ๋ฐ์ดํ„ฐ
};
  • ์˜ˆ์‹œ์ฝ”๋“œ
// ์˜ˆ์‹œ
// start of ์ถ”๊ฐ€๋˜๋Š” ๋ถ€๋ถ„
const isIOS = (/iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase()));
if(isIOS) {
    try {
        const params = {
          userCode : userCode,                                   // ๊ฐ€๋งน์  ์‹๋ณ„์ฝ”๋“œ
          iamportRequest : data,                                 // ๊ฒฐ์ œ ๋ฐ์ดํ„ฐ
        };
      window.webkit.messageHandlers.iamportmobilewebmode.postMessage(params)
    } catch (error) {
      console.error(error);
    }
}
// End of ์ถ”๊ฐ€๋˜๋Š” ๋ถ€๋ถ„

// ๊ธฐ์กด์˜ js IMP.request_pay
IMP.request_pay(data, ... // ์ƒ๋žต
  • Custom WKWebViewDelegate ์˜ ์‚ฌ์šฉ
/**
 webview url ์„ ํ†ตํ•ด ์ฒ˜๋ฆฌํ•˜๋Š” ๋กœ์ง์ด ์žˆ์„ ๊ฒฝ์šฐ์— 
 [IamportWKWebViewDelegate] ์ƒ์†ํ•˜์—ฌ ์‚ฌ์šฉ ํ•˜์‹œ๊ฑฐ๋‚˜,
 [Iamport.shared.updateWebViewUrl] ์˜ subscribe ์„ ํ†ตํ•ด ๋ณ€๊ฒฝ๋˜๋Š” url ์„ ์ฒดํฌ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
 */
// CASE1 : IamportWKWebViewDelegate ์ƒ์†
class MyWKWebViewDelegate: IamportWKWebViewDelegate {
    override func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
        if let url = navigationAction.request.url {
            // TODO : write your logic
            print("MyWKNavigationDelegate received url : \(url)")
        }

        super.webView(webView, decidePolicyFor: navigationAction, decisionHandler: decisionHandler)
    }
}

let webViewDelegate = MyWKWebViewDelegate()

class MyView: UIViewController {
    override func viewDidAppear(_ animated: Bool) {
        ..
        // IamportWKWebViewDelegate ์‚ฌ์šฉ
        wkWebView.navigationDelegate = webViewDelegate as WKNavigationDelegate
        
//       CASE2 : [Iamport.shared.updateWebViewUrl] ์‚ฌ์šฉ
        Iamport.shared.updateWebViewUrl.subscribe { [weak self] url in
            print("updateWebViewUrl received url : \(url.element)")
        }.disposed(by: disposeBag)
    }
}

Optional ๊ตฌํ˜„์‚ฌํ•ญ SwiftUI ์—์„œ์˜ ์‚ฌ์šฉ

ํŽผ์ณ๋ณด๊ธฐ

SwiftUI ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๋Š” ๋ถ„๋“ค์€ ์œ„์˜ WebViewMode ๋ฅผ ์‚ฌ์šฉํ•˜์‹œ๊ฑฐ๋‚˜,
์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฐธ์กฐํ•˜์‹œ์–ด UIViewContorller ๋ฅผ ๊ตฌ์„ฑํ•ด ์‚ฌ์šฉํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

๋˜ํ•œ Example app ์— ๋ฐ˜์˜๋˜์–ด ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
PaymentView.swift ์ฐธ์กฐ

struct IamportPaymentView: UIViewControllerRepresentable {

  func makeUIViewController(context: Context) -> UIViewController {
    let view = IamportPaymentViewController()
    return view
  }

  func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {}
}

class IamportPaymentViewController: UIViewController {

  // ์•„์ž„ํฌํŠธ SDK ๊ฒฐ์ œ ์š”์ฒญ 
  func requestIamportPayment() {
    let userCode = "iamport" // iamport ์—์„œ ๋ถ€์—ฌ๋ฐ›์€ ๊ฐ€๋งน์  ์‹๋ณ„์ฝ”๋“œ
    let payment = createPaymentData()
    
    Iamport.shared.payment(viewController: self,
            userCode: userCode, payment: payment) { [weak self] response in
      print("๊ฒฐ๊ณผ : \(response)")
    }
  }

  // ์•„์ž„ํฌํŠธ ๊ฒฐ์ œ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ
  func createPaymentData() -> IamportPayment {
    return IamportPayment(
            pg: PG.html5_inicis.makePgRawName(pgId: ""),
            merchant_uid: "swiftui_ios_\(Int(Date().timeIntervalSince1970))",
            amount: "1000").then {
      $0.pay_method = "card"
      $0.name = "SwiftUI ์—์„œ ์ฃผ๋ฌธ์ž…๋‹ˆ๋‹ค"
      $0.buyer_name = "SwiftUI"
      $0.app_scheme = "iamporttest" // ๊ฒฐ์ œ ํ›„ ๋Œ์•„์˜ฌ ์•ฑ์Šคํ‚ด
    }
  }
}

Optional ๊ตฌํ˜„์‚ฌํ•ญ SceneDelegate ์—์„œ์˜ ์‚ฌ์šฉ (target iOS13)

ํŽผ์ณ๋ณด๊ธฐ

iOS 13 ๋ถ€ํ„ฐ๋Š” ๊ธฐ์กด์˜ AppDelegate ์œผ๋กœ ๋ถ€ํ„ฐ UILifecycle ๊ด€๋ฆฌ๊ฐ€ ๋ถ„๋ฆฌ๋˜๋ฉด์„œ
SceneDelegate ๊ฐ€ ์ถ”๊ฐ€๋˜์—ˆ์Šต๋‹ˆ๋‹ค.
AppDelegate ์‚ฌ์šฉ ์ฝ”๋“œ ๋Œ€์‹  ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฐธ์กฐํ•ด์„œ ๋ฐ˜์˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.
SceneDelegate.swift ์ฐธ์กฐ

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    ..
  func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    if let url = URLContexts.first?.url {
      Iamport.shared.receivedURL(url)
    }
  }  
}

๐Ÿ’ก ์ƒ˜ํ”Œ์•ฑ

  • SwiftUI ๋กœ ์ž‘์„ฑ(Target iOS 13)

์•ฑ ์†Œ์Šค ํ™•์ธ ๊ฒฝ๋กœ

์‹คํ–‰๋ฐฉ๋ฒ•

  1. git clone
  2. Xcode project open
  3. connect iPhone via USB Cable(or use Simulator, Simulator ์‚ฌ์šฉ์‹œ ๊ฒฐ์ œ ํ™•์ธ์€ ๋ถˆ๊ฐ€๋Šฅ ํ•ฉ๋‹ˆ๋‹ค.)
  4. build Example app

Support

PortOne ๊ธฐ์ˆ ์ง€์›, support@portone.io

License

iamport-ios is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5