Skip to Content
Docs

Accept payments in your React Native app

Take a first payment in a React Native app, with Pay.com's drop-in or your own screen.

To take a payment in the sandbox, your server creates a payment session, the app takes the payment, and your server confirms the result. Show the drop-in, which takes the least code, or build your own screen. The React Native SDK reference describes the methods used here.

Choose a checkout UI

Pick the drop-in for the fastest integration, or build a custom form with native card inputs.

CapabilityDrop-in (recommended)Your own UI
What you buildA button that presents Pay.com's sheetA screen using payment methods and card fields
Payment methodsCards, redirect methods, Apple Pay on iOS, and Google Pay on AndroidCards and the redirect methods you render
Errors and retriesHandled by the sheetHandled in your UI
CustomizationNative platform styling, or custom colors and shapesFull custom UI

Both approaches display the customer's saved methods at checkout. The drop-in displays them in a carousel, and a custom screen handles them as shown in Pay with a saved payment method.

Integrate Pay.com

Create a payment session on your server, collect the payment in your app, and verify the final status on your server.

  1. 1

    Create a payment session on your server

    Call Create a payment session with your sandbox key. amount, currency, and customer_reference_id (your own identifier for the customer) are required. Amounts are in minor units. For example, 1000 is $10.00.

    curl -X POST https://api.sandbox.pay.com/v1/sessions/payment \
      -u ':sk-pay-com-sandbox-…' \
      -H "Content-Type: application/json" \
      -d '{
        "amount": 1000,
        "currency": "usd",
        "customer_reference_id": "cust-001"
      }'

    Send only the client_secret from the response to the app. Never put your API key in the app.

  2. 2

    Add the SDK

    Install the package, then run pod install for iOS:

    npm install @pay-com/react-native
    cd ios && pod install

    Both platforms' native SDKs come with it. See Install.

  3. 3

    Register the return URL

    Redirect payment methods return the customer to your app at its return URL, for example myshop://pay. Set up deep links for it on each platform. While a payment runs, the SDK picks the URL up from React Native's Linking.

  4. 4

    Start a checkout

    PayCheckout.create() checks the client_secret and loads the session. It rejects with a PayError when it can't.

    import { PayCheckout } from '@pay-com/react-native'
    
    const checkout = await PayCheckout.create(clientSecretFromYourServer, { returnUrl: 'myshop://pay' })

    Live and sandbox sessions use the same configuration.

  5. 5

    Take the payment

    Present the drop-in, or build your own card form and call pay.

    Present the sheet when the customer taps your checkout button. It shows the session's methods, the card form, and any failure. It also runs 3DS and closes when the payment is done.

    try {
      const result = await checkout.presentDropIn({ merchantDisplayName: 'My Shop' })
      switch (result.status) {
        case 'succeeded':
        case 'processing':
          showConfirmation(result.ids) // Client-side hint; verify on your server before fulfilling
          break
        case 'canceled':
          break // The customer closed the sheet
        case 'failed':
          showError(result.error) // The session can no longer be paid
          break
      }
    } finally {
      checkout.release()
    }

    To show the wallets in the sheet, set applePay and googlePay. Present the drop-in has the options and what the customer sees, and you can change its look and text.

  6. 6

    Confirm the payment on your server

    The result reflects only client-side state. Before you fulfill the order, retrieve the session with Retrieve a payment session or wait for the signed payment_session.completed webhook. Use the session ID your server got when it created the session.

If you offer payment methods that redirect, your server must create the session with return_url set to the same URL as returnUrl.

Next steps

Was this page helpful?