Accept Crypto Payment

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.

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

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

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

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

# Creating a Checkout Session for 1 USDC

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

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.

Last updated