Copperx Docs
LoginGet Started
  • Introduction
    • Welcome to Copperx Gateway
    • Understand Crypto Payment
    • API Reference
    • Setup an account
      • Payment Setting
      • Business Details Setting
      • Apply your Branding
      • Manage Promocode
  • Integrate Payments
    • Generate API Key
    • Accept Crypto Payment
    • Accept Crypto Subscription Payment
      • Subscription Lifecycle
    • Webhook
      • How to setup a Webhook
      • Webhook Event Object
      • Subscription webhooks
  • No-Code Payments
    • Payment Link
    • Recurring Subscription
    • Recurring Invoice
    • Crypto Invoice
  • Integrations
    • WooCommerce
    • Zapier
    • Stripe
    • BigCommerce
    • Magento
  • Support
    • Stuck payment
Powered by GitBook
On this page
  1. Integrate Payments

Accept Crypto Payment

PreviousGenerate API KeyNextAccept Crypto Subscription Payment

Last updated 1 year ago

Checkout Session is a standard object used to start accepting the crypto payments in USDC, USDT, DAI, ETH, BTC, MATIC, etc.

Let's create our first Checkout Session to accept 1 USDC from user.

Before we start, few things to keep in mind

  • We are using our dev environment which supports on Polygon Mumbai Testnet and Goerli Testnet.

  • We will be using a curl to request Copperx APIs.

  • Make sure you generate your API_KEY from our Dashboard. If you don't have one, then generate it from .

  • You will need test ERC20 Faucets to make the payment, you can request them from . If you need more faucet, then feel free to contact our team via .

  • As you are using test environment, there is no real money involved. So feel free to play around.

To create a checkout session, run below command in your terminal:

# Creating a Checkout Session for 1 USDC

curl --request POST \
--url 'https://api.copperx.dev/api/v1/checkout/sessions' \
--header 'Authorization: Bearer {YOUR_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "successUrl": "https://copperx.io/success?cid={CHECKOUT_SESSION_ID}",
    "lineItems": {
        "data": [
            {
                "priceData": {
                    "currency": "usdc",
                    "unitAmount": "100000000",
                    "productData": {
                        "name": "Basic",
                        "description": "For early stage projects who are getting started"
                    }
                }
            }
        ]
    }
}'

You will receive a response similar to given below:

# Sample response of a Checkout Session object

{
  "id": "6bce7b07-825f-454e-bea8-3a2bb04a570b",
  "createdAt": "2023-02-22T12:46:11.453Z",
  "updatedAt": "2023-02-22T12:46:11.553Z",
  "mode": "payment",
  "paymentMethodTypes": [
    "wallet"
  ],
  "paymentSetting": {
    "allowedChains": [
      {
        "chainId": 80001
      }
    ],
    "paymentMethodTypes": null,
    "preferredChainId": 80001
  },
  "expiresAt": "2023-02-22T13:46:11.441Z",
  "customerCreation": "if_required",
  "customerUpdate": null,
  "submitType": "pay",
  "afterCompletion": null,
  "organizationId": "ea2f521c-0f27-48bf-91f7-87dd8de98034",
  "amountTotal": "100000000",
  "currency": "usdc",
  "paymentLinkId": null,
  "subscriptionId": null,
  "customerId": null,
  "clientReferenceId": null,
  "successUrl": "https://copperx.io/success?cid=6bce7b07-825f-454e-bea8-3a2bb04a570b",
  "cancelUrl": null,
  "status": "open",
  "paymentStatus": "unpaid",
  "metadata": null,
  "emailCollection": false,
  "phoneNumberCollection": false,
  "shippingAddressCollection": false,
  "billingAddressCollection": false,
  "afterCompletionConfirmMsg": null,
  "shippingDetails": {},
  "billingDetails": {},
  "url": "https://buy.copperx.dev/payment/checkout-session/6bce7b07-825f-454e-bea8-3a2bb04a570b",
  "customerDetails": {
    "address": {}
  },
  "lineItems": {
    "object": "list",
    "data": [
      {
        "amountTotal": "100000000",
        "currency": "usdc",
        "description": null,
        "quantity": 1,
        "price": {
          "id": "49da18aa-c09a-4d36-9171-23474685f5bd",
          "createdAt": "2023-02-22T12:46:11.392Z",
          "updatedAt": "2023-02-22T12:46:11.392Z",
          "billingScheme": "per_unit",
          "currency": "usdc",
          "productId": "5a4b57b4-9bff-465e-bf4e-04e4d3659ca3",
          "interval": null,
          "usageType": null,
          "type": "one_time",
          "unitAmount": "100000000",
          "unitAmountDecimal": null,
          "customUnitMax": null,
          "customUnitMin": null,
          "customPreset": null,
          "customUnitAmountSuggestions": null,
          "product": {
            "id": "5a4b57b4-9bff-465e-bf4e-04e4d3659ca3",
            "createdAt": "2023-02-22T12:46:11.380Z",
            "updatedAt": "2023-02-22T12:46:11.420Z",
            "name": "Basic",
            "description": "For early stage projects who are getting started",
            "isActive": true,
            "images": [],
            "unitLabel": null,
            "url": null,
            "metadata": null,
            "defaultPriceId": "49da18aa-c09a-4d36-9171-23474685f5bd",
            "visibility": 10
          },
          "metadata": null,
          "isActive": true,
          "visibility": 20
        }
      }
    ]
  },
  "addresses": [
    {
      "id": "85f8fe19-3465-4201-b2a9-eefce83f1eeb",
      "createdAt": "2023-02-22T12:46:11.553Z",
      "updatedAt": "2023-02-22T12:46:11.553Z",
      "checkoutSessionId": "6bce7b07-825f-454e-bea8-3a2bb04a570b",
      "asset": {
        "id": "a60c79d2-7f9f-4b03-a597-85e7432edb5f",
        "name": "USDC",
        "address": "0x953ecae2e3c8ee8723fef049de53666d7126dde9",
        "chainId": 80001,
        "currency": "usdc",
        "symbol": "USDC",
        "decimals": 6,
        "coingeckoId": "usd-coin",
        "isPublic": true,
        "superToken": {
          "address": "0x6d691bd589cc175714a85bbd528b96c011a24fe6",
          "symbol": "CXUSDCx",
          "decimals": 18
        }
      },
      "paymentAddress": "0x81b63dc0daccee035b186e07356ac53fb1260af4"
    }
  ],
  "paymentIntent": {
    "id": "481d6649-aa07-444a-8fcc-929968514e65",
    "createdAt": "2023-02-22T12:46:11.442Z",
    "updatedAt": "2023-02-22T12:46:11.442Z",
    "organizationId": "ea2f521c-0f27-48bf-91f7-87dd8de98034",
    "amount": "100000000",
    "amountReceived": null,
    "currency": "usdc",
    "status": "requires_payment_method",
    "paymentMethodId": null,
    "paymentMethodTypes": [
      "wallet"
    ],
    "description": null,
    "transferAccountAddress": null,
    "transactions": []
  }
}

Here,

id = Unique Identifier for Checkout Session

amountTotal = Amount to be collected from user (in 8 decimal)

currency = Payment Currency

url = Hosted Checkout page for the Session. You need to redirect user to this URL.

Once you create a Checkout Session, you need to redirect user to the give URL in url parameter of the response.

Once user makes the payment, user will be redirected to the URL provided in successUrl.

If user cancels the payment, then user will be redirected to the URL provided in cancelUrl.

To know more about the full Checkout Session object, .

If you are facing issues while using our API, feel free to contact us on .

here
https://dashboard.copperx.dev/faucet
Telegram
click here
support@copperx.io