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 exposesIonic(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
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.
Deferred card preparation
To collect a card before creating a PaymentIntent, callionic.blocks({ tokenizationSession: session }) with the review session your
server creates in Review a card before payment.
This returns DeferredIonicBlocks. It lets
you create a token, read the card details, and show a total before charging.
Platform access must be enabled for the selected test/live mode. Do not pass
clientSecret when mounting these fields.
billingDetails accepts name, email, phone, and address. An address
requires postal_code and country; line1, line2, city, and state are
optional. After creating the token, resume collection before changing billing
details. They cannot be replaced in the confirmation request.
When the server created the session with setup_future_usage: "off_session",
the Block shows a save checkbox, or reads savePaymentMethod with
saveConsent: "external". A token the customer agreed to save has
setup_future_usage: "off_session". See
Save the card for future payments.
Read the token at result.confirmationToken and its card summary at
payment_method_preview.card. See the ConfirmationToken reference
for funding values, verification sources, expiry, and example responses.
Concurrent token-creation calls share one operation. While its result is
unknown, recover that operation before trying another card. If resuming fails,
keep the fields locked and retry. After a successful resume, discard the old
review and create a new token. The iframe and entered values remain in place
while the field session is usable.
To pay with the token from the browser, call
ionic.confirmPayment({ clientSecret, confirmParams: { confirmationToken: id } }).
This attempts payment using the card already collected and returns the usual
ConfirmPaymentResult. Do not pass blocks, new billing details, another card,
or saving options: the token already carries the customer’s save choice. Keep your order and payment IDs on the server so you can
check an interrupted payment after a page reload.
For a price calculated from the reviewed card, confirm on your server and keep
the intent’s client secret there. Follow Review before payment
for the full checkout flow and retry rules.
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:
- With
capture_method: automatic, a successful confirmation is a complete sale: it authorizes and captures the payment in one call, and the intent moves tosucceeded. No separate capture call is needed. Withmanual, confirmation only authorizes the payment, and the intent moves torequires_capture. - 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 returnincomplete_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 sameblocksinstance 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, and the intent returns torequires_payment_method; the customer corrects the card and your page calls confirm again on the same instance. Read the reason on your server from the Charge’sdecline_code. requires_actionreturnsauthentication_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.
Retrieval does not return savedPaymentMethod; a saved card is the intent’s
payment_method. 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).

