PaySwitcher
  • About PaySwitcher
    • ๐Ÿ›’For Online Businesses
    • ๐ŸชœFor Small & Medium Enterprises
    • ๐ŸขFor Enterprises
    • ๐Ÿ–ฅ๏ธFor SaaS Providers
    • ๐Ÿ›๏ธFor E-Commerce Businesses
    • ๐Ÿ“ฆFor Marketplace/Platforms
    • ๐ŸฆFor Banks & Financial Institutions
  • PaySwitcher Cloud
    • โšกQuickstart
      • ๐Ÿ“ฅMigrate from Stripe
        • Web
        • Android
        • iOS
        • React Native
      • ๐Ÿฅ—Payment Recipes
        • Use PayPal With Stripe
    • โš™๏ธControl Centre Account setup
    • ๐Ÿ“ฆIntegration guide
      • ๐ŸŒWeb
        • Node And React
        • Customization
        • Error Codes
        • Node and HTML
        • Vanilla JS and REST API Integration
      • ๐Ÿ“ฑAndroid
        • Kotlin with Node Backend
        • Customization
        • Features
      • ๐Ÿ“ฑiOS
        • Swift with Node Backend
        • Customization
        • Features
      • โบ๏ธReact Native
        • React Native with Node Backend (Beta)
        • Card Widget (Beta)
        • Customization
      • โบ๏ธFlutter
        • Flutter with Node Backend
        • Customization
      • Headless SDK
      • Payment Methods Management
    • ๐Ÿ’ณPayment methods setup
      • ๐Ÿ’ณCards
      • ๐Ÿ“ฑWallets
        • Apple Pay
          • Web Domain
          • iOS Application
        • Google Pay
        • PayPal
      • ๐Ÿ“†Pay Later
      • ๐ŸฆBanks
        • Bank Debits
        • Bank Redirects
        • Bank Transfers
      • ๐Ÿช™Crypto
      • ๐Ÿ”‘Test Credentials
    • ๐Ÿ”ŒConnectors
      • ๐Ÿ–ฒ๏ธAvailable Connectors
        • ACI
        • Adyen
        • Airwallex
        • Authorizedotnet
        • Bambora
        • Bank of America
        • Billwerk
        • Bluesnap
        • Braintree
        • Checkout
        • Coinbase
        • Cybersource
          • Apple Pay
          • Google Pay
        • dLocal
        • Fiserv
        • GlobalPayments
        • GoCardless
        • Klarna
        • Mollie
        • MultiSafepay
        • Nuvei
        • OpenNode
        • Paypal
        • PayU
        • Prophetpay
        • Rapyd
        • Shift4
        • Stripe
        • TrustPay
        • Volt
        • Worldline
        • Worldpay
        • Zen
      • Activate connector on PaySwitcher
      • Test a Payment with connector
    • ๐ŸชWebhooks
  • Features
    • ๐Ÿ”€Payment flows
      • ๐Ÿ”Saving payment methods & recurring payments
      • ๐Ÿ’ตPayouts
        • โž•Get started with payouts!
        • ๐Ÿ”—Process payouts using saved payment methods
        • ๐Ÿ›ฃ๏ธRoute your payout transactions using Smart Router
        • โ™ป๏ธSmart Retries in Payout
        • ๐Ÿ”—Payout links
      • 0๏ธ 0๏ธ 0๏ธ Zero Amount Authorization
      • ๐Ÿ”“Tokenization & saved cards
      • ๐Ÿ”—Payment links
      • โญ๏ธExternal Authentication for 3DS
      • ๐Ÿ’ฐManual Capture
      • ๐Ÿ›‘Fraud Blocklist
      • ๐Ÿ”Subscriptions
      • ๐Ÿ”ƒPG Agnostic Recurring Payments
    • ๐Ÿ•น๏ธMerchant controls
      • ๐Ÿ›ฃ๏ธSmart Router
        • Rule Based Routing
        • Volume Based Routing
        • Default Fallback Routing
      • ๐Ÿ›ก๏ธFraud & risk management
      • ๐Ÿ”ƒSmart retries
      • ๐ŸŽ›๏ธAnalytics & operations
      • ๐Ÿ“‹3DS decision manager
        • Setup guide
      • ๐Ÿ“‹Surcharge
        • Surcharge Setup guide
      • ๐Ÿ”ผ3DS Step-up retries
      • ๐ŸšฉDisputes/Chargebacks Management
      • ๐ŸคReconciliation
        • Getting Started with Recon
    • ๐Ÿ”‘Account management
      • ๐Ÿ”ขExporting payments data
      • ๐ŸคนMultiple accounts & profiles
      • ๐Ÿ›‚Manage your team
    • ๐Ÿ›๏ธE-commerce platform plugins
      • WooCommerce Plugin
        • Setup
        • Compatibility
        • FAQs
  • SECURITY AND COMPLIANCE
    • ๐Ÿ”Overview
    • ๐Ÿ’ณPCI Compliance
    • ๐Ÿ”Data Security
    • ๐Ÿ’ฝGDPR compliance
    • ๐Ÿ•ต๏ธIdentity and Access Management
  • Learn more
    • ๐ŸกSDK Reference
      • Node
      • React
      • JS
    • ๐Ÿ“PaySwitcher Architecture
      • Router
      • Storage
      • A Payments Switch with virtually zero overhead
    • ๐ŸŒŠPayment flows
Powered by GitBook
On this page
  • 1. Build card widget on the client
  • 1.1 Add HyperProvider to your React Native app
  • 1.2 Use HyperProvider
  • 1.3 Fetch the PaymentIntent client Secret
  • 1.4 Render your card widget
  • 1.5 Initiate payment session
  • 3.4 Confirm the payment
  1. PaySwitcher Cloud
  2. Integration guide
  3. React Native

Card Widget (Beta)

Integrate Card widget to your React Native App using payswitcher-node

Currently in beta please contact to get early access

PaySwitcher recommends using the PaymentSheet instead of the Card Widget. Using only the Payment Element, you can accept multiple payment methods.

1. Build card widget on the client

1.1 Add HyperProvider to your React Native app

Use HyperProvider to ensure that you stay PCI compliant by sending payment details directly to PaySwitcher server.

import { HyperProvider } from "@payswitcher/react-native-payswitcher";

1.2 Use HyperProvider

To initialize PaySwitcher in your React Native app, wrap your payment screen with the HyperProvider component. Only the API publishable key in publishableKey is required. The following example shows how to initialize PaySwitcher using the HyperProvider component.

import { HyperProvider } from "@payswitcher/react-native-payswitcher ";

function App() {
  return (
    <HyperProvider publishableKey="YOUR_PUBLISHABLE_KEY">
      // Your app code here
    </HyperProvider>
  );
}

1.3 Fetch the PaymentIntent client Secret

Make a network request to the backend endpoint you created in the previous step. The clientSecret returned by your endpoint is used to complete the payment.

const fetchPaymentParams = async () => {
  const response = await fetch(`${API_URL}/create-payment`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ items: [{ id: "xl-tshirt" }], country: "US" }),
  });
  const val = await response.json();
  return val;
};

1.4 Render your card widget

Use PaySwitcher CardField component to display a text field to securely collect card details. By using CardField, you guarantee that sensitive card details never touch your server.

import {CardField, useHyper} from '@stripe/stripe-react-native';

return(
 <View>
      <CardField
        postalCodeEnabled={true}
        placeholders={{
          number: '4242 4242 4242 4242',
        }}
        cardStyle={{
          backgroundColor: '#FFFFFF',
          textColor: '#000000',
        }}
        style={{
          width: '100%',
          height: 50,
          marginVertical: 30,
        }}
        onCardChange={cardDetails => {
          console.log('cardDetails', cardDetails);
        }}
        onFocus={focusedField => {
          console.log('focusField', focusedField);
        }}
        onBlur={blurField => {
          console.log('blurField', blurField);
        }}
      />
      <Button onPress={handlePayPress} title="Pay" disabled={loading} />
    </View>
)

1.5 Initiate payment session

Pass the PaymentIntentโ€™s clientSecret to initPaymentSession() function. PaySwitcher SDK automatically collects the card details from CardField component.

import {CardField, useHyper} from '@stripe/stripe-react-native';

const { initPaymentSession, confirmWithCardForm } = useHyper();
const [paymentSession,setPaymentSession]=React.useState(null);

const initializePaymentSession = async () => {
  const { clientSecret } = await fetchPaymentParams();
  const params={
      clientSecret: clientSecret,
  }
  const paymentSession = await initPaymentSession(params);
  await setPaymentSession(_=>paymentSession)
};

useEffect(() => {
  initializePaymentSheet();
}, []);

3.4 Confirm the payment

To confirm the Payment, integrate a "Pay Now" button within the checkout page, which, when clicked, invokes the confirmWithCardForm() function. This function will return an asynchronous payment response with various payment status.

const handlePayPress = async () => {
  const status = await confirmWithCardForm(paymentSession);
  console.log("presentPaymentSheet response: ", status);
  const { error, paymentOption } = status;
  if (error) {
    switch (error.code) {
      case "cancelled":
        Alert.alert("cancelled", `PaymentSheet was closed`);
        break;
      case "failed":
        Alert.alert("failed", `Payment failed`);
        break;
      default:
        Alert.alert("status not captured", "Please check the integration");
        break;
    }

    Alert.alert(`Error code: ${error.code}`, error.message);
  } else if (paymentOption) {
    switch (paymentOption.label) {
      case "succeeded":
        Alert.alert("succeeded", `Your order is succeeded`);
        break;
      case "requires_capture":
        Alert.alert("requires_capture", `Your order is requires_capture`);
        break;
      default:
        Alert.alert("status not captured", "Please check the integration");
        break;
    }
  } else {
    Alert.alert("Something went wrong", "Please check the integration");
  }
};

return (
  <Screen>
    <Button variant="primary" title="Pay with card form" onPress={handlePayPress} />
  </Screen>
);

Congratulations! Now that you have integrated the Card Widget

PreviousReact Native with Node Backend (Beta)NextCustomization

Last updated 11 months ago

๐Ÿ“ฆ
โบ๏ธ