PlexySDK DOCS
React Native

Sessions Flow

Accept payments in React Native with a single server-side API call

Sessions Flow

The sessions flow is the recommended integration. Your server makes one call to /v2/sessions; the SDK takes the session from there — rendering payment methods, handling 3D Secure and redirects, and reporting the outcome.

Call /v2/sessions with the amount, reference, and return URL.

Provide session (id + sessionData) along with your configuration.

Call start('dropIn') from usePlexyCheckout().

onComplete fires with the result; confirm it server-side and via webhooks.

1. Create a session on your server

Sessions are created with your secret API key (pr_...) — never from the app. The app only ever sees the session id and sessionData.

curl -X POST https://api.plexypay.com/v2/sessions \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "amount": { "value": 10000, "currency": "KZT" },
    "reference": "order_12345",
    "returnUrl": "yourapp://payment"
  }'

Response:

{
  "id": "ses_abc123xyz",
  "sessionData": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "expiresAt": "2026-12-31T23:59:59Z",
  "status": "active"
}

Return id and sessionData to your app.

On Android, Drop-in overrides the return URL — fetch the correct value with await PlexyDropIn.getReturnURL() and send it to your backend when creating the session. See Return URL.

2. Wire up PlexyCheckout

import { useCallback } from 'react';
import { Button } from 'react-native';

import {
  PlexyCheckout,
  usePlexyCheckout,
  Configuration,
} from '@plexy/react-native';

const configuration: Configuration = {
  environment: 'test',
  clientKey: 'YOUR_CLIENT_KEY',
  countryCode: 'KZ',
  amount: { currency: 'KZT', value: 10000 },
  returnUrl: 'yourapp://payment',
};

function CheckoutScreen({ session }) {
  const onComplete = useCallback((result, component) => {
    // Payment finished — dismiss the payment UI.
    component.hide(true);
    // Verify the outcome server-side:
    // GET /v2/sessions/{sessionId}?sessionResult={result}
  }, []);

  const onError = useCallback((error, component) => {
    // Shopper cancelled or the payment failed.
    component.hide(false);
  }, []);

  return (
    <PlexyCheckout
      config={configuration}
      session={session}
      onComplete={onComplete}
      onError={onError}
    >
      <PayButton />
    </PlexyCheckout>
  );
}

function PayButton() {
  const { start, isReady } = usePlexyCheckout();

  return (
    <Button
      title="Pay ₸100"
      disabled={!isReady}
      onPress={() => start('dropIn')}
    />
  );
}

Memoize your callbacks with useCallback. Inline functions cause the SDK to re-register native event listeners on every render, which hurts performance and can drop events.

3. Start a payment

start('dropIn') presents the all-in-one Drop-in sheet. To present a single payment method instead, pass its type from the session's payment methods — for example start('applepay').

For a card form embedded in your own layout (instead of a modal), render <CardView /> anywhere below the provider:

import { CardView } from '@plexy/react-native';

function EmbeddedCardForm() {
  return <CardView />;
}

CardView picks up the configuration and payment methods from the surrounding <PlexyCheckout> and sizes itself automatically. (start('scheme') still works but is deprecated in favor of <CardView>.)

4. Handle the result

  • onComplete(result, component) — the payment reached a final state. Call component.hide(true) to dismiss the native UI, then verify the result from your server before fulfilling the order.
  • onError(error, component) — the shopper cancelled or something failed. Call component.hide(false) to dismiss. Check error.errorCode — canceledByShopper is a normal outcome, not a failure. See error codes.

Treat webhooks as the source of truth for order fulfillment — the mobile result tells you what to show the shopper, not whether to ship. See Result codes.

Need more control?

If you want to make the /payments and /payments/details calls yourself — custom fraud checks, order orchestration, split payments — use the Advanced flow.

On this page