@adyen/adyen-web 6.0.0-alpha.0 → 6.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. package/auto/auto.js +2 -0
  2. package/dist/cjs/adyen.css +1 -1
  3. package/dist/cjs/index.cjs +2 -2
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/index.d.cts +161 -248
  6. package/dist/es/adyen.css +1 -1
  7. package/dist/es/components/ApplePay/ApplePay.js +1 -1
  8. package/dist/es/components/ApplePay/ApplePay.js.map +1 -1
  9. package/dist/es/components/Dropin/Dropin.js +1 -1
  10. package/dist/es/components/Dropin/Dropin.js.map +1 -1
  11. package/dist/es/components/Dropin/components/DropinComponent.js +1 -1
  12. package/dist/es/components/Dropin/components/DropinComponent.js.map +1 -1
  13. package/dist/es/components/Dropin/defaultProps.js +1 -1
  14. package/dist/es/components/Dropin/defaultProps.js.map +1 -1
  15. package/dist/es/components/GooglePay/GooglePay.js +1 -1
  16. package/dist/es/components/GooglePay/GooglePay.js.map +1 -1
  17. package/dist/es/components/PayPal/Paypal.js +1 -1
  18. package/dist/es/components/PayPal/Paypal.js.map +1 -1
  19. package/dist/es/components/PayPal/components/PaypalButtons.js +1 -1
  20. package/dist/es/components/PayPal/components/PaypalButtons.js.map +1 -1
  21. package/dist/es/components/PayPal/components/PaypalComponent.js +1 -1
  22. package/dist/es/components/PayPal/components/PaypalComponent.js.map +1 -1
  23. package/dist/es/components/PayPal/defaultProps.js +1 -1
  24. package/dist/es/components/PayPal/defaultProps.js.map +1 -1
  25. package/dist/es/components/PayPal/utils/format-paypal-order-contact-to-adyen-format.js +1 -1
  26. package/dist/es/components/PayPal/utils/format-paypal-order-contact-to-adyen-format.js.map +1 -1
  27. package/dist/es/components/PayPal/utils/get-paypal-locale.js +2 -0
  28. package/dist/es/components/PayPal/utils/get-paypal-locale.js.map +1 -0
  29. package/dist/es/components/PayPal/utils/get-paypal-settings.js +2 -0
  30. package/dist/es/components/PayPal/utils/get-paypal-settings.js.map +1 -0
  31. package/dist/es/components/PayPal/utils/get-paypal-styles.js +2 -0
  32. package/dist/es/components/PayPal/utils/get-paypal-styles.js.map +1 -0
  33. package/dist/es/components/PayPal/utils/get-paypal-url.js +2 -0
  34. package/dist/es/components/PayPal/utils/get-paypal-url.js.map +1 -0
  35. package/dist/es/components/helpers/IssuerListContainer/IssuerListContainer.js +1 -1
  36. package/dist/es/components/helpers/IssuerListContainer/IssuerListContainer.js.map +1 -1
  37. package/dist/es/components/internal/BaseElement/BaseElement.js +1 -1
  38. package/dist/es/components/internal/BaseElement/BaseElement.js.map +1 -1
  39. package/dist/es/components/internal/UIElement/UIElement.js +1 -1
  40. package/dist/es/components/internal/UIElement/UIElement.js.map +1 -1
  41. package/dist/es/components/internal/UIElement/utils.js.map +1 -1
  42. package/dist/es/core/AdyenCheckout.js +1 -1
  43. package/dist/es/core/AdyenCheckout.js.map +1 -1
  44. package/dist/es/core/Analytics/Analytics.js +1 -1
  45. package/dist/es/core/Analytics/Analytics.js.map +1 -1
  46. package/dist/es/core/Analytics/EventsQueue.js +1 -1
  47. package/dist/es/core/Analytics/EventsQueue.js.map +1 -1
  48. package/dist/es/core/Analytics/utils.js +1 -1
  49. package/dist/es/core/Analytics/utils.js.map +1 -1
  50. package/dist/es/core/Errors/AdyenCheckoutError.js +1 -1
  51. package/dist/es/core/Errors/AdyenCheckoutError.js.map +1 -1
  52. package/dist/es/core/Errors/utils.js +1 -1
  53. package/dist/es/core/Errors/utils.js.map +1 -1
  54. package/dist/es/core/Services/analytics/collect-id.js +1 -1
  55. package/dist/es/core/Services/analytics/collect-id.js.map +1 -1
  56. package/dist/es/core/Services/analytics/log-event.js +1 -1
  57. package/dist/es/core/config.js +1 -1
  58. package/dist/es/core/config.js.map +1 -1
  59. package/dist/es/core/core.js +1 -1
  60. package/dist/es/core/core.js.map +1 -1
  61. package/dist/es/index.d.ts +161 -248
  62. package/dist/es/language/locales/en-US.json.js +1 -1
  63. package/dist/es/utils/Script.js +1 -1
  64. package/dist/es/utils/Script.js.map +1 -1
  65. package/dist/es-legacy/adyen.css +1 -1
  66. package/dist/es-legacy/components/ApplePay/ApplePay.js +1 -1
  67. package/dist/es-legacy/components/ApplePay/ApplePay.js.map +1 -1
  68. package/dist/es-legacy/components/Dropin/Dropin.js +1 -1
  69. package/dist/es-legacy/components/Dropin/Dropin.js.map +1 -1
  70. package/dist/es-legacy/components/Dropin/components/DropinComponent.js +1 -1
  71. package/dist/es-legacy/components/Dropin/components/DropinComponent.js.map +1 -1
  72. package/dist/es-legacy/components/Dropin/defaultProps.js +1 -1
  73. package/dist/es-legacy/components/Dropin/defaultProps.js.map +1 -1
  74. package/dist/es-legacy/components/GooglePay/GooglePay.js +1 -1
  75. package/dist/es-legacy/components/GooglePay/GooglePay.js.map +1 -1
  76. package/dist/es-legacy/components/PayPal/Paypal.js +1 -1
  77. package/dist/es-legacy/components/PayPal/Paypal.js.map +1 -1
  78. package/dist/es-legacy/components/PayPal/components/PaypalButtons.js +1 -1
  79. package/dist/es-legacy/components/PayPal/components/PaypalButtons.js.map +1 -1
  80. package/dist/es-legacy/components/PayPal/components/PaypalComponent.js +1 -1
  81. package/dist/es-legacy/components/PayPal/components/PaypalComponent.js.map +1 -1
  82. package/dist/es-legacy/components/PayPal/defaultProps.js +1 -1
  83. package/dist/es-legacy/components/PayPal/defaultProps.js.map +1 -1
  84. package/dist/es-legacy/components/PayPal/utils/format-paypal-order-contact-to-adyen-format.js +1 -1
  85. package/dist/es-legacy/components/PayPal/utils/format-paypal-order-contact-to-adyen-format.js.map +1 -1
  86. package/dist/es-legacy/components/PayPal/utils/get-paypal-locale.js +2 -0
  87. package/dist/es-legacy/components/PayPal/utils/get-paypal-locale.js.map +1 -0
  88. package/dist/es-legacy/components/PayPal/utils/get-paypal-settings.js +2 -0
  89. package/dist/es-legacy/components/PayPal/utils/get-paypal-settings.js.map +1 -0
  90. package/dist/es-legacy/components/PayPal/utils/get-paypal-styles.js +2 -0
  91. package/dist/es-legacy/components/PayPal/utils/get-paypal-styles.js.map +1 -0
  92. package/dist/es-legacy/components/PayPal/utils/get-paypal-url.js +2 -0
  93. package/dist/es-legacy/components/PayPal/utils/get-paypal-url.js.map +1 -0
  94. package/dist/es-legacy/components/helpers/IssuerListContainer/IssuerListContainer.js +1 -1
  95. package/dist/es-legacy/components/helpers/IssuerListContainer/IssuerListContainer.js.map +1 -1
  96. package/dist/es-legacy/components/internal/BaseElement/BaseElement.js +1 -1
  97. package/dist/es-legacy/components/internal/BaseElement/BaseElement.js.map +1 -1
  98. package/dist/es-legacy/components/internal/UIElement/UIElement.js +1 -1
  99. package/dist/es-legacy/components/internal/UIElement/UIElement.js.map +1 -1
  100. package/dist/es-legacy/components/internal/UIElement/utils.js.map +1 -1
  101. package/dist/es-legacy/core/AdyenCheckout.js +1 -1
  102. package/dist/es-legacy/core/AdyenCheckout.js.map +1 -1
  103. package/dist/es-legacy/core/Analytics/Analytics.js +1 -1
  104. package/dist/es-legacy/core/Analytics/Analytics.js.map +1 -1
  105. package/dist/es-legacy/core/Analytics/EventsQueue.js +1 -1
  106. package/dist/es-legacy/core/Analytics/EventsQueue.js.map +1 -1
  107. package/dist/es-legacy/core/Analytics/utils.js +1 -1
  108. package/dist/es-legacy/core/Analytics/utils.js.map +1 -1
  109. package/dist/es-legacy/core/Errors/AdyenCheckoutError.js +1 -1
  110. package/dist/es-legacy/core/Errors/AdyenCheckoutError.js.map +1 -1
  111. package/dist/es-legacy/core/Errors/utils.js +1 -1
  112. package/dist/es-legacy/core/Errors/utils.js.map +1 -1
  113. package/dist/es-legacy/core/Services/analytics/collect-id.js +1 -1
  114. package/dist/es-legacy/core/Services/analytics/collect-id.js.map +1 -1
  115. package/dist/es-legacy/core/Services/analytics/log-event.js +1 -1
  116. package/dist/es-legacy/core/config.js +1 -1
  117. package/dist/es-legacy/core/config.js.map +1 -1
  118. package/dist/es-legacy/core/core.js +1 -1
  119. package/dist/es-legacy/core/core.js.map +1 -1
  120. package/dist/es-legacy/language/locales/en-US.json.js +1 -1
  121. package/dist/es-legacy/utils/Script.js +1 -1
  122. package/dist/es-legacy/utils/Script.js.map +1 -1
  123. package/dist/umd/adyen.css +1 -1
  124. package/dist/umd/adyen.js +2 -2
  125. package/dist/umd/adyen.js.map +1 -1
  126. package/package.json +2 -2
  127. package/dist/es/components/PayPal/utils.js +0 -2
  128. package/dist/es/components/PayPal/utils.js.map +0 -1
  129. package/dist/es-legacy/components/PayPal/utils.js +0 -2
  130. package/dist/es-legacy/components/PayPal/utils.js.map +0 -1
package/dist/es/adyen.css CHANGED
@@ -1,5 +1,5 @@
1
1
  .js-iframe{border:none;height:100%;overflow:hidden;width:100%}
2
- .adyen-checkout-card-input__wrapper{position:relative}.adyen-checkout-card-input__icon{border-radius:var(--adyen-checkout-border-radius-s);height:18px;margin-right:var(--adyen-checkout-spacer-060);width:27px}.adyen-checkout-card-input__form{opacity:1}.adyen-checkout-card-input__spinner{display:none;height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.adyen-checkout-card-input__spinner--active{display:block}.adyen-checkout-card-input__form--loading{opacity:0}.adyen-checkout__input{display:block;max-height:100px}.adyen-checkout__field.adyen-checkout__card__cvc__input--hidden,.adyen-checkout__field.adyen-checkout__card__exp-date__input--hidden{display:none}.adyen-checkout__card__exp-cvc__exp-date__input--hidden{justify-content:flex-end}.revolving-plan-installments__disabled{opacity:.4;pointer-events:none}.adyen-checkout__card-input__form{transition:opacity .25s ease-out}.adyen-checkout__card__cardNumber{max-width:400px}.adyen-checkout__card__cardNumber__input{padding-left:var(--adyen-checkout-spacer-060)}.adyen-checkout__card__exp-date__input--oneclick{font-weight:var(--adyen-checkout-text-body-font-weight);line-height:var(--adyen-checkout-text-title-line-height);overflow:hidden;text-align:left;text-overflow:ellipsis;white-space:nowrap}.adyen-checkout__card__holderName,.adyen-checkout__field--expiryDate,.adyen-checkout__field--storedCard{margin-bottom:0}.adyen-checkout__store-details{align-items:center;border:var(--adyen-checkout-border-width-s) solid var(--adyen-checkout-color-outline-primary);border-radius:var(--adyen-checkout-border-radius-m);display:flex;gap:var(--adyen-checkout-spacer-060);padding:var(--adyen-checkout-spacer-060) var(--adyen-checkout-spacer-070)}.adyen-checkout__card-input .adyen-checkout__fieldset--billingAddress,.adyen-checkout__card__holderName,.adyen-checkout__card__kcp-authentication,.adyen-checkout__card__socialSecurityNumber,.adyen-checkout__installments,.adyen-checkout__store-details{margin-top:var(--adyen-checkout-spacer-070)}.adyen-checkout__card-input.adyen-checkout__card-input--loading{pointer-events:none}.adyen-checkout__card__holderName:first-child{margin:0 0 var(--adyen-checkout-input-field-label-margin-bottom)}.adyen-checkout__field--cardNumber .adyen-checkout__input--error+.adyen-checkout__card__cardNumber__brandIcon,.adyen-checkout__field--cardNumber .adyen-checkout__input--valid:not(.adyen-checkout__card__cardNumber__input--noBrand)+.adyen-checkout-input__inline-validation--valid{display:none}.adyen-checkout__field--securityCode.adyen-checkout__field--error .adyen-checkout__card__cvc__hint,.adyen-checkout__field--securityCode.adyen-checkout__field--valid .adyen-checkout__card__cvc__hint{opacity:0}@keyframes cvc-indicate-location{0%{opacity:1}to{opacity:.3}}.adyen-checkout__label--focused .adyen-checkout__field__cvc--back-hint .adyen-checkout__card__cvc__hint--back .adyen-checkout__card__cvc__hint__location,.adyen-checkout__label--focused .adyen-checkout__field__cvc--front-hint .adyen-checkout__card__cvc__hint--front .adyen-checkout__card__cvc__hint__location{animation-direction:alternate;animation-duration:1s;animation-iteration-count:infinite;animation-name:cvc-indicate-location}.adyen-checkout__card__cvc__hint__wrapper{align-items:center;backface-visibility:visible;display:flex;height:100%;margin-right:var(--adyen-checkout-spacer-060);transform:translateZ(0);transform-origin:center;transform-style:preserve-3d;transition:transform .3s cubic-bezier(.455,.03,.515,.955);width:27px;will-change:transform}.adyen-checkout__field__cvc--front-hint.adyen-checkout__card__cvc__hint__wrapper{transform:rotateY(180deg)}.adyen-checkout__card__cvc__hint{backface-visibility:hidden;position:absolute;transition:opacity .1s linear}.adyen-checkout__field__exp-date_hint_wrapper{align-items:center;display:flex;margin-right:var(--adyen-checkout-spacer-060);transition:opacity .1s linear}.adyen-checkout__field__exp-date_hint_wrapper.adyen-checkout__field__exp-date_hint_wrapper--hidden{opacity:0}.adyen-checkout__field__exp-date_hint{height:18px;width:27px}.adyen-checkout__card__cvc__hint--front{transform:rotateY(180deg)}@media (prefers-reduced-motion:reduce){.adyen-checkout__card__cvc__hint__wrapper{transition:none}}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__fieldset__fields{justify-content:left}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__radio_group{display:flex;flex-direction:column}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__radio_group__input-wrapper{margin-top:var(--adyen-checkout-spacer-080)}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__field--revolving-plan-installments{margin-left:var(--adyen-checkout-spacer-070);position:relative;top:42px;width:30%}
2
+ .adyen-checkout-card-input__wrapper{position:relative}.adyen-checkout-card-input__icon{border-radius:var(--adyen-checkout-border-radius-s);height:18px;margin-right:var(--adyen-checkout-spacer-060);width:27px}.adyen-checkout-card-input__form{opacity:1}.adyen-checkout-card-input__spinner{display:none;height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.adyen-checkout-card-input__spinner--active{display:block}.adyen-checkout-card-input__form--loading{opacity:0}.adyen-checkout__input{display:block;max-height:100px}.adyen-checkout__field.adyen-checkout__card__cvc__input--hidden,.adyen-checkout__field.adyen-checkout__card__exp-date__input--hidden{display:none}.adyen-checkout__card__exp-cvc__exp-date__input--hidden{justify-content:flex-end}.revolving-plan-installments__disabled{opacity:.4;pointer-events:none}.adyen-checkout__card-input__form{transition:opacity .25s ease-out}.adyen-checkout__card__cardNumber{max-width:400px}.adyen-checkout__card__cardNumber__input{padding-left:var(--adyen-checkout-spacer-060)}.adyen-checkout__card__exp-date__input--oneclick{font-weight:var(--adyen-checkout-text-body-font-weight);line-height:var(--adyen-checkout-text-title-line-height);overflow:hidden;text-align:left;text-overflow:ellipsis;white-space:nowrap}.adyen-checkout__card__holderName,.adyen-checkout__field--expiryDate,.adyen-checkout__field--storedCard{margin-bottom:0}.adyen-checkout__store-details{align-items:center;background:var(--adyen-checkout-color-background-primary);border:var(--adyen-checkout-border-width-s) solid var(--adyen-checkout-color-outline-primary);border-radius:var(--adyen-checkout-border-radius-m);display:flex;gap:var(--adyen-checkout-spacer-060);padding:var(--adyen-checkout-spacer-060) var(--adyen-checkout-spacer-070)}.adyen-checkout__card-input .adyen-checkout__fieldset--billingAddress,.adyen-checkout__card__holderName,.adyen-checkout__card__kcp-authentication,.adyen-checkout__card__socialSecurityNumber,.adyen-checkout__installments,.adyen-checkout__store-details{margin-top:var(--adyen-checkout-spacer-070)}.adyen-checkout__card-input.adyen-checkout__card-input--loading{pointer-events:none}.adyen-checkout__card__holderName:first-child{margin:0 0 var(--adyen-checkout-input-field-label-margin-bottom)}.adyen-checkout__field--cardNumber .adyen-checkout__input--error+.adyen-checkout__card__cardNumber__brandIcon,.adyen-checkout__field--cardNumber .adyen-checkout__input--valid:not(.adyen-checkout__card__cardNumber__input--noBrand)+.adyen-checkout-input__inline-validation--valid{display:none}.adyen-checkout__field--securityCode.adyen-checkout__field--error .adyen-checkout__card__cvc__hint,.adyen-checkout__field--securityCode.adyen-checkout__field--valid .adyen-checkout__card__cvc__hint{opacity:0}@keyframes cvc-indicate-location{0%{opacity:1}to{opacity:.3}}.adyen-checkout__label--focused .adyen-checkout__field__cvc--back-hint .adyen-checkout__card__cvc__hint--back .adyen-checkout__card__cvc__hint__location,.adyen-checkout__label--focused .adyen-checkout__field__cvc--front-hint .adyen-checkout__card__cvc__hint--front .adyen-checkout__card__cvc__hint__location{animation-direction:alternate;animation-duration:1s;animation-iteration-count:infinite;animation-name:cvc-indicate-location}.adyen-checkout__card__cvc__hint__wrapper{align-items:center;backface-visibility:visible;display:flex;height:100%;margin-right:var(--adyen-checkout-spacer-060);transform:translateZ(0);transform-origin:center;transform-style:preserve-3d;transition:transform .3s cubic-bezier(.455,.03,.515,.955);width:27px;will-change:transform}.adyen-checkout__field__cvc--front-hint.adyen-checkout__card__cvc__hint__wrapper{transform:rotateY(180deg)}.adyen-checkout__card__cvc__hint{backface-visibility:hidden;position:absolute;transition:opacity .1s linear}.adyen-checkout__field__exp-date_hint_wrapper{align-items:center;display:flex;margin-right:var(--adyen-checkout-spacer-060);transition:opacity .1s linear}.adyen-checkout__field__exp-date_hint_wrapper.adyen-checkout__field__exp-date_hint_wrapper--hidden{opacity:0}.adyen-checkout__field__exp-date_hint{height:18px;width:27px}.adyen-checkout__card__cvc__hint--front{transform:rotateY(180deg)}@media (prefers-reduced-motion:reduce){.adyen-checkout__card__cvc__hint__wrapper{transition:none}}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__fieldset__fields{justify-content:left}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__radio_group{display:flex;flex-direction:column}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__radio_group__input-wrapper{margin-top:var(--adyen-checkout-spacer-080)}.adyen-checkout__fieldset--revolving-plan .adyen-checkout__field--revolving-plan-installments{margin-left:var(--adyen-checkout-spacer-070);position:relative;top:42px;width:30%}
3
3
  .adyen-checkout__spinner__wrapper{--adyen-checkout-loading-indicator-large-width:var(--adyen-checkout-spacer-120);--adyen-checkout-loading-indicator-large-height:var(--adyen-checkout-spacer-120);--adyen-checkout-loading-indicator-large-border-width:var(--adyen-checkout-spacer-020);--adyen-checkout-loading-indicator-medium-width:28px;--adyen-checkout-loading-indicator-medium-height:28px;--adyen-checkout-loading-indicator-small-width:var(--adyen-checkout-spacer-070);--adyen-checkout-loading-indicator-small-height:var(--adyen-checkout-spacer-070);--adyen-checkout-loading-indicator-small-border-width:var(--adyen-checkout-spacer-010);--adyen-checkout-loading-indicator-width:var(--adyen-checkout-spacer-090);--adyen-checkout-loading-indicator-height:var(--adyen-checkout-spacer-090);align-items:center;display:flex;height:100%;justify-content:center}.adyen-checkout__spinner__wrapper--inline{display:inline-block;height:auto;margin-right:var(--adyen-checkout-spacer-040)}[dir=rtl] .adyen-checkout__spinner__wrapper--inline{margin-left:var(--adyen-checkout-spacer-040);margin-right:0}.adyen-checkout__spinner{height:var(--adyen-checkout-loading-indicator-height);position:relative;width:var(--adyen-checkout-loading-indicator-width)}.adyen-checkout__spinner:after,.adyen-checkout__spinner:before{animation:bento-progress-circular-rotate 1s cubic-bezier(.785,.135,.15,.86) infinite;border:var(--adyen-checkout-border-width-l) solid transparent;border-radius:50%;box-sizing:border-box;content:"";display:block;height:100%;left:0;position:absolute;top:0;width:100%}.adyen-checkout__spinner:before{border-color:var(--adyen-checkout-loading-indicator-background-color);border-top-color:transparent;opacity:.1}.adyen-checkout__spinner:after{border-color:transparent;border-top-color:var(--adyen-checkout-loading-indicator-color)}.adyen-checkout__spinner--small{height:var(--adyen-checkout-loading-indicator-small-height);width:var(--adyen-checkout-loading-indicator-small-width)}.adyen-checkout__spinner--small:after,.adyen-checkout__spinner--small:before{border-width:var(--adyen-checkout-loading-indicator-small-border-width)}.adyen-checkout__spinner--medium{height:var(--adyen-checkout-loading-indicator-medium-height);width:var(--adyen-checkout-loading-indicator-medium-width)}.adyen-checkout__spinner--large{height:var(--adyen-checkout-loading-indicator-large-height);width:var(--adyen-checkout-loading-indicator-large-width)}.adyen-checkout__spinner--large:after,.adyen-checkout__spinner--large:before{border-width:var(--adyen-checkout-loading-indicator-large-border-width)}@keyframes bento-progress-circular-rotate{0%{transform:rotate(0deg)}to{transform:rotate(1turn)}}
4
4
  .loading-input__form{opacity:1}.loading-input__form--loading{opacity:0}.loading-input__spinner{display:none;height:100%;left:0;position:absolute;top:0;width:100%;z-index:1}.loading-input__spinner--active{display:block}
5
5
  .adyen-checkout__field{display:block;margin-bottom:var(--adyen-checkout-spacer-070);width:100%}.adyen-checkout__input-wrapper{align-items:center;background:var(--adyen-checkout-input-wrapper-background);border:var(--adyen-checkout-input-wrapper-border-width) solid var(--adyen-checkout-input-wrapper-border-color);border-radius:var(--adyen-checkout-input-wrapper-border-radius);display:flex;position:relative}.adyen-checkout__input-wrapper div,.adyen-checkout__input-wrapper input,.adyen-checkout__input-wrapper span{border-radius:inherit}.adyen-checkout__input-wrapper button,.adyen-checkout__input-wrapper div,.adyen-checkout__input-wrapper input{border:none}.adyen-checkout__input-wrapper:active,.adyen-checkout__input-wrapper:active:hover,.adyen-checkout__input-wrapper:focus-within,.adyen-checkout__input-wrapper:focus-within:hover{border-color:var(--adyen-checkout-input-wrapper-focus-border-color);box-shadow:0 0 0 .5px var(--adyen-checkout-input-wrapper-focus-border-color)}.adyen-checkout__input-wrapper:hover{border-color:var(--adyen-checkout-input-wrapper-hover-border-color)}.adyen-checkout__field--inactive>.adyen-checkout__input-wrapper{background:var(--adyen-checkout-input-wrapper-inactive-background);border-color:transparent}.adyen-checkout__field--valid:not(.adyen-checkout__field--inactive)>:not(.adyen-checkout__label--focused)+.adyen-checkout__input-wrapper:not(:focus-within,:active){border-bottom-color:var(--adyen-checkout-color-label-success)}.adyen-checkout__field--error>:not(.adyen-checkout__label--focused)+.adyen-checkout__input-wrapper:not(:focus-within,:active){border-color:var(--adyen-checkout-color-label-critical)}.adyen-checkout__label{display:block;position:relative}.adyen-checkout__label--focused+.adyen-checkout__input-wrapper{border-color:var(--adyen-checkout-input-wrapper-focus-border-color);box-shadow:0 0 0 .5px var(--adyen-checkout-input-wrapper-focus-border-color)}.adyen-checkout__label--disabled+.adyen-checkout__input-wrapper{background:var(--adyen-checkout-input-wrapper-inactive-background);border-color:transparent}.adyen-checkout__helper-text,.adyen-checkout__label__text{display:block;font-size:var(--adyen-checkout-font-size-small);margin-bottom:var(--adyen-checkout-input-field-label-margin-bottom)}.adyen-checkout__label-adornment--end{position:absolute;right:0;top:0}.adyen-checkout__helper-text{color:var(--adyen-checkout-input-field-context-color);font-weight:400;line-height:var(--adyen-checkout-line-height-100)}.adyen-checkout__label__text{color:var(--adyen-checkout-input-field-label-color);display:block;font-weight:var(--adyen-checkout-text-body-stronger-font-weight);line-height:var(--adyen-checkout-line-height-200);overflow:hidden;text-overflow:ellipsis;transition:color .1s ease-out;white-space:nowrap}.adyen-checkout__label__text--error{color:var(--adyen-checkout-color-label-critical)}.adyen-checkout__label--focused .adyen-checkout__label__text{color:var(--adyen-checkout-color-label-primary)}.adyen-checkout-contextual-text,.adyen-checkout-contextual-text--error{align-items:center;color:var(--adyen-checkout-input-field-context-color);display:flex;font-size:var(--adyen-checkout-font-size-xsmall);font-weight:400;line-height:var(--adyen-checkout-line-height-100);margin-top:var(--adyen-checkout-input-field-context-margin-top)}.adyen-checkout-contextual-text--error{color:var(--adyen-checkout-color-label-critical)}
@@ -1,2 +1,2 @@
1
- import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as t}from"../internal/UIElement/UIElement.js";import r from"./components/ApplePayButton.js";import s from"./ApplePayService.js";import n from"../../utils/base64.js";import i from"./defaultProps.js";import{httpPost as o}from"../../core/Services/http.js";import{APPLEPAY_SESSION_ENDPOINT as a}from"./config.js";import{preparePaymentRequest as p}from"./payment-request.js";import{resolveSupportedVersion as l,mapBrands as c,formatApplePayContactToAdyenAddressFormat as d}from"./utils.js";import h from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as m}from"../tx-variants.js";import{sanitizeResponse as u,verifyPaymentDidNotFail as y}from"../internal/UIElement/utils.js";import{ANALYTICS_SELECTED_STR as A,ANALYTICS_INSTANT_PAYMENT_BUTTON as P}from"../../core/Analytics/constants.js";class f extends t{static type=m.applepay;static defaultProps=i;constructor(e,t){super(e,t),this.startSession=this.startSession.bind(this),this.submit=this.submit.bind(this),this.validateMerchant=this.validateMerchant.bind(this),this.collectOrderTrackingDetailsIfNeeded=this.collectOrderTrackingDetailsIfNeeded.bind(this),this.handleAuthorization=this.handleAuthorization.bind(this)}formatProps(e){const t=e.version||l(14),r=e.brands?.length?c(e.brands):e.supportedNetworks;return{...e,configuration:e.configuration,supportedNetworks:r,version:t,totalPriceLabel:e.totalPriceLabel||e.configuration?.merchantName}}formatData(){const{applePayToken:e,billingAddress:t,deliveryAddress:r}=this.state;return{paymentMethod:{type:f.type,applePayToken:e},...t&&{billingAddress:t},...r&&{deliveryAddress:r}}}submit=()=>{this.props.isInstantPayment&&this.submitAnalytics({type:A,target:P}),this.startSession()};startSession(){const{version:e,onValidateMerchant:t,onPaymentMethodSelected:r,onShippingMethodSelected:n,onShippingContactSelected:i}=this.props,o=p({companyName:this.props.configuration.merchantName,countryCode:this.core.options.countryCode,...this.props}),a=new s(o,{version:e,onError:e=>{this.handleError(new h("ERROR","ApplePay - Something went wrong on ApplePayService",{cause:e}))},onCancel:e=>{this.handleError(new h("CANCEL","ApplePay UI dismissed",{cause:e}))},onPaymentMethodSelected:r,onShippingMethodSelected:n,onShippingContactSelected:i,onValidateMerchant:t||this.validateMerchant,onPaymentAuthorized:(e,t,r)=>{const s=d(r.payment.billingContact),n=d(r.payment.shippingContact,!0);this.setState({applePayToken:btoa(JSON.stringify(r.payment.token.paymentData)),authorizedEvent:r,...s&&{billingAddress:s},...n&&{deliveryAddress:n}}),this.handleAuthorization().then(this.makePaymentsCall).then(u).then(y).then(this.collectOrderTrackingDetailsIfNeeded).then((({paymentResponse:t,orderDetails:r})=>(e({status:ApplePaySession.STATUS_SUCCESS,...r&&{orderDetails:r}}),t))).then((e=>{this.handleResponse(e)})).catch((e=>{const r=e?.error?.applePayError;t({status:ApplePaySession.STATUS_FAILURE,errors:r?Array.isArray(r)?r:[r]:void 0}),this.handleFailedResult(e)}))}});return new Promise(((e,t)=>this.props.onClick(e,t))).then((()=>{a.begin()})).catch((()=>({})))}async handleAuthorization(){return new Promise(((e,t)=>{this.props.onAuthorized||e();const{authorizedEvent:r,billingAddress:s,deliveryAddress:n}=this.state;this.props.onAuthorized({authorizedEvent:r,...s&&{billingAddress:s},...n&&{deliveryAddress:n}},{resolve:e,reject:t})})).catch((e=>{const t={error:{applePayError:e}};return Promise.reject(t)}))}async collectOrderTrackingDetailsIfNeeded(e){return new Promise(((e,t)=>{if(!this.props.onOrderTrackingRequest)return e();this.props.onOrderTrackingRequest(e,t)})).then((t=>({paymentResponse:e,...t&&{orderDetails:t}}))).catch((()=>({paymentResponse:e})))}async validateMerchant(e,t){const{hostname:r}=window.location,{clientKey:s,configuration:i,loadingContext:p,initiative:l}=this.props,{merchantName:c,merchantId:d}=i,h={loadingContext:p,path:`${a}?clientKey=${s}`},m={displayName:c,domainName:r,initiative:l,merchantIdentifier:d};try{const r=await o(h,m),s=n.decode(r.data);s||t("Could not decode Apple Pay session");e(JSON.parse(s))}catch(e){t("Could not get Apple Pay session")}}get isValid(){return!0}async isAvailable(){if("https:"!==document.location.protocol)return Promise.reject(new h("IMPLEMENTATION_ERROR","Trying to start an Apple Pay session from an insecure document"));if(!this.props.onValidateMerchant&&!this.props.clientKey)return Promise.reject(new h("IMPLEMENTATION_ERROR","clientKey was not provided"));try{if(window.ApplePaySession&&ApplePaySession.canMakePayments()&&ApplePaySession.supportsVersion(this.props.version))return Promise.resolve()}catch(e){console.warn(e)}return Promise.reject(new h("ERROR","Apple Pay is not available on this device"))}render(){return this.props.showPayButton?e(r,{i18n:this.props.i18n,buttonColor:this.props.buttonColor,buttonType:this.props.buttonType,onClick:e=>{e.preventDefault(),this.submit()}}):null}}export{f as default};
1
+ import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as t}from"../internal/UIElement/UIElement.js";import r from"./components/ApplePayButton.js";import s from"./ApplePayService.js";import n from"../../utils/base64.js";import o from"./defaultProps.js";import{httpPost as i}from"../../core/Services/http.js";import{APPLEPAY_SESSION_ENDPOINT as a}from"./config.js";import{preparePaymentRequest as p}from"./payment-request.js";import{resolveSupportedVersion as l,mapBrands as c,formatApplePayContactToAdyenAddressFormat as d}from"./utils.js";import h from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as m}from"../tx-variants.js";import{sanitizeResponse as y,verifyPaymentDidNotFail as u}from"../internal/UIElement/utils.js";import{ANALYTICS_SELECTED_STR as A,ANALYTICS_INSTANT_PAYMENT_BUTTON as P}from"../../core/Analytics/constants.js";class f extends t{static type=m.applepay;static defaultProps=o;constructor(e,t){super(e,t),this.startSession=this.startSession.bind(this),this.submit=this.submit.bind(this),this.validateMerchant=this.validateMerchant.bind(this),this.collectOrderTrackingDetailsIfNeeded=this.collectOrderTrackingDetailsIfNeeded.bind(this),this.handleAuthorization=this.handleAuthorization.bind(this)}formatProps(e){const t=e.version||l(14),r=e.brands?.length?c(e.brands):e.supportedNetworks;return{...e,configuration:e.configuration,supportedNetworks:r,version:t,totalPriceLabel:e.totalPriceLabel||e.configuration?.merchantName}}formatData(){const{applePayToken:e,billingAddress:t,deliveryAddress:r}=this.state;return{paymentMethod:{type:f.type,applePayToken:e},...t&&{billingAddress:t},...r&&{deliveryAddress:r}}}submit=()=>{this.props.isInstantPayment&&this.submitAnalytics({type:A,target:P}),this.startSession()};startSession(){const{version:e,onValidateMerchant:t,onPaymentMethodSelected:r,onShippingMethodSelected:n,onShippingContactSelected:o}=this.props,i=p({companyName:this.props.configuration.merchantName,countryCode:this.core.options.countryCode,...this.props}),a=new s(i,{version:e,onError:e=>{this.handleError(new h("ERROR","ApplePay - Something went wrong on ApplePayService",{cause:e}))},onCancel:e=>{this.handleError(new h("CANCEL","ApplePay UI dismissed",{cause:e}))},onPaymentMethodSelected:r,onShippingMethodSelected:n,onShippingContactSelected:o,onValidateMerchant:t||this.validateMerchant,onPaymentAuthorized:(e,t,r)=>{const s=d(r.payment.billingContact),n=d(r.payment.shippingContact,!0);this.setState({applePayToken:btoa(JSON.stringify(r.payment.token.paymentData)),authorizedEvent:r,...s&&{billingAddress:s},...n&&{deliveryAddress:n}}),this.handleAuthorization().then(this.makePaymentsCall).then(y).then(u).then(this.collectOrderTrackingDetailsIfNeeded).then((({paymentResponse:t,orderDetails:r})=>(e({status:ApplePaySession.STATUS_SUCCESS,...r&&{orderDetails:r}}),t))).then((e=>{this.handleResponse(e)})).catch((e=>{const r=e?.error?.applePayError;t({status:ApplePaySession.STATUS_FAILURE,errors:r?Array.isArray(r)?r:[r]:void 0});const s={...e,error:{applePayError:r}};this.handleFailedResult(s)}))}});return new Promise(((e,t)=>this.props.onClick(e,t))).then((()=>{a.begin()})).catch((()=>({})))}async handleAuthorization(){return new Promise(((e,t)=>{this.props.onAuthorized||e();const{authorizedEvent:r,billingAddress:s,deliveryAddress:n}=this.state;this.props.onAuthorized({authorizedEvent:r,...s&&{billingAddress:s},...n&&{deliveryAddress:n}},{resolve:e,reject:t})})).catch((e=>{const t={error:{applePayError:e}};return Promise.reject(t)}))}async collectOrderTrackingDetailsIfNeeded(e){return new Promise(((e,t)=>{if(!this.props.onOrderTrackingRequest)return e();this.props.onOrderTrackingRequest(e,t)})).then((t=>({paymentResponse:e,...t&&{orderDetails:t}}))).catch((()=>({paymentResponse:e})))}async validateMerchant(e,t){const{hostname:r}=window.location,{clientKey:s,configuration:o,loadingContext:p,initiative:l}=this.props,{merchantName:c,merchantId:d}=o,h={loadingContext:p,path:`${a}?clientKey=${s}`},m={displayName:c,domainName:r,initiative:l,merchantIdentifier:d};try{const r=await i(h,m),s=n.decode(r.data);s||t("Could not decode Apple Pay session");e(JSON.parse(s))}catch(e){t("Could not get Apple Pay session")}}get isValid(){return!0}async isAvailable(){if("https:"!==document.location.protocol)return Promise.reject(new h("IMPLEMENTATION_ERROR","Trying to start an Apple Pay session from an insecure document"));if(!this.props.onValidateMerchant&&!this.props.clientKey)return Promise.reject(new h("IMPLEMENTATION_ERROR","clientKey was not provided"));try{if(window.ApplePaySession&&ApplePaySession.canMakePayments()&&ApplePaySession.supportsVersion(this.props.version))return Promise.resolve()}catch(e){console.warn(e)}return Promise.reject(new h("ERROR","Apple Pay is not available on this device"))}render(){return this.props.showPayButton?e(r,{i18n:this.props.i18n,buttonColor:this.props.buttonColor,buttonType:this.props.buttonType,onClick:e=>{e.preventDefault(),this.submit()}}):null}}export{f as default};
2
2
  //# sourceMappingURL=ApplePay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApplePay.js","sources":["../../../../src/components/ApplePay/ApplePay.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport ApplePayButton from './components/ApplePayButton';\nimport ApplePayService from './ApplePayService';\nimport base64 from '../../utils/base64';\nimport defaultProps from './defaultProps';\nimport { httpPost } from '../../core/Services/http';\nimport { APPLEPAY_SESSION_ENDPOINT } from './config';\nimport { preparePaymentRequest } from './payment-request';\nimport { resolveSupportedVersion, mapBrands, formatApplePayContactToAdyenAddressFormat } from './utils';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { TxVariants } from '../tx-variants';\nimport { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';\nimport type { ApplePayConfiguration, ApplePayElementData, ApplePayPaymentOrderDetails, ApplePaySessionRequest } from './types';\nimport type { ICore } from '../../core/types';\nimport type { PaymentResponseData, RawPaymentResponse } from '../../types/global-types';\nimport { ANALYTICS_INSTANT_PAYMENT_BUTTON, ANALYTICS_SELECTED_STR } from '../../core/Analytics/constants';\n\nconst latestSupportedVersion = 14;\n\nclass ApplePayElement extends UIElement<ApplePayConfiguration> {\n public static type = TxVariants.applepay;\n protected static defaultProps = defaultProps;\n\n constructor(checkout: ICore, props?: ApplePayConfiguration) {\n super(checkout, props);\n this.startSession = this.startSession.bind(this);\n this.submit = this.submit.bind(this);\n this.validateMerchant = this.validateMerchant.bind(this);\n this.collectOrderTrackingDetailsIfNeeded = this.collectOrderTrackingDetailsIfNeeded.bind(this);\n this.handleAuthorization = this.handleAuthorization.bind(this);\n }\n\n /**\n * Formats the component props\n */\n protected formatProps(props) {\n const version = props.version || resolveSupportedVersion(latestSupportedVersion);\n const supportedNetworks = props.brands?.length ? mapBrands(props.brands) : props.supportedNetworks;\n\n return {\n ...props,\n configuration: props.configuration,\n supportedNetworks,\n version,\n totalPriceLabel: props.totalPriceLabel || props.configuration?.merchantName\n };\n }\n\n /**\n * Formats the component data output\n */\n protected formatData(): ApplePayElementData {\n const { applePayToken, billingAddress, deliveryAddress } = this.state;\n\n return {\n paymentMethod: {\n type: ApplePayElement.type,\n applePayToken\n },\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n };\n }\n\n public submit = (): void => {\n // Analytics\n if (this.props.isInstantPayment) {\n this.submitAnalytics({ type: ANALYTICS_SELECTED_STR, target: ANALYTICS_INSTANT_PAYMENT_BUTTON });\n }\n void this.startSession();\n };\n\n private startSession() {\n const { version, onValidateMerchant, onPaymentMethodSelected, onShippingMethodSelected, onShippingContactSelected } = this.props;\n\n const paymentRequest = preparePaymentRequest({\n companyName: this.props.configuration.merchantName,\n countryCode: this.core.options.countryCode,\n ...this.props\n });\n\n const session = new ApplePayService(paymentRequest, {\n version,\n onError: (error: unknown) => {\n this.handleError(\n new AdyenCheckoutError('ERROR', 'ApplePay - Something went wrong on ApplePayService', {\n cause: error\n })\n );\n },\n onCancel: event => {\n this.handleError(new AdyenCheckoutError('CANCEL', 'ApplePay UI dismissed', { cause: event }));\n },\n onPaymentMethodSelected,\n onShippingMethodSelected,\n onShippingContactSelected,\n onValidateMerchant: onValidateMerchant || this.validateMerchant,\n onPaymentAuthorized: (resolve, reject, event) => {\n const billingAddress = formatApplePayContactToAdyenAddressFormat(event.payment.billingContact);\n const deliveryAddress = formatApplePayContactToAdyenAddressFormat(event.payment.shippingContact, true);\n\n this.setState({\n applePayToken: btoa(JSON.stringify(event.payment.token.paymentData)),\n authorizedEvent: event,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n this.handleAuthorization()\n .then(this.makePaymentsCall)\n .then(sanitizeResponse)\n .then(verifyPaymentDidNotFail)\n .then(this.collectOrderTrackingDetailsIfNeeded)\n .then(({ paymentResponse, orderDetails }) => {\n resolve({\n status: ApplePaySession.STATUS_SUCCESS,\n ...(orderDetails && { orderDetails })\n });\n return paymentResponse;\n })\n .then(paymentResponse => {\n this.handleResponse(paymentResponse);\n })\n .catch((paymentResponse: RawPaymentResponse) => {\n const errors = paymentResponse?.error?.applePayError;\n\n reject({\n status: ApplePaySession.STATUS_FAILURE,\n errors: errors ? (Array.isArray(errors) ? errors : [errors]) : undefined\n });\n\n this.handleFailedResult(paymentResponse);\n });\n }\n });\n\n return new Promise((resolve, reject) => this.props.onClick(resolve, reject))\n .then(() => {\n session.begin();\n })\n .catch(() => ({\n // Swallow exception triggered by onClick reject\n }));\n }\n\n /**\n * Call the 'onAuthorized' callback if available.\n * Must be resolved/reject for the payment flow to continue\n *\n * @private\n */\n private async handleAuthorization(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (!this.props.onAuthorized) {\n resolve();\n }\n\n const { authorizedEvent, billingAddress, deliveryAddress } = this.state;\n\n this.props.onAuthorized(\n {\n authorizedEvent,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n );\n }).catch((error?: ApplePayJS.ApplePayError) => {\n // Format error in a way that the 'catch' of the 'onPaymentAuthorize' block accepts it\n const data = { error: { applePayError: error } };\n return Promise.reject(data);\n });\n }\n\n /**\n * Verify if the 'onOrderTrackingRequest' is provided. If so, triggers the callback expecting an\n * Apple Pay order details back\n *\n * @private\n */\n private async collectOrderTrackingDetailsIfNeeded(\n paymentResponse: PaymentResponseData\n ): Promise<{ orderDetails?: ApplePayPaymentOrderDetails; paymentResponse: PaymentResponseData }> {\n return new Promise<ApplePayPaymentOrderDetails | void>((resolve, reject) => {\n if (!this.props.onOrderTrackingRequest) {\n return resolve();\n }\n\n this.props.onOrderTrackingRequest(resolve, reject);\n })\n .then(orderDetails => {\n return {\n paymentResponse,\n ...(orderDetails && { orderDetails })\n };\n })\n .catch(() => {\n return { paymentResponse };\n });\n }\n\n private async validateMerchant(resolve, reject) {\n const { hostname: domainName } = window.location;\n const { clientKey, configuration, loadingContext, initiative } = this.props;\n const { merchantName, merchantId } = configuration;\n const path = `${APPLEPAY_SESSION_ENDPOINT}?clientKey=${clientKey}`;\n const options = { loadingContext, path };\n const request: ApplePaySessionRequest = {\n displayName: merchantName,\n domainName,\n initiative,\n merchantIdentifier: merchantId\n };\n\n try {\n const response = await httpPost(options, request);\n const decodedData = base64.decode(response.data);\n if (!decodedData) reject('Could not decode Apple Pay session');\n const session = JSON.parse(decodedData as string);\n resolve(session);\n } catch (e) {\n reject('Could not get Apple Pay session');\n }\n }\n\n /**\n * Validation\n *\n * @remarks\n * Apple Pay does not require any specific validation\n */\n get isValid(): boolean {\n return true;\n }\n\n /**\n * Determine a shopper's ability to return a form of payment from Apple Pay.\n * @returns Promise Resolve/Reject whether the shopper can use Apple Pay\n */\n public override async isAvailable(): Promise<void> {\n if (document.location.protocol !== 'https:') {\n return Promise.reject(new AdyenCheckoutError('IMPLEMENTATION_ERROR', 'Trying to start an Apple Pay session from an insecure document'));\n }\n\n if (!this.props.onValidateMerchant && !this.props.clientKey) {\n return Promise.reject(new AdyenCheckoutError('IMPLEMENTATION_ERROR', 'clientKey was not provided'));\n }\n\n try {\n if (window.ApplePaySession && ApplePaySession.canMakePayments() && ApplePaySession.supportsVersion(this.props.version)) {\n return Promise.resolve();\n }\n } catch (error) {\n console.warn(error);\n }\n\n return Promise.reject(new AdyenCheckoutError('ERROR', 'Apple Pay is not available on this device'));\n }\n\n /**\n * Renders the Apple Pay button or nothing in the Dropin\n */\n render() {\n if (this.props.showPayButton) {\n return (\n <ApplePayButton\n i18n={this.props.i18n}\n buttonColor={this.props.buttonColor}\n buttonType={this.props.buttonType}\n onClick={e => {\n e.preventDefault();\n this.submit();\n }}\n />\n );\n }\n\n return null;\n }\n}\n\nexport default ApplePayElement;\n"],"names":["ApplePayElement","UIElement","static","TxVariants","applepay","defaultProps","constructor","checkout","props","super","this","startSession","bind","submit","validateMerchant","collectOrderTrackingDetailsIfNeeded","handleAuthorization","formatProps","version","resolveSupportedVersion","supportedNetworks","brands","length","mapBrands","configuration","totalPriceLabel","merchantName","formatData","applePayToken","billingAddress","deliveryAddress","state","paymentMethod","type","isInstantPayment","submitAnalytics","ANALYTICS_SELECTED_STR","target","ANALYTICS_INSTANT_PAYMENT_BUTTON","onValidateMerchant","onPaymentMethodSelected","onShippingMethodSelected","onShippingContactSelected","paymentRequest","preparePaymentRequest","companyName","countryCode","core","options","session","ApplePayService","onError","error","handleError","AdyenCheckoutError","cause","onCancel","event","onPaymentAuthorized","resolve","reject","formatApplePayContactToAdyenAddressFormat","payment","billingContact","shippingContact","setState","btoa","JSON","stringify","token","paymentData","authorizedEvent","then","makePaymentsCall","sanitizeResponse","verifyPaymentDidNotFail","paymentResponse","orderDetails","status","ApplePaySession","STATUS_SUCCESS","handleResponse","catch","errors","applePayError","STATUS_FAILURE","Array","isArray","undefined","handleFailedResult","Promise","onClick","begin","onAuthorized","data","onOrderTrackingRequest","hostname","domainName","window","location","clientKey","loadingContext","initiative","merchantId","path","APPLEPAY_SESSION_ENDPOINT","request","displayName","merchantIdentifier","response","httpPost","decodedData","base64","decode","parse","e","isValid","isAvailable","document","protocol","canMakePayments","supportsVersion","console","warn","render","showPayButton","h","ApplePayButton","i18n","buttonColor","buttonType","preventDefault"],"mappings":"i3BAoBA,MAAMA,UAAwBC,EAC1BC,YAAqBC,EAAWC,SAChCF,oBAAgCG,EAEhCC,WAAAA,CAAYC,EAAiBC,GACzBC,MAAMF,EAAUC,GAChBE,KAAKC,aAAeD,KAAKC,aAAaC,KAAKF,MAC3CA,KAAKG,OAASH,KAAKG,OAAOD,KAAKF,MAC/BA,KAAKI,iBAAmBJ,KAAKI,iBAAiBF,KAAKF,MACnDA,KAAKK,oCAAsCL,KAAKK,oCAAoCH,KAAKF,MACzFA,KAAKM,oBAAsBN,KAAKM,oBAAoBJ,KAAKF,KAC7D,CAKUO,WAAAA,CAAYT,GAClB,MAAMU,EAAUV,EAAMU,SAAWC,EAnBV,IAoBjBC,EAAoBZ,EAAMa,QAAQC,OAASC,EAAUf,EAAMa,QAAUb,EAAMY,kBAEjF,MAAO,IACAZ,EACHgB,cAA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UAClCC,UAAEA,EAAS5E,cAAEA,EAAa6E,eAAEA,EAAcC,WAAEA,GAAe5F,KAAKF,OAChEkB,aAAEA,EAAY6E,WAAEA,GAAe/E,EAE/BwB,EAAU,CAAEqD,iBAAgBG,KADrB,GAAGC,eAAuCL,KAEjDM,EAAkC,CACpCC,YAAajF,EACbuE,aACAK,aACAM,mBAAoBL,GAGxB,IACI,MAAMM,QAAiBC,EAAS9D,EAAS0D,GACnCK,EAAcC,EAAOC,OAAOJ,EAASf,MACtCiB,GAAanD,EAAO,sCAEzBD,EADgBQ,KAAK+C,MAAMH,GAE/B,CAAE,MAAOI,GACLvD,EAAO,kCACX,CACJ,CAQA,WAAIwD,GACA,OAAO,CACX,CAMA,iBAAsBC,GAClB,GAAmC,WAA/BC,SAASnB,SAASoB,SAClB,OAAO7B,QAAQ9B,OAAO,IAAIN,EAAmB,uBAAwB,mEAGzE,IAAK5C,KAAKF,MAAM+B,qBAAuB7B,KAAKF,MAAM4F,UAC9C,OAAOV,QAAQ9B,OAAO,IAAIN,EAAmB,uBAAwB,+BAGzE,IACI,GAAI4C,OAAOnB,iBAAmBA,gBAAgByC,mBAAqBzC,gBAAgB0C,gBAAgB/G,KAAKF,MAAMU,SAC1G,OAAOwE,QAAQ/B,SAEvB,CAAE,MAAOP,GACLsE,QAAQC,KAAKvE,EACjB,CAEA,OAAOsC,QAAQ9B,OAAO,IAAIN,EAAmB,QAAS,6CAC1D,CAKAsE,MAAAA,GACI,OAAIlH,KAAKF,MAAMqH,cAEPC,EAACC,EAAAA,CACGC,KAAMtH,KAAKF,MAAMwH,KACjBC,YAAavH,KAAKF,MAAMyH,YACxBC,WAAYxH,KAAKF,MAAM0H,WACvBvC,QAASwB,IACLA,EAAEgB,iBACFzH,KAAKG,QAAM,IAMpB,IACX"}
1
+ {"version":3,"file":"ApplePay.js","sources":["../../../../src/components/ApplePay/ApplePay.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport ApplePayButton from './components/ApplePayButton';\nimport ApplePayService from './ApplePayService';\nimport base64 from '../../utils/base64';\nimport defaultProps from './defaultProps';\nimport { httpPost } from '../../core/Services/http';\nimport { APPLEPAY_SESSION_ENDPOINT } from './config';\nimport { preparePaymentRequest } from './payment-request';\nimport { resolveSupportedVersion, mapBrands, formatApplePayContactToAdyenAddressFormat } from './utils';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { TxVariants } from '../tx-variants';\nimport { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';\nimport { ANALYTICS_INSTANT_PAYMENT_BUTTON, ANALYTICS_SELECTED_STR } from '../../core/Analytics/constants';\nimport type { ApplePayConfiguration, ApplePayElementData, ApplePayPaymentOrderDetails, ApplePaySessionRequest } from './types';\nimport type { ICore } from '../../core/types';\nimport type { PaymentResponseData, RawPaymentResponse } from '../../types/global-types';\n\nconst latestSupportedVersion = 14;\n\nclass ApplePayElement extends UIElement<ApplePayConfiguration> {\n public static type = TxVariants.applepay;\n protected static defaultProps = defaultProps;\n\n constructor(checkout: ICore, props?: ApplePayConfiguration) {\n super(checkout, props);\n this.startSession = this.startSession.bind(this);\n this.submit = this.submit.bind(this);\n this.validateMerchant = this.validateMerchant.bind(this);\n this.collectOrderTrackingDetailsIfNeeded = this.collectOrderTrackingDetailsIfNeeded.bind(this);\n this.handleAuthorization = this.handleAuthorization.bind(this);\n }\n\n /**\n * Formats the component props\n */\n protected formatProps(props) {\n const version = props.version || resolveSupportedVersion(latestSupportedVersion);\n const supportedNetworks = props.brands?.length ? mapBrands(props.brands) : props.supportedNetworks;\n\n return {\n ...props,\n configuration: props.configuration,\n supportedNetworks,\n version,\n totalPriceLabel: props.totalPriceLabel || props.configuration?.merchantName\n };\n }\n\n /**\n * Formats the component data output\n */\n protected formatData(): ApplePayElementData {\n const { applePayToken, billingAddress, deliveryAddress } = this.state;\n\n return {\n paymentMethod: {\n type: ApplePayElement.type,\n applePayToken\n },\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n };\n }\n\n public submit = (): void => {\n // Analytics\n if (this.props.isInstantPayment) {\n this.submitAnalytics({ type: ANALYTICS_SELECTED_STR, target: ANALYTICS_INSTANT_PAYMENT_BUTTON });\n }\n void this.startSession();\n };\n\n private startSession() {\n const { version, onValidateMerchant, onPaymentMethodSelected, onShippingMethodSelected, onShippingContactSelected } = this.props;\n\n const paymentRequest = preparePaymentRequest({\n companyName: this.props.configuration.merchantName,\n countryCode: this.core.options.countryCode,\n ...this.props\n });\n\n const session = new ApplePayService(paymentRequest, {\n version,\n onError: (error: unknown) => {\n this.handleError(\n new AdyenCheckoutError('ERROR', 'ApplePay - Something went wrong on ApplePayService', {\n cause: error\n })\n );\n },\n onCancel: event => {\n this.handleError(new AdyenCheckoutError('CANCEL', 'ApplePay UI dismissed', { cause: event }));\n },\n onPaymentMethodSelected,\n onShippingMethodSelected,\n onShippingContactSelected,\n onValidateMerchant: onValidateMerchant || this.validateMerchant,\n onPaymentAuthorized: (resolve, reject, event) => {\n const billingAddress = formatApplePayContactToAdyenAddressFormat(event.payment.billingContact);\n const deliveryAddress = formatApplePayContactToAdyenAddressFormat(event.payment.shippingContact, true);\n\n this.setState({\n applePayToken: btoa(JSON.stringify(event.payment.token.paymentData)),\n authorizedEvent: event,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n this.handleAuthorization()\n .then(this.makePaymentsCall)\n .then(sanitizeResponse)\n .then(verifyPaymentDidNotFail)\n .then(this.collectOrderTrackingDetailsIfNeeded)\n .then(({ paymentResponse, orderDetails }) => {\n resolve({\n status: ApplePaySession.STATUS_SUCCESS,\n ...(orderDetails && { orderDetails })\n });\n return paymentResponse;\n })\n .then(paymentResponse => {\n this.handleResponse(paymentResponse);\n })\n .catch((paymentResponse?: RawPaymentResponse) => {\n const errors = paymentResponse?.error?.applePayError;\n\n reject({\n status: ApplePaySession.STATUS_FAILURE,\n errors: errors ? (Array.isArray(errors) ? errors : [errors]) : undefined\n });\n\n const responseWithError: RawPaymentResponse = {\n ...paymentResponse,\n error: {\n applePayError: errors\n }\n };\n\n this.handleFailedResult(responseWithError);\n });\n }\n });\n\n return new Promise((resolve, reject) => this.props.onClick(resolve, reject))\n .then(() => {\n session.begin();\n })\n .catch(() => ({\n // Swallow exception triggered by onClick reject\n }));\n }\n\n /**\n * Call the 'onAuthorized' callback if available.\n * Must be resolved/reject for the payment flow to continue\n *\n * @private\n */\n private async handleAuthorization(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (!this.props.onAuthorized) {\n resolve();\n }\n\n const { authorizedEvent, billingAddress, deliveryAddress } = this.state;\n\n this.props.onAuthorized(\n {\n authorizedEvent,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n );\n }).catch((error?: ApplePayJS.ApplePayError) => {\n // Format error in a way that the 'catch' of the 'onPaymentAuthorize' block accepts it\n const data = { error: { applePayError: error } };\n return Promise.reject(data);\n });\n }\n\n /**\n * Verify if the 'onOrderTrackingRequest' is provided. If so, triggers the callback expecting an\n * Apple Pay order details back\n *\n * @private\n */\n private async collectOrderTrackingDetailsIfNeeded(\n paymentResponse: PaymentResponseData\n ): Promise<{ orderDetails?: ApplePayPaymentOrderDetails; paymentResponse: PaymentResponseData }> {\n return new Promise<ApplePayPaymentOrderDetails | void>((resolve, reject) => {\n if (!this.props.onOrderTrackingRequest) {\n return resolve();\n }\n\n this.props.onOrderTrackingRequest(resolve, reject);\n })\n .then(orderDetails => {\n return {\n paymentResponse,\n ...(orderDetails && { orderDetails })\n };\n })\n .catch(() => {\n return { paymentResponse };\n });\n }\n\n private async validateMerchant(resolve, reject) {\n const { hostname: domainName } = window.location;\n const { clientKey, configuration, loadingContext, initiative } = this.props;\n const { merchantName, merchantId } = configuration;\n const path = `${APPLEPAY_SESSION_ENDPOINT}?clientKey=${clientKey}`;\n const options = { loadingContext, path };\n const request: ApplePaySessionRequest = {\n displayName: merchantName,\n domainName,\n initiative,\n merchantIdentifier: merchantId\n };\n\n try {\n const response = await httpPost(options, request);\n const decodedData = base64.decode(response.data);\n if (!decodedData) reject('Could not decode Apple Pay session');\n const session = JSON.parse(decodedData as string);\n resolve(session);\n } catch (e) {\n reject('Could not get Apple Pay session');\n }\n }\n\n /**\n * Validation\n *\n * @remarks\n * Apple Pay does not require any specific validation\n */\n get isValid(): boolean {\n return true;\n }\n\n /**\n * Determine a shopper's ability to return a form of payment from Apple Pay.\n * @returns Promise Resolve/Reject whether the shopper can use Apple Pay\n */\n public override async isAvailable(): Promise<void> {\n if (document.location.protocol !== 'https:') {\n return Promise.reject(new AdyenCheckoutError('IMPLEMENTATION_ERROR', 'Trying to start an Apple Pay session from an insecure document'));\n }\n\n if (!this.props.onValidateMerchant && !this.props.clientKey) {\n return Promise.reject(new AdyenCheckoutError('IMPLEMENTATION_ERROR', 'clientKey was not provided'));\n }\n\n try {\n if (window.ApplePaySession && ApplePaySession.canMakePayments() && ApplePaySession.supportsVersion(this.props.version)) {\n return Promise.resolve();\n }\n } catch (error) {\n console.warn(error);\n }\n\n return Promise.reject(new AdyenCheckoutError('ERROR', 'Apple Pay is not available on this device'));\n }\n\n /**\n * Renders the Apple Pay button or nothing in the Dropin\n */\n render() {\n if (this.props.showPayButton) {\n return (\n <ApplePayButton\n i18n={this.props.i18n}\n buttonColor={this.props.buttonColor}\n buttonType={this.props.buttonType}\n onClick={e => {\n e.preventDefault();\n this.submit();\n }}\n />\n );\n }\n\n return null;\n }\n}\n\nexport default ApplePayElement;\n"],"names":["ApplePayElement","UIElement","static","TxVariants","applepay","defaultProps","constructor","checkout","props","super","this","startSession","bind","submit","validateMerchant","collectOrderTrackingDetailsIfNeeded","handleAuthorization","formatProps","version","resolveSupportedVersion","supportedNetworks","brands","length","mapBrands","configuration","totalPriceLabel","merchantName","formatData","applePayToken","billingAddress","deliveryAddress","state","paymentMethod","type","isInstantPayment","submitAnalytics","ANALYTICS_SELECTED_STR","target","ANALYTICS_INSTANT_PAYMENT_BUTTON","onValidateMerchant","onPaymentMethodSelected","onShippingMethodSelected","onShippingContactSelected","paymentRequest","preparePaymentRequest","companyName","countryCode","core","options","session","ApplePayService","onError","error","handleError","AdyenCheckoutError","cause","onCancel","event","onPaymentAuthorized","resolve","reject","formatApplePayContactToAdyenAddressFormat","payment","billingContact","shippingContact","setState","btoa","JSON","stringify","token","paymentData","authorizedEvent","then","makePaymentsCall","sanitizeResponse","verifyPaymentDidNotFail","paymentResponse","orderDetails","status","ApplePaySession","STATUS_SUCCESS","handleResponse","catch","errors","applePayError","STATUS_FAILURE","Array","isArray","undefined","responseWithError","handleFailedResult","Promise","onClick","begin","onAuthorized","data","onOrderTrackingRequest","hostname","domainName","window","location","clientKey","loadingContext","initiative","merchantId","path","APPLEPAY_SESSION_ENDPOINT","request","displayName","merchantIdentifier","response","httpPost","decodedData","base64","decode","parse","e","isValid","isAvailable","document","protocol","canMakePayments","supportsVersion","console","warn","render","showPayButton","h","ApplePayButton","i18n","buttonColor","buttonType","preventDefault"],"mappings":"i3BAoBA,MAAMA,UAAwBC,EAC1BC,YAAqBC,EAAWC,SAChCF,oBAAgCG,EAEhCC,WAAAA,CAAYC,EAAiBC,GACzBC,MAAMF,EAAUC,GAChBE,KAAKC,aAAeD,KAAKC,aAAaC,KAAKF,MAC3CA,KAAKG,OAASH,KAAKG,OAAOD,KAAKF,MAC/BA,KAAKI,iBAAmBJ,KAAKI,iBAAiBF,KAAKF,MACnDA,KAAKK,oCAAsCL,KAAKK,oCAAoCH,KAAKF,MACzFA,KAAKM,oBAAsBN,KAAKM,oBAAoBJ,KAAKF,KAC7D,CAKUO,WAAAA,CAAYT,GAClB,MAAMU,EAAUV,EAAMU,SAAWC,EAnBV,IAoBjBC,EAAoBZ,EAAMa,QAAQC,OAASC,EAAUf,EAAMa,QAAUb,EAAMY,kBAEjF,MAAO,IACAZ,EACHgB,cAAehB,EAAMgB,cACrBJ,oBACAF,UACAO,gBAAiBjB,E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OAAOC,UAClCC,UAAEA,EAAS7E,cAAEA,EAAa8E,eAAEA,EAAcC,WAAEA,GAAe7F,KAAKF,OAChEkB,aAAEA,EAAY8E,WAAEA,GAAehF,EAE/BwB,EAAU,CAAEsD,iBAAgBG,KADrB,GAAGC,eAAuCL,KAEjDM,EAAkC,CACpCC,YAAalF,EACbwE,aACAK,aACAM,mBAAoBL,GAGxB,IACI,MAAMM,QAAiBC,EAAS/D,EAAS2D,GACnCK,EAAcC,EAAOC,OAAOJ,EAASf,MACtCiB,GAAapD,EAAO,sCAEzBD,EADgBQ,KAAKgD,MAAMH,GAE/B,CAAE,MAAOI,GACLxD,EAAO,kCACX,CACJ,CAQA,WAAIyD,GACA,OAAO,CACX,CAMA,iBAAsBC,GAClB,GAAmC,WAA/BC,SAASnB,SAASoB,SAClB,OAAO7B,QAAQ/B,OAAO,IAAIN,EAAmB,uBAAwB,mEAGzE,IAAK5C,KAAKF,MAAM+B,qBAAuB7B,KAAKF,MAAM6F,UAC9C,OAAOV,QAAQ/B,OAAO,IAAIN,EAAmB,uBAAwB,+BAGzE,IACI,GAAI6C,OAAOpB,iBAAmBA,gBAAgB0C,mBAAqB1C,gBAAgB2C,gBAAgBhH,KAAKF,MAAMU,SAC1G,OAAOyE,QAAQhC,SAEvB,CAAE,MAAOP,GACLuE,QAAQC,KAAKxE,EACjB,CAEA,OAAOuC,QAAQ/B,OAAO,IAAIN,EAAmB,QAAS,6CAC1D,CAKAuE,MAAAA,GACI,OAAInH,KAAKF,MAAMsH,cAEPC,EAACC,EAAAA,CACGC,KAAMvH,KAAKF,MAAMyH,KACjBC,YAAaxH,KAAKF,MAAM0H,YACxBC,WAAYzH,KAAKF,MAAM2H,WACvBvC,QAASwB,IACLA,EAAEgB,iBACF1H,KAAKG,QAAM,IAMpB,IACX"}
@@ -1,2 +1,2 @@
1
- import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import o from"./defaultProps.js";import{DropinComponent as s}from"./components/DropinComponent.js";import n from"../../core/Context/CoreProvider.js";import{getCommonProps as i}from"./components/utils.js";import r from"./elements/createElements.js";import a from"./elements/createStoredElements.js";import h from"./elements/createInstantPaymentElements.js";import{hasOwnProperty as m}from"../../utils/hasOwnProperty.js";import d from"../../core/Errors/SRPanelProvider.js";import p from"./elements/splitPaymentMethods.js";const c=["paywithgoogle","googlepay","applepay"];class l extends e{static defaultProps=o;dropinRef=null;paymentMethodsConfiguration;componentFromAction;constructor(t,e){super(t,e),this.submit=this.submit.bind(this),this.handleAction=this.handleAction.bind(this),this.props.paymentMethodComponents.forEach((t=>this.core.register(t))),this.paymentMethodsConfiguration=this.props.paymentMethodsConfiguration||{}}storeElementRefOnCore(){this.core.storeElementReference(this)}formatProps(t){return{type:"dropin",...super.formatProps(t),instantPaymentTypes:Array.from(new Set(t.instantPaymentTypes)).filter((t=>c.includes(t)))}}get isValid(){return!!this.dropinRef&&!!this.dropinRef.state.activePaymentMethod&&!!this.dropinRef.state.activePaymentMethod.isValid}showValidation(){return this.dropinRef.state.activePaymentMethod&&this.dropinRef.state.activePaymentMethod.showValidation(),this}setStatus(t,e={}){return this.dropinRef?.setStatus(t,e),this}get activePaymentMethod(){return this.dropinRef?.state||this.dropinRef?.state.activePaymentMethod?this.dropinRef.state.activePaymentMethod:null}get data(){return this.activePaymentMethod?this.dropinRef.state.activePaymentMethod.data:null}submit(){if(!this.activePaymentMethod)throw new Error("No active payment method.");this.activePaymentMethod.isValid||this.activePaymentMethod.showValidation(),this.activePaymentMethod.isInstantPayment&&this.closeActivePaymentMethod(),this.activePaymentMethod.submit()}handleCreate=()=>{const{paymentMethodsConfiguration:t,showStoredPaymentMethods:e,showPaymentMethods:o,instantPaymentTypes:s}=this.props,{paymentMethods:n,storedPaymentMethods:m,instantPaymentMethods:d}=p(this.core.paymentMethodsResponse,s),c=i({...this.props,elementRef:this.elementRef});return[e?a(m,t,c,this.core):[],o?r(n,t,c,this.core):[],h(d,t,c,this.core)]};handleAction(t,e={}){if(!t||!t.type){if(m(t,"action")&&m(t,"resultCode"))throw new Error('handleAction::Invalid Action - the passed action object itself has an "action" property and a "resultCode": have you passed in the whole response object by mistake?');throw new Error('handleAction::Invalid Action - the passed action object does not have a "type" property')}if("redirect"!==t.type&&this.activePaymentMethod?.updateWithAction)return this.activePaymentMethod.updateWithAction(t);this.elementRef instanceof l&&(e={...this.elementRef.activePaymentMethod?.props,...e});const o=this.core.createFromAction(t,{...e,elementRef:this.elementRef,onAdditionalDetails:this.handleAdditionalDetails,isDropin:!0});return o?(this.setStatus(o.props.statusType,{component:o}),this.componentFromAction=o,this):null}handleOrder=({order:t})=>{this.updateParent({order:t})};closeActivePaymentMethod(){this.dropinRef.closeActivePaymentMethod()}render(){return t(n,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},t(d,{srPanel:this.props.modules.srPanel},t(s,{...this.props,core:this.core,onChange:this.setState,elementRef:this.elementRef,onCreateElements:this.handleCreate,ref:t=>{this.dropinRef=t}})))}}export{l as default};
1
+ import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import o from"./defaultProps.js";import{DropinComponent as s}from"./components/DropinComponent.js";import n from"../../core/Context/CoreProvider.js";import{getCommonProps as i}from"./components/utils.js";import r from"./elements/createElements.js";import a from"./elements/createStoredElements.js";import h from"./elements/createInstantPaymentElements.js";import{hasOwnProperty as m}from"../../utils/hasOwnProperty.js";import d from"../../core/Errors/SRPanelProvider.js";import p from"./elements/splitPaymentMethods.js";const l=["paywithgoogle","googlepay","applepay"];class c extends e{static defaultProps=o;dropinRef=null;paymentMethodsConfiguration;componentFromAction;constructor(t,e){super(t,e),this.submit=this.submit.bind(this),this.handleAction=this.handleAction.bind(this),this.props.paymentMethodComponents.forEach((t=>this.core.register(t))),this.paymentMethodsConfiguration=this.props.paymentMethodsConfiguration||{}}storeElementRefOnCore(){this.core.storeElementReference(this)}formatProps(t){return{type:"dropin",...super.formatProps(t),instantPaymentTypes:Array.from(new Set(t.instantPaymentTypes)).filter((t=>l.includes(t)))}}get isValid(){return!!this.dropinRef&&!!this.dropinRef.state.activePaymentMethod&&!!this.dropinRef.state.activePaymentMethod.isValid}showValidation(){return this.dropinRef.state.activePaymentMethod&&this.dropinRef.state.activePaymentMethod.showValidation(),this}setStatus(t,e={}){return this.dropinRef?.setStatus(t,e),this}get activePaymentMethod(){return this.dropinRef?.state||this.dropinRef?.state.activePaymentMethod?this.dropinRef.state.activePaymentMethod:null}get data(){return this.activePaymentMethod?this.dropinRef.state.activePaymentMethod.data:null}displayFinalAnimation(t){this.props.disableFinalAnimation||this.dropinRef.setStatus(t)}submit(){if(!this.activePaymentMethod)throw new Error("No active payment method.");this.activePaymentMethod.isValid||this.activePaymentMethod.showValidation(),this.activePaymentMethod.isInstantPayment&&this.closeActivePaymentMethod(),this.activePaymentMethod.submit()}handleCreate=()=>{const{paymentMethodsConfiguration:t,showStoredPaymentMethods:e,showPaymentMethods:o,instantPaymentTypes:s}=this.props,{paymentMethods:n,storedPaymentMethods:m,instantPaymentMethods:d}=p(this.core.paymentMethodsResponse,s),l=i({...this.props,elementRef:this.elementRef});return[e?a(m,t,l,this.core):[],o?r(n,t,l,this.core):[],h(d,t,l,this.core)]};handleAction(t,e={}){if(!t||!t.type){if(m(t,"action")&&m(t,"resultCode"))throw new Error('handleAction::Invalid Action - the passed action object itself has an "action" property and a "resultCode": have you passed in the whole response object by mistake?');throw new Error('handleAction::Invalid Action - the passed action object does not have a "type" property')}if("redirect"!==t.type&&this.activePaymentMethod?.updateWithAction)return this.activePaymentMethod.updateWithAction(t);this.elementRef instanceof c&&(e={...this.elementRef.activePaymentMethod?.props,...e});const o=this.core.createFromAction(t,{...e,elementRef:this.elementRef,onAdditionalDetails:this.handleAdditionalDetails,isDropin:!0});return o?(this.setStatus(o.props.statusType,{component:o}),this.componentFromAction=o,this):null}handleOrder=({order:t})=>{this.updateParent({order:t})};closeActivePaymentMethod(){this.dropinRef.closeActivePaymentMethod()}render(){return t(n,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},t(d,{srPanel:this.props.modules.srPanel},t(s,{...this.props,core:this.core,onChange:this.setState,elementRef:this.elementRef,onCreateElements:this.handleCreate,ref:t=>{this.dropinRef=t}})))}}export{c as default};
2
2
  //# sourceMappingURL=Dropin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Dropin.js","sources":["../../../../src/components/Dropin/Dropin.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport defaultProps from './defaultProps';\nimport DropinComponent from '../../components/Dropin/components/DropinComponent';\nimport CoreProvider from '../../core/Context/CoreProvider';\nimport { PaymentAction, PaymentResponseData } from '../../types/global-types';\nimport { DropinConfiguration, InstantPaymentTypes, PaymentMethodsConfiguration } from './types';\nimport { getCommonProps } from './components/utils';\nimport { createElements, createStoredElements } from './elements';\nimport createInstantPaymentElements from './elements/createInstantPaymentElements';\nimport { hasOwnProperty } from '../../utils/hasOwnProperty';\nimport SRPanelProvider from '../../core/Errors/SRPanelProvider';\nimport splitPaymentMethods from './elements/splitPaymentMethods';\nimport type { ICore } from '../../core/types';\nimport type { IDropin } from './types';\n\nconst SUPPORTED_INSTANT_PAYMENTS = ['paywithgoogle', 'googlepay', 'applepay'];\n\nclass DropinElement extends UIElement<DropinConfiguration> implements IDropin {\n protected static defaultProps = defaultProps;\n\n public dropinRef = null;\n\n private paymentMethodsConfiguration: PaymentMethodsConfiguration;\n /**\n * Reference to the component created from `handleAction` (Ex.: ThreeDS2Challenge)\n */\n public componentFromAction?: UIElement;\n\n constructor(checkout: ICore, props?: DropinConfiguration) {\n super(checkout, props);\n this.submit = this.submit.bind(this);\n this.handleAction = this.handleAction.bind(this);\n\n this.props.paymentMethodComponents.forEach(PaymentMethod => this.core.register(PaymentMethod));\n this.paymentMethodsConfiguration = this.props.paymentMethodsConfiguration || {};\n }\n\n protected override storeElementRefOnCore() {\n this.core.storeElementReference(this);\n }\n\n formatProps(props) {\n return {\n type: 'dropin', // for analytics\n ...super.formatProps(props),\n instantPaymentTypes: Array.from<InstantPaymentTypes>(new Set(props.instantPaymentTypes)).filter(value =>\n SUPPORTED_INSTANT_PAYMENTS.includes(value)\n )\n };\n }\n\n get isValid() {\n return !!this.dropinRef && !!this.dropinRef.state.activePaymentMethod && !!this.dropinRef.state.activePaymentMethod.isValid;\n }\n\n showValidation() {\n if (this.dropinRef.state.activePaymentMethod) {\n this.dropinRef.state.activePaymentMethod.showValidation();\n }\n\n return this;\n }\n\n public setStatus(status, props = {}): this {\n this.dropinRef?.setStatus(status, props);\n return this;\n }\n\n get activePaymentMethod() {\n if (!this.dropinRef?.state && !this.dropinRef?.state.activePaymentMethod) {\n return null;\n }\n\n return this.dropinRef.state.activePaymentMethod;\n }\n\n get data() {\n if (!this.activePaymentMethod) {\n return null;\n }\n\n return this.dropinRef.state.activePaymentMethod.data;\n }\n\n /**\n * Calls the onSubmit event with the state of the activePaymentMethod\n */\n public override submit(): void {\n if (!this.activePaymentMethod) {\n throw new Error('No active payment method.');\n }\n\n if (!this.activePaymentMethod.isValid) {\n this.activePaymentMethod.showValidation();\n }\n\n if (this.activePaymentMethod.isInstantPayment) {\n this.closeActivePaymentMethod();\n }\n\n this.activePaymentMethod.submit();\n }\n\n /**\n * Creates the Drop-in elements\n */\n private handleCreate = () => {\n const { paymentMethodsConfiguration, showStoredPaymentMethods, showPaymentMethods, instantPaymentTypes } = this.props;\n\n const { paymentMethods, storedPaymentMethods, instantPaymentMethods } = splitPaymentMethods(\n this.core.paymentMethodsResponse,\n instantPaymentTypes\n );\n\n const commonProps = getCommonProps({ ...this.props, elementRef: this.elementRef });\n\n const storedElements = showStoredPaymentMethods\n ? createStoredElements(storedPaymentMethods, paymentMethodsConfiguration, commonProps, this.core)\n : [];\n const elements = showPaymentMethods ? createElements(paymentMethods, paymentMethodsConfiguration, commonProps, this.core) : [];\n const instantPaymentElements = createInstantPaymentElements(instantPaymentMethods, paymentMethodsConfiguration, commonProps, this.core);\n\n return [storedElements, elements, instantPaymentElements];\n };\n\n public handleAction(action: PaymentAction, props = {}): this | null {\n if (!action || !action.type) {\n if (hasOwnProperty(action, 'action') && hasOwnProperty(action, 'resultCode')) {\n throw new Error(\n 'handleAction::Invalid Action - the passed action object itself has an \"action\" property and ' +\n 'a \"resultCode\": have you passed in the whole response object by mistake?'\n );\n }\n throw new Error('handleAction::Invalid Action - the passed action object does not have a \"type\" property');\n }\n\n if (action.type !== 'redirect' && this.activePaymentMethod?.updateWithAction) {\n return this.activePaymentMethod.updateWithAction(action);\n }\n\n if (this.elementRef instanceof DropinElement) {\n props = {\n ...this.elementRef.activePaymentMethod?.props,\n ...props\n };\n }\n\n const paymentAction: UIElement = this.core.createFromAction(action, {\n ...props,\n elementRef: this.elementRef, // maintain elementRef for 3DS2 flow\n onAdditionalDetails: this.handleAdditionalDetails,\n isDropin: true\n });\n\n if (paymentAction) {\n this.setStatus(paymentAction.props.statusType, { component: paymentAction });\n this.componentFromAction = paymentAction;\n return this;\n }\n\n return null;\n }\n\n /**\n * handleOrder is implemented so we don't trigger a callback like in the components\n * @param response - PaymentResponse\n */\n protected handleOrder = ({ order }: PaymentResponseData): void => {\n this.updateParent({ order });\n };\n\n closeActivePaymentMethod() {\n this.dropinRef.closeActivePaymentMethod();\n }\n\n render() {\n return (\n <CoreProvider i18n={this.props.i18n} loadingContext={this.props.loadingContext} resources={this.resources}>\n <SRPanelProvider srPanel={this.props.modules.srPanel}>\n <DropinComponent\n {...this.props}\n core={this.core}\n onChange={this.setState}\n elementRef={this.elementRef}\n onCreateElements={this.handleCreate}\n ref={dropinRef => {\n this.dropinRef = dropinRef;\n }}\n />\n </SRPanelProvider>\n </CoreProvider>\n );\n }\n}\n\nexport default DropinElement;\n"],"names":["SUPPORTED_INSTANT_PAYMENTS","DropinElement","UIElement","static","defaultProps","dropinRef","paymentMethodsConfiguration","componentFromAction","constructor","checkout","props","super","this","submit","bind","handleAction","paymentMethodComponents","forEach","PaymentMethod","core","register","storeElementRefOnCore","storeElementReference","formatProps","type","instantPaymentTypes","Array","from","Set","filter","value","includes","isValid","state","activePaymentMethod","showValidation","setStatus","status","data","Error","isInstantPayment","closeActivePaymentMethod","handleCreate","showStoredPaymentMethods","showPaymentMethods","paymentMethods","storedPaymentMethods","instantPaymentMethods","splitPaymentMethods","paymentMethodsResponse","commonProps","getCommonProps","elementRef","createStoredElements","createElements","createInstantPaymentElements","action","hasOwnProperty","updateWithAction","paymentAction","createFromAction","onAdditionalDetails","handleAdditionalDetails","isDropin","statusType","component","handleOrder","order","updateParent","render","h","CoreProvider","i18n","loadingContext","resources","SRPanelProvider","srPanel","modules","DropinComponent","onChange","setState","onCreateElements","ref"],"mappings":"4oBAgBA,MAAMA,EAA6B,CAAC,gBAAiB,YAAa,YAElE,MAAMC,UAAsBC,EACxBC,oBAAgCC,EAEzBC,UAAY,KAEXC,4BAIRC,oBAEAC,WAAAA,CAAYC,EAAiBC,GACzBC,MAAMF,EAAUC,GAChBE,KAAKC,OAASD,KAAKC,OAAOC,KAAKF,MAC/BA,KAAKG,aAAeH,KAAKG,aAAaD,KAAKF,MAE3CA,KAAKF,MAAMM,wBAAwBC,SAAQC,GAAiBN,KAAKO,KAAKC,SAASF,KAC/EN,KAAKN,4BAA8BM,KAAKF,MAAMJ,6BAA+B,CAAA,CACjF,CAEmBe,qBAAAA,GACfT,KAAKO,KAAKG,sBAAsBV,KACpC,CAEAW,WAAAA,CAAYb,GACR,MAAO,CACHc,KAAM,YACHb,MAAMY,YAAYb,GACrBe,oBAAqBC,MAAMC,KAA0B,IAAIC,IAAIlB,EAAMe,sBAAsBI,QAAOC,GAC5F9B,EAA2B+B,SAASD,KAGhD,CAEA,WAAIE,GACA,QAASpB,KAAKP,aAAeO,KAAKP,UAAU4B,MAAMC,uBAAyBtB,KAAKP,UAAU4B,MAAMC,oBAAoBF,OACxH,CAEAG,cAAAA,GAKI,OAJIvB,KAAKP,UAAU4B,MAAMC,qBACrBtB,KAAKP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MAAuBZ,KAAKsB,qBAAqBwB,iBACxD,OAAO9C,KAAKsB,oBAAoBwB,iBAAiBF,GAGjD5C,KAAKwC,sBAAsBnD,IAC3BS,EAAQ,IACDE,KAAKwC,WAAWlB,qBAAqBxB,SACrCA,IAIX,MAAMiD,EAA2B/C,KAAKO,KAAKyC,iBAAiBJ,EAAQ,IAC7D9C,EACH0C,WAAYxC,KAAKwC,WACjBS,oBAAqBjD,KAAKkD,wBAC1BC,UAAU,IAGd,OAAIJ,GACA/C,KAAKwB,UAAUuB,EAAcjD,MAAMsD,WAAY,CAAEC,UAAWN,IAC5D/C,KAAKL,oBAAsBoD,EACpB/C,MAGJ,IACX,CAMAsD,YAAwB,EAAGC,YACvBvD,KAAKwD,aAAa,CAAED,SAAM,EAG9B1B,wBAAAA,GACI7B,KAAKP,UAAUoC,0BACnB,CAEA4B,MAAAA,GACI,OACIC,EAACC,EAAAA,CAAaC,KAAM5D,KAAKF,MAAM8D,KAAMC,eAAgB7D,KAAKF,MAAM+D,eAAgBC,UAAW9D,KAAK8D,WAC5FJ,EAACK,EAAAA,CAAgBC,QAAShE,KAAKF,MAAMmE,QAAQD,SACzCN,EAACQ,EAAAA,IACOlE,KAAKF,MACTS,KAAMP,KAAKO,KACX4D,SAAUnE,KAAKoE,SACf5B,WAAYxC,KAAKwC,WACjB6B,iBAAkBrE,KAAK8B,aACvBwC,IAAK7E,IACDO,KAAKP,UAAYA,CAAAA,KAMzC"}
1
+ {"version":3,"file":"Dropin.js","sources":["../../../../src/components/Dropin/Dropin.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport defaultProps from './defaultProps';\nimport DropinComponent from '../../components/Dropin/components/DropinComponent';\nimport CoreProvider from '../../core/Context/CoreProvider';\nimport { getCommonProps } from './components/utils';\nimport { createElements, createStoredElements } from './elements';\nimport createInstantPaymentElements from './elements/createInstantPaymentElements';\nimport { hasOwnProperty } from '../../utils/hasOwnProperty';\nimport SRPanelProvider from '../../core/Errors/SRPanelProvider';\nimport splitPaymentMethods from './elements/splitPaymentMethods';\n\nimport type { DropinConfiguration, InstantPaymentTypes, PaymentMethodsConfiguration } from './types';\nimport type { PaymentAction, PaymentResponseData } from '../../types/global-types';\nimport type { ICore } from '../../core/types';\nimport type { IDropin } from './types';\n\nconst SUPPORTED_INSTANT_PAYMENTS = ['paywithgoogle', 'googlepay', 'applepay'];\n\nclass DropinElement extends UIElement<DropinConfiguration> implements IDropin {\n protected static defaultProps = defaultProps;\n\n public dropinRef = null;\n\n private paymentMethodsConfiguration: PaymentMethodsConfiguration;\n /**\n * Reference to the component created from `handleAction` (Ex.: ThreeDS2Challenge)\n */\n public componentFromAction?: UIElement;\n\n constructor(checkout: ICore, props?: DropinConfiguration) {\n super(checkout, props);\n this.submit = this.submit.bind(this);\n this.handleAction = this.handleAction.bind(this);\n\n this.props.paymentMethodComponents.forEach(PaymentMethod => this.core.register(PaymentMethod));\n this.paymentMethodsConfiguration = this.props.paymentMethodsConfiguration || {};\n }\n\n protected override storeElementRefOnCore() {\n this.core.storeElementReference(this);\n }\n\n formatProps(props) {\n return {\n type: 'dropin', // for analytics\n ...super.formatProps(props),\n instantPaymentTypes: Array.from<InstantPaymentTypes>(new Set(props.instantPaymentTypes)).filter(value =>\n SUPPORTED_INSTANT_PAYMENTS.includes(value)\n )\n };\n }\n\n get isValid() {\n return !!this.dropinRef && !!this.dropinRef.state.activePaymentMethod && !!this.dropinRef.state.activePaymentMethod.isValid;\n }\n\n showValidation() {\n if (this.dropinRef.state.activePaymentMethod) {\n this.dropinRef.state.activePaymentMethod.showValidation();\n }\n\n return this;\n }\n\n public setStatus(status, props = {}): this {\n this.dropinRef?.setStatus(status, props);\n return this;\n }\n\n get activePaymentMethod() {\n if (!this.dropinRef?.state && !this.dropinRef?.state.activePaymentMethod) {\n return null;\n }\n\n return this.dropinRef.state.activePaymentMethod;\n }\n\n get data() {\n if (!this.activePaymentMethod) {\n return null;\n }\n\n return this.dropinRef.state.activePaymentMethod.data;\n }\n\n public displayFinalAnimation(type: 'success' | 'error') {\n if (this.props.disableFinalAnimation) return;\n\n this.dropinRef.setStatus(type);\n }\n\n /**\n * Calls the onSubmit event with the state of the activePaymentMethod\n */\n public override submit(): void {\n if (!this.activePaymentMethod) {\n throw new Error('No active payment method.');\n }\n\n if (!this.activePaymentMethod.isValid) {\n this.activePaymentMethod.showValidation();\n }\n\n if (this.activePaymentMethod.isInstantPayment) {\n this.closeActivePaymentMethod();\n }\n\n this.activePaymentMethod.submit();\n }\n\n /**\n * Creates the Drop-in elements\n */\n private handleCreate = () => {\n const { paymentMethodsConfiguration, showStoredPaymentMethods, showPaymentMethods, instantPaymentTypes } = this.props;\n\n const { paymentMethods, storedPaymentMethods, instantPaymentMethods } = splitPaymentMethods(\n this.core.paymentMethodsResponse,\n instantPaymentTypes\n );\n\n const commonProps = getCommonProps({ ...this.props, elementRef: this.elementRef });\n\n const storedElements = showStoredPaymentMethods\n ? createStoredElements(storedPaymentMethods, paymentMethodsConfiguration, commonProps, this.core)\n : [];\n const elements = showPaymentMethods ? createElements(paymentMethods, paymentMethodsConfiguration, commonProps, this.core) : [];\n const instantPaymentElements = createInstantPaymentElements(instantPaymentMethods, paymentMethodsConfiguration, commonProps, this.core);\n\n return [storedElements, elements, instantPaymentElements];\n };\n\n public handleAction(action: PaymentAction, props = {}): this | null {\n if (!action || !action.type) {\n if (hasOwnProperty(action, 'action') && hasOwnProperty(action, 'resultCode')) {\n throw new Error(\n 'handleAction::Invalid Action - the passed action object itself has an \"action\" property and ' +\n 'a \"resultCode\": have you passed in the whole response object by mistake?'\n );\n }\n throw new Error('handleAction::Invalid Action - the passed action object does not have a \"type\" property');\n }\n\n if (action.type !== 'redirect' && this.activePaymentMethod?.updateWithAction) {\n return this.activePaymentMethod.updateWithAction(action);\n }\n\n if (this.elementRef instanceof DropinElement) {\n props = {\n ...this.elementRef.activePaymentMethod?.props,\n ...props\n };\n }\n\n const paymentAction: UIElement = this.core.createFromAction(action, {\n ...props,\n elementRef: this.elementRef, // maintain elementRef for 3DS2 flow\n onAdditionalDetails: this.handleAdditionalDetails,\n isDropin: true\n });\n\n if (paymentAction) {\n this.setStatus(paymentAction.props.statusType, { component: paymentAction });\n this.componentFromAction = paymentAction;\n return this;\n }\n\n return null;\n }\n\n /**\n * handleOrder is implemented so we don't trigger a callback like in the components\n * @param response - PaymentResponse\n */\n protected handleOrder = ({ order }: PaymentResponseData): void => {\n this.updateParent({ order });\n };\n\n closeActivePaymentMethod() {\n this.dropinRef.closeActivePaymentMethod();\n }\n\n render() {\n return (\n <CoreProvider i18n={this.props.i18n} loadingContext={this.props.loadingContext} resources={this.resources}>\n <SRPanelProvider srPanel={this.props.modules.srPanel}>\n <DropinComponent\n {...this.props}\n core={this.core}\n onChange={this.setState}\n elementRef={this.elementRef}\n onCreateElements={this.handleCreate}\n ref={dropinRef => {\n this.dropinRef = dropinRef;\n }}\n />\n </SRPanelProvider>\n </CoreProvider>\n );\n }\n}\n\nexport default DropinElement;\n"],"names":["SUPPORTED_INSTANT_PAYMENTS","DropinElement","UIElement","static","defaultProps","dropinRef","paymentMethodsConfiguration","componentFromAction","constructor","checkout","props","super","this","submit","bind","handleAction","paymentMethodComponents","forEach","PaymentMethod","core","register","storeElementRefOnCore","storeElementReference","formatProps","type","instantPaymentTypes","Array","from","Set","filter","value","includes","isValid","state","activePaymentMethod","showValidation","setStatus","status","data","displayFinalAnimation","disableFinalAnimation","Error","isInstantPayment","closeActivePaymentMethod","handleCreate","showStoredPaymentMethods","showPaymentMethods","paymentMethods","storedPaymentMethods","instantPaymentMethods","splitPaymentMethods","paymentMethodsResponse","commonProps","getCommonProps","elementRef","createStoredElements","createElements","createInstantPaymentElements","action","hasOwnProperty","updateWithAction","paymentAction","createFromAction","onAdditionalDetails","handleAdditionalDetails","isDropin","statusType","component","handleOrder","order","updateParent","render","h","CoreProvider","i18n","loadingContext","resources","SRPanelProvider","srPanel","modules","DropinComponent","onChange","setState","onCreateElements","ref"],"m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Y,CAAEC,UAAWN,IAC5DjD,KAAKL,oBAAsBsD,EACpBjD,MAGJ,IACX,CAMAwD,YAAwB,EAAGC,YACvBzD,KAAK0D,aAAa,CAAED,SAAM,EAG9B1B,wBAAAA,GACI/B,KAAKP,UAAUsC,0BACnB,CAEA4B,MAAAA,GACI,OACIC,EAACC,EAAAA,CAAaC,KAAM9D,KAAKF,MAAMgE,KAAMC,eAAgB/D,KAAKF,MAAMiE,eAAgBC,UAAWhE,KAAKgE,WAC5FJ,EAACK,EAAAA,CAAgBC,QAASlE,KAAKF,MAAMqE,QAAQD,SACzCN,EAACQ,EAAAA,IACOpE,KAAKF,MACTS,KAAMP,KAAKO,KACX8D,SAAUrE,KAAKsE,SACf5B,WAAY1C,KAAK0C,WACjB6B,iBAAkBvE,KAAKgC,aACvBwC,IAAK/E,IACDO,KAAKP,UAAYA,CAAAA,KAMzC"}
@@ -1,2 +1,2 @@
1
- import{Component as t,createElement as e}from"../../../external/preact/dist/preact.js";import s from"./PaymentMethod/PaymentMethodList.js";import n from"./status/index.js";import o from"../../../core/Services/order-status.js";import{ANALYTICS_RENDERED_STR as a}from"../../../core/Analytics/constants.js";class r extends t{state={elements:[],instantPaymentElements:[],storedPaymentElements:[],orderStatus:null,isDisabling:!1,status:{type:"loading",props:void 0},activePaymentMethod:null,cachedPaymentMethods:{}};componentDidMount(){this.prepareDropinData()}prepareDropinData=()=>{const{order:t,clientKey:e,loadingContext:s}=this.props,[n,r,i]=this.props.onCreateElements(),d=t?o({clientKey:e,loadingContext:s},t):null;Promise.all([n,r,i,d]).then((([t,e,s,n])=>{this.setState({instantPaymentElements:s,elements:e,storedPaymentElements:t,orderStatus:n}),this.setStatus("ready"),this.props.modules?.analytics.sendAnalytics("dropin",{type:a})})),this.onOrderCancel=this.getOnOrderCancel()};setStatus=(t,e={})=>{this.setState({status:{type:t,props:e}})};setActivePaymentMethod=t=>{this.setState((e=>({activePaymentMethod:t,cachedPaymentMethods:{...e.cachedPaymentMethods,[t._id]:!0}})))};componentDidUpdate(t,e){e.status.type!==this.state.status.type&&this.state.activePaymentMethod&&this.state.activePaymentMethod.setStatus(this.state.status.type),"ready"===this.state.status.type&&"ready"!==e.status.type&&this.props.onReady&&this.props.onReady()}handleOnSelectPaymentMethod=t=>{const{activePaymentMethod:e}=this.state;this.setActivePaymentMethod(t),(e&&e._id!==t._id||!e)&&(this.props.onSelect(t),t.submitAnalytics({type:a}))};handleDisableStoredPaymentMethod=t=>{this.setState({isDisabling:!0}),new Promise(((e,s)=>this.props.onDisableStoredPaymentMethod(t.props.storedPaymentMethodId,e,s))).then((()=>{this.setState((e=>({elements:e.elements.filter((e=>e._id!==t._id))}))),this.setState({isDisabling:!1})})).catch((()=>{this.setState({isDisabling:!1})}))};closeActivePaymentMethod(){this.setState({activePaymentMethod:null})}getOnOrderCancel=()=>this.props.onOrderCancel?t=>{this.props.onOrderCancel(t)}:this.props.session?t=>this.props.session.cancelOrder(t).then((()=>this.props.core.update({order:null}))).catch((t=>this.setStatus(t?.message||"error"))):null;onOrderCancel;render(t,{elements:o,instantPaymentElements:a,storedPaymentElements:r,status:i,activePaymentMethod:d,cachedPaymentMethods:h}){const p="loading"===i.type,m="redirect"===i.type,c=o?.length||a?.length||r?.length;switch(i.type){case"success":return e(n.Success,{message:0===t?.amount?.value?"resultMessages.preauthorized":i.props?.message});case"error":return e(n.Error,{message:i.props?.message});case"custom":return i.props?.component?.render();default:return e("div",{className:`adyen-checkout__dropin adyen-checkout__dropin--${i.type}`},m&&i.props.component&&i.props.component.render(),p&&i.props&&i.props.component&&i.props.component.render(),c&&e(s,{isLoading:p||m,isDisablingPaymentMethod:this.state.isDisabling,paymentMethods:o,instantPaymentMethods:a,storedPaymentMethods:r,activePaymentMethod:d,cachedPaymentMethods:h,order:this.props.order,orderStatus:this.state.orderStatus,onOrderCancel:this.onOrderCancel,onSelect:this.handleOnSelectPaymentMethod,openFirstPaymentMethod:this.props.openFirstPaymentMethod,openFirstStoredPaymentMethod:this.props.openFirstStoredPaymentMethod,onDisableStoredPaymentMethod:this.handleDisableStoredPaymentMethod,showRemovePaymentMethodButton:this.props.showRemovePaymentMethodButton,showRadioButton:this.props.showRadioButton}))}}}export{r as DropinComponent,r as default};
1
+ import{Component as t,createElement as e}from"../../../external/preact/dist/preact.js";import s from"./PaymentMethod/PaymentMethodList.js";import n from"./status/index.js";import o from"../../../core/Services/order-status.js";import{ANALYTICS_RENDERED_STR as a}from"../../../core/Analytics/constants.js";class r extends t{state={elements:[],instantPaymentElements:[],storedPaymentElements:[],orderStatus:null,isDisabling:!1,status:{type:"loading",props:void 0},activePaymentMethod:null,cachedPaymentMethods:{}};componentDidMount(){this.prepareDropinData()}prepareDropinData=()=>{const{order:t,clientKey:e,loadingContext:s}=this.props,[n,r,i]=this.props.onCreateElements(),d=t?o({clientKey:e,loadingContext:s},t):null;Promise.all([n,r,i,d]).then((([t,e,s,n])=>{this.setState({instantPaymentElements:s,elements:e,storedPaymentElements:t,orderStatus:n}),this.setStatus("ready"),this.props.modules?.analytics.sendAnalytics("dropin",{type:a})})),this.onOrderCancel=this.getOnOrderCancel()};setStatus=(t,e={})=>{this.setState({status:{type:t,props:e}})};setActivePaymentMethod=t=>{this.setState((e=>({activePaymentMethod:t,cachedPaymentMethods:{...e.cachedPaymentMethods,[t._id]:!0}})))};componentDidUpdate(t,e){e.status.type!==this.state.status.type&&this.state.activePaymentMethod&&this.state.activePaymentMethod.setStatus(this.state.status.type),"ready"===this.state.status.type&&"ready"!==e.status.type&&this.props.onReady&&this.props.onReady()}handleOnSelectPaymentMethod=t=>{const{activePaymentMethod:e}=this.state;this.setActivePaymentMethod(t),(e&&e._id!==t._id||!e)&&(this.props.onSelect?.(t),t.submitAnalytics({type:a}))};handleDisableStoredPaymentMethod=t=>{this.setState({isDisabling:!0}),new Promise(((e,s)=>this.props.onDisableStoredPaymentMethod(t.props.storedPaymentMethodId,e,s))).then((()=>{this.setState((e=>({elements:e.elements.filter((e=>e._id!==t._id))}))),this.setState({isDisabling:!1})})).catch((()=>{this.setState({isDisabling:!1})}))};closeActivePaymentMethod(){this.setState({activePaymentMethod:null})}getOnOrderCancel=()=>this.props.onOrderCancel?t=>{this.props.onOrderCancel(t)}:this.props.session?t=>this.props.session.cancelOrder(t).then((()=>this.props.core.update({order:null}))).catch((t=>this.setStatus(t?.message||"error"))):null;onOrderCancel;render(t,{elements:o,instantPaymentElements:a,storedPaymentElements:r,status:i,activePaymentMethod:d,cachedPaymentMethods:h}){const p="loading"===i.type,m="redirect"===i.type,c=o?.length||a?.length||r?.length;switch(i.type){case"success":return e(n.Success,{message:0===t?.amount?.value?"resultMessages.preauthorized":i.props?.message});case"error":return e(n.Error,{message:i.props?.message});case"custom":return i.props?.component?.render();default:return e("div",{className:`adyen-checkout__dropin adyen-checkout__dropin--${i.type}`},m&&i.props.component&&i.props.component.render(),p&&i.props&&i.props.component&&i.props.component.render(),c&&e(s,{isLoading:p||m,isDisablingPaymentMethod:this.state.isDisabling,paymentMethods:o,instantPaymentMethods:a,storedPaymentMethods:r,activePaymentMethod:d,cachedPaymentMethods:h,order:this.props.order,orderStatus:this.state.orderStatus,onOrderCancel:this.onOrderCancel,onSelect:this.handleOnSelectPaymentMethod,openFirstPaymentMethod:this.props.openFirstPaymentMethod,openFirstStoredPaymentMethod:this.props.openFirstStoredPaymentMethod,onDisableStoredPaymentMethod:this.handleDisableStoredPaymentMethod,showRemovePaymentMethodButton:this.props.showRemovePaymentMethodButton,showRadioButton:this.props.showRadioButton}))}}}export{r as DropinComponent,r as default};
2
2
  //# sourceMappingURL=DropinComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"DropinComponent.js","sources":["../../../../../src/components/Dropin/components/DropinComponent.tsx"],"sourcesContent":["import { Component, h } from 'preact';\nimport PaymentMethodList from './PaymentMethod/PaymentMethodList';\nimport Status from './status';\nimport getOrderStatus from '../../../core/Services/order-status';\nimport { DropinComponentProps, DropinComponentState, DropinStatusProps, onOrderCancelData } from '../types';\nimport './DropinComponent.scss';\nimport { UIElementStatus } from '../../internal/UIElement/types';\nimport { ANALYTICS_RENDERED_STR } from '../../../core/Analytics/constants';\n\nexport class DropinComponent extends Component<DropinComponentProps, DropinComponentState> {\n public state: DropinComponentState = {\n elements: [],\n instantPaymentElements: [],\n storedPaymentElements: [],\n orderStatus: null,\n isDisabling: false,\n status: { type: 'loading', props: undefined },\n activePaymentMethod: null,\n cachedPaymentMethods: {}\n };\n\n componentDidMount() {\n this.prepareDropinData();\n }\n\n public prepareDropinData = () => {\n const { order, clientKey, loadingContext } = this.props;\n const [storedElementsPromises, elementsPromises, instantPaymentsPromises] = this.props.onCreateElements();\n const orderStatusPromise = order ? getOrderStatus({ clientKey, loadingContext }, order) : null;\n\n Promise.all([storedElementsPromises, elementsPromises, instantPaymentsPromises, orderStatusPromise]).then(\n ([storedPaymentElements, elements, instantPaymentElements, orderStatus]) => {\n this.setState({ instantPaymentElements, elements, storedPaymentElements, orderStatus });\n this.setStatus('ready');\n\n this.props.modules?.analytics.sendAnalytics('dropin', { type: ANALYTICS_RENDERED_STR });\n }\n );\n\n this.onOrderCancel = this.getOnOrderCancel();\n };\n\n public setStatus = (status: UIElementStatus, props: DropinStatusProps = {}) => {\n this.setState({ status: { type: status, props } });\n };\n\n private setActivePaymentMethod = paymentMethod => {\n this.setState(prevState => ({\n activePaymentMethod: paymentMethod,\n cachedPaymentMethods: { ...prevState.cachedPaymentMethods, [paymentMethod._id]: true }\n }));\n };\n\n componentDidUpdate(prevProps, prevState) {\n if (prevState.status.type !== this.state.status.type && this.state.activePaymentMethod) {\n this.state.activePaymentMethod.setStatus(this.state.status.type);\n }\n\n if (this.state.status.type === 'ready' && prevState.status.type !== 'ready' && this.props.onReady) {\n this.props.onReady();\n }\n }\n\n private handleOnSelectPaymentMethod = paymentMethod => {\n const { activePaymentMethod } = this.state;\n\n this.setActivePaymentMethod(paymentMethod);\n\n // onSelect event\n if ((activePaymentMethod && activePaymentMethod._id !== paymentMethod._id) || !activePaymentMethod) {\n this.props.onSelect(paymentMethod);\n\n paymentMethod.submitAnalytics({ type: ANALYTICS_RENDERED_STR });\n }\n };\n\n private handleDisableStoredPaymentMethod = storedPaymentMethod => {\n this.setState({ isDisabling: true });\n\n new Promise((resolve, reject) => this.props.onDisableStoredPaymentMethod(storedPaymentMethod.props.storedPaymentMethodId, resolve, reject))\n .then(() => {\n this.setState(prevState => ({ elements: prevState.elements.filter(pm => pm._id !== storedPaymentMethod._id) }));\n this.setState({ isDisabling: false });\n })\n .catch(() => {\n this.setState({ isDisabling: false });\n });\n };\n\n closeActivePaymentMethod() {\n this.setState({ activePaymentMethod: null });\n }\n\n /**\n * getOnOrderCancel decides which onOrderCancel logic should be used, manual or sessions\n */\n private getOnOrderCancel = () => {\n if (this.props.onOrderCancel) {\n return (data: onOrderCancelData) => {\n this.props.onOrderCancel(data);\n };\n }\n if (this.props.session) {\n return (data: onOrderCancelData) =>\n this.props.session\n .cancelOrder(data)\n .then(() => this.props.core.update({ order: null }))\n .catch(error => this.setStatus(error?.message || 'error'));\n }\n return null;\n };\n\n private onOrderCancel: (data: onOrderCancelData) => void;\n\n render(props, { elements, instantPaymentElements, storedPaymentElements, status, activePaymentMethod, cachedPaymentMethods }) {\n const isLoading = status.type === 'loading';\n const isRedirecting = status.type === 'redirect';\n const hasPaymentMethodsToBeDisplayed = elements?.length || instantPaymentElements?.length || storedPaymentElements?.length;\n\n switch (status.type) {\n case 'success':\n return <Status.Success message={props?.amount?.value === 0 ? 'resultMessages.preauthorized' : status.props?.message} />;\n\n case 'error':\n return <Status.Error message={status.props?.message} />;\n\n case 'custom':\n return status.props?.component?.render();\n\n default:\n return (\n <div className={`adyen-checkout__dropin adyen-checkout__dropin--${status.type}`}>\n {isRedirecting && status.props.component && status.props.component.render()}\n {isLoading && status.props && status.props.component && status.props.component.render()}\n {hasPaymentMethodsToBeDisplayed && (\n <PaymentMethodList\n isLoading={isLoading || isRedirecting}\n isDisablingPaymentMethod={this.state.isDisabling}\n paymentMethods={elements}\n instantPaymentMethods={instantPaymentElements}\n storedPaymentMethods={storedPaymentElements}\n activePaymentMethod={activePaymentMethod}\n cachedPaymentMethods={cachedPaymentMethods}\n order={this.props.order}\n orderStatus={this.state.orderStatus}\n onOrderCancel={this.onOrderCancel}\n onSelect={this.handleOnSelectPaymentMethod}\n openFirstPaymentMethod={this.props.openFirstPaymentMethod}\n openFirstStoredPaymentMethod={this.props.openFirstStoredPaymentMethod}\n onDisableStoredPaymentMethod={this.handleDisableStoredPaymentMethod}\n showRemovePaymentMethodButton={this.props.showRemovePaymentMethodButton}\n showRadioButton={this.props.showRadioButton}\n />\n )}\n </div>\n );\n }\n }\n}\n\nexport default DropinComponent;\n"],"names":["DropinComponent","Component","state","elements","instantPaymentElements","storedPaymentElements","orderStatus","isDisabling","status","type","props","undefined","activePaymentMethod","cachedPaymentMethods","componentDidMount","this","prepareDropinData","order","clientKey","loadingContext","storedElementsPromises","elementsPromises","instantPaymentsPromises","onCreateElements","orderStatusPromise","getOrderStatus","Promise","all","then","setState","setStatus","modules","analytics","sendAnalytics","ANALYTICS_RENDERED_STR","onOrderCancel","getOnOrderCancel","setActivePaymentMethod","paymentMethod","prevState","_id","componentDidUpdate","prevProps","onReady","handleOnSelectPaymentMethod","onSelect","submitAnalytics","handleDisableStoredPaymentMethod","storedPaymentMethod","resolve","reject","onDisableStoredPaymentMethod","storedPaymentMethodId","filter","pm","catch","closeActivePaymentMethod","data","session","cancelOrder","core","update","error","message","render","isLoading","isRedirecting","hasPaymentMethodsToBeDisplayed","length","h","Status","Success","amount","value","Error","component","div","className","PaymentMethodList","isDisablingPaymentMethod","paymentMethods","instantPaymentMethods","storedPaymentMethods","openFirstPaymentMethod","openFirstStoredPaymentMethod","showRemovePaymentMethodButton","showRadioButton"],"mappings":"gTASO,MAAMA,UAAwBC,EAC1BC,MAA8B,CACjCC,SAAU,GACVC,uBAAwB,GACxBC,sBAAuB,GACvBC,YAAa,KACbC,aAAa,EACbC,OAAQ,CAAEC,KAAM,UAAWC,WAA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EAAOE,OAAOqD,UAEhD,IAAK,SACD,OAAOvD,EAAOE,OAAOiE,WAAWX,SAEpC,QACI,OACIK,EAACO,MAAAA,CAAIC,UAAW,kDAAkDrE,EAAOC,QACpEyD,GAAiB1D,EAAOE,MAAMiE,WAAanE,EAAOE,MAAMiE,UAAUX,SAClEC,GAAazD,EAAOE,OAASF,EAAOE,MAAMiE,WAAanE,EAAOE,MAAMiE,UAAUX,SAC9EG,GACGE,EAACS,EAAAA,CACGb,UAAWA,GAAaC,EACxBa,yBAA0BhE,KAAKb,MAAMK,YACrCyE,eAAgB7E,EAChB8E,sBAAuB7E,EACvB8E,qBAAsB7E,EACtBO,oBAAqBA,EACrBC,qBAAsBA,EACtBI,MAAOF,KAAKL,MAAMO,MAClBX,YAAaS,KAAKb,MAAMI,YACxB6B,cAAepB,KAAKoB,cACpBU,SAAU9B,KAAK6B,4BACfuC,uBAAwBpE,KAAKL,MAAMyE,uBACnCC,6BAA8BrE,KAAKL,MAAM0E,6BACzCjC,6BAA8BpC,KAAKgC,iCACnCsC,8BAA+BtE,KAAKL,MAAM2E,8BAC1CC,gBAAiBvE,KAAKL,MAAM4E,mBAMxD"}
1
+ {"version":3,"file":"DropinComponent.js","sources":["../../../../../src/components/Dropin/components/DropinComponent.tsx"],"sourcesContent":["import { Component, h } from 'preact';\nimport PaymentMethodList from './PaymentMethod/PaymentMethodList';\nimport Status from './status';\nimport getOrderStatus from '../../../core/Services/order-status';\nimport { DropinComponentProps, DropinComponentState, DropinStatusProps, onOrderCancelData } from '../types';\nimport './DropinComponent.scss';\nimport { UIElementStatus } from '../../internal/UIElement/types';\nimport { ANALYTICS_RENDERED_STR } from '../../../core/Analytics/constants';\n\nexport class DropinComponent extends Component<DropinComponentProps, DropinComponentState> {\n public state: DropinComponentState = {\n elements: [],\n instantPaymentElements: [],\n storedPaymentElements: [],\n orderStatus: null,\n isDisabling: false,\n status: { type: 'loading', props: undefined },\n activePaymentMethod: null,\n cachedPaymentMethods: {}\n };\n\n componentDidMount() {\n this.prepareDropinData();\n }\n\n public prepareDropinData = () => {\n const { order, clientKey, loadingContext } = this.props;\n const [storedElementsPromises, elementsPromises, instantPaymentsPromises] = this.props.onCreateElements();\n const orderStatusPromise = order ? getOrderStatus({ clientKey, loadingContext }, order) : null;\n\n Promise.all([storedElementsPromises, elementsPromises, instantPaymentsPromises, orderStatusPromise]).then(\n ([storedPaymentElements, elements, instantPaymentElements, orderStatus]) => {\n this.setState({ instantPaymentElements, elements, storedPaymentElements, orderStatus });\n this.setStatus('ready');\n\n this.props.modules?.analytics.sendAnalytics('dropin', { type: ANALYTICS_RENDERED_STR });\n }\n );\n\n this.onOrderCancel = this.getOnOrderCancel();\n };\n\n public setStatus = (status: UIElementStatus, props: DropinStatusProps = {}) => {\n this.setState({ status: { type: status, props } });\n };\n\n private setActivePaymentMethod = paymentMethod => {\n this.setState(prevState => ({\n activePaymentMethod: paymentMethod,\n cachedPaymentMethods: { ...prevState.cachedPaymentMethods, [paymentMethod._id]: true }\n }));\n };\n\n componentDidUpdate(prevProps, prevState) {\n if (prevState.status.type !== this.state.status.type && this.state.activePaymentMethod) {\n this.state.activePaymentMethod.setStatus(this.state.status.type);\n }\n\n if (this.state.status.type === 'ready' && prevState.status.type !== 'ready' && this.props.onReady) {\n this.props.onReady();\n }\n }\n\n private handleOnSelectPaymentMethod = paymentMethod => {\n const { activePaymentMethod } = this.state;\n\n this.setActivePaymentMethod(paymentMethod);\n\n // onSelect event\n if ((activePaymentMethod && activePaymentMethod._id !== paymentMethod._id) || !activePaymentMethod) {\n this.props.onSelect?.(paymentMethod);\n\n paymentMethod.submitAnalytics({ type: ANALYTICS_RENDERED_STR });\n }\n };\n\n private handleDisableStoredPaymentMethod = storedPaymentMethod => {\n this.setState({ isDisabling: true });\n\n new Promise((resolve, reject) => this.props.onDisableStoredPaymentMethod(storedPaymentMethod.props.storedPaymentMethodId, resolve, reject))\n .then(() => {\n this.setState(prevState => ({ elements: prevState.elements.filter(pm => pm._id !== storedPaymentMethod._id) }));\n this.setState({ isDisabling: false });\n })\n .catch(() => {\n this.setState({ isDisabling: false });\n });\n };\n\n closeActivePaymentMethod() {\n this.setState({ activePaymentMethod: null });\n }\n\n /**\n * getOnOrderCancel decides which onOrderCancel logic should be used, manual or sessions\n */\n private getOnOrderCancel = () => {\n if (this.props.onOrderCancel) {\n return (data: onOrderCancelData) => {\n this.props.onOrderCancel(data);\n };\n }\n if (this.props.session) {\n return (data: onOrderCancelData) =>\n this.props.session\n .cancelOrder(data)\n .then(() => this.props.core.update({ order: null }))\n .catch(error => this.setStatus(error?.message || 'error'));\n }\n return null;\n };\n\n private onOrderCancel: (data: onOrderCancelData) => void;\n\n render(props, { elements, instantPaymentElements, storedPaymentElements, status, activePaymentMethod, cachedPaymentMethods }) {\n const isLoading = status.type === 'loading';\n const isRedirecting = status.type === 'redirect';\n const hasPaymentMethodsToBeDisplayed = elements?.length || instantPaymentElements?.length || storedPaymentElements?.length;\n\n switch (status.type) {\n case 'success':\n return <Status.Success message={props?.amount?.value === 0 ? 'resultMessages.preauthorized' : status.props?.message} />;\n\n case 'error':\n return <Status.Error message={status.props?.message} />;\n\n case 'custom':\n return status.props?.component?.render();\n\n default:\n return (\n <div className={`adyen-checkout__dropin adyen-checkout__dropin--${status.type}`}>\n {isRedirecting && status.props.component && status.props.component.render()}\n {isLoading && status.props && status.props.component && status.props.component.render()}\n {hasPaymentMethodsToBeDisplayed && (\n <PaymentMethodList\n isLoading={isLoading || isRedirecting}\n isDisablingPaymentMethod={this.state.isDisabling}\n paymentMethods={elements}\n instantPaymentMethods={instantPaymentElements}\n storedPaymentMethods={storedPaymentElements}\n activePaymentMethod={activePaymentMethod}\n cachedPaymentMethods={cachedPaymentMethods}\n order={this.props.order}\n orderStatus={this.state.orderStatus}\n onOrderCancel={this.onOrderCancel}\n onSelect={this.handleOnSelectPaymentMethod}\n openFirstPaymentMethod={this.props.openFirstPaymentMethod}\n openFirstStoredPaymentMethod={this.props.openFirstStoredPaymentMethod}\n onDisableStoredPaymentMethod={this.handleDisableStoredPaymentMethod}\n showRemovePaymentMethodButton={this.props.showRemovePaymentMethodButton}\n showRadioButton={this.props.showRadioButton}\n />\n )}\n </div>\n );\n }\n }\n}\n\nexport default DropinComponent;\n"],"names":["DropinComponent","Component","state","elements","instantPaymentElements","storedPaymentElements","orderStatus","isDisabling","status","type","props","undefined","activePaymentMethod","cachedPaymentMethods","componentDidMount","this","prepareDropinData","order","clientKey","loadingContext","storedElementsPromises","elementsPromises","instantPaymentsPromises","onCreateElements","orderStatusPromise","getOrderStatus","Promise","all","then","setState","setStatus","modules","analytics","sendAnalytics","ANALYTICS_RENDERED_STR","onOrderCancel","getOnOrderCancel","setActivePaymentMethod","paymentMethod","prevState","_id","componentDidUpdate","prevProps","onReady","handleOnSelectPaymentMethod","onSelect","submitAnalytics","handleDisableStoredPaymentMethod","storedPaymentMethod","resolve","reject","onDisableStoredPaymentMethod","storedPaymentMethodId","filter","pm","catch","closeActivePaymentMethod","data","session","cancelOrder","core","update","error","message","render","isLoading","isRedirecting","hasPaymentMethodsToBeDisplayed","length","h","Status","Success","amount","value","Error","component","div","className","PaymentMethodList","isDisablingPaymentMethod","paymentMethods","instantPaymentMethods","storedPaymentMethods","openFirstPaymentMethod","openFirstStoredPaymentMethod","showRemovePaymentMethodButton","showRadioButton"],"mappings":"gTASO,MAAMA,UAAwBC,EAC1BC,MAA8B,CACjCC,SAAU,GACVC,uBAAwB,GACxBC,sBAAuB,GACvBC,YAAa,KACbC,aAAa,EACbC,OAAQ,CAAEC,KAAM,UAAWC,WAAOC,GAClCC,oBAAqB,KACrBC,qBAAsB,CAAC,GAG3BC,iBAAAA,GACIC,KAAKC,mBACT,CAEOA,kBAAoB,KACvB,MAAMC,MAAEA,EAAKC,UAAEA,EAASC,eAAEA,GAAmBJ,KAAKL,OAC3CU,EAAwBC,EAAkBC,GAA2BP,KAAKL,MAAMa,mBACjFC,EAAqBP,EAAQQ,EAAe,CAAEP,YAAWC,kBAAkBF,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AUX,SAC9EG,GACGE,EAACS,EAAAA,CACGb,UAAWA,GAAaC,EACxBa,yBAA0BhE,KAAKb,MAAMK,YACrCyE,eAAgB7E,EAChB8E,sBAAuB7E,EACvB8E,qBAAsB7E,EACtBO,oBAAqBA,EACrBC,qBAAsBA,EACtBI,MAAOF,KAAKL,MAAMO,MAClBX,YAAaS,KAAKb,MAAMI,YACxB6B,cAAepB,KAAKoB,cACpBU,SAAU9B,KAAK6B,4BACfuC,uBAAwBpE,KAAKL,MAAMyE,uBACnCC,6BAA8BrE,KAAKL,MAAM0E,6BACzCjC,6BAA8BpC,KAAKgC,iCACnCsC,8BAA+BtE,KAAKL,MAAM2E,8BAC1CC,gBAAiBvE,KAAKL,MAAM4E,mBAMxD"}
@@ -1,2 +1,2 @@
1
- var e={instantPaymentTypes:[],paymentMethodComponents:[],isDropin:!0,onReady:()=>{},onComplete:()=>{},onError:()=>{},onSelect:()=>{},onDisableStoredPaymentMethod:null,onChange:()=>{},amount:{},paymentMethodsConfiguration:{},openFirstPaymentMethod:!0,openFirstStoredPaymentMethod:!0,showStoredPaymentMethods:!0,showPaymentMethods:!0,showRemoveStoredPaymentMethodButton:!1};export{e as default};
1
+ const t={isDropin:!0,instantPaymentTypes:[],paymentMethodComponents:[],paymentMethodsConfiguration:{},openFirstPaymentMethod:!0,openFirstStoredPaymentMethod:!0,showStoredPaymentMethods:!0,showPaymentMethods:!0,disableFinalAnimation:!1};export{t as default};
2
2
  //# sourceMappingURL=defaultProps.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defaultProps.js","sources":["../../../../src/components/Dropin/defaultProps.ts"],"sourcesContent":["export default {\n instantPaymentTypes: [],\n paymentMethodComponents: [],\n\n isDropin: true,\n onReady: () => {}, // triggered when the Dropin is fully loaded\n onComplete: () => {}, // triggered when the shopper completes a payment\n onError: () => {}, // triggered when an error occurs (for example, could not submit a payment)\n onSelect: () => {}, // triggered when a paymentMethod is selected\n onDisableStoredPaymentMethod: null, // triggered when a shopper removes a storedPaymentMethod\n onChange: () => {},\n\n amount: {},\n paymentMethodsConfiguration: {}, // per paymentMethod configuration\n openFirstPaymentMethod: true, // focus the first payment method automatically on load\n openFirstStoredPaymentMethod: true, // focus the first one click payment method automatically on load\n showStoredPaymentMethods: true, // shows/hides oneclick paymentMethods\n showPaymentMethods: true, // shows/hides regular paymentMethods\n showRemoveStoredPaymentMethodButton: false\n};\n"],"names":["defaultProps","instantPaymentTypes","paymentMethodComponents","isDropin","onReady","onComplete","onError","onSelect","onDisableStoredPaymentMethod","onChange","amount","paymentMethodsConfiguration","openFirstPaymentMethod","openFirstStoredPaymentMethod","showStoredPaymentMethods","showPaymentMethods","showRemoveStoredPaymentMethodButton"],"mappings":"AAAA,IAAeA,EAAA,CACXC,oBAAqB,GACrBC,wBAAyB,GAEzBC,UAAU,EACVC,QAAS,OACTC,WAAY,OACZC,QAAS,OACTC,SAAU,OACVC,6BAA8B,KAC9BC,SAAU,OAEVC,OAAQ,CAAC,EACTC,4BAA6B,CAAC,EAC9BC,wBAAwB,EACxBC,8BAA8B,EAC9BC,0BAA0B,EAC1BC,oBAAoB,EACpBC,qCAAqC"}
1
+ {"version":3,"file":"defaultProps.js","sources":["../../../../src/components/Dropin/defaultProps.ts"],"sourcesContent":["import type { DropinConfiguration } from './types';\n\nconst props: DropinConfiguration = {\n isDropin: true,\n instantPaymentTypes: [],\n paymentMethodComponents: [],\n paymentMethodsConfiguration: {},\n openFirstPaymentMethod: true,\n openFirstStoredPaymentMethod: true,\n showStoredPaymentMethods: true,\n showPaymentMethods: true,\n disableFinalAnimation: false\n};\n\nexport default props;\n"],"names":["props","isDropin","instantPaymentTypes","paymentMethodComponents","paymentMethodsConfiguration","openFirstPaymentMethod","openFirstStoredPaymentMethod","showStoredPaymentMethods","showPaymentMethods","disableFinalAnimation"],"mappings":"AAEA,MAAMA,EAA6B,CAC/BC,UAAU,EACVC,oBAAqB,GACrBC,wBAAyB,GACzBC,4BAA6B,CAAC,EAC9BC,wBAAwB,EACxBC,8BAA8B,EAC9BC,0BAA0B,EAC1BC,oBAAoB,EACpBC,uBAAuB"}
@@ -1,2 +1,2 @@
1
- import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import o from"./GooglePayService.js";import r from"./components/GooglePayButton.js";import s from"./defaultProps.js";import{getGooglePayLocale as n,formatGooglePayContactToAdyenAddressFormat as i}from"./utils.js";import a from"../../utils/browserInfo.js";import l from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as h}from"../tx-variants.js";import{sanitizeResponse as p,verifyPaymentDidNotFail as d}from"../internal/UIElement/utils.js";import{ANALYTICS_SELECTED_STR as y,ANALYTICS_INSTANT_PAYMENT_BUTTON as c}from"../../core/Analytics/constants.js";class g extends e{static type=h.googlepay;static txVariants=[h.googlepay,h.paywithgoogle];static defaultProps=s;googlePay;constructor(t,e){super(t,e),this.handleAuthorization=this.handleAuthorization.bind(this),this.googlePay=new o({...this.props,paymentDataCallbacks:{...this.props.paymentDataCallbacks,onPaymentAuthorized:this.onPaymentAuthorized}})}formatProps(t){const e=t.buttonSizeMode??(t.isDropin?"fill":"static"),o=n(t.buttonLocale??t.i18n?.locale),r=[...t.callbackIntents,"PAYMENT_AUTHORIZATION"];return{...t,configuration:t.configuration,buttonSizeMode:e,buttonLocale:o,callbackIntents:r}}formatData(){const{googlePayCardNetwork:t,googlePayToken:e,billingAddress:o,deliveryAddress:r}=this.state;return{paymentMethod:{type:this.type,googlePayCardNetwork:t,googlePayToken:e},browserInfo:this.browserInfo,origin:!!window&&window.location.origin,...o&&{billingAddress:o},...r&&{deliveryAddress:r}}}submit=()=>{this.props.isInstantPayment&&this.submitAnalytics({type:y,target:c}),new Promise(((t,e)=>this.props.onClick(t,e))).then((()=>this.googlePay.initiatePayment(this.props,this.core.options.countryCode))).catch((t=>{"CANCELED"===t.statusCode?this.handleError(new l("CANCEL",t.toString(),{cause:t})):this.handleError(new l("ERROR",t.toString(),{cause:t}))}))};onPaymentAuthorized=async t=>{const e=i(t.paymentMethodData.info.billingAddress),o=i(t.shippingAddress,!0);return this.setState({authorizedEvent:t,googlePayToken:t.paymentMethodData.tokenizationData.token,googlePayCardNetwork:t.paymentMethodData.info.cardNetwork,...e&&{billingAddress:e},...o&&{deliveryAddress:o}}),new Promise((t=>{this.handleAuthorization().then(this.makePaymentsCall).then(p).then(d).then((e=>(t({transactionState:"SUCCESS"}),e))).then((t=>{this.handleResponse(t)})).catch((e=>{this.setElementStatus("ready");const o=e.error?.googlePayError,r=this.props.i18n.get("error.subtitle.payment");t({transactionState:"ERROR",error:"string"==typeof o?{intent:"PAYMENT_AUTHORIZATION",reason:"OTHER_ERROR",message:o||r}:{intent:o?.intent||"PAYMENT_AUTHORIZATION",reason:o?.reason||"OTHER_ERROR",message:o?.message||r}}),this.handleFailedResult(e)}))}))};async handleAuthorization(){return new Promise(((t,e)=>{this.props.onAuthorized||t();const{authorizedEvent:o,billingAddress:r,deliveryAddress:s}=this.state;this.props.onAuthorized({authorizedEvent:o,...r&&{billingAddress:r},...s&&{deliveryAddress:s}},{resolve:t,reject:e})})).catch((t=>{const e={error:{googlePayError:t}};return Promise.reject(e)}))}get isValid(){return!!this.state.googlePayToken}async isAvailable(){return this.isReadyToPay().then((t=>{if(!t.result)throw new Error("Google Pay is not available");if(!1===t.paymentMethodPresent)throw new Error("Google Pay - No paymentMethodPresent");return Promise.resolve()})).catch((t=>Promise.reject(t)))}isReadyToPay=()=>this.googlePay.isReadyToPay(this.props);prefetch=()=>this.googlePay.prefetchPaymentData(this.props,this.core.options.countryCode);get browserInfo(){return a()}get icon(){return this.props.icon??this.resources.getImage()("googlepay")}render(){return this.props.showPayButton?t(r,{buttonColor:this.props.buttonColor,buttonType:this.props.buttonType,buttonSizeMode:this.props.buttonSizeMode,buttonLocale:this.props.buttonLocale,buttonRootNode:this.props.buttonRootNode,paymentsClient:this.googlePay.paymentsClient,onClick:this.submit}):null}}export{g as default};
1
+ import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import o from"./GooglePayService.js";import r from"./components/GooglePayButton.js";import s from"./defaultProps.js";import{getGooglePayLocale as n,formatGooglePayContactToAdyenAddressFormat as i}from"./utils.js";import a from"../../utils/browserInfo.js";import l from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as h}from"../tx-variants.js";import{sanitizeResponse as p,verifyPaymentDidNotFail as d}from"../internal/UIElement/utils.js";import{ANALYTICS_SELECTED_STR as y,ANALYTICS_INSTANT_PAYMENT_BUTTON as c}from"../../core/Analytics/constants.js";class g extends e{static type=h.googlepay;static txVariants=[h.googlepay,h.paywithgoogle];static defaultProps=s;googlePay;constructor(t,e){super(t,e),this.handleAuthorization=this.handleAuthorization.bind(this),this.googlePay=new o({...this.props,paymentDataCallbacks:{...this.props.paymentDataCallbacks,onPaymentAuthorized:this.onPaymentAuthorized}})}formatProps(t){const e=t.buttonSizeMode??(t.isDropin?"fill":"static"),o=n(t.buttonLocale??t.i18n?.locale),r=[...t.callbackIntents,"PAYMENT_AUTHORIZATION"];return{...t,configuration:t.configuration,buttonSizeMode:e,buttonLocale:o,callbackIntents:r}}formatData(){const{googlePayCardNetwork:t,googlePayToken:e,billingAddress:o,deliveryAddress:r}=this.state;return{paymentMethod:{type:this.type,googlePayCardNetwork:t,googlePayToken:e},browserInfo:this.browserInfo,origin:!!window&&window.location.origin,...o&&{billingAddress:o},...r&&{deliveryAddress:r}}}submit=()=>{this.props.isInstantPayment&&this.submitAnalytics({type:y,target:c}),new Promise(((t,e)=>this.props.onClick(t,e))).then((()=>this.googlePay.initiatePayment(this.props,this.core.options.countryCode))).catch((t=>{"CANCELED"===t.statusCode?this.handleError(new l("CANCEL",t.toString(),{cause:t})):this.handleError(new l("ERROR",t.toString(),{cause:t}))}))};onPaymentAuthorized=async t=>{const e=i(t.paymentMethodData.info.billingAddress),o=i(t.shippingAddress,!0);return this.setState({authorizedEvent:t,googlePayToken:t.paymentMethodData.tokenizationData.token,googlePayCardNetwork:t.paymentMethodData.info.cardNetwork,...e&&{billingAddress:e},...o&&{deliveryAddress:o}}),new Promise((t=>{this.handleAuthorization().then(this.makePaymentsCall).then(p).then(d).then((e=>(t({transactionState:"SUCCESS"}),e))).then((t=>{this.handleResponse(t)})).catch((e=>{this.setElementStatus("ready");const o=e?.error?.googlePayError,r=this.props.i18n.get("error.subtitle.payment"),s="string"==typeof o?{intent:"PAYMENT_AUTHORIZATION",reason:"OTHER_ERROR",message:o||r}:{intent:o?.intent||"PAYMENT_AUTHORIZATION",reason:o?.reason||"OTHER_ERROR",message:o?.message||r};t({transactionState:"ERROR",error:s});const n={...e,error:{googlePayError:s}};this.handleFailedResult(n)}))}))};async handleAuthorization(){return new Promise(((t,e)=>{this.props.onAuthorized||t();const{authorizedEvent:o,billingAddress:r,deliveryAddress:s}=this.state;this.props.onAuthorized({authorizedEvent:o,...r&&{billingAddress:r},...s&&{deliveryAddress:s}},{resolve:t,reject:e})})).catch((t=>{const e={error:{googlePayError:t}};return Promise.reject(e)}))}get isValid(){return!!this.state.googlePayToken}async isAvailable(){return this.isReadyToPay().then((t=>{if(!t.result)throw new l("ERROR","GooglePay is not available");if(!1===t.paymentMethodPresent)throw new l("ERROR","GooglePay - No paymentMethodPresent");return Promise.resolve()})).catch((t=>Promise.reject(t)))}isReadyToPay=()=>this.googlePay.isReadyToPay(this.props);prefetch=()=>this.googlePay.prefetchPaymentData(this.props,this.core.options.countryCode);get browserInfo(){return a()}get icon(){return this.props.icon??this.resources.getImage()("googlepay")}render(){return this.props.showPayButton?t(r,{buttonColor:this.props.buttonColor,buttonType:this.props.buttonType,buttonSizeMode:this.props.buttonSizeMode,buttonLocale:this.props.buttonLocale,buttonRootNode:this.props.buttonRootNode,paymentsClient:this.googlePay.paymentsClient,onClick:this.submit}):null}}export{g as default};
2
2
  //# sourceMappingURL=GooglePay.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GooglePay.js","sources":["../../../../src/components/GooglePay/GooglePay.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport GooglePayService from './GooglePayService';\nimport GooglePayButton from './components/GooglePayButton';\nimport defaultProps from './defaultProps';\nimport { formatGooglePayContactToAdyenAddressFormat, getGooglePayLocale } from './utils';\nimport collectBrowserInfo from '../../utils/browserInfo';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { TxVariants } from '../tx-variants';\nimport { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';\nimport type { AddressData, PaymentResponseData, RawPaymentResponse } from '../../types/global-types';\nimport type { GooglePayConfiguration } from './types';\nimport { ICore } from '../../core/types';\nimport { ANALYTICS_INSTANT_PAYMENT_BUTTON, ANALYTICS_SELECTED_STR } from '../../core/Analytics/constants';\n\nclass GooglePay extends UIElement<GooglePayConfiguration> {\n public static type = TxVariants.googlepay;\n public static txVariants = [TxVariants.googlepay, TxVariants.paywithgoogle];\n public static defaultProps = defaultProps;\n\n protected readonly googlePay;\n\n constructor(checkout: ICore, props?: GooglePayConfiguration) {\n super(checkout, props);\n this.handleAuthorization = this.handleAuthorization.bind(this);\n\n this.googlePay = new GooglePayService({\n ...this.props,\n paymentDataCallbacks: {\n ...this.props.paymentDataCallbacks,\n onPaymentAuthorized: this.onPaymentAuthorized\n }\n });\n }\n\n formatProps(props): GooglePayConfiguration {\n const buttonSizeMode = props.buttonSizeMode ?? (props.isDropin ? 'fill' : 'static');\n const buttonLocale = getGooglePayLocale(props.buttonLocale ?? props.i18n?.locale);\n\n const callbackIntents: google.payments.api.CallbackIntent[] = [...props.callbackIntents, 'PAYMENT_AUTHORIZATION'];\n\n return {\n ...props,\n configuration: props.configuration,\n buttonSizeMode,\n buttonLocale,\n callbackIntents\n };\n }\n\n /**\n * Formats the component data output\n */\n formatData() {\n const { googlePayCardNetwork, googlePayToken, billingAddress, deliveryAddress } = this.state;\n\n return {\n paymentMethod: {\n type: this.type,\n googlePayCardNetwork,\n googlePayToken\n },\n browserInfo: this.browserInfo,\n origin: !!window && window.location.origin,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n };\n }\n\n public override submit = () => {\n // Analytics\n if (this.props.isInstantPayment) {\n this.submitAnalytics({ type: ANALYTICS_SELECTED_STR, target: ANALYTICS_INSTANT_PAYMENT_BUTTON });\n }\n\n new Promise((resolve, reject) => this.props.onClick(resolve, reject))\n .then(() => this.googlePay.initiatePayment(this.props, this.core.options.countryCode))\n .catch((error: google.payments.api.PaymentsError) => {\n if (error.statusCode === 'CANCELED') {\n this.handleError(new AdyenCheckoutError('CANCEL', error.toString(), { cause: error }));\n } else {\n this.handleError(new AdyenCheckoutError('ERROR', error.toString(), { cause: error }));\n }\n });\n };\n\n /**\n * Method called when the payment is authorized in the payment sheet\n *\n * @see https://developers.google.com/pay/api/web/reference/client#onPaymentAuthorized\n **/\n private onPaymentAuthorized = async (paymentData: google.payments.api.PaymentData): Promise<google.payments.api.PaymentAuthorizationResult> => {\n const billingAddress: AddressData = formatGooglePayContactToAdyenAddressFormat(paymentData.paymentMethodData.info.billingAddress);\n const deliveryAddress: AddressData = formatGooglePayContactToAdyenAddressFormat(paymentData.shippingAddress, true);\n\n this.setState({\n authorizedEvent: paymentData,\n googlePayToken: paymentData.paymentMethodData.tokenizationData.token,\n googlePayCardNetwork: paymentData.paymentMethodData.info.cardNetwork,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n return new Promise<google.payments.api.PaymentAuthorizationResult>(resolve => {\n this.handleAuthorization()\n .then(this.makePaymentsCall)\n .then(sanitizeResponse)\n .then(verifyPaymentDidNotFail)\n .then((paymentResponse: PaymentResponseData) => {\n resolve({ transactionState: 'SUCCESS' });\n return paymentResponse;\n })\n .then(paymentResponse => {\n this.handleResponse(paymentResponse);\n })\n .catch((paymentResponse: RawPaymentResponse) => {\n this.setElementStatus('ready');\n\n const googlePayError = paymentResponse.error?.googlePayError;\n const fallbackMessage = this.props.i18n.get('error.subtitle.payment');\n\n const error: google.payments.api.PaymentDataError =\n typeof googlePayError === 'string' || undefined\n ? {\n intent: 'PAYMENT_AUTHORIZATION',\n reason: 'OTHER_ERROR',\n message: (googlePayError as string) || fallbackMessage\n }\n : {\n intent: googlePayError?.intent || 'PAYMENT_AUTHORIZATION',\n reason: googlePayError?.reason || 'OTHER_ERROR',\n message: googlePayError?.message || fallbackMessage\n };\n\n resolve({\n transactionState: 'ERROR',\n error\n });\n\n this.handleFailedResult(paymentResponse);\n });\n });\n };\n\n /**\n * Call the 'onAuthorized' callback if available.\n * Must be resolved/reject for the payment flow to continue\n */\n private async handleAuthorization(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (!this.props.onAuthorized) {\n resolve();\n }\n\n const { authorizedEvent, billingAddress, deliveryAddress } = this.state;\n\n this.props.onAuthorized(\n {\n authorizedEvent,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n );\n }).catch((error?: google.payments.api.PaymentDataError | string) => {\n // Format error in a way that the 'catch' of the 'onPaymentAuthorize' block accepts it\n const data = { error: { googlePayError: error } };\n return Promise.reject(data);\n });\n }\n\n /**\n * Validation\n */\n get isValid(): boolean {\n return !!this.state.googlePayToken;\n }\n\n /**\n * Determine a shopper's ability to return a form of payment from the Google Pay API.\n */\n public override async isAvailable(): Promise<void> {\n return this.isReadyToPay()\n .then(response => {\n if (!response.result) {\n throw new Error('Google Pay is not available');\n }\n\n if (response.paymentMethodPresent === false) {\n throw new Error('Google Pay - No paymentMethodPresent');\n }\n\n return Promise.resolve();\n })\n .catch(error => {\n return Promise.reject(error);\n });\n }\n\n /**\n * Determine a shopper's ability to return a form of payment from the Google Pay API.\n */\n public isReadyToPay = (): Promise<google.payments.api.IsReadyToPayResponse> => {\n return this.googlePay.isReadyToPay(this.props);\n };\n\n /**\n * Use this method to prefetch a PaymentDataRequest configuration to improve loadPaymentData execution time on later user interaction. No value is returned.\n */\n public prefetch = (): void => {\n return this.googlePay.prefetchPaymentData(this.props, this.core.options.countryCode);\n };\n\n get browserInfo() {\n return collectBrowserInfo();\n }\n\n get icon(): string {\n return this.props.icon ?? this.resources.getImage()('googlepay');\n }\n\n render() {\n if (this.props.showPayButton) {\n return (\n <GooglePayButton\n buttonColor={this.props.buttonColor}\n buttonType={this.props.buttonType}\n buttonSizeMode={this.props.buttonSizeMode}\n buttonLocale={this.props.buttonLocale}\n buttonRootNode={this.props.buttonRootNode}\n paymentsClient={this.googlePay.paymentsClient}\n onClick={this.submit}\n />\n );\n }\n\n return null;\n }\n}\n\nexport default GooglePay;\n"],"names":["GooglePay","UIElement","static","TxVariants","googlepay","paywithgoogle","defaultProps","googlePay","constructor","checkout","props","super","this","handleAuthorization","bind","GooglePayService","paymentDataCallbacks","onPaymentAuthorized","formatProps","buttonSizeMode","isDropin","buttonLocale","getGooglePayLocale","i18n","locale","callbackIntents","configuration","formatData","googlePayCardNetwork","googlePayToken","billingAddress","deliveryAddress","state","paymentMethod","type","browserInfo","origin","window","location","submit","isInstantPayment","submitAnalytics","ANALYTICS_SELECTED_STR","target","ANALYTICS_INSTANT_PAYMENT_BUTTON","Promise","resolve","reject","onClick","then","initiatePayment","core","options","countryCode","catch","error","statusCode","handleError","AdyenCheckoutError","toString","cause","async","paymentData","formatGooglePayContactToAdyenAddressFormat","paymentMethodData","info","shippingAddress","setState","authorizedEvent","tokenizationData","token","cardNetwork","makePaymentsCall","sanitizeResponse","verifyPaymentDidNotFail","paymentResponse","transactionState","handleResponse","setElementStatus","googlePayError","fallbackMessage","get","intent","reason","message","handleFailedResult","onAuthorized","data","isValid","isAvailable","isReadyToPay","response","result","Error","paymentMethodPresent","prefetch","prefetchPaymentData","collectBrowserInfo","icon","resources","getImage","render","showPayButton","h","GooglePayButton","buttonColor","buttonType","buttonRootNode","paymentsClient"],"mappings":"yrBAeA,MAAMA,UAAkBC,EACpBC,YAAqBC,EAAWC,UAChCF,kBAA2B,CAACC,EAAWC,UAAWD,EAAWE,eAC7D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,GAE9B,CAKA,WAAIC,GACA,QAAS5E,KAAKoB,MAAMH,cACxB,CAKA,iBAAsB4D,GAClB,OAAO7E,KAAK8E,eACPzC,MAAK0C,IACF,IAAKA,EAASC,OACV,MAAM,IAAIC,MAAM,+BAGpB,IAAsC,IAAlCF,EAASG,qBACT,MAAM,IAAID,MAAM,wCAGpB,OAAOhD,QAAQC,SAAO,IAEzBQ,OAAMC,GACIV,QAAQE,OAAOQ,IAElC,CAKAmC,aAAsB,IACX9E,KAAKL,UAAUmF,aAAa9E,KAAKF,OAM5CqF,SAAkB,IACPnF,KAAKL,UAAUyF,oBAAoBpF,KAAKF,MAAOE,KAAKuC,KAAKC,QAAQC,aAG5E,eAAIlB,GACA,OAAO8D,GACX,CAEA,QAAIC,GACA,OAAOtF,KAAKF,MAAMwF,MAAQtF,KAAKuF,UAAUC,UAAfxF,CAA0B,YACxD,CAEAyF,MAAAA,GACI,OAAIzF,KAAKF,MAAM4F,cAEPC,EAACC,EAAAA,CACGC,YAAa7F,KAAKF,MAAM+F,YACxBC,WAAY9F,KAAKF,MAAMgG,WACvBvF,eAAgBP,KAAKF,MAAMS,eAC3BE,aAAcT,KAAKF,MAAMW,aACzBsF,eAAgB/F,KAAKF,MAAMiG,eAC3BC,eAAgBhG,KAAKL,UAAUqG,eAC/B5D,QAASpC,KAAK2B,SAKnB,IACX"}
1
+ {"version":3,"file":"GooglePay.js","sources":["../../../../src/components/GooglePay/GooglePay.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport GooglePayService from './GooglePayService';\nimport GooglePayButton from './components/GooglePayButton';\nimport defaultProps from './defaultProps';\nimport { formatGooglePayContactToAdyenAddressFormat, getGooglePayLocale } from './utils';\nimport collectBrowserInfo from '../../utils/browserInfo';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { TxVariants } from '../tx-variants';\nimport { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';\nimport { ANALYTICS_INSTANT_PAYMENT_BUTTON, ANALYTICS_SELECTED_STR } from '../../core/Analytics/constants';\nimport type { AddressData, PaymentResponseData, RawPaymentResponse } from '../../types/global-types';\nimport type { GooglePayConfiguration } from './types';\nimport type { ICore } from '../../core/types';\n\nclass GooglePay extends UIElement<GooglePayConfiguration> {\n public static type = TxVariants.googlepay;\n public static txVariants = [TxVariants.googlepay, TxVariants.paywithgoogle];\n public static defaultProps = defaultProps;\n\n protected readonly googlePay;\n\n constructor(checkout: ICore, props?: GooglePayConfiguration) {\n super(checkout, props);\n this.handleAuthorization = this.handleAuthorization.bind(this);\n\n this.googlePay = new GooglePayService({\n ...this.props,\n paymentDataCallbacks: {\n ...this.props.paymentDataCallbacks,\n onPaymentAuthorized: this.onPaymentAuthorized\n }\n });\n }\n\n formatProps(props): GooglePayConfiguration {\n const buttonSizeMode = props.buttonSizeMode ?? (props.isDropin ? 'fill' : 'static');\n const buttonLocale = getGooglePayLocale(props.buttonLocale ?? props.i18n?.locale);\n\n const callbackIntents: google.payments.api.CallbackIntent[] = [...props.callbackIntents, 'PAYMENT_AUTHORIZATION'];\n\n return {\n ...props,\n configuration: props.configuration,\n buttonSizeMode,\n buttonLocale,\n callbackIntents\n };\n }\n\n /**\n * Formats the component data output\n */\n formatData() {\n const { googlePayCardNetwork, googlePayToken, billingAddress, deliveryAddress } = this.state;\n\n return {\n paymentMethod: {\n type: this.type,\n googlePayCardNetwork,\n googlePayToken\n },\n browserInfo: this.browserInfo,\n origin: !!window && window.location.origin,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n };\n }\n\n public override submit = () => {\n // Analytics\n if (this.props.isInstantPayment) {\n this.submitAnalytics({ type: ANALYTICS_SELECTED_STR, target: ANALYTICS_INSTANT_PAYMENT_BUTTON });\n }\n\n new Promise((resolve, reject) => this.props.onClick(resolve, reject))\n .then(() => this.googlePay.initiatePayment(this.props, this.core.options.countryCode))\n .catch((error: google.payments.api.PaymentsError) => {\n if (error.statusCode === 'CANCELED') {\n this.handleError(new AdyenCheckoutError('CANCEL', error.toString(), { cause: error }));\n } else {\n this.handleError(new AdyenCheckoutError('ERROR', error.toString(), { cause: error }));\n }\n });\n };\n\n /**\n * Method called when the payment is authorized in the payment sheet\n *\n * @see https://developers.google.com/pay/api/web/reference/client#onPaymentAuthorized\n **/\n private onPaymentAuthorized = async (paymentData: google.payments.api.PaymentData): Promise<google.payments.api.PaymentAuthorizationResult> => {\n const billingAddress: AddressData = formatGooglePayContactToAdyenAddressFormat(paymentData.paymentMethodData.info.billingAddress);\n const deliveryAddress: AddressData = formatGooglePayContactToAdyenAddressFormat(paymentData.shippingAddress, true);\n\n this.setState({\n authorizedEvent: paymentData,\n googlePayToken: paymentData.paymentMethodData.tokenizationData.token,\n googlePayCardNetwork: paymentData.paymentMethodData.info.cardNetwork,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n return new Promise<google.payments.api.PaymentAuthorizationResult>(resolve => {\n this.handleAuthorization()\n .then(this.makePaymentsCall)\n .then(sanitizeResponse)\n .then(verifyPaymentDidNotFail)\n .then((paymentResponse: PaymentResponseData) => {\n resolve({ transactionState: 'SUCCESS' });\n return paymentResponse;\n })\n .then(paymentResponse => {\n this.handleResponse(paymentResponse);\n })\n .catch((paymentResponse?: RawPaymentResponse) => {\n this.setElementStatus('ready');\n\n const googlePayError = paymentResponse?.error?.googlePayError;\n const fallbackMessage = this.props.i18n.get('error.subtitle.payment');\n\n const error: google.payments.api.PaymentDataError =\n typeof googlePayError === 'string' || undefined\n ? {\n intent: 'PAYMENT_AUTHORIZATION',\n reason: 'OTHER_ERROR',\n message: (googlePayError as string) || fallbackMessage\n }\n : {\n intent: googlePayError?.intent || 'PAYMENT_AUTHORIZATION',\n reason: googlePayError?.reason || 'OTHER_ERROR',\n message: googlePayError?.message || fallbackMessage\n };\n\n resolve({\n transactionState: 'ERROR',\n error\n });\n\n const responseWithError = {\n ...paymentResponse,\n error: {\n googlePayError: error\n }\n };\n\n this.handleFailedResult(responseWithError);\n });\n });\n };\n\n /**\n * Call the 'onAuthorized' callback if available.\n * Must be resolved/reject for the payment flow to continue\n */\n private async handleAuthorization(): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n if (!this.props.onAuthorized) {\n resolve();\n }\n\n const { authorizedEvent, billingAddress, deliveryAddress } = this.state;\n\n this.props.onAuthorized(\n {\n authorizedEvent,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n );\n }).catch((error?: google.payments.api.PaymentDataError | string) => {\n // Format error in a way that the 'catch' of the 'onPaymentAuthorize' block accepts it\n const data = { error: { googlePayError: error } };\n return Promise.reject(data);\n });\n }\n\n /**\n * Validation\n */\n get isValid(): boolean {\n return !!this.state.googlePayToken;\n }\n\n /**\n * Determine a shopper's ability to return a form of payment from the Google Pay API.\n */\n public override async isAvailable(): Promise<void> {\n return this.isReadyToPay()\n .then(response => {\n if (!response.result) {\n throw new AdyenCheckoutError('ERROR', 'GooglePay is not available');\n }\n\n if (response.paymentMethodPresent === false) {\n throw new AdyenCheckoutError('ERROR', 'GooglePay - No paymentMethodPresent');\n }\n\n return Promise.resolve();\n })\n .catch(error => {\n return Promise.reject(error);\n });\n }\n\n /**\n * Determine a shopper's ability to return a form of payment from the Google Pay API.\n */\n public isReadyToPay = (): Promise<google.payments.api.IsReadyToPayResponse> => {\n return this.googlePay.isReadyToPay(this.props);\n };\n\n /**\n * Use this method to prefetch a PaymentDataRequest configuration to improve loadPaymentData execution time on later user interaction. No value is returned.\n */\n public prefetch = (): void => {\n return this.googlePay.prefetchPaymentData(this.props, this.core.options.countryCode);\n };\n\n get browserInfo() {\n return collectBrowserInfo();\n }\n\n get icon(): string {\n return this.props.icon ?? this.resources.getImage()('googlepay');\n }\n\n render() {\n if (this.props.showPayButton) {\n return (\n <GooglePayButton\n buttonColor={this.props.buttonColor}\n buttonType={this.props.buttonType}\n buttonSizeMode={this.props.buttonSizeMode}\n buttonLocale={this.props.buttonLocale}\n buttonRootNode={this.props.buttonRootNode}\n paymentsClient={this.googlePay.paymentsClient}\n onClick={this.submit}\n />\n );\n }\n\n return null;\n }\n}\n\nexport default GooglePay;\n"],"names":["GooglePay","UIElement","static","TxVariants","googlepay","paywithgoogle","defaultProps","googlePay","constructor","checkout","props","super","this","handleAuthorization","bind","GooglePayService","paymentDataCallbacks","onPaymentAuthorized","formatProps","buttonSizeMode","isDropin","buttonLocale","getGooglePayLocale","i18n","locale","callbackIntents","configuration","formatData","googlePayCardNetwork","googlePayToken","billingAddress","deliveryAddress","state","paymentMethod","type","browserInfo","origin","window","location","submit","isInstantPayment","submitAnalytics","ANALYTICS_SELECTED_STR","target","ANALYTICS_INSTANT_PAYMENT_BUTTON","Promise","resolve","reject","onClick","then","initiatePayment","core","options","countryCode","catch","error","statusCode","handleError","AdyenCheckoutError","toString","cause","async","paymentData","formatGooglePayContactToAdyenAddressFormat","paymentMethodData","info","shippingAddress","setState","authorizedEvent","tokenizationData","token","cardNetwork","makePaymentsCall","sanitizeResponse","verifyPaymentDidNotFail","paymentResponse","transactionState","handleResponse","setElementStatus","googlePayError","fallbackMessage","get","intent","reason","message","responseWithError","handleFailedResult","onAuthorized","data","isValid","isAvailable","isReadyToPay","response","result","paymentMethodPresent","prefetch","prefetchPaymentData","collectBrowserInfo","icon","resources","getImage","render","showPayButton","h","GooglePayButton","buttonColor","buttonType","buttonRootNode","paymentsClient"],"mappings":"yrBAeA,MAAMA,UAAkBC,EACpBC,YAAqBC,EAAWC,UAChCF,kBAA2B,CAACC,EAAWC,UAAWD,EAAWE,eAC7DH,oBAA6BI,EAEVC,UAEnBC,WAAAA,CAAYC,EAAiBC,GACzBC,MAAMF,EAAUC,GAChBE,KAAKC,oBAAsBD,KAAKC,oBAAoBC,KAAKF,MAEzDA,KAAKL,UAAY,IAAIQ,EAAiB,IAC/BH,KAAKF,MACRM,qBAAsB,IACfJ,KAAKF,MAAMM,qBACdC,oBAAqBL,KA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8BAG1C,IAAsC,IAAlCkC,EAASE,qBACT,MAAM,IAAIpC,EAAmB,QAAS,uCAG1C,OAAOb,QAAQC,SAAO,IAEzBQ,OAAMC,GACIV,QAAQE,OAAOQ,IAElC,CAKAoC,aAAsB,IACX/E,KAAKL,UAAUoF,aAAa/E,KAAKF,OAM5CqF,SAAkB,IACPnF,KAAKL,UAAUyF,oBAAoBpF,KAAKF,MAAOE,KAAKuC,KAAKC,QAAQC,aAG5E,eAAIlB,GACA,OAAO8D,GACX,CAEA,QAAIC,GACA,OAAOtF,KAAKF,MAAMwF,MAAQtF,KAAKuF,UAAUC,UAAfxF,CAA0B,YACxD,CAEAyF,MAAAA,GACI,OAAIzF,KAAKF,MAAM4F,cAEPC,EAACC,EAAAA,CACGC,YAAa7F,KAAKF,MAAM+F,YACxBC,WAAY9F,KAAKF,MAAMgG,WACvBvF,eAAgBP,KAAKF,MAAMS,eAC3BE,aAAcT,KAAKF,MAAMW,aACzBsF,eAAgB/F,KAAKF,MAAMiG,eAC3BC,eAAgBhG,KAAKL,UAAUqG,eAC/B5D,QAASpC,KAAK2B,SAKnB,IACX"}
@@ -1,2 +1,2 @@
1
- import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import n from"./components/PaypalComponent.js";import i from"./defaultProps.js";import r from"../../core/Context/CoreProvider.js";import s from"../../core/Errors/AdyenCheckoutError.js";import{ERRORS as a}from"./constants.js";import{TxVariants as o}from"../tx-variants.js";import{formatPaypalOrderContatcToAdyenFormat as h}from"./utils/format-paypal-order-contact-to-adyen-format.js";class p extends e{static type=o.paypal;static subtype="sdk";paymentData=null;resolve=null;reject=null;static defaultProps=i;constructor(t,e){super(t,e),this.handleSubmit=this.handleSubmit.bind(this),this.handleOnShippingAddressChange=this.handleOnShippingAddressChange.bind(this),this.handleOnShippingOptionsChange=this.handleOnShippingOptionsChange.bind(this)}formatProps(t){const{merchantId:e,intent:n}=t.configuration,i=0===t.amount?.value?"tokenize":t.intent||n,r="tokenize"===i||t.vault,s="continue"===t.userAction;return{...t,commit:!s&&t.commit,vault:r,configuration:{intent:i,merchantId:e}}}submit=()=>{this.handleError(new s("IMPLEMENTATION_ERROR",a.SUBMIT_NOT_SUPPORTED))};updatePaymentData(t){t||console.warn("PayPal - Updating payment data with an invalid value"),this.paymentData=t}formatData(){const{isExpress:t,userAction:e}=this.props;return{paymentMethod:{type:p.type,userAction:e,subtype:t?"express":p.subtype}}}handleAction=t=>this.updateWithAction(t);updateWithAction=t=>{if(t.paymentMethodType!==this.type)throw new Error("Invalid Action");return t.paymentData&&(this.paymentData=t.paymentData),t.sdkData&&t.sdkData.token?this.handleResolve(t.sdkData.token):this.handleReject(a.NO_TOKEN_PROVIDED),null};get isValid(){return!0}handleOnApprove=(t,e)=>{const{onAuthorized:n}=this.props,i={data:{details:t,paymentData:this.paymentData}};if(n)return e.order.get().then((t=>{const e=h(t?.payer),i=h(t?.purchase_units?.[0].shipping,!0);return this.setState({authorizedEvent:t,...e&&{billingAddress:e},...i&&{deliveryAddress:i}}),new Promise(((r,s)=>n({authorizedEvent:t,...e&&{billingAddress:e},...i&&{deliveryAddress:i}},{resolve:r,reject:s})))})).then((()=>this.handleAdditionalDetails(i))).catch((t=>this.handleError(new s("ERROR","Something went wrong while parsing PayPal Order",{cause:t}))));this.handleAdditionalDetails(i)};handleResolve(t){if(!this.resolve)return this.handleError(new s("ERROR",a.WRONG_INSTANCE));this.resolve(t)}handleReject(t){if(!this.reject)return this.handleError(new s("ERROR",a.WRONG_INSTANCE));this.reject(new Error(t))}handleSubmit(){return super.submit(),new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}handleOnShippingAddressChange(t,e){return this.props.onShippingAddressChange(t,e,this)}handleOnShippingOptionsChange(t,e){return this.props.onShippingOptionsChange(t,e,this)}render(){if(!this.props.showPayButton)return null;const{onShippingAddressChange:e,onShippingOptionsChange:i,...a}=this.props;return t(r,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},t(n,{ref:t=>{this.componentRef=t},...a,...e&&{onShippingAddressChange:this.handleOnShippingAddressChange},...i&&{onShippingOptionsChange:this.handleOnShippingOptionsChange},onCancel:()=>this.handleError(new s("CANCEL")),onChange:this.setState,onApprove:this.handleOnApprove,onError:t=>{this.handleError(new s("ERROR",t.toString(),{cause:t}))},onSubmit:this.handleSubmit}))}}export{p as default};
1
+ import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import n from"./components/PaypalComponent.js";import i from"./defaultProps.js";import r from"../../core/Context/CoreProvider.js";import s from"../../core/Errors/AdyenCheckoutError.js";import{ERRORS as a}from"./constants.js";import{TxVariants as o}from"../tx-variants.js";import{formatPaypalOrderContactToAdyenFormat as h}from"./utils/format-paypal-order-contact-to-adyen-format.js";class p extends e{static type=o.paypal;static subtype="sdk";paymentData=null;resolve=null;reject=null;static defaultProps=i;constructor(t,e){super(t,e),this.handleSubmit=this.handleSubmit.bind(this),this.handleOnShippingAddressChange=this.handleOnShippingAddressChange.bind(this),this.handleOnShippingOptionsChange=this.handleOnShippingOptionsChange.bind(this)}formatProps(t){const e=t.configuration?.merchantId,n=t.configuration?.intent,i=0===t.amount?.value?"tokenize":t.intent||n,r="tokenize"===i||t.vault,s="continue"===t.userAction;return{...t,commit:!s&&t.commit,vault:r,configuration:{intent:i,merchantId:e}}}submit=()=>{this.handleError(new s("IMPLEMENTATION_ERROR",a.SUBMIT_NOT_SUPPORTED))};updatePaymentData(t){t||console.warn("PayPal - Updating payment data with an invalid value"),this.paymentData=t}formatData(){const{isExpress:t,userAction:e}=this.props;return{paymentMethod:{type:p.type,userAction:e,subtype:t?"express":p.subtype}}}handleAction=t=>this.updateWithAction(t);updateWithAction=t=>{if(t.paymentMethodType!==this.type)throw new Error("Invalid Action");return t.paymentData&&(this.paymentData=t.paymentData),t.sdkData&&t.sdkData.token?this.handleResolve(t.sdkData.token):this.handleReject(a.NO_TOKEN_PROVIDED),null};get isValid(){return!0}handleOnApprove=(t,e)=>{const{onAuthorized:n}=this.props,i={data:{details:t,paymentData:this.paymentData}};if(n)return e.order.get().then((t=>{const e=h(t?.payer),i=h(t?.purchase_units?.[0].shipping,!0);return this.setState({authorizedEvent:t,...e&&{billingAddress:e},...i&&{deliveryAddress:i}}),new Promise(((r,s)=>n({authorizedEvent:t,...e&&{billingAddress:e},...i&&{deliveryAddress:i}},{resolve:r,reject:s})))})).then((()=>this.handleAdditionalDetails(i))).catch((t=>this.handleError(new s("ERROR","Something went wrong while parsing PayPal Order",{cause:t}))));this.handleAdditionalDetails(i)};handleResolve(t){if(!this.resolve)return this.handleError(new s("ERROR",a.WRONG_INSTANCE));this.resolve(t)}handleReject(t){if(!this.reject)return this.handleError(new s("ERROR",a.WRONG_INSTANCE));this.reject(new Error(t))}handleSubmit(){return super.submit(),new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}handleOnShippingAddressChange(t,e){return this.props.onShippingAddressChange(t,e,this)}handleOnShippingOptionsChange(t,e){return this.props.onShippingOptionsChange(t,e,this)}render(){if(!this.props.showPayButton)return null;const{onShippingAddressChange:e,onShippingOptionsChange:i,...a}=this.props;return t(r,{i18n:this.props.i18n,loadingContext:this.props.loadingContext,resources:this.resources},t(n,{ref:t=>{this.componentRef=t},...a,...e&&{onShippingAddressChange:this.handleOnShippingAddressChange},...i&&{onShippingOptionsChange:this.handleOnShippingOptionsChange},onCancel:()=>this.handleError(new s("CANCEL")),onChange:this.setState,onApprove:this.handleOnApprove,onError:t=>{this.handleError(new s("ERROR",t.toString(),{cause:t}))},onScriptLoadFailure:t=>this.handleError(t),onSubmit:this.handleSubmit}))}}export{p as default};
2
2
  //# sourceMappingURL=Paypal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Paypal.js","sources":["../../../../src/components/PayPal/Paypal.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport PaypalComponent from './components/PaypalComponent';\nimport defaultProps from './defaultProps';\nimport CoreProvider from '../../core/Context/CoreProvider';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { ERRORS } from './constants';\nimport { TxVariants } from '../tx-variants';\nimport { formatPaypalOrderContatcToAdyenFormat } from './utils/format-paypal-order-contact-to-adyen-format';\n\nimport type { ICore } from '../../core/types';\nimport type { PaymentAction } from '../../types/global-types';\nimport type { Intent, PayPalConfiguration } from './types';\n\nimport './Paypal.scss';\n\nclass PaypalElement extends UIElement<PayPalConfiguration> {\n public static type = TxVariants.paypal;\n public static subtype = 'sdk';\n\n public paymentData: string = null;\n\n private resolve = null;\n private reject = null;\n\n protected static defaultProps = defaultProps;\n\n constructor(checkout: ICore, props?: PayPalConfiguration) {\n super(checkout, props);\n this.handleSubmit = this.handleSubmit.bind(this);\n this.handleOnShippingAddressChange = this.handleOnShippingAddressChange.bind(this);\n this.handleOnShippingOptionsChange = this.handleOnShippingOptionsChange.bind(this);\n }\n\n formatProps(props: PayPalConfiguration): PayPalConfiguration {\n const { merchantId, intent: intentFromConfig } = props.configuration;\n const isZeroAuth = props.amount?.value === 0;\n const intent: Intent = isZeroAuth ? 'tokenize' : props.intent || intentFromConfig;\n const vault = intent === 'tokenize' || props.vault;\n\n const displayContinueToReviewPageButton = props.userAction === 'continue';\n\n return {\n ...props,\n commit: displayContinueToReviewPageButton ? false : props.commit,\n vault,\n configuration: {\n intent,\n merchantId\n }\n };\n }\n\n public submit = () => {\n this.handleError(new AdyenCheckoutError('IMPLEMENTATION_ERROR', ERRORS.SUBMIT_NOT_SUPPORTED));\n };\n\n /**\n * Updates the paymentData value. It must be used in the PayPal Express flow, when patching the amount\n * @param paymentData - Payment data value\n */\n public updatePaymentData(paymentData: string): void {\n if (!paymentData) console.warn('PayPal - Updating payment data with an invalid value');\n this.paymentData = paymentData;\n }\n\n /**\n * Formats the component data output\n */\n protected formatData() {\n const { isExpress, userAction } = this.props;\n\n return {\n paymentMethod: {\n type: PaypalElement.type,\n userAction,\n subtype: isExpress ? 'express' : PaypalElement.subtype\n }\n };\n }\n\n public handleAction = (action: PaymentAction) => {\n return this.updateWithAction(action);\n };\n\n public updateWithAction = (action: PaymentAction) => {\n if (action.paymentMethodType !== this.type) throw new Error('Invalid Action');\n\n if (action.paymentData) {\n this.paymentData = action.paymentData;\n }\n\n if (action.sdkData && action.sdkData.token) {\n this.handleResolve(action.sdkData.token);\n } else {\n this.handleReject(ERRORS.NO_TOKEN_PROVIDED);\n }\n\n return null;\n };\n\n /**\n * Dropin Validation\n *\n * @remarks\n * Paypal does not require any specific Dropin validation\n */\n get isValid() {\n return true;\n }\n\n private handleOnApprove = (data: any, actions: any): Promise<void> | void => {\n const { onAuthorized } = this.props;\n const state = { data: { details: data, paymentData: this.paymentData } };\n\n if (!onAuthorized) {\n this.handleAdditionalDetails(state);\n return;\n }\n\n return actions.order\n .get()\n .then((paypalOrder: any) => {\n const billingAddress = formatPaypalOrderContatcToAdyenFormat(paypalOrder?.payer);\n const deliveryAddress = formatPaypalOrderContatcToAdyenFormat(paypalOrder?.purchase_units?.[0].shipping, true);\n\n this.setState({\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n return new Promise<void>((resolve, reject) =>\n onAuthorized(\n {\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n )\n );\n })\n .then(() => this.handleAdditionalDetails(state))\n .catch(error => this.handleError(new AdyenCheckoutError('ERROR', 'Something went wrong while parsing PayPal Order', { cause: error })));\n };\n\n handleResolve(token: string) {\n if (!this.resolve) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.resolve(token);\n }\n\n handleReject(errorMessage: string) {\n if (!this.reject) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.reject(new Error(errorMessage));\n }\n\n private handleSubmit(): Promise<void> {\n super.submit();\n\n return new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n\n /**\n * If the merchant provides the 'onShippingAddressChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingAddressChange(data, actions): Promise<void> {\n return this.props.onShippingAddressChange(data, actions, this);\n }\n\n /**\n * If the merchant provides the 'onShippingOptionsChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingOptionsChange(data, actions): Promise<void> {\n return this.props.onShippingOptionsChange(data, actions, this);\n }\n\n render() {\n if (!this.props.showPayButton) return null;\n\n const { onShippingAddressChange, onShippingOptionsChange, ...rest } = this.props;\n\n return (\n <CoreProvider i18n={this.props.i18n} loadingContext={this.props.loadingContext} resources={this.resources}>\n <PaypalComponent\n ref={ref => {\n this.componentRef = ref;\n }}\n {...rest}\n {...(onShippingAddressChange && { onShippingAddressChange: this.handleOnShippingAddressChange })}\n {...(onShippingOptionsChange && { onShippingOptionsChange: this.handleOnShippingOptionsChange })}\n onCancel={() => this.handleError(new AdyenCheckoutError('CANCEL'))}\n onChange={this.setState}\n onApprove={this.handleOnApprove}\n onError={error => {\n this.handleError(new AdyenCheckoutError('ERROR', error.toString(), { cause: error }));\n }}\n onSubmit={this.handleSubmit}\n />\n </CoreProvider>\n );\n }\n}\n\nexport default PaypalElement;\n"],"names":["PaypalElement","UIElement","static","TxVariants","paypal","paymentData","resolve","reject","defaultProps","constructor","checkout","props","super","this","handleSubmit","bind","handleOnShippingAddressChange","handleOnShippingOptionsChange","formatProps","merchantId","intent","intentFromConfig","configuration","amount","value","vault","displayContinueToReviewPageButton","userAction","commit","submit","handleError","AdyenCheckoutError","ERRORS","SUBMIT_NOT_SUPPORTED","updatePaymentData","console","warn","formatData","isExpress","paymentMethod","type","subtype","handleAction","action","updateWithAction","paymentMethodType","Error","sdkData","token","handleResolve","handleReject","NO_TOKEN_PROVIDED","isValid","handleOnApprove","data","actions","onAuthorized","state","details","order","get","then","paypalOrder","billingAddress","formatPaypalOrderContatcToAdyenFormat","payer","deliveryAddress","purchase_units","shipping","setState","authorizedEvent","Promise","handleAdditionalDetails","catch","error","cause","WRONG_INSTANCE","errorMessage","onShippingAddressChange","onShippingOptionsChange","render","showPayButton","rest","h","CoreProvider","i18n","loadingContext","resources","PaypalComponent","ref","componentRef","onCancel","onChange","onApprove","onError","toString","onSubmit"],"mappings":"mgBAgBA,MAAMA,UAAsBC,EACxBC,YAAqBC,EAAWC,OAChCF,eAAwB,MAEjBG,YAAsB,KAErBC,QAAU,KACVC,OAAS,KAEjBL,oBAAgCM,EAEhCC,WAAAA,CAAYC,EAAiBC,GACzBC,MAAMF,EAAUC,GAChBE,KAAKC,aAAeD,KAAKC,aAAaC,KAAKF,MAC3CA,KAAKG,8BAAgCH,KAAKG,8BAA8BD,KAAKF,MAC7EA,KAAKI,8BAAgCJ,KAAKI,8BAA8BF,KAAKF,KACjF,CAEAK,WAAAA,CAAYP,GACR,MAAMQ,WAAEA,EAAYC,OAAQC,GAAqBV,EAAMW,cAEjDF,EADqC,IAAxBT,EAAMY,QAAQC,MACG,WAAab,EAAMS,QAAUC,EAC3DI,EAAmB,aAAXL,GAAyBT,EAAMc,MAEvCC,EAAyD,aAArBf,EAAMgB,WAEhD,MAAO,IACAhB,EACHiB,QAAQF,GAA4Cf,EAAMiB,OAC1DH,QACAH,cAAe,CACXF,SACAD,cAGZ,CAEOU,OAAS,KACZhB,KAAKiB,YAAY,IAAIC,EAAmB,uBAAwBC,EAAOC,sBAAoB,EAOxFC,iBAAAA,CAAkB7B,GAChBA,GAAa8B,QAAQC,KAAK,wDAC/BvB,KAAKR,YAAcA,CACvB,CAKA,UAAAgC,GACI,MAAMC,UAAEA,EAASX,WAAEA,GAAed,KAAKF,MAEvC,MAAO,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AAa2B,GACT,IAAKhE,KAAKN,OAAQ,OAAOM,KAAKiB,YAAY,IAAIC,EAAmB,QAASC,EAAO4C,iBACjF/D,KAAKN,OAAO,IAAIuC,MAAM+B,GAC1B,CAEQ/D,YAAAA,GAGJ,OAFAF,MAAMiB,SAEC,IAAI0C,SAAQ,CAACjE,EAASC,KACzBM,KAAKP,QAAUA,EACfO,KAAKN,OAASA,CAAAA,GAEtB,CAUA,6BAAAS,CAAsCsC,EAAMC,GACxC,OAAO1C,KAAKF,MAAMmE,wBAAwBxB,EAAMC,EAAS1C,KAC7D,CAUA,6BAAAI,CAAsCqC,EAAMC,GACxC,OAAO1C,KAAKF,MAAMoE,wBAAwBzB,EAAMC,EAAS1C,KAC7D,CAEAmE,MAAAA,GACI,IAAKnE,KAAKF,MAAMsE,cAAe,OAAO,KAEtC,MAAMH,wBAAEA,EAAuBC,wBAAEA,KAA4BG,GAASrE,KAAKF,MAE3E,OACIwE,EAACC,EAAAA,CAAaC,KAAMxE,KAAKF,MAAM0E,KAAMC,eAAgBzE,KAAKF,MAAM2E,eAAgBC,UAAW1E,KAAK0E,WAC5FJ,EAACK,EAAAA,CACGC,IAAKA,IACD5E,KAAK6E,aAAeD,CAAAA,KAEpBP,KACCJ,GAA2B,CAAEA,wBAAyBjE,KAAKG,kCAC3D+D,GAA2B,CAAEA,wBAAyBlE,KAAKI,+BAChE0E,SAAU,IAAM9E,KAAKiB,YAAY,IAAIC,EAAmB,WACxD6D,SAAU/E,KAAKwD,SACfwB,UAAWhF,KAAKwC,gBAChByC,QAASpB,IACL7D,KAAKiB,YAAY,IAAIC,EAAmB,QAAS2C,EAAMqB,WAAY,CAAEpB,MAAOD,IAAM,EAEtFsB,SAAUnF,KAAKC,eAI/B"}
1
+ {"version":3,"file":"Paypal.js","sources":["../../../../src/components/PayPal/Paypal.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport PaypalComponent from './components/PaypalComponent';\nimport defaultProps from './defaultProps';\nimport CoreProvider from '../../core/Context/CoreProvider';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { ERRORS } from './constants';\nimport { TxVariants } from '../tx-variants';\nimport { formatPaypalOrderContactToAdyenFormat } from './utils/format-paypal-order-contact-to-adyen-format';\n\nimport type { ICore } from '../../core/types';\nimport type { PaymentAction } from '../../types/global-types';\nimport type { Intent, PayPalConfiguration } from './types';\n\nimport './Paypal.scss';\n\nclass PaypalElement extends UIElement<PayPalConfiguration> {\n public static type = TxVariants.paypal;\n public static subtype = 'sdk';\n\n public paymentData: string = null;\n\n private resolve = null;\n private reject = null;\n\n protected static defaultProps = defaultProps;\n\n constructor(checkout: ICore, props?: PayPalConfiguration) {\n super(checkout, props);\n this.handleSubmit = this.handleSubmit.bind(this);\n this.handleOnShippingAddressChange = this.handleOnShippingAddressChange.bind(this);\n this.handleOnShippingOptionsChange = this.handleOnShippingOptionsChange.bind(this);\n }\n\n formatProps(props: PayPalConfiguration): PayPalConfiguration {\n const merchantId = props.configuration?.merchantId;\n const intentFromConfig = props.configuration?.intent;\n const isZeroAuth = props.amount?.value === 0;\n const intent: Intent = isZeroAuth ? 'tokenize' : props.intent || intentFromConfig;\n const vault = intent === 'tokenize' || props.vault;\n\n const displayContinueToReviewPageButton = props.userAction === 'continue';\n\n return {\n ...props,\n commit: displayContinueToReviewPageButton ? false : props.commit,\n vault,\n configuration: {\n intent,\n merchantId\n }\n };\n }\n\n public submit = () => {\n this.handleError(new AdyenCheckoutError('IMPLEMENTATION_ERROR', ERRORS.SUBMIT_NOT_SUPPORTED));\n };\n\n /**\n * Updates the paymentData value. It must be used in the PayPal Express flow, when patching the amount\n * @param paymentData - Payment data value\n */\n public updatePaymentData(paymentData: string): void {\n if (!paymentData) console.warn('PayPal - Updating payment data with an invalid value');\n this.paymentData = paymentData;\n }\n\n /**\n * Formats the component data output\n */\n protected formatData() {\n const { isExpress, userAction } = this.props;\n\n return {\n paymentMethod: {\n type: PaypalElement.type,\n userAction,\n subtype: isExpress ? 'express' : PaypalElement.subtype\n }\n };\n }\n\n public handleAction = (action: PaymentAction) => {\n return this.updateWithAction(action);\n };\n\n public updateWithAction = (action: PaymentAction) => {\n if (action.paymentMethodType !== this.type) throw new Error('Invalid Action');\n\n if (action.paymentData) {\n this.paymentData = action.paymentData;\n }\n\n if (action.sdkData && action.sdkData.token) {\n this.handleResolve(action.sdkData.token);\n } else {\n this.handleReject(ERRORS.NO_TOKEN_PROVIDED);\n }\n\n return null;\n };\n\n /**\n * Dropin Validation\n *\n * @remarks\n * Paypal does not require any specific Dropin validation\n */\n get isValid() {\n return true;\n }\n\n private handleOnApprove = (data: any, actions: any): Promise<void> | void => {\n const { onAuthorized } = this.props;\n const state = { data: { details: data, paymentData: this.paymentData } };\n\n if (!onAuthorized) {\n this.handleAdditionalDetails(state);\n return;\n }\n\n return actions.order\n .get()\n .then((paypalOrder: any) => {\n const billingAddress = formatPaypalOrderContactToAdyenFormat(paypalOrder?.payer);\n const deliveryAddress = formatPaypalOrderContactToAdyenFormat(paypalOrder?.purchase_units?.[0].shipping, true);\n\n this.setState({\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n return new Promise<void>((resolve, reject) =>\n onAuthorized(\n {\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n )\n );\n })\n .then(() => this.handleAdditionalDetails(state))\n .catch(error => this.handleError(new AdyenCheckoutError('ERROR', 'Something went wrong while parsing PayPal Order', { cause: error })));\n };\n\n handleResolve(token: string) {\n if (!this.resolve) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.resolve(token);\n }\n\n handleReject(errorMessage: string) {\n if (!this.reject) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.reject(new Error(errorMessage));\n }\n\n private handleSubmit(): Promise<void> {\n super.submit();\n\n return new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n\n /**\n * If the merchant provides the 'onShippingAddressChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingAddressChange(data: any, actions: any): Promise<void> {\n return this.props.onShippingAddressChange(data, actions, this);\n }\n\n /**\n * If the merchant provides the 'onShippingOptionsChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingOptionsChange(data: any, actions: any): Promise<void> {\n return this.props.onShippingOptionsChange(data, actions, this);\n }\n\n render() {\n if (!this.props.showPayButton) return null;\n\n const { onShippingAddressChange, onShippingOptionsChange, ...rest } = this.props;\n\n return (\n <CoreProvider i18n={this.props.i18n} loadingContext={this.props.loadingContext} resources={this.resources}>\n <PaypalComponent\n ref={ref => {\n this.componentRef = ref;\n }}\n {...rest}\n {...(onShippingAddressChange && { onShippingAddressChange: this.handleOnShippingAddressChange })}\n {...(onShippingOptionsChange && { onShippingOptionsChange: this.handleOnShippingOptionsChange })}\n onCancel={() => this.handleError(new AdyenCheckoutError('CANCEL'))}\n onChange={this.setState}\n onApprove={this.handleOnApprove}\n onError={error => {\n this.handleError(new AdyenCheckoutError('ERROR', error.toString(), { cause: error }));\n }}\n onScriptLoadFailure={error => this.handleError(error)}\n onSubmit={this.handleSubmit}\n />\n </CoreProvider>\n );\n }\n}\n\nexport default PaypalElement;\n"],"names":["PaypalElement","UIElement","static","TxVariants","paypal","paymentData","resolve","reject","defaultProps","constructor","checkout","props","super","this","handleSubmit","bind","handleOnShippingAddressChange","handleOnShippingOptionsChange","formatProps","merchantId","configuration","intentFromConfig","intent","amount","value","vault","displayContinueToReviewPageButton","userAction","commit","submit","handleError","AdyenCheckoutError","ERRORS","SUBMIT_NOT_SUPPORTED","updatePaymentData","console","warn","formatData","isExpress","paymentMethod","type","subtype","handleAction","action","updateWithAction","paymentMethodType","Error","sdkData","token","handleResolve","handleReject","NO_TOKEN_PROVIDED","isValid","handleOnApprove","data","actions","onAuthorized","state","details","order","get","then","paypalOrder","billingAddress","formatPaypalOrderContactToAdyenFormat","payer","deliveryAddress","purchase_units","shipping","setState","authorizedEvent","Promise","handleAdditionalDetails","catch","error","cause","WRONG_INSTANCE","errorMessage","onShippingAddressChange","onShippingOptionsChange","render","showPayButton","rest","h","CoreProvider","i18n","loadingContext","resources","PaypalComponent","ref","componentRef","onCancel","onChange","onApprove","onError","toString","onScriptLoadFailure","onSubmit"],"mappings":"mgBAgBA,MAAMA,UAAsBC,EACxBC,YAAqBC,EAAWC,OAChCF,eAAwB,MAEjBG,YAAsB,KAErBC,QAAU,KACVC,OAAS,KAEjBL,oBAAgCM,EAEhCC,WAAAA,CAAYC,EAAiBC,GACzBC,MAAMF,EAAUC,GAChBE,KAAKC,aAAeD,KAAKC,aAAaC,KAAKF,MAC3CA,KAAKG,8BAAgCH,KAAKG,8BAA8BD,KAAKF,MAC7EA,KAAKI,8BAAgCJ,KAAKI,8BAA8BF,KAAKF,KACjF,CAEAK,WAAAA,CAAYP,GACR,MAAMQ,EAAaR,EAAMS,eAAeD,WAClCE,EAAmBV,EAAMS,eAAeE,OAExCA,EADqC,IAAxBX,EAAMY,QAAQC,MACG,WAAab,EAAMW,QAAUD,EAC3DI,EAAmB,aAAXH,GAAyBX,EAAMc,MAEvCC,EAAyD,aAArBf,EAAMgB,WAEhD,MAAO,IACAhB,EACHiB,QAAQF,GAA4Cf,EAAMiB,OAC1DH,QACAL,cAAe,CACXE,SACAH,cAGZ,CAEOU,OAAS,KACZhB,KAAKiB,YAAY,IAAIC,EAAmB,uBAAwBC,EAAOC,sBAAoB,EAOxFC,iBAAAA,CAAkB7B,GAChBA,GAAa8B,QAAQC,KAAK,wDAC/BvB,KA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2 @@
1
- import{createElement as e}from"../../../external/preact/dist/preact.js";import{useRef as n,useEffect as a}from"../../../external/preact/hooks/dist/hooks.js";import t from"../../../external/classnames/index.js";import{getStyle as o}from"../utils.js";import i from"../../internal/Spinner/Spinner.js";import p from"../../../core/Context/useCoreContext.js";function s({onInit:s,onApprove:c,onClick:r,onCancel:l,onError:_,onShippingChange:u,onShippingAddressChange:d,onShippingOptionsChange:y,onSubmit:m,isProcessingPayment:h,paypalRef:g,style:k,...f}){const{i18n:C}=p(),P="tokenize"===f.configuration?.intent,b=n(null),S=n(null),v=n(null),A=n(null),N=(e,n)=>{const a={...P&&{createBillingAgreement:m},...!P&&{createOrder:m},...!P&&"venmo"!==e&&u&&{onShippingChange:u},...!P&&"venmo"!==e&&d&&{onShippingAddressChange:d},...!P&&"venmo"!==e&&y&&{onShippingOptionsChange:y},fundingSource:e,style:o(e,k),onInit:s,onClick:r,onCancel:l,onError:_,onApprove:c},t=g.Buttons(a);t.isEligible()&&t.render(n.current)};a((()=>{u&&d&&console.warn('PayPal - "onShippingChange" and "onShippingAddressChange" are defined. It is recommended to only use "onShippingAddressChange", as "onShippingChange" is getting deprecated')}),[u,d]),a((()=>{const{PAYPAL:e,CREDIT:n,PAYLATER:a,VENMO:t}=g.FUNDING;N(e,b),f.blockPayPalCreditButton||N(n,S),f.blockPayPalPayLaterButton||N(a,v),f.blockPayPalVenmoButton||N(t,A)}),[]);const E=!0===f.commit;return e("div",{className:t("adyen-checkout__paypal__buttons",{"adyen-checkout__paypal-processing":h})},e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--paypal",ref:b}),e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--credit",ref:S}),e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--pay-later",ref:v}),e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--venmo",ref:A}),h&&e("div",{className:"adyen-checkout__paypal"},e("div",{className:"adyen-checkout__paypal__status adyen-checkout__paypal__status--processing"},e(i,{size:"medium",inline:!0}),E&&C.get("paypal.processingPayment"))))}export{s as default};
1
+ import{createElement as e}from"../../../external/preact/dist/preact.js";import{useRef as n,useEffect as a}from"../../../external/preact/hooks/dist/hooks.js";import t from"../../../external/classnames/index.js";import{getStyle as o}from"../utils/get-paypal-styles.js";import s from"../../internal/Spinner/Spinner.js";import p from"../../../core/Context/useCoreContext.js";function c({onInit:c,onApprove:r,onClick:i,onCancel:l,onError:_,onShippingAddressChange:u,onShippingOptionsChange:y,onSubmit:d,isProcessingPayment:m,paypalRef:h,style:k,...g}){const{i18n:f}=p(),b="tokenize"===g.configuration?.intent,C=n(null),P=n(null),v=n(null),N=n(null),A=(e,n)=>{const a={...b&&{createBillingAgreement:d},...!b&&{createOrder:d},...!b&&"venmo"!==e&&u&&{onShippingAddressChange:u},...!b&&"venmo"!==e&&y&&{onShippingOptionsChange:y},fundingSource:e,style:o(e,k),onInit:c,onClick:i,onCancel:l,onError:_,onApprove:r},t=h.Buttons(a);t.isEligible()&&t.render(n.current)};a((()=>{const{PAYPAL:e,CREDIT:n,PAYLATER:a,VENMO:t}=h.FUNDING;A(e,C),g.blockPayPalCreditButton||A(n,P),g.blockPayPalPayLaterButton||A(a,v),g.blockPayPalVenmoButton||A(t,N)}),[]);const E=!0===g.commit;return e("div",{className:t("adyen-checkout__paypal__buttons",{"adyen-checkout__paypal-processing":m})},e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--paypal",ref:C}),e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--credit",ref:P}),e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--pay-later",ref:v}),e("div",{className:"adyen-checkout__paypal__button adyen-checkout__paypal__button--venmo",ref:N}),m&&e("div",{className:"adyen-checkout__paypal"},e("div",{className:"adyen-checkout__paypal__status adyen-checkout__paypal__status--processing"},e(s,{size:"medium",inline:!0}),E&&f.get("paypal.processingPayment"))))}export{c as default};
2
2
  //# sourceMappingURL=PaypalButtons.js.map