| [ Web Proxy ] |
| Viewing: https://docs.payrails.com/docs/sdk-api-reference-1 | [Back] [Original] |
Current version: 1.26.1
Minimum deployment target: iOS 14.0
Swift version: 5.0+
Distribution: CocoaPods (Payrails/Checkout) Swift Package Manager
pod 'Payrails/Checkout', '~> 1.26'https://github.com/payrails/ios-sdk.git
Payrails.InitDataHolds the init payload returned by your backend after calling the Payrails initialization endpoint.
public struct Payrails.InitData: Codable {
public init(version: String, data: String)
public let version: String // Version string from backend response
public let data: String // Base64-encoded JSON payload from backend response
}Payrails.OptionsRuntime options passed to Configuration.
public struct Payrails.Options {
public init(env: Payrails.Env = .production)
public let env: Payrails.Env
}
public enum Payrails.Env: String {
case production
case test
}Payrails.ConfigurationWraps InitData and Options as the input to createSession.
public struct Payrails.Configuration {
public init(initData: Payrails.InitData, option: Payrails.Options)
public let initData: Payrails.InitData
public let option: Payrails.Options
}Payrails.createSession(with:)Creates and stores a session. All factory methods use the most recently created session.
// Async/await
public static func createSession(
with configuration: Payrails.Configuration
) async throws -> Payrails.Session
// Callback
public static func createSession(
with configuration: Payrails.Configuration,
onInit: OnInitCallback
)
public typealias OnInitCallback = (Result<Payrails.Session, PayrailsError>) -> VoidPayrails.Session is returned from createSession. You rarely need to call methods on it directly; prefer the static factory methods on Payrails instead.
public class Payrails.Session {
var isPaymentInProgress: Bool { get }
func isPaymentAvailable(type: PaymentType) -> Bool
func isPaymentCodeAvailable(paymentMethodCode: String) -> Bool
var isApplePayAvailable: Bool { get }
func storedInstruments(for type: Payrails.PaymentType) -> [StoredInstrument]
func executePayment(
with type: PaymentType,
paymentMethodCode: String?,
saveInstrument: Bool,
presenter: PaymentPresenter?,
onResult: @escaping OnPayCallback
)
func executePayment(
withStoredInstrument instrument: StoredInstrument,
presenter: PaymentPresenter?,
onResult: @escaping OnPayCallback
)
func cancelPayment()
// Async variants
@MainActor func executePayment(
with type: Payrails.PaymentType,
paymentMethodCode: String?,
saveInstrument: Bool,
presenter: PaymentPresenter?
) async -> OnPayResult
@MainActor func executePayment(
withStoredInstrument instrument: StoredInstrument,
presenter: PaymentPresenter?
) async -> OnPayResult
func update(_ options: UpdateOptions)
func query(_ key: PayrailsQueryKey) -> PayrailsQueryResult?
func tokenize(encryptedData: String, options: TokenizeOptions) async throws -> SaveInstrumentResponse
func deleteInstrument(instrumentId: String) async throws -> DeleteInstrumentResponse
func updateInstrument(instrumentId: String, body: UpdateInstrumentBody) async throws -> UpdateInstrumentResponse
}public enum Payrails.PaymentType: String {
case card
case applePay
case payPal
case genericRedirect
}All factory methods are static methods on Payrails and require an active session.
public static func createCardForm(
config: CardFormConfig? = nil,
showSaveInstrument: Bool = false
) -> Payrails.CardFormPayrails.CardForm is a UIStackView subclass. Add it to your view hierarchy and constrain with Auto Layout.
// Card form mode requires prior createCardForm()
public static func createCardPaymentButton(
buttonStyle: CardButtonStyle? = nil,
translations: CardPaymenButtonTranslations
) -> Payrails.CardPaymentButton
// Stored instrument mode
public static func createCardPaymentButton(
storedInstrument: StoredInstrument,
buttonStyle: StoredInstrumentButtonStyle? = nil,
translations: CardPaymenButtonTranslations,
storedInstrumentTranslations: StoredInstrumentButtonTranslations? = nil
) -> Payrails.CardPaymentButtonpublic static func createApplePayButton(
type: PKPaymentButtonType,
style: PKPaymentButtonStyle,
showSaveInstrument: Bool = false
) -> ApplePayElementpublic static func createPayPalButton(showSaveInstrument: Bool = false) -> PaypalElementpublic static func createGenericRedirectButton(
buttonStyle: CardButtonStyle? = nil,
translations: CardPaymenButtonTranslations,
paymentMethodCode: String
) -> Payrails.GenericRedirectButtonpublic static func createStoredInstruments(
style: StoredInstrumentsStyle? = nil,
translations: StoredInstrumentsTranslations? = nil,
showDeleteButton: Bool = false,
showUpdateButton: Bool = false,
showPayButton: Bool = false
) -> Payrails.StoredInstruments// Returns all stored instruments (card + PayPal)
public static func getStoredInstruments() -> [StoredInstrument]
// Returns stored instruments for a specific payment type
public static func getStoredInstruments(for type: Payrails.PaymentType) -> [StoredInstrument]
// Instrument management
public static func api(
_ operation: String, // "deleteInstrument" | "updateInstrument"
_ instrumentId: String,
_ body: UpdateInstrumentBody? = nil
) async throws -> InstrumentAPIResponse
// Runtime session state update
public static func update(_ options: UpdateOptions)
// Query session state
public static func query(_ key: PayrailsQueryKey) -> PayrailsQueryResult?PayrailsQueryKeypublic enum PayrailsQueryKey {
case executionId
case holderReference
case amount
case binLookup
case instrumentDelete
case instrumentUpdate
case paymentMethodConfig(PaymentMethodFilter)
case paymentMethodInstruments(type: Payrails.PaymentType)
}PaymentMethodFilterpublic enum PaymentMethodFilter {
case all
case redirect
case specific(String) // paymentMethodCode
}PayrailsQueryResultpublic enum PayrailsQueryResult {
case string(String)
case amount(PayrailsAmount)
case link(PayrailsLink)
case paymentOptions([PayrailsPaymentOption])
case storedInstruments([StoredInstrument])
}public struct PayrailsAmount {
public let value: String
public let currency: String
}
public struct PayrailsLink {
public let method: String?
public let href: String?
}
public struct PayrailsPaymentOption {
public let paymentMethodCode: String
public let description: String?
public let integrationType: String
public let clientConfig: ClientConfig?
public struct ClientConfig {
public let displayName: String?
public let flow: String?
public let supportsSaveInstrument: Bool?
public let supportsBillingInfo: Bool?
}
}public struct UpdateOptions {
public var amount: PayrailsAmount?
public init(amount: PayrailsAmount? = nil)
}
// Usage
Payrails.update(UpdateOptions(amount: PayrailsAmount(value: "57.49", currency: "USD")))public typealias OnInitCallback = (Result<Payrails.Session, PayrailsError>) -> Void
public typealias OnPayCallback = (OnPayResult) -> Void
public enum OnPayResult {
case success
case authorizationFailed
case failure
case error(PayrailsError)
case cancelledByUser
}Required to present view controllers during payment (e.g. 3DS challenges):
public protocol PaymentPresenter: AnyObject {
func presentPayment(_ viewController: UIViewController)
var encryptedCardData: String? { get set }
}Typically conformed to by a UIViewController:
extension MyCheckoutViewController: PaymentPresenter {
func presentPayment(_ viewController: UIViewController) {
present(viewController, animated: true)
}
}PayrailsCardPaymentButtonDelegatepublic protocol PayrailsCardPaymentButtonDelegate: AnyObject {
func onPaymentButtonClicked(_ button: Payrails.CardPaymentButton)
func onAuthorizeSuccess(_ button: Payrails.CardPaymentButton)
func onThreeDSecureChallenge(_ button: Payrails.CardPaymentButton)
func onAuthorizeFailed(_ button: Payrails.CardPaymentButton)
// Optional default implementation provided
func onStoredInstrumentChanged(_ button: Payrails.CardPaymentButton, instrument: StoredInstrument?)
}PayrailsCardFormDelegatepublic protocol PayrailsCardFormDelegate: AnyObject {
func cardForm(_ view: Payrails.CardForm, didCollectCardData data: String)
func cardForm(_ view: Payrails.CardForm, didFailWithError error: Error)
}PayrailsApplePayButtonDelegatepublic protocol PayrailsApplePayButtonDelegate: AnyObject {
// Called on payment result
}PayrailsPayPalButtonDelegatepublic protocol PayrailsPayPalButtonDelegate: AnyObject {
// Called on payment result
}PayrailsStoredInstrumentsDelegatepublic protocol PayrailsStoredInstrumentsDelegate: AnyObject {
func storedInstruments(_ view: Payrails.StoredInstruments, didSelectInstrument instrument: StoredInstrument)
func storedInstruments(_ view: Payrails.StoredInstruments, didCompletePaymentForInstrument instrument: StoredInstrument)
func storedInstruments(_ view: Payrails.StoredInstruments, didFailPaymentForInstrument instrument: StoredInstrument, error: PayrailsError)
func storedInstruments(_ view: Payrails.StoredInstruments, didRequestDeleteInstrument instrument: StoredInstrument)
func storedInstruments(_ view: Payrails.StoredInstruments, didRequestUpdateInstrument instrument: StoredInstrument)
}PayrailsErrorpublic enum PayrailsError: Error, LocalizedError {
case authenticationError
case sdkNotInitialized
case missingData(String?)
case invalidDataFormat
case invalidCardData
case unknown(error: Error?)
case unsupportedPayment(type: Payrails.PaymentType)
case incorrectPaymentSetup(type: Payrails.PaymentType)
case pollingFailed(String)
case failedToDerivePaymentStatus(String)
case finalStatusNotFoundAfterLongPoll(String)
case longPollingFailed(underlyingError: Error?)
}PayrailsError conforms to LocalizedError; use error.errorDescription for a human-readable message.
public struct TokenizeOptions {
public let storeInstrument: Bool
public let futureUsage: FutureUsage
}
public enum FutureUsage: String {
case cardOnFile
case subscription
case unscheduledCardOnFile
}public struct UpdateInstrumentBody: Codable {
// Fields depend on the update operation (e.g. isDefault)
}
public enum InstrumentAPIResponse {
case delete(DeleteInstrumentResponse)
case update(UpdateInstrumentResponse)
}See Styling Guide for full details.
public struct CardFormConfig {
public init(
showNameField: Bool = false,
showSaveInstrument: Bool = false,
showCardIcon: Bool = false,
showRequiredAsterisk: Bool = true,
cardIconAlignment: CardIconAlignment = .left,
fieldVariant: FieldVariant = .outlined,
layout: CardLayoutConfig? = nil,
styles: CardFormStylesConfig? = nil,
translations: CardTranslations? = nil
)
}
public enum FieldVariant {
case outlined
case filled
}
public enum CardIconAlignment {
case left
case right
}public extension Payrails {
struct Debug {
// Returns a SwiftUI view displaying the parsed SDK config and logs
public static func configViewer() -> some View
}
}
// Logs a message to both the Xcode console and the on-screen LogStore
public static func log(_ items: Any..., separator: String, terminator: String)Updated 5 months ago
| Web Proxy Viewer | New URL | Original Page |