Quickly integrate payments into your app with our easy-to-use SDK.
- Overview
- Installation
- Security Best Practices
- Usage
- Payment Process
- UI Customization
- Apple Pay Integration
The Monext iOS SDK is designed for seamless integration of payment features. It provides a drop-in SwiftUI view that can be easily embedded into your existing UI.
Minimum Requirement:
- iOS 16.0
Before using the SDK, ensure you have an active Monext merchant account. Visit our website for details.
Monext iOS SDK is available via Swift Package Manager.
-
Add the Package Dependency:
Follow Apple’s guide on Adding Package Dependencies to Your App. -
Enter the Repository URL:
https://github.com/Monext/monext-ios-sdk
(Ensure you replace this with the correct repository URL if needed.)
-
Specify the Version:
Use version1.0.0
or later.
- BasicToken
- MerchantID
Never expose these credentials in your app’s code.
Once the SDK is installed and your Monext account is set up, you can integrate payment functionality into your app.
The main component is PaymentButton
, a ready-to-use SwiftUI view that manages the entire payment process. It integrates the presentPaymentSheet call:
import Monext
struct ExampleView: View {
var sessionToken: String?
var paymentSheetConfiguration: PaymentSheetConfiguration
var body: some View {
VStack {
if let sessionToken = sessionToken {
PaymentButton(
sessionToken: sessionToken,
configuration: paymentSheetConfiguration
) {
Text("CHECKOUT")
} onResult: { result in
switch result {
case .tokenExpired:
print("Token expired")
case .paymentPending:
print("Payment is pending...")
case .paymentSuccess:
print("Payment successful")
case .paymentFailure:
print("Payment failed")
case .paymentCanceled:
print("Payment canceled")
}
}
}
}
}
}
For greater control over the user interface, use the presentPaymentSheet
view modifier directly:
import Monext
struct CustomPaymentView: View {
@State var isPresented: Bool = false
var sessionToken: String
var configuration: PaymentSheetConfiguration
var applePayConfiguration: ApplePayConfiguration
var onResult: (PaymentResult) -> Void
var body: some View {
Button(action: { isPresented.toggle() }) {
Text("Pay")
}
.presentPaymentSheet(
isPresented: $isPresented,
sessionToken: sessionToken,
paymentSheetConfiguration: configuration,
applePayConfiguration: applePayConfiguration,
onResult: onResult
)
}
}
-
Create a Monext Payment Session Token:
Your backend must create a payment session via the Monext Retail API. Refer to the session creation documentation. -
Pass the Required Parameters to
PaymentButton
:sessionToken
PaymentSheetConfiguration
for UI customization
(See UI Customization)- Button content and
onResult
closure to handle payment outcomes
-
Handle Payment Results:
TheonResult
closure receives aPaymentResult
when the payment session ends. The payment sheet dismisses automatically. -
Get a session detail You can then retrieve the payment data via an API call with a GET Session, for more information: Documentation.
Customize the payment sheet using PaymentSheetConfiguration
. Modify colors, texts, and themes to match your branding.
All available UI customizations are contained in this class. You are not required to modify any element, the default is a light theme.
It is recommended to provide the headerTitle
or headerImage
at a minimum to identify your brand.
Monext iOS SDK supports Apple Pay via the PassKit framework. Setup requires:
-
Register a Merchant ID:
Create one on the Apple Developer portal. -
Generate a Payment Processing Certificate:
Follow Apple’s instructions to generate a CSR. -
Submit the Certificate to Monext:
Follow these steps. -
Enable Apple Pay in Xcode:
Add the Apple Pay capability in Signing & Capabilities and enter your merchant ID. -
Customize Apple Pay Button:
UseApplePayConfiguration
to customize the appearance of the Apple Pay button. You can modify its label and style:public struct ApplePayConfiguration { let buttonLabel: PayWithApplePayButtonLabel let buttonStyle: PayWithApplePayButtonStyle public init(buttonLabel: PayWithApplePayButtonLabel = .plain, buttonStyle: PayWithApplePayButtonStyle = .black) { self.buttonLabel = buttonLabel self.buttonStyle = buttonStyle } }
See Apple's official documentation for available options.