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

> ## Agent Instructions
> Test in the sandbox first: base URL https://api-sandbox.y.uno (Test Mode in the Dashboard). Production is https://api.y.uno (Live Mode).
> Every API request needs the public-api-key and private-secret-key headers. Get them in the Dashboard at https://dashboard.y.uno/developers (Developers > Credentials); sandbox and production keys are different.
> Send an X-Idempotency-Key (a UUID) when creating payments, refunds and cancels, so retries do not create duplicates.
> Start with the Quickstart (https://docs.y.uno/docs/quickstart.md) and the agent guide (https://docs.y.uno/agents.md). To search these docs from a coding agent, connect the docs MCP server at https://docs.y.uno/mcp.

# 代码示例

> 适用于常见场景的现成 React Native 代码示例。

> [!NOTE]
>
> **This page documents a legacy SDK.** Starting a new integration? Use the [Yuno SDK](https://docs.y.uno/docs/yuno-sdk/get-started.md). Already on a legacy SDK? Follow the [migration guide](https://docs.y.uno/docs/yuno-sdk/migration/overview.md).
>
> The new **Yuno SDK** (Web v2.x, iOS v3.x, Android v3.x, React Native v2.x) replaces the Full, Lite, Seamless, Render, Headless, and Secure Fields SDKs with one API across every platform. Legacy SDKs remain supported side by side during the transition and are scheduled for deprecation in **2027**. Contact your Account Manager for migration planning.

> [!WARNING]
>
> **Orientation: Choosing Your Integration Flow**, before you begin, please review the [Official Integration Flow](https://docs.y.uno/docs/sdks/overview/understanding-flows.md).
>
> * **Standard Flow ([Full Checkout](https://docs.y.uno/docs/sdks/full-checkout/web-payments))**: Recommended for most merchants. Yuno handles the UI, security, and automatic updates for payment methods.
> * **Custom Flow (This SDK)**: Use this only if you require full control over the UX. **Note**: You will be responsible for manually handling payment statuses, 3DS transitions, and fraud routing data collection.

浏览这些示例，在您的 React Native 应用中快速实现 Yuno。

## 基本支付流程

使用预构建的支付方式选择组件集成 Yuno 的最简单方式。

```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
import React, { useState, useEffect } from 'react';
import { View, Button, Text, StyleSheet, ScrollView } from 'react-native';
import { YunoSdk, YunoPaymentMethods } from '@yuno-payments/yuno-sdk-react-native';

export default function PaymentScreen() {
  const [checkoutSession, setCheckoutSession] = useState<string | null>(null);
  const [paymentMethodSelected, setPaymentMethodSelected] = useState(false);
  
  useEffect(() => {
    initCheckout();
    
    const subscription = YunoSdk.onPaymentStatus((state) => {
      if (state.status === 'SUCCEEDED') {
        Alert.alert('Success', 'Payment successful!');
      }
    });
    
    return () => subscription.remove();
  }, []);
  
  const initCheckout = async () => {
    const session = await fetch('https://api.example.com/checkout', {
      method: 'POST',
      body: JSON.stringify({ amount: { currency: 'USD', value: 2500 } }),
    }).then(r => r.json());
    
    setCheckoutSession(session.checkoutSession);
  };
  
  const processPayment = async () => {
    await YunoSdk.startPayment(true);
  };
  
  return (
    <ScrollView style={styles.container}>
      <Text style={styles.amount}>$25.00</Text>
      
      {checkoutSession && (
        <YunoPaymentMethods
          checkoutSession={checkoutSession}
          countryCode="US"
          onPaymentMethodSelected={(event) => {
            setPaymentMethodSelected(event.isSelected);
          }}
        />
      )}
      
      <Button 
        title="Pay Now" 
        onPress={processPayment}
        disabled={!paymentMethodSelected}
      />
    </ScrollView>
  );
}

const styles = StyleSheet.create({
  container: { flex: 1, padding: 20 },
  amount: { fontSize: 32, fontWeight: 'bold', textAlign: 'center', marginBottom: 24 },
});
```

## React Navigation 集成

```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { YunoSdk, YunoPaymentMethods } from '@yuno-payments/yuno-sdk-react-native';

const Stack = createStackNavigator();

function CheckoutScreen({ navigation }) {
  const [checkoutSession, setCheckoutSession] = useState<string | null>(null);
  const [paymentMethodSelected, setPaymentMethodSelected] = useState(false);
  
  useEffect(() => {
    initCheckout();
    
    const subscription = YunoSdk.onPaymentStatus((state) => {
      if (state.status === 'SUCCEEDED') {
        navigation.navigate('Success');
      }
    });
    
    return () => subscription.remove();
  }, []);
  
  const handlePayment = async () => {
    await YunoSdk.startPayment(true);
  };
  
  return (
    <ScrollView style={{ padding: 20 }}>
      {checkoutSession && (
        <YunoPaymentMethods
          checkoutSession={checkoutSession}
          countryCode="US"
          onPaymentMethodSelected={(event) => {
            setPaymentMethodSelected(event.isSelected);
          }}
        />
      )}
      <Button 
        title="Continue to Payment" 
        onPress={handlePayment}
        disabled={!paymentMethodSelected}
      />
    </ScrollView>
  );
}

export default function App() {
  useEffect(() => {
    YunoSdk.initialize({ apiKey: 'pk_test_key', countryCode: 'US' });
  }, []);
  
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Checkout" component={CheckoutScreen} />
        <Stack.Screen name="Success" component={SuccessScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}
```

## 一键支付（存储令牌）

```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const payWithCard = async (card) => {
  const session = await createCheckoutSession();
  
  await YunoSdk.startPaymentLite({
    checkoutSession: session.id,
    methodSelected: {
      vaultedToken: card.vaultedToken,
      paymentMethodType: 'CARD',
    },
    showPaymentStatus: true,
  }, 'US');
};
```

## 订阅注册

```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
const enrollCard = async () => {
  const customerSession = await createCustomerSession('cus_123');
  
  await YunoSdk.enrollmentPayment({
    customerSession: customerSession.id,
    countryCode: 'US',
    showPaymentStatus: true,
  });
};
```

## Context API 集成

```typescript theme={"theme":{"light":"github-dark","dark":"github-dark-dimmed"}}
import React, { createContext, useContext, useState, useEffect } from 'react';

const PaymentContext = createContext(null);

export function PaymentProvider({ children }) {
  const [isProcessing, setIsProcessing] = useState(false);
  
  useEffect(() => {
    const subscription = YunoSdk.onPaymentStatus((state) => {
      setIsProcessing(false);
      if (state.status === 'SUCCEEDED') { /* ... */ }
    });
    return () => subscription.remove();
  }, []);
  
  const processPayment = async () => {
    setIsProcessing(true);
    await YunoSdk.startPayment(true);
  };
  
  return (
    <PaymentContext.Provider value={{ isProcessing, processPayment }}>
      {children}
    </PaymentContext.Provider>
  );
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.