Adyen Web Drop In OnChange 触发超过一次

huangapple go评论52阅读模式
英文:

Adyen Web Drop In OnChange fires more than once

问题

I have the Adyen Web Drop In integrated, which works fine. Now I want to add tracking so I can see when a customer changes the payment option or payment info. I use the OnSelect and OnChange event for this.

Problem:

  • OnChange fires immediately after OnSelect only when it's the first time the payment option is selected. When the page and thus the Drop In is loaded it fires in order: OnSelect, OnReady, OnChange. So I can't check if the component is done loading.
    By default Ideal is selected. When you then select "Card" it fires OnSelect again and then OnChange 3 times. This also only happens the first time you select the "Card" payment option.

Is there a solid way to either:

  • only track user changes?
  • preload the options underneath a payment option, so that the changes don't get fired when the form is loaded?
  • wait on form load when changing payment option selection

Adyen Web Drop In OnChange 触发超过一次

=============== CODE ===============================


const configuration = {
  environment: this.model.environment || 'test',
  clientKey: this.model.clientKey,
  locale: this.model.locale,
  showPayButton: true,
  session: {
    id: this.model.sessionId,
    sessionData: this.model.sessionData,
  },
  onError: this.onFailed,
  paymentMethodsConfiguration: {
    ideal: {
      showImage: true
    },
    card: {
      hasHolderName: true,
      holderNameRequired: true,
    },
  },
  // https://github.com/Adyen/adyen-web/blob/master/packages/lib/src/language/locales/nl-NL.json
  translations: {
    'nl-NL': {
      payButton: this.$t('Veilig betalen').toString(),
      "idealIssuer.selectField.placeholder": this.$t('Kies uw bank').toString(),
      continue: this.$t('Veilig betalen')
    },
  },
  onChange: (state, component) => {
    console.log("ONCHANGE");
    if (this.tracking) {
      this.tracking.ecommerce.payment_method = state.data.paymentMethod.type;
      AnalyticsManager.getInstance().pushTracking(JSON.parse(JSON.stringify(this.tracking)));
    }
  },
  onPaymentCompleted: (result, component) => {
    this.handleCompleted(result, component);
  },
};



this.checkoutApi
  .create('dropin', {
    onReady: () => {
      console.log("OnReady");
    },
    onSelect: () => {
      console.log("ONSelect");
    }
  })

英文:

I have the Adyen Web Drop In integrated, which works fine. Now I want to add tracking so I can see when a customer changes the payment option or payment info. I use the OnSelect and OnChange event for this.

Problem:

  • OnChange fires immediately after OnSelect only when it's the first time the payment option is selected. When the page and thus the Drop In is loaded it fires in order: OnSelect, OnReady, OnChange. So I can't check if the component is done loading.
    By default Ideal is selected. When you then select "Card" it fires OnSelect again and then OnChange 3 times. This also only happens the first time you select the "Card" payment option.

Is there a solid way to either:

  • only track user changes?
  • preload the options underneath a payment option, so that the changes don't get fired when the form is loaded?
  • wait on form load when changing payment option selection

Adyen Web Drop In OnChange 触发超过一次

=============== CODE ===============================

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const configuration = {
  environment: this.model.environment || &#39;test&#39;,
  clientKey: this.model.clientKey,
  locale: this.model.locale,
  showPayButton: true,
  session: {
    id: this.model.sessionId,
    sessionData: this.model.sessionData,
  },
  onError: this.onFailed,
  paymentMethodsConfiguration: {
    ideal: {
      showImage: true
    },
    card: {
      hasHolderName: true,
      holderNameRequired: true,
    },
  },
  // https://github.com/Adyen/adyen-web/blob/master/packages/lib/src/language/locales/nl-NL.json
  translations: {
    &#39;nl-NL&#39;: {
      payButton: this.$t(&#39;Veilig betalen&#39;).toString(),
      &quot;idealIssuer.selectField.placeholder&quot;: this.$t(&#39;Kies uw bank&#39;).toString(),
      continue: this.$t(&#39;Veilig betalen&#39;)
    },
  },
  onChange: (state, component) =&gt; {
    console.log(&quot;ONCHANGE&quot;);
    if (this.tracking) {
      this.tracking.ecommerce.payment_method = state.data.paymentMethod.type;
      AnalyticsManager.getInstance().pushTracking(JSON.parse(JSON.stringify(this.tracking)));
    }
  },
  onPaymentCompleted: (result, component) =&gt; {
    this.handleCompleted(result, component);
  },
};

<!-- end snippet -->

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

this.checkoutApi
  .create(&#39;dropin&#39;, {
    onReady: () =&gt; {
      console.log(&quot;OnReady&quot;);
    },
    onSelect: () =&gt; {
      console.log(&quot;ONSelect&quot;);
    }
  })

<!-- end snippet -->

答案1

得分: 2

我也在 Adyen DropIn 的 GitHub 上提了这个问题。
https://github.com/Adyen/adyen-web/issues/2011#issuecomment-1460319246

在 OnChange 事件中,您可以检查该支付方式的表单是否有效。我现在检查并且仅在表单有效时跟踪更改。这样在页面加载时就不会跟踪任何更改。

```javascript
onChange: (state, component) => {
    if (this.tracking, state.isValid) {
        // 仅在表单有效时执行某些操作
    }
},

此外,我使用 OnReady 事件来设置一个布尔值。在 OnSelect 方法中,我仅在布尔值为 true 时跟踪更改,以便在页面加载时不跟踪更改。

this.checkoutApi
    .create('dropin', {
        onSelect: (state) => {
            if (!this.isReady)
                return;

            // 执行某些操作
        },
        onReady: () => {
            this.isReady = true;
        }
    })
英文:

I also asked this in the GitHub for the Adyen DropIn.
https://github.com/Adyen/adyen-web/issues/2011#issuecomment-1460319246

In the OnChange event you can check if the form for that payment method is valid. I now check that and only track changes if the form is valid. This way no changes are tracked on page load.

					onChange: (state, component) =&gt; {
					if (this.tracking, state.isValid) {
                       //only do something when form valid
					}
				},

Besides that I use the OnReady event to set a boolean. In the OnSelect method I only track changes if the boolean is true, so that I don't track changes on page load there.

				this.checkoutApi
				.create(&#39;dropin&#39;, {
					onSelect: (state) =&gt; {
						if (!this.isReady)
							return;

						//do something
					},
					onReady: () =&gt; {
						this.isReady = true;
					}
				})

答案2

得分: 1

We're investigating the onChange behavior internally. In the meantime, you can use the onSelect optional configuration event handler.

const checkout = await createAdyenCheckout(checkoutSessionResponse);
checkout.create(type, {
    onSelect: obj => console.log('Payment method Selected:', obj.props.name)
}).mount(document.getElementById(type));

This will do exactly what you need, by raising an event every time a customer selects a different enabled payment method.

英文:

We're investigating the onChange behavior internally. In the meantime, you can use the onSelect optional configuration event handler.

const checkout = await createAdyenCheckout(checkoutSessionResponse)
checkout.create(type, {
      onSelect: obj =&gt; console.log(&#39;Payment method Selected:&#39;, obj.props.name)
}).mount(document.getElementById(type));

This will do exactly what you need, by raising an event every time a customer selects a different enabled payment method.

huangapple
  • 本文由 发表于 2023年3月1日 16:40:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75601302.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定