This page documents a legacy SDK. Starting a new integration? Use the Yuno SDK. Already on a legacy SDK? Follow the migration guide.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.
Orientation: Choosing Your Integration Flow, before you begin, please review the Official Integration Flow.
- Standard Flow (Full Checkout): 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.
基本支付流程
使用预构建的支付方式选择组件集成 Yuno 的最简单方式。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 集成
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>
);
}
一键支付(存储令牌)
const payWithCard = async (card) => {
const session = await createCheckoutSession();
await YunoSdk.startPaymentLite({
checkoutSession: session.id,
methodSelected: {
vaultedToken: card.vaultedToken,
paymentMethodType: 'CARD',
},
showPaymentStatus: true,
}, 'US');
};
订阅注册
const enrollCard = async () => {
const customerSession = await createCustomerSession('cus_123');
await YunoSdk.enrollmentPayment({
customerSession: customerSession.id,
countryCode: 'US',
showPaymentStatus: true,
});
};
Context API 集成
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>
);
}