Fragments (all-in-one)
Getting Started
1
2
Initialization
import SDK from '@d24/sdk';
// Instantiate the SDK
const d24 = new SDK('YOUR_PUBLIC_KEY', { environment: 'stg', locale: 'en' });
// Instantiate the SDK from the global window object
const d24 = new window.D24.SDK('YOUR_PUBLIC_KEY', { environment: 'stg', locale: 'en' });
3
Implementing the Credit Card Form
Basic Example
// Make sure you have instantiated the SDK before this step
<CreditCardForm
authToken="YOUR_CHECKOUT_TOKEN"
country="BR"
onSuccess={handlePaymentSuccess}
onError={handlePaymentError}
onBack={handleGoBack}
onTokenGenerationError={handleTokenError}
messages={handleMessages}
/>4
Handling Callbacks
function handlePaymentSuccess() {
console.log('Payment was successful!');
// e.g., Redirect to a success page or show a success message
}
function handlePaymentError(error) {
console.error('Payment failed:', error);
// e.g., Display an error message to the user
}
function handleGoBack() {
console.log('User clicked go back.');
// e.g., Navigate to the previous step in your checkout flow
}
function handleTokenError(error) {
console.error('Could not generate token:', error);
// This is often a configuration or setup issue.
}
5
Build the solution


Last updated
Was this helpful?

