iOS SDK
The Omise iOS SDK provides a secure and convenient way to integrate payment processing into your iOS applications. Built for Swift and Objective-C, it handles tokenization of sensitive payment data and supports all major payment methods available in Southeast Asia.
概要
The iOS SDK enables you to:
- Tokenize credit cards securely without card data touching your servers
- Create payment sources for alternative payment methods
- Implement 3D Secure authentication flows
- Build custom payment forms with native iOS UI components
- サポート biometric authentication with Touch ID and Face ID
- Handle errors gracefully with comprehensive error types
Key Features
- Native Swift API with async/await support
- Objective-C compatibility for legacy projects
- Pre-built UI components for rapid integration
- Comprehensive input validation
- Network resilience and automatic retries
- Full type safety with Swift generics
- SwiftUI and UIKit support
- Combine framework integration
要件
- iOS 12.0 or later
- Xcode 13.0 or later
- Swift 5.5+ or Objective-C
- CocoaPods 1.10+, Swift Package Manager, or Carthage
インストール
Swift Package Manager (Recommended)
Add the iOS SDK to your project using Swift Package Manager:
- In Xcode, go to File > Add Packages
- Enter the repository URL:
https://github.com/omise/omise-ios - Select version 5.0.0 or later
- Add to your target
Or add it to your Package.swift:
dependencies: [
.package(url: "https://github.com/omise/omise-ios", from: "5.0.0")
]
CocoaPods
Add the SDK to your Podfile:
platform :ios, '12.0'
use_frameworks!
target 'YourApp' do
pod 'OmiseSDK', '~> 5.0'
end
Then run:
pod install
Carthage
Add to your Cartfile:
github "omise/omise-ios" ~> 5.0
Run:
carthage update --use-xcframeworks
Then drag the built OmiseSDK.xcframework into your project.
クイックスタート
1. Import the SDK
import OmiseSDK
// Objective-C
@import OmiseSDK;
2. Configure the Client
Initialize the SDK with your public key:
import OmiseSDK
class Paymentサービス {
let client: OmiseClient
init() {
// Initialize with public key
client = OmiseClient(publicKey: "pkey_test_5xyzyx5xyzyx5xyzyx5")
}
}
// Objective-C
@interface Paymentサービス : NSObject
@property (nonatomic, strong) OMSClient *client;
@end
@implementation Paymentサービス
- (instancetype)init {
self = [super init];
if (self) {
_client = [[OMSClient alloc] initWithPublicKey:@"pkey_test_5xyzyx5xyzyx5xyzyx5"];
}
return self;
}
@end
3. Create a Token
Using Async/Await (Swift 5.5+)
func createToken() async throws -> Token {
let request = Token.CreateRequest(
name: "John Doe",
number: "4242424242424242",
expirationMonth: 12,
expirationYear: 2025,
securityCode: "123"
)
let token = try await client.send(request)
print("Token created: \(token.id)")
return token
}
// 使用方法
Task {
do {
let token = try await createToken()
// Send token to your server
await sendTokenToServer(token.id)
} catch {
print("Error: \(error.localizedDescription)")
}
}
Using Completion Handlers
func createToken(completion: @escaping (Result<Token, Error>) -> Void) {
let request = Token.CreateRequest(
name: "John Doe",
number: "4242424242424242",
expirationMonth: 12,
expirationYear: 2025,
securityCode: "123"
)
client.send(request) { result in
DispatchQueue.main.async {
completion(result)
}
}
}
// 使用方法
createToken { result in
switch result {
case .success(let token):
print("Token created: \(token.id)")
self.sendTokenToServer(token.id)
case .failure(let error):
print("Error: \(error.localizedDescription)")
}
}
Objective-C
OMSTokenRequest *request = [[OMSTokenRequest alloc] init];
request.name = @"John Doe";
request.number = @"4242424242424242";
request.expirationMonth = 12;
request.expirationYear = 2025;
request.securityCode = @"123";
[self.client send:request callback:^(OMSToken * _Nullable token, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error.localizedDescription);
return;
}
NSLog(@"Token created: %@", token.tokenId);
[self sendTokenToServer:token.tokenId];
}];