Build with AI

How to add payments to your app

Plan payment lifecycles, protect keys, verify provider events, and choose checkout that fits your app and store rules.

Apirex TeamUpdated
On this page
  1. Choose a provider
  2. One-time vs subscriptions
  3. Keep keys server-side
  4. Testing
  5. App store payment rules
  6. Frequently asked questions

Choose a provider

Choose a payment provider by your merchant location, customer payment methods, currency, and product category. Before integrating Stripe or Razorpay, establish whether the purchase is eligible for external checkout on the platform where you will distribute the app.

Apirex can help implement Stripe or Razorpay checkout with server-created orders, server verification, and webhook signature checks. Your merchant account belongs to you. This implementation assistance does not replace provider onboarding, store billing requirements, or your decisions about prices and refunds.

As of November 2026, payment-method availability depends on the merchant country, currency, product, and account eligibility. Stripe documents country and currency support by method; Razorpay's India Standard Checkout guide covers cards, UPI, netbanking, and other methods. Do not assume a method available to one merchant is enabled for another.

Stripe vs Razorpay: evaluate your actual account
QuestionStripeRazorpay
RegionsCheck merchant-country eligibility and the country/currency matrix for each method.India Standard Checkout supports Indian payment workflows; other regional offerings require their own eligibility checks.
MethodsCards and eligible local methods or wallets, depending on country and integration.Cards, UPI, netbanking, wallets, and other enabled methods in the India guide.
Recurring purchasesConfirm the selected method supports your subscription design.Confirm recurring support separately rather than assuming every checkout method supports renewals.
Selection testCan your business onboard and accept the desired currency and method?Can your business onboard and offer the methods your customers actually use?

Use the official provider documentation linked below to confirm your account's requirements before designing the final checkout. Avoid choosing purely from a sample payment form: onboarding and settlement eligibility are separate from how checkout looks. Keep a written record of the product, currency, and supported payment methods you verified.

One-time vs subscriptions

Use a one-time payment for a single purchase and a subscription for continuing access or recurring delivery. Define the lifecycle before implementation, including failure, cancellation, refund, and what the customer receives after a successful payment.

For a physical salon appointment, you might collect a deposit once and associate it with a booking. Explain whether the deposit reduces the remaining balance, whether rescheduling preserves it, and what cancellation means. The builder should ask you about those policies rather than silently inventing commercial terms.

Subscriptions need more than a recurring price label. Specify the billing interval, what access is granted, when cancellation takes effect, and what happens after a failed renewal. Keep subscription status and the user's application entitlement related but distinct so an old success screen does not become permanent access.

Treat payment processing as a state machine rather than a single Boolean controlled by the client. An order can be created, awaiting payment, paid, failed, or refunded according to your design and verified provider information. Store the provider identifiers needed to reconcile those transitions with your internal record.

Make fulfillment idempotent: receiving the same event or callback again must not grant the same purchase twice. Use database uniqueness constraints and an atomic transaction around recording the verified payment and granting its benefit. Deduplicate event identifiers and protect the underlying order or entitlement as well, since different events can concern the same purchase.

When creating an order, derive the amount and currency from trusted server data. The client can identify a service or product, but it must not determine what that product costs. Reconcile the verified payment with the expected customer, order, currency, amount, and final payment state before fulfillment.

Keep keys server-side

Keep secret API keys and webhook signing secrets on the server, while using only the provider's intended public identifiers in the client. Stripe publishable keys and Razorpay checkout key IDs are not substitutes for their corresponding secret credentials.

In Apirex, you can connect your own Supabase project and use backend functions and secrets. Ask for order creation, verification, and fulfillment to happen server-side. Never place a secret in a web environment variable that is bundled for visitors, or in mobile source distributed with the application.

The following TypeScript fragment is for a Node.js server with Node type definitions. It verifies Razorpay's checkout payment signature using HMAC-SHA256 over order_id|payment_id. Pass the order ID retrieved from your own stored order, not an order ID trusted solely because it arrived from the client.

typescript
import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyRazorpayPayment(
  storedOrderId: string, paymentId: string,
  signatureHex: string, keySecret: string
): boolean {
  if (!/^[a-f0-9]{64}$/i.test(signatureHex)) return false;
  const expected = createHmac("sha256", keySecret)
    .update(`${storedOrderId}|${paymentId}`).digest();
  const received = Buffer.from(signatureHex, "hex");
  return received.length === expected.length &&
    timingSafeEqual(received, expected);
}

A valid checkout signature does not by itself prove the expected amount is captured or that fulfillment has not already occurred. Verify the payment's relationship to the stored order and its authoritative status before granting anything. Razorpay webhook verification is a separate operation using the webhook secret and raw webhook payload, not this checkout formula.

The next fragment uses the Stripe Node library on a Node.js server. Give it the exact raw request bytes and the Stripe-Signature header before JSON middleware changes the body. The endpoint must catch verification errors and return a failure response without processing an unverified event.

typescript
import Stripe from "stripe";

export function verifyStripeWebhook(
  rawBody: Buffer, signature: string,
  apiSecret: string, endpointSecret: string
): Stripe.Event {
  const stripe = new Stripe(apiSecret);
  return stripe.webhooks.constructEvent(
    rawBody, signature, endpointSecret
  );
}

This verification helper is not a complete endpoint. After verification, accept only the event types your integration needs, validate their association with your order, and process the update idempotently. Store durable work before acknowledging success so a crash does not permanently lose fulfillment after the provider considers delivery complete.

Testing

Use provider test environments with matching test keys and test webhook configuration before accepting real payments. Test your server state and fulfillment, not just whether the checkout window displays a success message.

As of November 2026, Stripe documents 4242 4242 4242 4242 for an interactive successful card test, with a valid future expiry and any three-digit CVC. Use test API keys and test values, not real card details. Its official testing page also supplies decline and authentication scenarios for exercising unsuccessful journeys.

As of November 2026, Razorpay's India Standard Checkout guide documents success@razorpay and failure@razorpay for supported test UPI flows, plus pending@razorpay for a pending scenario. These are test inputs, not real payment addresses. Follow the current instructions for the specific integration and method instead of assuming every UPI intent or QR flow uses the same simulator.

Test a completed payment, a decline, checkout cancellation, loss of connectivity, and returning after closing the app. A user may close checkout before your app receives the result. The server should eventually reconcile verified payment information without requiring the user to repeat a charge merely to refresh the screen.

Send a duplicate event and confirm that it does not produce duplicate access, inventory changes, or booking deposits. Also test invalid signatures and altered request bodies. Check that rejected requests do not update the order and that the logs contain enough identifiers to investigate without recording credentials or unnecessary personal details.

For recurring products, test renewal success, renewal failure, and cancellation according to your policy. For all products, test refunds and the corresponding application state. Before switching to live mode, verify that live keys, endpoint signing secrets, product identifiers, currency, and webhook routing belong to the intended merchant account.

App store payment rules

As of November 2026, Google Play Billing and Apple In-App Purchase generally apply to purchases of digital goods or functionality consumed in native apps, subject to policy exceptions and regional programs. Physical goods and physical services follow different rules, so classify the purchase before reusing web checkout inside a mobile app.

Google's official Payments policy explains that in-app digital content, subscriptions, and application functionality generally require its billing system for Play-distributed apps unless otherwise permitted. It distinguishes physical purchases such as groceries, transportation, and food delivery from these digital purchases. A provider checkout integration does not by itself establish permission to use it for a digital unlock.

Apple's App Review Guidelines describe In-App Purchase requirements for unlocking digital features or content. They also address physical goods and services consumed outside the app, where other payment methods apply. A physical salon appointment and a subscription to prerecorded digital lessons are different purchase categories even if their booking screens look similar.

Rules differ by region and change. Eligibility for alternative billing, external links, entitlements, or specific storefront arrangements depends on the current policy and your circumstances. Do not infer universal permission from a regional exception, and recheck the official pages immediately before implementing the purchase route and before submission.

Write a purchase classification for every item you sell, including where it is consumed and which distribution channels offer it. If an item mixes physical services and digital benefits, resolve the policy implications before building a single checkout for both. Ask qualified advisers when the product classification or regional requirements remain unclear.

You submit native apps using your own developer accounts; Apirex does not submit them for you. Keep the review description consistent with the actual purchase flow and test the permitted route end to end. Neither a successful provider payment nor a successful application build guarantees store approval.

Frequently asked questions

Can a publishable key go in the app?

A provider key explicitly intended for client use can. Secret API keys and webhook signing secrets must remain server-side.

Does a success screen prove payment?

No. Verify payment information on the server and reconcile the order, amount, currency, and required payment status before fulfillment.

Why do I need idempotency?

Callbacks and events can repeat. An atomic, deduplicated fulfillment operation prevents granting the same purchase twice.

Can Stripe replace store billing for digital features?

Not automatically. As of November 2026, native digital purchases generally fall under store billing requirements, with exceptions and regional programs that must be checked.

Do test payments move money?

Use the provider test environment and its documented test values to simulate payments without real charges. Keep test and live credentials and webhook configuration separate.

All guides

Build it on your own computer

Describe the app and Apirex writes real source you own, then builds it on your machine.

AndroidKotlin · Jetpack ComposeReal source on your computer

Opens Apirex with this prompt. Pick the Android · Kotlin tab before you send. The Free plan includes 5 Rex Credits a day.