Checkout/Card Checkout

Card Checkout

Accept credit cards, debit cards, Apple Pay, and Google Pay with enterprise-grade security

Supported Card Types

Visa, Mastercard, American Express, Discover, JCB, Diners Club, and UnionPay. Plus Apple Pay and Google Pay for seamless mobile checkout.

📋 Prerequisites

  • Hedge Payments account with API credentials
  • Completed business verification (for live payments)
  • SSL certificate on your domain (required for card processing)

Step 1: Install the SDK

Install the Hedge Payments React SDK to get started with card checkout:

npm

npm install @hedgepayments/react

yarn

yarn add @hedgepayments/react

Step 2: Configure the Provider

Wrap your application with the HedgePaymentsProvider:

import { HedgePaymentsProvider } from '@hedgepayments/react'

function App() {
  return (
    <HedgePaymentsProvider
      merchantId="your_merchant_id"
      env="sandbox" // or 'prod' for production
    >
      <YourApp />
    </HedgePaymentsProvider>
  )
}

💡 Tip: Use env="sandbox" during development. Switch to env="prod" when you're ready to accept real payments.

Step 3: Add the Card Form

Use the HedgeCardForm component to collect card details securely:

import { HedgeCardForm, useHedgePayments } from '@hedgepayments/react'

function CheckoutPage() {
  const { tokenize, processing } = useHedgePayments()

  const handleSubmit = async () => {
    try {
      // Tokenize the card details
      const token = await tokenize()

      // Send token to your backend to create the charge
      const response = await fetch('/api/charge', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          token,
          amount: 9999, // $99.99 in cents
          currency: 'USD'
        })
      })

      const result = await response.json()
      console.log('Payment successful:', result)
    } catch (error) {
      console.error('Payment failed:', error)
    }
  }

  return (
    <div className="max-w-md mx-auto">
      <h2>Payment Details</h2>

      <HedgeCardForm
        onReady={() => console.log('Form ready')}
        onError={(error) => console.error('Form error:', error)}
        styles={{
          input: {
            fontSize: '16px',
            color: '#333',
          }
        }}
      />

      <button
        onClick={handleSubmit}
        disabled={processing}
        className="w-full mt-4 py-3 bg-green-600 text-white rounded"
      >
        {processing ? 'Processing...' : 'Pay $99.99'}
      </button>
    </div>
  )
}

Step 4: Create the Charge (Backend)

On your backend, use the token to create a charge:

Node.js

import { HedgePayments } from '@hedgepayments/node'

const hedge = new HedgePayments({
  apiKey: process.env.HEDGE_API_KEY,
  apiSecret: process.env.HEDGE_API_SECRET
})

app.post('/api/charge', async (req, res) => {
  const { token, amount, currency } = req.body

  try {
    const charge = await hedge.charges.create({
      token,
      amount,
      currency,
      description: 'Order #12345',
      metadata: {
        orderId: '12345',
        customerId: 'cust_abc123'
      }
    })

    res.json({
      success: true,
      chargeId: charge.id,
      status: charge.status
    })
  } catch (error) {
    res.status(400).json({
      success: false,
      error: error.message
    })
  }
})

cURL

curl -X POST https://api.hedgepayments.com/v1/charges \
  -H "Authorization: Bearer YOUR_API_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "token": "tok_abc123...",
    "amount": 9999,
    "currency": "USD",
    "description": "Order #12345"
  }'

Apple Pay & Google Pay

Enable digital wallet payments with minimal additional configuration:

import { HedgeCardForm, ApplePayButton, GooglePayButton } from '@hedgepayments/react'

function CheckoutPage() {
  const handlePaymentComplete = (result) => {
    console.log('Payment completed:', result)
  }

  return (
    <div className="max-w-md mx-auto">
      {/* Digital Wallet Buttons */}
      <div className="flex gap-4 mb-6">
        <ApplePayButton
          amount={9999}
          currency="USD"
          onComplete={handlePaymentComplete}
          className="flex-1"
        />
        <GooglePayButton
          amount={9999}
          currency="USD"
          onComplete={handlePaymentComplete}
          className="flex-1"
        />
      </div>

      <div className="text-center text-gray-500 my-4">
        — or pay with card —
      </div>

      {/* Card Form */}
      <HedgeCardForm />

      <button className="w-full mt-4 py-3 bg-green-600 text-white rounded">
        Pay $99.99
      </button>
    </div>
  )
}

⚠️ Note: Apple Pay requires domain verification. Follow our Apple Pay Setup Guide to register your domain.

3D Secure Authentication

3D Secure is automatically enabled for all card transactions. When required, customers will see a verification step from their bank:

const charge = await hedge.charges.create({
  token,
  amount: 9999,
  currency: 'USD',
  // 3D Secure options
  threeDSecure: {
    required: true, // Force 3DS for all transactions
    challengePreference: 'challenge_requested' // or 'no_preference'
  },
  // Return URL after 3DS verification
  returnUrl: 'https://yoursite.com/checkout/complete'
})

✓ Liability Shift: Successful 3D Secure authentication shifts chargeback liability to the card issuer, protecting your business from fraud disputes.

Test Cards

Use these test card numbers in sandbox mode:

Card NumberBrandResult
4242 4242 4242 4242VisaSuccess
5555 5555 5555 4444MastercardSuccess
3782 822463 10005AmexSuccess
4000 0000 0000 0002VisaDeclined
4000 0000 0000 3220Visa3DS Required
4000 0000 0000 9995VisaInsufficient Funds

Use any future expiration date and any 3-digit CVC (4-digit for Amex).