> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alignet.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Initialize Alignet One SDK for iOS

> It creates the instance of PaymeClient, sets up the environment and starts the collection flow at iOS.

The collection function can be invoked Alignet One SDK from your app iOS to display the payment form and get the result of the operation.

<Info>
  Before starting SDKcomplete [Installation SDK iOS](/en/virtual-payments/sdk-mobile/ios/installation) and generates an `Access Token` from your backend using [Authentication](https://docs.pay-me.com/api-de-pagos/autenticacion).
</Info>

## Methods available

<CardGroup cols={3}>
  <Card title="CARD" icon="credit-card">
    Credit and debit cards.
  </Card>

  <Card title="YAPE" icon="mobile">
    Recovery with wallet Yape.
  </Card>

  <Card title="QR" icon="qrcode">
    Recovery with mobile bills by QR.
  </Card>

  <Card title="BANK_TRANSFER" icon="building-columns">
    Loan by Bank Transfer.
  </Card>

  <Card title="CUOTEALO" icon="receipt">
    Payment financed with Cuotéalo.
  </Card>

  <Card title="PAGO_EFECTIVO" icon="money-bill">
    Payment with code or channel PagoEfectivo.
  </Card>
</CardGroup>

## Integration Flow

<Steps>
  <Step title="The SDK">
    Add `UIKit` and `Alignet One` at `ViewController` from where you will start the flow.
  </Step>

  <Step title="Build the request">
    Crea `PAYMEChargesRequest` with transaction data, buyer, billing and configuration.
  </Step>

  <Step title="PaymeClient Configure">
    Initiates `PaymeClient` with `delegate`, `merchantCode` and atmosphere.
  </Step>

  <Step title="Invoked form">
    Send `accessToken` and `paymeChargesRequest` in `invokeCaptureForm`.
  </Step>

  <Step title="That's a quiet procedure.">
    Implement `onRespondsPayme` and `onPaymeEvents` To close the flow into your app.
  </Step>
</Steps>

## Import PaymeSDK

```swift theme={"system"} theme={"system"}
import UIKit
import Alignet One
```

## Main parameters

<AccordionGroup>
  <Accordion title="PaymeClient" icon="code" defaultOpen>
    * `delegate`: instance that implements methods of `PaymeClientDelegate`.
    * `merchantCode`: Merchant code delivered by Alignet.
  </Accordion>

  <Accordion title="SetEnvironment" icon="globe">
    * `PaymeEnviroment.development`: Test environment.
    * `PaymeEnviroment.production`: production environment.
  </Accordion>

  <Accordion title="invokeCaptureForm" icon="credit-card">
    * `from`: `UINavigationController` or controller from where the SDK.
    * `accessToken`: token generated from backend for this request.
    * `paymeChargesRequest`: with information about the transaction.
  </Accordion>
</AccordionGroup>

## Example of initiation

```swift theme={"system"} theme={"system"}
let customer = PAYMEAddressData(
    firstName: "Levis Antonio",
    lastName: "Silvestre Maylle",
    email: "levis.silvestre@alignet.com",
    phone: "51-958435685",
    identityDocument: PAYMEIdentityDocument(
        type: "DNI",
        identifier: "72111111",
        country: "PE"
    ),
    addressLine1: "Av casimiro Ulloa 333",
    addressLine2: nil,
    city: "Lima",
    state: "Lima",
    country: "PE"
)

let billingShipping = PAYMEAddressData(
    firstName: "Levis Antonio",
    lastName: "Silvestre Maylle",
    email: "levis.silvestre@alignet.com",
    phone: "51-958435685",
    addressLine1: "Av casimiro Ulloa 333",
    addressLine2: nil,
    city: "Lima",
    state: "Lima",
    country: "PE"
)

var additionalFields = [String: String]()
additionalFields["reserved1"] = "1"
additionalFields["reserved2"] = "2"
additionalFields["reserved3"] = "3"

let paymeChargesRequest = PAYMEChargesRequest(
    transaction: PAYMETransactionData(
        operationNumber: "0000001",
        amount: "1000",
        currency: "604",
        additionalFields: additionalFields,
        customer: customer,
        billing: billingShipping,
        shipping: billingShipping
    ),
    setting: PAYMESettingData(
        locale: "es_PE",
        paymentMethods: ["CARD", "YAPE", "CUOTEALO"],
        walletUserID: nil
    )
)

let paymeClient = PaymeClient(
    delegate: self,
    merchantCode: "MERCHANT_CODE"
)

paymeClient.setEnvironment(
    environment: PaymeEnviroment.development
)

paymeClient.invokeCaptureForm(
    from: self.navigationController!,
    accessToken: "TOKEN_GENERADO_PARA_ESTA_SOLICITUD",
    paymeChargesRequest: paymeChargesRequest
)
```

<Warning>
  The `accessToken` should be generated from backend for the application. Do not include credentials or secrets inside the app.
</Warning>

## Implement delegates

To complete integration, class should implement `PaymeClientDelegate`.

```swift theme={"system"} theme={"system"}
extension MainController: PaymeClientDelegate {
    func onRespondsPayme(response: PAYMEChargesResponse) {
        // Procesa el resultado final del flujo.
    }

    func onPaymeEvents(event: PaymeEvent) {
        // Registra eventos de navegación o interacción del SDK.
    }
}
```

## Events available

<CardGroup cols={2}>
  <Card title="BUILD_FORM" icon="list-check">
    It indicates what methods were shown to the user.
  </Card>

  <Card title="CHOOSE_PAYMENT_METHOD" icon="hand-pointer">
    It indicates the payment method chosen by the user.
  </Card>

  <Card title="RETURN_LIST_PAYMENT_METHODS" icon="arrow-left">
    He indicates that his user returned to his list of methods.
  </Card>

  <Card title="CANCEL_PAYMENT_METHOD" icon="ban">
    He indicates that the user cancelled a payment method.
  </Card>

  <Card title="PRESS_PAY_BUTTON" icon="mouse-pointer-click">
    It indicates that the user pressed the payment button.
  </Card>

  <Card title="CLOSE_PAYME" icon="xmark">
    indicates that the user closed the SDK.
  </Card>
</CardGroup>

## Validation of result

<Note>
  Use `onRespondsPayme` to update the user experience but confirms the final status from backend as required by the flow or payment method.
</Note>

## Next step

<Card title="Input and exit parameters" icon="arrow-right" href="/en/virtual-payments/sdk-mobile/ios/payment-flow/alignet-one-sdk-ios-parameters">
  Check the complete details of objects sent and received by SDK.
</Card>
