# Integrate the Virtual Cards SDK

## Prerequisites

1. [Complete the Getting Started Guide](https://docs.sudoplatform.com/guides/getting-started)
2. [Integrate the User SDK](https://docs.sudoplatform.com/guides/users/integrate-the-user-sdk)
3. [Integrate the Sudo Profiles SDK](https://docs.sudoplatform.com/guides/sudos/integrate-the-sudo-sdk)

## Get Started

* [Integrate the JS SDK](#integrate-the-js-sdk)
* [Integrate the iOS SDK](#integrate-the-ios-sdk)
* [Integrate the Android SDK](#integrate-the-android-sdk)

## Integrate the JS SDK

To use the **Virtual Cards SDK** in a Web or Node.js project, you must add `@sudoplatform/sudo-virtual-cards` as a dependency to your project.

```typescript
yarn add '@sudoplatform/sudo-virtual-cards'
# or
npm install --save '@sudoplatform/sudo-virtual-cards'
```

{% hint style="info" %}
In order to instantiate a Virtual Cards client, make sure you have followed instructions for [Getting Started](https://docs.sudoplatform.com/guides/getting-started), [User SDK](https://docs.sudoplatform.com/guides/users/integrate-the-user-sdk) and [Sudo Profiles SDK](https://docs.sudoplatform.com/guides/sudos/integrate-the-sudo-sdk) (see [Prerequisites](#prerequisites) above).
{% endhint %}

To instantiate and initialize a client in your application, add the following:

{% tabs %}
{% tab title="TypeScript" %}

```javascript
import { DefaultApiClientManager } from '@sudoplatform/sudo-api-client'
import { DefaultConfigurationManager } from '@sudoplatform/sudo-common'
import { DefaultSudoVirtualCardsClient } from '@sudoplatform/sudo-virtual-cards'
import { DefaultSudoProfilesClient } from '@sudoplatform/sudo-profiles'
import { DefaultSudoUserClient } from '@sudoplatform/sudo-user'

const sdkConfigJSON = /* ... refer to Users documentation ... */
DefaultConfigurationManager.getInstance().setConfig(sdkConfigJSON)

const userClient = new DefaultSudoUserClient(/* refer to Users documentation */)
const profilesClient = new DefaultSudoProfilesClient(/* refer to Sudos documentation */)
const apiClientManager = DefaultApiClientManager.getInstance().setAuthClient(userClient)

const virtualCardsClient = new DefaultSudoVirtualCardsClient(
    apiClientManager,
    userClient,
    profilesClient
)
```

{% endtab %}
{% endtabs %}

## Integrate the iOS SDK

To use the Virtual Cards SDK in an iOS app, you need to install the SudoVirtualCards package via Swift Package Manager

Open your project settings in XCode, and go to the `Package Dependencies` tab. Click on the `+` sign to add a dependency.&#x20;

Enter the repository URL [`https://github.com/sudoplatform/sudo-virtual-cards-ios`](https://github.com/sudoplatform/sudo-virtual-cards-ios) in the top right search box and select the `sudo-virtual-cards-ios` repository.&#x20;

Select the required version and `Add Package`.&#x20;

Sudo Platform SDKs conform to semantic versioning so in most cases you will leave the Dependency Rule as `Up to Next Major Version` to receive regular updates without introducing any breaking changes.

This will resolve the local package dependency and install the latest version of the Virtual Cards SDK.

{% hint style="info" %}
In order to instantiate a Virtual Cards client, make sure you have followed instructions for [Getting Started](https://github.com/sudoplatform/developer-documentation/blob/master/guides/virtual-cards/broken-reference/README.md), [User SDK](https://github.com/sudoplatform/developer-documentation/blob/master/guides/virtual-cards/broken-reference/README.md) and [Sudo Profiles SDK](https://github.com/sudoplatform/developer-documentation/blob/master/guides/virtual-cards/broken-reference/README.md) (see [Prerequisites](#prerequisites) above)
{% endhint %}

To instantiate a client in your application, add the following:

{% tabs %}
{% tab title="Swift" %}

```swift
import SudoVirtualCards
import SudoProfiles
import SudoUser

let userClient = // ... see "Users" docs
let profilesClient = // ... see "Sudos" docs

do {
    let virtualCardsClient = DefaultSudoVirtualCardsClient(
        keyNamespace: keyNamespace,
        userClient: userClient,
        profilesClient: profilesClient
    )
} catch {
    // Handle initialization error. An error might be thrown due to invalid
    // or missing confiugration file.
}s
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
You only need one client instance for a given user per device. Instantiating multiple clients with the same configuration and using them at the same time may cause unexpected runtime errors to occur.
{% endhint %}

{% hint style="success" %}
**See it in action**. Be sure to take a look at the [open source iOS sample app](https://github.com/sudoplatform/samples-ios) on Github that our team published as a reference for integrating the Virtual Cards SDK into your app as quickly and seamlessly as possible.
{% endhint %}

## Integrate the Android SDK

The Android SDK is open source and compatible with Android 6 (API level 23) and above.

{% tabs %}
{% tab title="Gradle" %}
Add this line to the dependencies section of the app module `build.gradle` and synchronize your project with Android Studio.

```typescript
dependencies {
    implementation 'com.sudoplatform:sudovirtualcards:$latest_version'
    // For Stripe funding source. https://github.com/stripe/stripe-android
    implementation 'com.stripe:stripe-android:20.5.0'
    // For Checkout funding source. https://github.com/checkout/frames-android
    implementation 'com.github.checkout:frames-android:3.1.2'
}
```

{% hint style="info" %}
The latest version of the SDK can be found at [SDK Releases](https://docs.sudoplatform.com/guides/virtual-cards/sdk-releases).
{% endhint %}

{% hint style="info" %}
In order to instantiate a Virtual Cards client, make sure you have followed instructions for [Getting Started](https://docs.sudoplatform.com/guides/getting-started), [User SDK](https://docs.sudoplatform.com/guides/users/integrate-the-user-sdk) and [Sudo SDK ](https://docs.sudoplatform.com/guides/sudos/integrate-the-sudo-sdk)(see Prerequisities above)
{% endhint %}
{% endtab %}
{% endtabs %}

To instantiate a client in your application, add the following

{% tabs %}
{% tab title="Kotlin" %}

```kotlin
val userClient = // ... see "Users" docs
val profilesClient = // ... see "Sudos" docs

val virtualCardsClient = SudoVirtualCardsClient.builder()
    .setContext(appContext)
    .setSudoUserClient(userClient)
    .setSudoProfilesClient(profilesClient)
    .build()
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
You only need one client instance for a given user per device. Instantiating multiple clients with the same configuration and using them at the same time may cause unexpected runtime errors to occur.
{% endhint %}

{% hint style="success" %}
**See it in action.** Be sure to take a look at the [open source Android sample app](https://github.com/sudoplatform/samples-android) on Github that our team published as a reference for integrating the Virtual Cards SDK into your app as quickly and seamlessly as possible.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sudoplatform.com/guides/virtual-cards/integrate-the-virtual-cards-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
