Skip to main content
Ionic Blocks collects card details and confirms a PaymentIntent on your page. Your application owns the amount, customer authorization, payment lifecycle, and fulfillment policy. This guide uses a direct merchant’s keys. For a platform, see Accept payments for connected accounts. Blocks take card payments. To offer Apple Pay or Google Pay, use Checkout: the hosted page shows both wallets, and embedded checkout shows Apple Pay.

Before you begin

Use test keys while building. Subdomains and different ports are separate origins. Authentication covers keys; SDK upgrades covers the supported package versions. Install @ionicfi/js in your payment page’s project and @ionicfi/sdk on your backend with npm, which is included with Node.js.
A page without a build step can load the runtime with the script tag instead.

PaymentIntent creation

paymentIntents.create creates a new intent. With no payment method or token, the request sets up a payment for later collection through Blocks.
amount is in minor units: 12500 is $125.00 for USD. The amount and receiving merchant must be authorized by your backend. requestKey represents an application-assigned key for this API operation; reuse it with the same body when repeating that operation. The SDK generates a new key for each call when one is omitted. See Idempotency. capture_method sets what confirmation does. With automatic, the default, a successful confirmation is a complete sale: it authorizes and captures the payment in one call, and the intent moves directly to succeeded. No separate capture call is needed. With manual, confirmation only authorizes the payment, the intent moves to requires_capture, and your backend captures it later. The creation response includes the client secret. Secret-key retrieval and webhook payloads omit its value; a reload cannot recover it through those interfaces. Your application controls authorized access to any retained secret. The optional reference field is your correlation value. Ionic does not enforce its uniqueness or use it to deduplicate creation. Two create requests with different idempotency keys can create two intents with the same reference.

Mount a Payment Block

The browser needs a publishable key and the client secret of the intended PaymentIntent. The strings below stand for those values from your backend. The mount target must be an empty element already in the document.
The loader loads Ionic.js from https://js.ionicfi.com/v1/ionic.js. The script tag also exposes the runtime as Ionic. Ionic automatically loads the secure card fields in an iframe hosted at embed.ionicfi.com. If your site uses a Content Security Policy, follow the CSP configuration. A Blocks instance belongs to one intent and creates one Block. Mounting resolves when initialization finishes. If the intent is already completed or otherwise not collectable, the Block displays its state instead of card fields. blocks.destroy() removes the UI and listeners; it does not cancel a payment.

Confirmation and status

Your application decides when to submit in response to the customer’s action. These methods return results; they do not implement your application’s payment or fulfillment policy.

Handle the result

A browser result is a display signal. Authoritative payment state is available to your backend through the PaymentIntent API and verified events.

Reloads and retries

Idempotency applies to an API operation, not to your application’s reference or checkout lifecycle. Ionic retains API idempotency keys for 24 hours in their merchant and mode scope. A repeated key with a changed body is rejected. Idempotency documents replay and concurrent requests. Blocks shares concurrent confirmation calls on the same instance. After an uncertain response, another confirmation call on that instance reads the intent and can replay the original confirmation with its original key and body. That in-memory attempt does not survive a page reload or a new Blocks instance. A lost response does not establish failure. Creating a replacement intent can produce another payment. Your application owns recovery across requests, tabs, and server restarts using the existing intent’s state. Ionic does not supply a payment store, locking scheme, or replacement-payment policy.

Payment events

A webhook endpoint delivers signed events to your backend. Domain registration and webhook registration are separate. See Webhook endpoints and Signature verification. event.account identifies the merchant; event.livemode identifies the mode; event.data.object contains the PaymentIntent snapshot. An application must establish the expected merchant, mode, intent, amount, and currency before using that event as a payment result. A reference alone is not proof of ownership. Events can be duplicated or arrive out of order. Delivery acknowledgment, retry behavior, and event verification are Ionic contracts. Storage and fulfillment decisions belong to your application.

Save the card being entered

A PaymentIntent with a merchant-owned customer and setup_future_usage: "off_session" permits optional saving for future payments. The Block displays an unchecked consent checkbox. confirmPayment uses the customer’s selection; leaving it unchecked pays without saving. A successful charge does not by itself establish that a card was saved. When the card is saved, the PaymentIntent’s payment_method becomes the saved card: reusable and attached to the customer. savedPaymentMethod in the confirmation response is the same ID, and retrieval and payment_intent.* events return it as payment_method. When the customer asked to save but saving is skipped or fails, savedPaymentMethod is null and the payment method stays single-use. When no save was asked, savedPaymentMethod is absent. A one-time card that was sent for a payment and not saved is rejected with 422 PAYMENT_METHOD_CONSUMED before any charge attempt. A saved card keeps working by its payment method ID. Its original payment token can’t be used again. saveConsent: "external" leaves the consent control to your page. In this mode, confirmParams.savePaymentMethod carries the customer’s explicit choice. false or omission does not request saving. The default auto mode reads the Block’s checkbox and rejects a supplied savePaymentMethod parameter. Ionic retains the submitted consent choice when retrying an uncertain attempt on the same instance. Your UI must represent the choice that was submitted. The Blocks reference lists the parameters. For saving without taking a payment, use a SetupIntent with confirmSetup. Blocks collects a new card; saved-card selection is owned by your application.

Style the Block

blocks.create accepts layout, field appearance, styles, and consent placement. The Blocks reference lists the supported options, defaults, events, and validation errors. Options are set before mount.

Content Security Policy

Include the Ionic hosts alongside the sources required by your page:
For tokenization without Blocks confirmation, see Advanced card fields. For Ionic-managed checkout submission, see Embedded checkout.

What’s next

Save a card for later

Save a card with a SetupIntent and the customer’s consent.

Read the Blocks reference

Look up every option, event, result shape, and error code.

Handle webhook events

Verify each event’s signature and fulfill orders from it.