# Online Payments

The Finix iOS SDK lets you securely collect card and bank account details in your iOS app using a pre-built payment sheet. Payment data is tokenized before it reaches your application, keeping sensitive card data out of your code and ensuring PCI compliance.

Tokens are created in Finix's vault and returned to your app. Use the token immediately to [create a Payment Instrument](/api/payment-instruments) via the Finix API.

Token Expiration
Tokens expire **30 minutes** after creation. Create a Payment Instrument as soon as you receive the token.

## Installing the Library

The library is distributed via CocoaPods. Add it to your `Podfile`:


```ruby
pod 'FinixPaymentSheet', :git => 'https://github.com/finix-payments/FinixPaymentSheet.git', :tag => 'v1.0.9'
```

Then run:


```bash
pod install
```

After installation, import the SDK in your source files:


```swift
import FinixPaymentSheet
```

No bridging headers or additional configuration are required.

## System Requirements

| Requirement | Value |
|  --- | --- |
| iOS | 12.0+ |
| Xcode | 14.0+ |
| Swift | 5.8+ |


## Quick Start

Initialize `FinixCredentials`, create a `PaymentAction`, present a payment sheet, and handle the token response via the delegate.


```swift
class CheckoutViewController: UIViewController {
    var paymentAction: PaymentAction!

    override func viewDidLoad() {
        super.viewDidLoad()

        let credentials = FinixCredentials(
            applicationId: "YOUR_APPLICATION_ID",
            environment: .Sandbox // set to .Production for production
        )
        paymentAction = PaymentAction(credentials: credentials, delegate: self)
    }

    func showPaymentSheet() {
        let sheet = paymentAction.paymentSheet(style: .complete)
        paymentAction.present(from: self, paymentSheet: sheet, animated: true)
    }
}

extension CheckoutViewController: PaymentActionDelegate {
    func paymentAction(_ action: PaymentAction, didSucceedWith response: TokenResponse) {
        // response.id — use this to create a Payment Instrument via the Finix API
        print("Token: \(response.id)")
    }

    func paymentAction(_ action: PaymentAction, didFailWith error: Error) {
        print("Error: \(error.localizedDescription)")
    }
}
```