Skip to main content
This page is the reference for Ionic Blocks. For the integration itself, follow Build a payment page or Save a card for later. The same API is available from the https://js.ionicfi.com/v1/ionic.js script tag and from the @ionicfi/js loader.

Available Blocks

Ionic Blocks currently provides one Block, which collects the card number, expiry, and CVC and shows the save-card consent checkbox when saving is possible. It is available under two type names: The only difference at runtime is the wrapper attribute, data-ionic-block="payment" or data-ionic-block="card", which your CSS can target. Wallet buttons are available on hosted and embedded checkout. Listing previously saved cards and 3DS challenges are not available in Blocks; your application owns any saved-card selection UI, using the payment methods API.

Create a client

The script tag exposes Ionic(publishableKey, options). With the npm loader:
A malformed key or account throws an invalid_request error synchronously.

Create Blocks

Returns an IonicBlocks instance bound to that intent, with create and destroy. The calls below describe individual methods; placeholders refer to values provided by your application. One instance serves one intent; a new intent requires a new instance. A malformed secret throws invalid_request.

Create a Block

Each IonicBlocks instance creates one Block. A second create call, an unknown type, or an unsupported saveConsent value throws invalid_request synchronously. The remaining options are validated when the Block mounts: an unknown option or an invalid value makes mount reject with collection_unavailable. Options are read at creation; to change them, destroy the Blocks instance and create a new one.

Options

FieldConfig:

Styles

styles takes one object per state. Each value is a CSS value string. Selectors, URLs, fonts loaded from other origins, and stylesheets are not accepted. Text properties: color, fontFamily, fontSize, fontWeight, fontStyle, lineHeight, letterSpacing, textAlign. Field properties: backgroundColor, borderColor, borderRadius, borderStyle, borderWidth, boxShadow, outlineColor, outlineOffset, outlineStyle, outlineWidth, padding. An alternative configuration for the create call above:

Mount

Resolves after the fields are ready and emits ready. Mounting a Block twice, or into an element that is missing, detached, or not empty, rejects with invalid_request. If the fields cannot load, or an option passed to create is invalid, mount rejects with collection_unavailable and emits the same error. When the intent is no longer collectable, for example after it has succeeded on a previous page load, mount renders a short status line instead of the fields and resolves. Your page can read the intent’s state from a change event or from retrievePaymentIntent.

Events

payment.on(eventName, listener) subscribes to a Block event. on returns a function that removes the listener. Exceptions thrown by a listener are ignored. BlockChange: BlockIntent: CardMetadata carries the card’s bin (the first 6 to 8 digits, or null), brand (or null), funding (credit, debit, prepaid, or unknown), and source (lookup while the customer types, tokenize after submission). It is provisional and never a basis for fees, acceptance, or fulfillment.

Destroy

Removes the Block’s UI and listeners. Both blocks.destroy() and payment.destroy() destroy the whole instance. A confirmation already sent continues to completion on the intent; destroying never creates a replacement intent. Call it when the payment view unmounts, and before creating a Blocks instance for another intent or merchant.

Confirm

These are alternative operations for their respective intent types. The method is called in response to the customer’s submission after mounting. Results: Behavior:
  • Concurrent calls share one in-flight confirmation; the second call receives the same promise.
  • Confirmation validates consent and card details before submitting a new attempt. Missing required consent returns consent_required; incomplete fields return incomplete_payment_details. An uncertain earlier attempt is checked before collecting new details.
  • Each attempt sends one idempotency key. After payment_status_unknown, calling again with the same blocks instance checks the existing intent and can replay the original request if the intent remains collectable. The attempt’s key, token, and saving choice are kept in memory on that instance; they do not survive a reload.
  • A card decline returns payment_failed with the intent in requires_payment_method; the customer corrects the card and your page calls confirm again on the same instance.
  • requires_action returns authentication_required. Blocks does not run 3DS challenges; the intent still requires action and has not succeeded.
  • Requests time out after 30 seconds.

Retrieve

Reads the intent’s current state with the publishable key and client secret, without a Blocks instance. Returns the matching intent and/or error. savedPaymentMethod is not returned by retrieval. A malformed secret, request failure, or unreadable response returns payment_status_unknown; a well-formed secret of the other intent type returns invalid_request. See Payment events for server-side state.

Error codes

Errors are { type, code, message }. message is written for the customer and safe to display. type groups the codes: validation_error (the customer or your page can correct it), payment_error (the payment itself), and api_error (the form or the connection).