This method allows you get a new instance of KlarnaComponent
.
1
async provide(props: KlarnaManagerProps): Promise<KlarnaComponent>
Parameters
Properties
Called whenever the component emits a new step. This usually happens when calling start or submit or whenever the component collects data.
Parameters
Properties
Properties
- klarna
- pay_later
- pay_now
- pay_over_time
- direct_bank_transfer
- direct_debit
Properties
Properties
Properties
This method will be called when an error occurs. It may return PrimerCheckoutData
if the error occurs after the payment creation.
Please note, that if you override
this method, you must call the errorHandler
to finalize the flow.
Properties
Properties
Properties
Can be either payment-failed
which is an error from the PSP side, or cancelled-by-customer
which means the failure initiated on the customer side. I.e. cancelling a 3DS flow.
Variations
Methods
Parameters
Interface that indicates that the data has been considered invalid after validation.
Properties
Interface representing Klarna payment options required for configuring KlarnaComponent
Properties
Properties
- klarna
- pay_later
- pay_now
- pay_over_time
- direct_bank_transfer
- direct_debit
Properties
A list of PrimerValidationError
explaining why the data is considered invalid.
Properties
Parameters
Interface that indicates that the data has been successfully validated.
Properties
Interface representing Klarna payment options required for configuring KlarnaComponent
Properties
Properties
- klarna
- pay_later
- pay_now
- pay_over_time
- direct_bank_transfer
- direct_debit
Properties
Parameters
Interface that indicates that data is currently in the process of being validated.
Properties
Interface representing Klarna payment options required for configuring KlarnaComponent
Properties
Properties
- klarna
- pay_later
- pay_now
- pay_over_time
- direct_bank_transfer
- direct_debit
Properties
Parameters
Interface that represents an error that occurred during the validation process.
Properties
Interface representing Klarna payment options required for configuring KlarnaComponent
Properties
Properties
- klarna
- pay_later
- pay_now
- pay_over_time
- direct_bank_transfer
- direct_debit
Properties
The PrimerError
that ocurred during the validation attempt.
Properties
Returns
An instance of KlarnaComponent
:
KlarnaComponent
Initialize the component by calling the start
function. This method should be called only once.
Call submit
function in order to process collected data and move component to next state.
To validate the collected data, you can refer to the appropriate KlarnaManagerProps callback functions.
Parameters
Interface representing Klarna payment options required for configuring KlarnaComponent
Properties
Properties
- klarna
- pay_later
- pay_now
- pay_over_time
- direct_bank_transfer
- direct_debit
To validate the collected data, you can refer to the appropriate KlarnaManagerProps callback functions.
Example
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
// 👇 Add thisconst klarnaManagerProps: KlarnaManagerProps = { primerSessionIntent: PrimerSessionIntent.CHECKOUT, onStep: (data: KlarnaPaymentStep) => { // Show loading indicator, render categories or finalize payment. switch(data.stepName) { case "paymentSessionCreated": // Render categories break; case "paymentViewLoaded": // Render payment view break; case "paymentSessionAuthorized": if (data.isFinalized) { // Finalize payment } break; case "paymentSessionFinalized": // ... break; } }, onError: (error: PrimerError) => { // An error that occurred during the component's operation. }, onInvalid: (data: PrimerInvalidComponentData<KlarnaPaymentValidatableData>) => { // Data was considered invalid during validation. switch(data.data.validatableDataName) { case 'klarnaPaymentOptions': // ... break; case 'klarnaPaymentFinalization': // ... break; } }, onValid: (data: PrimerValidComponentData<KlarnaPaymentValidatableData>) => { // Data was successfully validated. switch(data.data.validatableDataName) { case 'klarnaPaymentOptions': // ... break; case 'klarnaPaymentFinalization': // ... break; } }, onValidating: (data: PrimerValidatingComponentData<KlarnaPaymentValidatableData>) => { // Data is in the process of being validated. switch(data.data.validatableDataName) { case 'klarnaPaymentOptions': // ... break; case 'klarnaPaymentFinalization': // ... break; } }, onValidationError: (data: PrimerComponentDataValidationError<KlarnaPaymentValidatableData>) => { // Error occurred during data validation. switch(data.data.validatableDataName) { case 'klarnaPaymentOptions': // ... break; case 'klarnaPaymentFinalization': // ... break; } },};const klarnaManager = new KlarnaManager();const klarnaComponent: KlarnaComponent = await klarnaManager.provide(klarnaManagerProps);