Skip to content

Commit

Permalink
Detect when a PM is cached and sent signal that it should reinitialise
Browse files Browse the repository at this point in the history
  • Loading branch information
sponglord committed Nov 27, 2024
1 parent c0b6125 commit 7f08208
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,19 @@ export class DropinComponent extends Component<DropinComponentProps, DropinCompo
};

private setActivePaymentMethod = paymentMethod => {
// console.log('\n### DropinComponent::setActivePaymentMethod:: cachedPaymentMethods', this.state.cachedPaymentMethods);
this.setState(prevState => ({
activePaymentMethod: paymentMethod,
cachedPaymentMethods: { ...prevState.cachedPaymentMethods, [paymentMethod._id]: true }
}));

for (const [key] of Object.entries(this.state.cachedPaymentMethods)) {
if (key === paymentMethod._id) {
// console.log('### DropinComponent::setActivePaymentMethod:: payment method is cached=', key);
paymentMethod.onPaymentMethodActive();
break;
}
}
};

componentDidUpdate(prevProps, prevState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class PaymentMethodItem extends Component<PaymentMethodItemProps> {
const showBrands = !paymentMethod.props.oneClick && paymentMethod.brands && paymentMethod.brands.length > 0;

return (
// eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions
<div key={paymentMethod._id} className={paymentMethodClassnames} onClick={this.handleOnListItemClick}>
<div className="adyen-checkout__payment-method__header">
<div key={paymentMethod._id} className={paymentMethodClassnames}>
{/*eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions*/}
<div className="adyen-checkout__payment-method__header" onClick={this.handleOnListItemClick}>
<ExpandButton buttonId={buttonId} showRadioButton={showRadioButton} isSelected={isSelected} expandContentId={containerId}>
<PaymentMethodIcon
// Only add alt attribute to storedPaymentMethods (to avoid SR reading the PM name twice)
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/src/components/Klarna/KlarnaPayments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class KlarnaPayments extends UIElement<KlarnConfiguration> {
this.setElementStatus('ready');
}

protected onPaymentMethodActive() {
// TODO do something to reinit the PM
}

render() {
return (
<CoreProvider i18n={this.props.i18n} loadingContext={this.props.loadingContext} resources={this.resources}>
Expand Down
4 changes: 4 additions & 0 deletions packages/lib/src/components/internal/UIElement/UIElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ export abstract class UIElement<P extends UIElementProps = UIElementProps> exten
return this;
}

protected onPaymentMethodActive() {
return null;
}

protected onChange(): void {
this.props.onChange?.(
{
Expand Down

0 comments on commit 7f08208

Please sign in to comment.