@adyen/adyen-web 6.32.1 → 6.33.0
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.
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +25 -6
- package/dist/es/components/ApplePay/ApplePay.js +1 -1
- package/dist/es/components/ApplePay/ApplePay.js.map +1 -1
- package/dist/es/components/ApplePay/services/ApplePayService.js +1 -1
- package/dist/es/components/ApplePay/services/ApplePayService.js.map +1 -1
- package/dist/es/components/ApplePay/utils/payment-request.js +1 -1
- package/dist/es/components/ApplePay/utils/payment-request.js.map +1 -1
- package/dist/es/core/Environment/constants.js +1 -1
- package/dist/es/core/Environment/constants.js.map +1 -1
- package/dist/es/core/config.js +1 -1
- package/dist/es/index.d.ts +25 -6
- package/dist/es-legacy/components/ApplePay/ApplePay.js +1 -1
- package/dist/es-legacy/components/ApplePay/ApplePay.js.map +1 -1
- package/dist/es-legacy/components/ApplePay/services/ApplePayService.js +1 -1
- package/dist/es-legacy/components/ApplePay/services/ApplePayService.js.map +1 -1
- package/dist/es-legacy/components/ApplePay/utils/payment-request.js +1 -1
- package/dist/es-legacy/components/ApplePay/utils/payment-request.js.map +1 -1
- package/dist/es-legacy/core/Environment/constants.js +1 -1
- package/dist/es-legacy/core/Environment/constants.js.map +1 -1
- package/dist/es-legacy/core/config.js +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -849,12 +849,12 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
849
849
|
/**
|
|
850
850
|
* The Apple Pay version number your website supports.
|
|
851
851
|
* @default highest supported version by the shopper device
|
|
852
|
-
* @see {@link https://developer.apple.com/documentation/
|
|
852
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/apple-pay-on-the-web-version-history Apple Pay on the Web Version History}
|
|
853
853
|
*/
|
|
854
854
|
version?: number;
|
|
855
855
|
/**
|
|
856
856
|
* Part of the 'ApplePayLineItem' object, which sets the label of the payment request
|
|
857
|
-
* @see {@link https://developer.apple.com/documentation/
|
|
857
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaylineitem ApplePayLineItem docs}
|
|
858
858
|
*/
|
|
859
859
|
totalPriceLabel?: string;
|
|
860
860
|
/**
|
|
@@ -908,7 +908,7 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
908
908
|
supportedNetworks?: string[];
|
|
909
909
|
/**
|
|
910
910
|
* ApplePayRecurringPaymentRequest - Represents a request to set up a recurring payment, typically a subscription.
|
|
911
|
-
* {@link https://developer.apple.com/documentation/
|
|
911
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepayrecurringpaymentrequest}
|
|
912
912
|
*/
|
|
913
913
|
recurringPaymentRequest?: ApplePayJS.ApplePayRecurringPaymentRequest;
|
|
914
914
|
/**
|
|
@@ -973,7 +973,7 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
973
973
|
* Collect the order tracking details if available.
|
|
974
974
|
* This callback is invoked when a successfull payment is resolved
|
|
975
975
|
*
|
|
976
|
-
* {@link https://developer.apple.com/documentation/
|
|
976
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepaypaymentorderdetails}
|
|
977
977
|
* @param resolve - Must be called with the orderDetails fields
|
|
978
978
|
* @param reject - Must be called if something failed during the order creation. Calling 'reject' won't cancel the payment flow
|
|
979
979
|
*/
|
|
@@ -1014,6 +1014,25 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
1014
1014
|
* @param event - The event parameter contains the shippingMethod attribute.
|
|
1015
1015
|
*/
|
|
1016
1016
|
onShippingMethodSelected?: (resolve: (shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => void, reject: (shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => void, event: ApplePayJS.ApplePayShippingMethodSelectedEvent) => void;
|
|
1017
|
+
/**
|
|
1018
|
+
* The initial coupon code for the payment request.
|
|
1019
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaypaymentrequest/couponcode couponCode docs}
|
|
1020
|
+
*/
|
|
1021
|
+
couponCode?: ApplePayJS.ApplePayPaymentRequest['couponCode'];
|
|
1022
|
+
/**
|
|
1023
|
+
* A Boolean value that determines whether the payment sheet displays the coupon code field.
|
|
1024
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaypaymentrequest/supportscouponcode supportsCouponCode docs}
|
|
1025
|
+
*/
|
|
1026
|
+
supportsCouponCode?: ApplePayJS.ApplePayPaymentRequest['supportsCouponCode'];
|
|
1027
|
+
/**
|
|
1028
|
+
* An event handler called by the system when the user enters or updates a coupon code.
|
|
1029
|
+
*
|
|
1030
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/oncouponcodechanged}
|
|
1031
|
+
* @param resolve - Completes the change of a coupon code with an update.
|
|
1032
|
+
* @param reject - Completes the change of a coupon code with no update.
|
|
1033
|
+
* @param event - The event parameter contains the couponCode attribute.
|
|
1034
|
+
*/
|
|
1035
|
+
onCouponCodeChanged?: (resolve: (update: ApplePayJS.ApplePayCouponCodeUpdate) => void, reject: (update: ApplePayJS.ApplePayCouponCodeUpdate) => void, event: ApplePayJS.ApplePayCouponCodeChangedEvent) => void;
|
|
1017
1036
|
buttonColor?: ApplePayButtonStyle;
|
|
1018
1037
|
buttonType?: ApplePayButtonType;
|
|
1019
1038
|
/**
|
|
@@ -3646,7 +3665,7 @@ declare class ApplePayElement extends UIElement<ApplePayConfiguration> {
|
|
|
3646
3665
|
* not mean there are no cards available, it means the status cannot be determined and as such defaulting
|
|
3647
3666
|
* and upstreaming should still be considered.
|
|
3648
3667
|
*
|
|
3649
|
-
* {@link https://developer.apple.com/documentation/
|
|
3668
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/4440085-applepaycapabilities}
|
|
3650
3669
|
* @param merchantIdentifier
|
|
3651
3670
|
*/
|
|
3652
3671
|
applePayCapabilities(merchantIdentifier?: string): Promise<ApplePayJS.PaymentCredentialStatusResponse>;
|
|
@@ -6139,7 +6158,7 @@ interface CoreConfiguration {
|
|
|
6139
6158
|
/**
|
|
6140
6159
|
* Use 'test'. When you're ready to accept live payments, change the value to one of our {@link https://docs.adyen.com/checkout/drop-in-web#testing-your-integration | live environments}.
|
|
6141
6160
|
*/
|
|
6142
|
-
environment?: 'test' | 'live' | 'live-us' | 'live-au' | 'live-apse' | 'live-in';
|
|
6161
|
+
environment?: 'test' | 'live' | 'live-us' | 'live-au' | 'live-apse' | 'live-in' | 'live-nea';
|
|
6143
6162
|
/**
|
|
6144
6163
|
* Show or hides a Pay Button for each payment method
|
|
6145
6164
|
* @default true
|
|
@@ -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 s from"./components/ApplePayButton.js";import o from"./services/ApplePayService.js";import
|
|
1
|
+
import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as t}from"../internal/UIElement/UIElement.js";import s from"./components/ApplePayButton.js";import o from"./services/ApplePayService.js";import n from"../../utils/base64.js";import i from"./defaultProps.js";import{httpPost as r}from"../../core/Services/http.js";import{preparePaymentRequest as a}from"./utils/payment-request.js";import p from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as l}from"../tx-variants.js";import{sanitizeResponse as d,verifyPaymentDidNotFail as c}from"../internal/UIElement/utils.js";import{resolveSupportedVersion as h}from"./utils/resolve-supported-version.js";import{formatApplePayContactToAdyenAddressFormat as y}from"./utils/format-applepay-contact-to-adyen-format.js";import{mapBrands as m}from"./utils/map-adyen-brands-to-applepay-brands.js";import u from"./services/ApplePaySdkLoader.js";import{detectInIframe as P}from"../../utils/detectInIframe.js";import{AnalyticsInfoEvent as A,InfoEventType as b,UiTarget as f}from"../../core/Analytics/events/AnalyticsInfoEvent.js";function g(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}class S extends t{formatProps(e){const t=e.brands?.length?m(e.brands):e.supportedNetworks;return{...e,configuration:e.configuration,supportedNetworks:t,buttonLocale:e.buttonLocale??e.i18n?.locale,totalPriceLabel:e.totalPriceLabel||e.configuration?.merchantName,renderApplePayCodeAs:e.renderApplePayCodeAs??(P()?"window":"modal")}}formatData(){const{applePayToken:e,billingAddress:t,deliveryAddress:s}=this.state,{isExpress:o}=this.props;return{paymentMethod:{type:S.type,applePayToken:e,...o&&{subtype:"express"}},...t&&{billingAddress:t},...s&&{deliveryAddress:s}}}beforeRender(e){const t=new A({type:b.rendered,component:this.type,configData:{...e,showPayButton:this.props.showPayButton},...e?.isExpress&&{isExpress:e.isExpress},...e?.expressPage&&{expressPage:e.expressPage}});this.analytics.sendAnalytics(t)}get isValid(){return!0}async applePayCapabilities(e){const t=e||this.props.configuration.merchantId;try{return await this.sdkLoader.isSdkLoaded(),await(ApplePaySession?.applePayCapabilities(t))}catch(e){throw new p("ERROR","Apple Pay: Error when requesting applePayCapabilities()",{cause:e})}}async isAvailable(){if("https:"!==window.location.protocol)return Promise.reject(new p("IMPLEMENTATION_ERROR","Trying to start an Apple Pay session from an insecure document"));try{return await this.sdkLoader.isSdkLoaded(),ApplePaySession?.canMakePayments()?Promise.resolve():Promise.reject(new p("ERROR","Apple Pay is not available on this device"))}catch(e){return Promise.reject(new p("ERROR","Apple Pay SDK failed to load",{cause:e}))}}defineApplePayVersionNumber(){"https:"===window.location.protocol&&(this.applePayVersionNumber=this.props.version||h(14))}configureApplePayWebOptions(){if(window.ApplePayWebOptions){const{renderApplePayCodeAs:e,onApplePayCodeClose:t}=this.props;window.ApplePayWebOptions.set({renderApplePayCodeAs:e,...t&&{onApplePayCodeClose:t}})}}startSession(){const{onValidateMerchant:e,onPaymentMethodSelected:t,onShippingMethodSelected:s,onShippingContactSelected:n,onCouponCodeChanged:i}=this.props,r=a({companyName:this.props.configuration.merchantName,countryCode:this.core.options.countryCode,...this.props}),l=new o(r,{version:this.applePayVersionNumber,onError:e=>{this.handleError(new p("ERROR","ApplePay - Something went wrong on ApplePayService",{cause:e}))},onCancel:e=>{this.handleError(new p("CANCEL","ApplePay UI dismissed",{cause:e}))},onPaymentMethodSelected:t,onShippingMethodSelected:s,onShippingContactSelected:n,onCouponCodeChanged:i,onValidateMerchant:e||this.validateMerchant,onPaymentAuthorized:(e,t,s)=>{const o=y(s.payment.billingContact),n=y(s.payment.shippingContact,!0);this.setState({applePayToken:btoa(JSON.stringify(s.payment.token.paymentData)),authorizedEvent:s,...o&&{billingAddress:o},...n&&{deliveryAddress:n}}),this.handleAuthorization().then(this.makePaymentsCall).then(d).then(c).then(this.collectOrderTrackingDetailsIfNeeded).then(({paymentResponse:t,orderDetails:s})=>(e({status:ApplePaySession.STATUS_SUCCESS,...s&&{orderDetails:s}}),t)).then(e=>{this.handleResponse(e)}).catch(e=>{const s=e?.error?.applePayError;t({status:ApplePaySession.STATUS_FAILURE,errors:s?Array.isArray(s)?s:[s]:void 0});const o={...e,error:{applePayError:s}};this.handleFailedResult(o)})}});return new Promise((e,t)=>this.props.onClick(e,t)).then(()=>{l.begin()}).catch(()=>({}))}async handleAuthorization(){return new Promise((e,t)=>{this.props.onAuthorized||e();const{authorizedEvent:s,billingAddress:o,deliveryAddress:n}=this.state;this.props.onAuthorized({authorizedEvent:s,...o&&{billingAddress:o},...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:s}=window.location,{clientKey:o,configuration:i,loadingContext:a,initiative:p,domainName:l}=this.props,{merchantName:d,merchantId:c}=i,h={loadingContext:a,path:`v1/applePay/sessions?clientKey=${o}`},y={displayName:d,domainName:l||s,initiative:p,merchantIdentifier:c};try{const s=await r(h,y),o=n.decode(s.data);if(o.success){e(JSON.parse(o.data))}else t("Could not decode Apple Pay session")}catch(e){t("Could not get Apple Pay session")}}componentToRender(){return this.props.showPayButton?e(s,{buttonStyle:this.props.buttonColor,buttonType:this.props.buttonType,buttonLocale:this.props.buttonLocale,onClick:this.submit}):null}constructor(e,t){super(e,t),g(this,"sdkLoader",void 0),g(this,"applePayVersionNumber",void 0),g(this,"submit",()=>{if(this.props.isInstantPayment){const e=new A({component:this.type,type:b.selected,target:f.instantPaymentButton});this.submitAnalytics(e)}this.startSession()});const{isExpress:s,onShippingContactSelected:o,onShippingMethodSelected:n}=this.props;if(!1===s&&(o||n))throw new p("IMPLEMENTATION_ERROR",'ApplePay - You must set "isExpress" flag to "true" in order to use "onShippingContactSelected" and/or "onShippingMethodSelected" callbacks');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),this.defineApplePayVersionNumber=this.defineApplePayVersionNumber.bind(this),this.configureApplePayWebOptions=this.configureApplePayWebOptions.bind(this),this.sdkLoader=new u({analytics:this.analytics}),this.sdkLoader.load().then(this.defineApplePayVersionNumber).then(this.configureApplePayWebOptions).catch(e=>{this.handleError(e)})}}g(S,"type",l.applepay),g(S,"defaultProps",i);export{S 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 './services/ApplePayService';\nimport base64 from '../../utils/base64';\nimport defaultProps from './defaultProps';\nimport { httpPost } from '../../core/Services/http';\nimport { preparePaymentRequest } from './utils/payment-request';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { DecodeObject } from '../../types/global-types';\nimport { TxVariants } from '../tx-variants';\nimport { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';\nimport { resolveSupportedVersion } from './utils/resolve-supported-version';\nimport { formatApplePayContactToAdyenAddressFormat } from './utils/format-applepay-contact-to-adyen-format';\nimport { mapBrands } from './utils/map-adyen-brands-to-applepay-brands';\nimport ApplePaySdkLoader from './services/ApplePaySdkLoader';\nimport { detectInIframe } from '../../utils/detectInIframe';\nimport type { ApplePayConfiguration, ApplePayElementData, ApplePayPaymentOrderDetails, ApplePaySessionRequest } from './types';\nimport type { ICore } from '../../core/types';\nimport type { PaymentResponseData, RawPaymentResponse } from '../../types/global-types';\nimport { AnalyticsInfoEvent, InfoEventType, UiTarget } from '../../core/Analytics/events/AnalyticsInfoEvent';\n\nconst LATEST_APPLE_PAY_VERSION = 14;\n\nclass ApplePayElement extends UIElement<ApplePayConfiguration> {\n public static readonly type = TxVariants.applepay;\n\n protected static readonly defaultProps = defaultProps;\n\n private sdkLoader: ApplePaySdkLoader;\n private applePayVersionNumber: number = undefined;\n\n constructor(checkout: ICore, props?: ApplePayConfiguration) {\n super(checkout, props);\n\n const { isExpress, onShippingContactSelected, onShippingMethodSelected } = this.props;\n\n if (isExpress === false && (onShippingContactSelected || onShippingMethodSelected)) {\n throw new AdyenCheckoutError(\n 'IMPLEMENTATION_ERROR',\n 'ApplePay - You must set \"isExpress\" flag to \"true\" in order to use \"onShippingContactSelected\" and/or \"onShippingMethodSelected\" callbacks'\n );\n }\n\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 this.defineApplePayVersionNumber = this.defineApplePayVersionNumber.bind(this);\n this.configureApplePayWebOptions = this.configureApplePayWebOptions.bind(this);\n\n this.sdkLoader = new ApplePaySdkLoader({ analytics: this.analytics });\n\n void this.sdkLoader\n .load()\n .then(this.defineApplePayVersionNumber)\n .then(this.configureApplePayWebOptions)\n .catch(error => {\n this.handleError(error);\n });\n }\n\n /**\n * Formats the component props\n */\n protected override formatProps(props: ApplePayConfiguration): ApplePayConfiguration {\n // @ts-ignore TODO: Fix brands prop\n const supportedNetworks = props.brands?.length ? mapBrands(props.brands) : props.supportedNetworks;\n\n return {\n ...props,\n configuration: props.configuration,\n supportedNetworks,\n buttonLocale: props.buttonLocale ?? props.i18n?.locale,\n totalPriceLabel: props.totalPriceLabel || props.configuration?.merchantName,\n renderApplePayCodeAs: props.renderApplePayCodeAs ?? (detectInIframe() ? 'window' : 'modal')\n };\n }\n\n /**\n * Formats the component data output\n */\n protected override formatData(): ApplePayElementData {\n const { applePayToken, billingAddress, deliveryAddress } = this.state;\n const { isExpress } = this.props;\n\n return {\n paymentMethod: {\n type: ApplePayElement.type,\n applePayToken,\n ...(isExpress && { subtype: 'express' })\n },\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n };\n }\n\n protected override beforeRender(configSetByMerchant?: ApplePayConfiguration) {\n const event = new AnalyticsInfoEvent({\n type: InfoEventType.rendered,\n component: this.type,\n configData: { ...configSetByMerchant, showPayButton: this.props.showPayButton },\n ...(configSetByMerchant?.isExpress && { isExpress: configSetByMerchant.isExpress }),\n ...(configSetByMerchant?.expressPage && { expressPage: configSetByMerchant.expressPage })\n });\n\n this.analytics.sendAnalytics(event);\n }\n\n public override submit = (): void => {\n if (this.props.isInstantPayment) {\n const event = new AnalyticsInfoEvent({ component: this.type, type: InfoEventType.selected, target: UiTarget.instantPaymentButton });\n this.submitAnalytics(event);\n }\n void this.startSession();\n };\n\n public get isValid(): boolean {\n return true;\n }\n\n /**\n * This API is only intended for upstreaming or defaulting to Apple Pay, all other scenarios should continue to\n * use canMakePayments(). For Safari browsers, this API will indicate whether there is a card available to make\n * payments. For third-party browsers a new status of paymentCredentialStatusUnknown will be returned. This does\n * not mean there are no cards available, it means the status cannot be determined and as such defaulting\n * and upstreaming should still be considered.\n *\n * {@link https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/4440085-applepaycapabilities}\n * @param merchantIdentifier\n */\n public async applePayCapabilities(merchantIdentifier?: string): Promise<ApplePayJS.PaymentCredentialStatusResponse> {\n const identifier = merchantIdentifier || this.props.configuration.merchantId;\n\n try {\n await this.sdkLoader.isSdkLoaded();\n return await ApplePaySession?.applePayCapabilities(identifier);\n } catch (error) {\n throw new AdyenCheckoutError('ERROR', 'Apple Pay: Error when requesting applePayCapabilities()', { cause: error });\n }\n }\n\n /**\n * Determines if Apple Pay component can be displayed or not\n */\n public override async isAvailable(): Promise<void> {\n if (window.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 try {\n await this.sdkLoader.isSdkLoaded();\n\n if (ApplePaySession?.canMakePayments()) {\n return Promise.resolve();\n }\n\n return Promise.reject(new AdyenCheckoutError('ERROR', 'Apple Pay is not available on this device'));\n } catch (error) {\n return Promise.reject(new AdyenCheckoutError('ERROR', 'Apple Pay SDK failed to load', { cause: error }));\n }\n }\n\n /**\n * Sets the Apple Pay version available for the shopper.\n * This code needs to be executed once the Apple Pay SDK is fully loaded\n * @private\n */\n private defineApplePayVersionNumber() {\n if (window.location.protocol !== 'https:') return;\n this.applePayVersionNumber = this.props.version || resolveSupportedVersion(LATEST_APPLE_PAY_VERSION);\n }\n\n /**\n * Sets the configuration/callbacks that pertain to the Apple Pay code overlay/modal.\n * @private\n */\n private configureApplePayWebOptions() {\n if (window.ApplePayWebOptions) {\n const { renderApplePayCodeAs, onApplePayCodeClose } = this.props;\n\n window.ApplePayWebOptions.set({\n renderApplePayCodeAs,\n ...(onApplePayCodeClose && { onApplePayCodeClose })\n });\n }\n }\n\n private startSession() {\n const { 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: this.applePayVersionNumber,\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<void>((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: (merchantSession: any) => void, reject: (error: string) => void) {\n const { hostname } = window.location;\n const { clientKey, configuration, loadingContext, initiative, domainName } = this.props;\n const { merchantName, merchantId } = configuration;\n const path = `v1/applePay/sessions?clientKey=${clientKey}`;\n const options = { loadingContext, path };\n const request: ApplePaySessionRequest = {\n displayName: merchantName,\n domainName: domainName || hostname,\n initiative,\n merchantIdentifier: merchantId\n };\n\n try {\n const response = await httpPost(options, request);\n const decodedData: DecodeObject = base64.decode(response.data);\n if (!decodedData.success) {\n reject('Could not decode Apple Pay session');\n } else {\n const session = JSON.parse(decodedData.data);\n resolve(session);\n }\n } catch (e) {\n reject('Could not get Apple Pay session');\n }\n }\n\n protected override componentToRender(): h.JSX.Element {\n if (!this.props.showPayButton) {\n return null;\n }\n\n return (\n <ApplePayButton\n buttonStyle={this.props.buttonColor}\n buttonType={this.props.buttonType}\n buttonLocale={this.props.buttonLocale}\n onClick={this.submit}\n />\n );\n }\n}\n\nexport default ApplePayElement;\n"],"names":["ApplePayElement","UIElement","formatProps","props","supportedNetworks","brands","length","mapBrands","configuration","buttonLocale","i18n","locale","totalPriceLabel","merchantName","renderApplePayCodeAs","detectInIframe","formatData","applePayToken","billingAddress","deliveryAddress","this","state","isExpress","paymentMethod","type","subtype","beforeRender","configSetByMerchant","event","AnalyticsInfoEvent","InfoEventType","rendered","component","configData","showPayButton","expressPage","analytics","sendAnalytics","isValid","applePayCapabilities","merchantIdentifier","identifier","merchantId","sdkLoader","isSdkLoaded","ApplePaySession","error","AdyenCheckoutError","cause","isAvailable","window","location","protocol","Promise","reject","canMakePayments","resolve","defineApplePayVersionNumber","applePayVersionNumber","version","resolveSupportedVersion","configureApplePayWebOptions","ApplePayWebOptions","onApplePayCodeClose","set","startSession","onValidateMerchant","onPaymentMethodSelected","onShippingMethodSelected","onShippingContactSelected","paymentRequest","preparePaymentRequest","companyName","countryCode","core","options","session","ApplePayService","onError","handleError","onCancel","validateMerchant","onPaymentAuthorized","formatApplePayContactToAdyenAddressFormat","payment","billingContact","shippingContact","setState","btoa","JSON","stringify","token","paymentData","authorizedEvent","handleAuthorization","then","makePaymentsCall","sanitizeResponse","verifyPaymentDidNotFail","collectOrderTrackingDetailsIfNeeded","paymentResponse","orderDetails","status","STATUS_SUCCESS","handleResponse","catch","errors","applePayError","STATUS_FAILURE","Array","isArray","undefined","responseWithError","handleFailedResult","onClick","begin","onAuthorized","data","onOrderTrackingRequest","hostname","clientKey","loadingContext","initiative","domainName","path","request","displayName","response","httpPost","decodedData","base64","decode","success","parse","e","componentToRender","h","ApplePayButton","buttonStyle","buttonColor","buttonType","submit","constructor","checkout","super","_define_property","isInstantPayment","selected","target","UiTarget","instantPaymentButton","submitAnalytics","bind","ApplePaySdkLoader","load","TxVariants","applepay","defaultProps"],"mappings":"2sCAwBA,MAAMA,UAAwBC,EA0CPC,WAAAA,CAAYC,GAE3B,MAAMC,EAAoBD,EAAME,QAAQC,OAASC,EAAUJ,EAAME,QAAUF,EAAMC,kBAEjF,MAAO,IACAD,EACHK,cAAeL,EAAMK,cACrBJ,oBACAK,aAAcN,EAAMM,cAAgBN,EAAMO,MAAMC,OAChDC,gBAAiBT,EAAMS,iBAAmBT,EAAMK,eAAeK,aAC/DC,qBAAsBX,EAAMW,uBAAyBC,IAAmB,SAAW,SAE3F,CAKA,UAAAC,GACI,MAAMC,cAAEA,EAAaC,eAAEA,EAAcC,gBAAEA,GAAoBC,KAAKC,OAC1DC,UAAEA,GAAcF,KAAKjB,MAE3B,MAAO,CACHoB,cAAe,CACXC,KAAMxB,EAAgBwB,KACtBP,mBACIK,GAAa,CAAEG,QAAS,eAE5BP,GAAkB,CAAEA,qBACpBC,GAAmB,CAAEA,mBAEjC,CAEmBO,YAAAA,CAAaC,GAC5B,MAAMC,EAAQ,IAAIC,EAAmB,CACjCL,KAAMM,EAAcC,SACpBC,UAAWZ,KAAKI,KAChBS,WAAY,IAAKN,EAAqBO,cAAed,KAAKjB,MAAM+B,kBAC5DP,GAAqBL,WAAa,CAAEA,UAAWK,EAAoBL,cACnEK,GAAqBQ,aAAe,CAAEA,YAAaR,EAAoBQ,eAG/Ef,KAAKgB,UAAUC,cAAcT,EACjC,CAUA,WAAWU,GACP,OAAO,CACX,CAYA,0BAAaC,CAAqBC,GAC9B,MAAMC,EAAaD,GAAsBpB,KAAKjB,MAAMK,cAAckC,WAElE,IAEI,aADMtB,KAAKuB,UAAUC,oBACRC,iBAAiBN,qBAAqBE,GACvD,CAAE,MAAOK,GACL,MAAM,IAAIC,EAAmB,QAAS,0DAA2D,CAAEC,MAAOF,GAC9G,CACJ,CAKA,iBAAsBG,GAClB,GAAi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iBAhFV,MAAM3C,UAAEA,EAAS+C,0BAAEA,EAAyBD,yBAAEA,GAA6BhD,KAAKjB,MAEhF,IAAkB,IAAdmB,IAAwB+C,GAA6BD,GACrD,MAAM,IAAIrB,EACN,uBACA,8IAIR3B,KAAK6C,aAAe7C,KAAK6C,aAAauF,KAAKpI,MAC3CA,KAAKyH,OAASzH,KAAKyH,OAAOW,KAAKpI,MAC/BA,KAAK6D,iBAAmB7D,KAAK6D,iBAAiBuE,KAAKpI,MACnDA,KAAK+E,oCAAsC/E,KAAK+E,oCAAoCqD,KAAKpI,MACzFA,KAAK0E,oBAAsB1E,KAAK0E,oBAAoB0D,KAAKpI,MACzDA,KAAKqC,4BAA8BrC,KAAKqC,4BAA4B+F,KAAKpI,MACzEA,KAAKyC,4BAA8BzC,KAAKyC,4BAA4B2F,KAAKpI,MAEzEA,KAAKuB,UAAY,IAAI8G,EAAkB,CAAErH,UAAWhB,KAAKgB,YAEpDhB,KAAKuB,UACL+G,OACA3D,KAAK3E,KAAKqC,6BACVsC,KAAK3E,KAAKyC,6BACV4C,MAAM3D,IACH1B,KAAK2D,YAAYjC,IAE7B,EApCAmG,EADEjJ,EACqBwB,OAAOmI,EAAWC,UAEzCX,EAHEjJ,EAGwB6J,eAAeA"}
|
|
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 './services/ApplePayService';\nimport base64 from '../../utils/base64';\nimport defaultProps from './defaultProps';\nimport { httpPost } from '../../core/Services/http';\nimport { preparePaymentRequest } from './utils/payment-request';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { DecodeObject } from '../../types/global-types';\nimport { TxVariants } from '../tx-variants';\nimport { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';\nimport { resolveSupportedVersion } from './utils/resolve-supported-version';\nimport { formatApplePayContactToAdyenAddressFormat } from './utils/format-applepay-contact-to-adyen-format';\nimport { mapBrands } from './utils/map-adyen-brands-to-applepay-brands';\nimport ApplePaySdkLoader from './services/ApplePaySdkLoader';\nimport { detectInIframe } from '../../utils/detectInIframe';\nimport type { ApplePayConfiguration, ApplePayElementData, ApplePayPaymentOrderDetails, ApplePaySessionRequest } from './types';\nimport type { ICore } from '../../core/types';\nimport type { PaymentResponseData, RawPaymentResponse } from '../../types/global-types';\nimport { AnalyticsInfoEvent, InfoEventType, UiTarget } from '../../core/Analytics/events/AnalyticsInfoEvent';\n\nconst LATEST_APPLE_PAY_VERSION = 14;\n\nclass ApplePayElement extends UIElement<ApplePayConfiguration> {\n public static readonly type = TxVariants.applepay;\n\n protected static readonly defaultProps = defaultProps;\n\n private sdkLoader: ApplePaySdkLoader;\n private applePayVersionNumber: number = undefined;\n\n constructor(checkout: ICore, props?: ApplePayConfiguration) {\n super(checkout, props);\n\n const { isExpress, onShippingContactSelected, onShippingMethodSelected } = this.props;\n\n if (isExpress === false && (onShippingContactSelected || onShippingMethodSelected)) {\n throw new AdyenCheckoutError(\n 'IMPLEMENTATION_ERROR',\n 'ApplePay - You must set \"isExpress\" flag to \"true\" in order to use \"onShippingContactSelected\" and/or \"onShippingMethodSelected\" callbacks'\n );\n }\n\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 this.defineApplePayVersionNumber = this.defineApplePayVersionNumber.bind(this);\n this.configureApplePayWebOptions = this.configureApplePayWebOptions.bind(this);\n\n this.sdkLoader = new ApplePaySdkLoader({ analytics: this.analytics });\n\n void this.sdkLoader\n .load()\n .then(this.defineApplePayVersionNumber)\n .then(this.configureApplePayWebOptions)\n .catch(error => {\n this.handleError(error);\n });\n }\n\n /**\n * Formats the component props\n */\n protected override formatProps(props: ApplePayConfiguration): ApplePayConfiguration {\n // @ts-ignore TODO: Fix brands prop\n const supportedNetworks = props.brands?.length ? mapBrands(props.brands) : props.supportedNetworks;\n\n return {\n ...props,\n configuration: props.configuration,\n supportedNetworks,\n buttonLocale: props.buttonLocale ?? props.i18n?.locale,\n totalPriceLabel: props.totalPriceLabel || props.configuration?.merchantName,\n renderApplePayCodeAs: props.renderApplePayCodeAs ?? (detectInIframe() ? 'window' : 'modal')\n };\n }\n\n /**\n * Formats the component data output\n */\n protected override formatData(): ApplePayElementData {\n const { applePayToken, billingAddress, deliveryAddress } = this.state;\n const { isExpress } = this.props;\n\n return {\n paymentMethod: {\n type: ApplePayElement.type,\n applePayToken,\n ...(isExpress && { subtype: 'express' })\n },\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n };\n }\n\n protected override beforeRender(configSetByMerchant?: ApplePayConfiguration) {\n const event = new AnalyticsInfoEvent({\n type: InfoEventType.rendered,\n component: this.type,\n configData: { ...configSetByMerchant, showPayButton: this.props.showPayButton },\n ...(configSetByMerchant?.isExpress && { isExpress: configSetByMerchant.isExpress }),\n ...(configSetByMerchant?.expressPage && { expressPage: configSetByMerchant.expressPage })\n });\n\n this.analytics.sendAnalytics(event);\n }\n\n public override submit = (): void => {\n if (this.props.isInstantPayment) {\n const event = new AnalyticsInfoEvent({ component: this.type, type: InfoEventType.selected, target: UiTarget.instantPaymentButton });\n this.submitAnalytics(event);\n }\n void this.startSession();\n };\n\n public get isValid(): boolean {\n return true;\n }\n\n /**\n * This API is only intended for upstreaming or defaulting to Apple Pay, all other scenarios should continue to\n * use canMakePayments(). For Safari browsers, this API will indicate whether there is a card available to make\n * payments. For third-party browsers a new status of paymentCredentialStatusUnknown will be returned. This does\n * not mean there are no cards available, it means the status cannot be determined and as such defaulting\n * and upstreaming should still be considered.\n *\n * {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/4440085-applepaycapabilities}\n * @param merchantIdentifier\n */\n public async applePayCapabilities(merchantIdentifier?: string): Promise<ApplePayJS.PaymentCredentialStatusResponse> {\n const identifier = merchantIdentifier || this.props.configuration.merchantId;\n\n try {\n await this.sdkLoader.isSdkLoaded();\n return await ApplePaySession?.applePayCapabilities(identifier);\n } catch (error) {\n throw new AdyenCheckoutError('ERROR', 'Apple Pay: Error when requesting applePayCapabilities()', { cause: error });\n }\n }\n\n /**\n * Determines if Apple Pay component can be displayed or not\n */\n public override async isAvailable(): Promise<void> {\n if (window.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 try {\n await this.sdkLoader.isSdkLoaded();\n\n if (ApplePaySession?.canMakePayments()) {\n return Promise.resolve();\n }\n\n return Promise.reject(new AdyenCheckoutError('ERROR', 'Apple Pay is not available on this device'));\n } catch (error) {\n return Promise.reject(new AdyenCheckoutError('ERROR', 'Apple Pay SDK failed to load', { cause: error }));\n }\n }\n\n /**\n * Sets the Apple Pay version available for the shopper.\n * This code needs to be executed once the Apple Pay SDK is fully loaded\n * @private\n */\n private defineApplePayVersionNumber() {\n if (window.location.protocol !== 'https:') return;\n this.applePayVersionNumber = this.props.version || resolveSupportedVersion(LATEST_APPLE_PAY_VERSION);\n }\n\n /**\n * Sets the configuration/callbacks that pertain to the Apple Pay code overlay/modal.\n * @private\n */\n private configureApplePayWebOptions() {\n if (window.ApplePayWebOptions) {\n const { renderApplePayCodeAs, onApplePayCodeClose } = this.props;\n\n window.ApplePayWebOptions.set({\n renderApplePayCodeAs,\n ...(onApplePayCodeClose && { onApplePayCodeClose })\n });\n }\n }\n\n private startSession() {\n const { onValidateMerchant, onPaymentMethodSelected, onShippingMethodSelected, onShippingContactSelected, onCouponCodeChanged } = 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: this.applePayVersionNumber,\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 onCouponCodeChanged,\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<void>((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: (merchantSession: any) => void, reject: (error: string) => void) {\n const { hostname } = window.location;\n const { clientKey, configuration, loadingContext, initiative, domainName } = this.props;\n const { merchantName, merchantId } = configuration;\n const path = `v1/applePay/sessions?clientKey=${clientKey}`;\n const options = { loadingContext, path };\n const request: ApplePaySessionRequest = {\n displayName: merchantName,\n domainName: domainName || hostname,\n initiative,\n merchantIdentifier: merchantId\n };\n\n try {\n const response = await httpPost(options, request);\n const decodedData: DecodeObject = base64.decode(response.data);\n if (!decodedData.success) {\n reject('Could not decode Apple Pay session');\n } else {\n const session = JSON.parse(decodedData.data);\n resolve(session);\n }\n } catch (e) {\n reject('Could not get Apple Pay session');\n }\n }\n\n protected override componentToRender(): h.JSX.Element {\n if (!this.props.showPayButton) {\n return null;\n }\n\n return (\n <ApplePayButton\n buttonStyle={this.props.buttonColor}\n buttonType={this.props.buttonType}\n buttonLocale={this.props.buttonLocale}\n onClick={this.submit}\n />\n );\n }\n}\n\nexport default ApplePayElement;\n"],"names":["ApplePayElement","UIElement","formatProps","props","supportedNetworks","brands","length","mapBrands","configuration","buttonLocale","i18n","locale","totalPriceLabel","merchantName","renderApplePayCodeAs","detectInIframe","formatData","applePayToken","billingAddress","deliveryAddress","this","state","isExpress","paymentMethod","type","subtype","beforeRender","configSetByMerchant","event","AnalyticsInfoEvent","InfoEventType","rendered","component","configData","showPayButton","expressPage","analytics","sendAnalytics","isValid","applePayCapabilities","merchantIdentifier","identifier","merchantId","sdkLoader","isSdkLoaded","ApplePaySession","error","AdyenCheckoutError","cause","isAvailable","window","location","protocol","Promise","reject","canMakePayments","resolve","defineApplePayVersionNumber","applePayVersionNumber","version","resolveSupportedVersion","configureApplePayWebOptions","ApplePayWebOptions","onApplePayCodeClose","set","startSession","onValidateMerchant","onPaymentMethodSelected","onShippingMethodSelected","onShippingContactSelected","onCouponCodeChanged","paymentRequest","preparePaymentRequest","companyName","countryCode","core","options","session","ApplePayService","onError","handleError","onCancel","validateMerchant","onPaymentAuthorized","formatApplePayContactToAdyenAddressFormat","payment","billingContact","shippingContact","setState","btoa","JSON","stringify","token","paymentData","authorizedEvent","handleAuthorization","then","makePaymentsCall","sanitizeResponse","verifyPaymentDidNotFail","collectOrderTrackingDetailsIfNeeded","paymentResponse","orderDetails","status","STATUS_SUCCESS","handleResponse","catch","errors","applePayError","STATUS_FAILURE","Array","isArray","undefined","responseWithError","handleFailedResult","onClick","begin","onAuthorized","data","onOrderTrackingRequest","hostname","clientKey","loadingContext","initiative","domainName","path","request","displayName","response","httpPost","decodedData","base64","decode","success","parse","e","componentToRender","h","ApplePayButton","buttonStyle","buttonColor","buttonType","submit","constructor","checkout","super","_define_property","isInstantPayment","selected","target","UiTarget","instantPaymentButton","submitAnalytics","bind","ApplePaySdkLoader","load","TxVariants","applepay","defaultProps"],"mappings":"2sCAwBA,MAAMA,UAAwBC,EA0CPC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wB+C,GAA6BD,GACrD,MAAM,IAAIrB,EACN,uBACA,8IAIR3B,KAAK6C,aAAe7C,KAAK6C,aAAawF,KAAKrI,MAC3CA,KAAK0H,OAAS1H,KAAK0H,OAAOW,KAAKrI,MAC/BA,KAAK8D,iBAAmB9D,KAAK8D,iBAAiBuE,KAAKrI,MACnDA,KAAKgF,oCAAsChF,KAAKgF,oCAAoCqD,KAAKrI,MACzFA,KAAK2E,oBAAsB3E,KAAK2E,oBAAoB0D,KAAKrI,MACzDA,KAAKqC,4BAA8BrC,KAAKqC,4BAA4BgG,KAAKrI,MACzEA,KAAKyC,4BAA8BzC,KAAKyC,4BAA4B4F,KAAKrI,MAEzEA,KAAKuB,UAAY,IAAI+G,EAAkB,CAAEtH,UAAWhB,KAAKgB,YAEpDhB,KAAKuB,UACLgH,OACA3D,KAAK5E,KAAKqC,6BACVuC,KAAK5E,KAAKyC,6BACV6C,MAAM5D,IACH1B,KAAK4D,YAAYlC,IAE7B,EApCAoG,EADElJ,EACqBwB,OAAOoI,EAAWC,UAEzCX,EAHElJ,EAGwB8J,eAAeA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t
|
|
1
|
+
function e(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}class n{begin(){return this.session.begin()}onvalidatemerchant(e,n){return new Promise((t,o)=>{n(t,o,e.validationURL)}).then(e=>{this.session.completeMerchantValidation(e)}).catch(e=>{console.error(e),this.session.abort(),this.options.onError(e)})}onpaymentauthorized(e,n){return new Promise((t,o)=>n(t,o,e)).then(e=>{this.session.completePayment(e)}).catch(e=>{this.session.completePayment(e)})}onpaymentmethodselected(e,n){return new Promise((t,o)=>n(t,o,e)).then(e=>{this.session.completePaymentMethodSelection(e)}).catch(e=>{this.session.completePaymentMethodSelection(e)})}onshippingcontactselected(e,n){return new Promise((t,o)=>n(t,o,e)).then(e=>{this.session.completeShippingContactSelection(e)}).catch(e=>{this.session.completeShippingContactSelection(e)})}onshippingmethodselected(e,n){return new Promise((t,o)=>n(t,o,e)).then(e=>{this.session.completeShippingMethodSelection(e)}).catch(e=>{this.session.completeShippingMethodSelection(e)})}oncouponcodechanged(e,n){return new Promise((t,o)=>n(t,o,e)).then(e=>{this.session.completeCouponCodeChange(e)}).catch(e=>{this.session.completeCouponCodeChange(e)})}oncancel(e,n){n(e)}constructor(n,t){e(this,"session",void 0),e(this,"options",void 0),this.options=t,this.session=new ApplePaySession(t.version,n),this.session.onvalidatemerchant=e=>{this.onvalidatemerchant(e,t.onValidateMerchant)},this.session.onpaymentauthorized=e=>{this.onpaymentauthorized(e,t.onPaymentAuthorized)},this.session.oncancel=e=>{this.oncancel(e,t.onCancel)},"function"==typeof t.onPaymentMethodSelected&&(this.session.onpaymentmethodselected=e=>{this.onpaymentmethodselected(e,t.onPaymentMethodSelected)}),"function"==typeof t.onShippingContactSelected&&(this.session.onshippingcontactselected=e=>{this.onshippingcontactselected(e,t.onShippingContactSelected)}),"function"==typeof t.onShippingMethodSelected&&(this.session.onshippingmethodselected=e=>{this.onshippingmethodselected(e,t.onShippingMethodSelected)}),"function"==typeof t.onCouponCodeChanged&&(this.session.oncouponcodechanged=e=>{this.oncouponcodechanged(e,t.onCouponCodeChanged)})}}export{n as default};
|
|
2
2
|
//# sourceMappingURL=ApplePayService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApplePayService.js","sources":["../../../../../src/components/ApplePay/services/ApplePayService.ts"],"sourcesContent":["import { ApplePayConfiguration, ApplePayPaymentAuthorizationResult } from '../types';\n\nexport interface ApplePayServiceOptions {\n version: number;\n onError: (error?: unknown) => void;\n onCancel?: (event: ApplePayJS.Event) => void;\n onValidateMerchant: ApplePayConfiguration['onValidateMerchant'];\n onPaymentMethodSelected?: ApplePayConfiguration['onPaymentMethodSelected'];\n onShippingMethodSelected?: ApplePayConfiguration['onShippingMethodSelected'];\n onShippingContactSelected?: ApplePayConfiguration['onShippingContactSelected'];\n onPaymentAuthorized: (\n resolve: (result: ApplePayPaymentAuthorizationResult) => void,\n reject: (result: ApplePayPaymentAuthorizationResult) => void,\n event: ApplePayJS.ApplePayPaymentAuthorizedEvent\n ) => void;\n}\n\nclass ApplePayService {\n private session: ApplePaySession;\n private readonly options: ApplePayServiceOptions;\n\n constructor(paymentRequest: ApplePayJS.ApplePayPaymentRequest, options: ApplePayServiceOptions) {\n this.options = options;\n\n this.session = new ApplePaySession(options.version, paymentRequest);\n this.session.onvalidatemerchant = event => {\n void this.onvalidatemerchant(event, options.onValidateMerchant);\n };\n this.session.onpaymentauthorized = event => {\n void this.onpaymentauthorized(event, options.onPaymentAuthorized);\n };\n\n this.session.oncancel = event => {\n this.oncancel(event, options.onCancel);\n };\n\n if (typeof options.onPaymentMethodSelected === 'function') {\n this.session.onpaymentmethodselected = event => {\n void this.onpaymentmethodselected(event, options.onPaymentMethodSelected);\n };\n }\n\n if (typeof options.onShippingContactSelected === 'function') {\n this.session.onshippingcontactselected = event => {\n void this.onshippingcontactselected(event, options.onShippingContactSelected);\n };\n }\n\n if (typeof options.onShippingMethodSelected === 'function') {\n this.session.onshippingmethodselected = event => {\n void this.onshippingmethodselected(event, options.onShippingMethodSelected);\n };\n }\n }\n\n /**\n * Begins the merchant validation process.\n * When this method is called, the payment sheet is presented and the merchant validation process is initiated.\n * @see {@link https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778001-begin}\n */\n begin() {\n return this.session.begin();\n }\n\n /**\n * An event handler that is called when the payment sheet is displayed.\n * Use this attribute to request and return a merchant session.\n * @param event - An ApplePayValidateMerchantEvent object (contains validationURL)\n * @param onValidateMerchant - A promise implemented by the merchant that will resolve with the merchantSession\n * @see {@link https://developer.apple.com/documentation/apple_pay_on_the_web/apple_pay_js_api/providing_merchant_validation}\n */\n onvalidatemerchant(event: ApplePayJS.ApplePayValidateMerchantEvent, onValidateMerchant: ApplePayConfiguration['onValidateMerchant']) {\n return new Promise((resolve, reject) => {\n void onValidateMerchant(resolve, reject, event.validationURL);\n })\n .then(response => {\n this.session.completeMerchantValidation(response);\n })\n .catch(error => {\n console.error(error);\n this.session.abort();\n this.options.onError(error);\n });\n }\n\n /**\n * An event handler that is called when the user has authorized the Apple Pay payment with Touch ID, Face ID, or passcode.\n * The onpaymentauthorized function must complete the payment and respond by calling completePayment before the 30 second timeout.\n *\n * @param event - The event parameter contains the payment (ApplePayPayment) attribute.\n * @param onPaymentAuthorized - A promise that will complete the payment when resolved. Use this promise to process the payment.\n * @see {@link https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778020-onpaymentauthorized}\n */\n onpaymentauthorized(\n event: ApplePayJS.ApplePayPaymentAuthorizedEvent,\n onPaymentAuthorized: ApplePayServiceOptions['onPaymentAuthorized']\n ): Promise<void> {\n return new Promise((resolve, reject) => onPaymentAuthorized(resolve, reject, event))\n .then((result: ApplePayPaymentAuthorizationResult) => {\n this.session.completePayment(result);\n })\n .catch((result: ApplePayPaymentAuthorizationResult) => {\n this.session.completePayment(result);\n });\n }\n\n /**\n * An event handler that is called when a new payment method is selected.\n * The onpaymentmethodselected function must resolve before the 30 second timeout\n *\n * @param event - The event parameter contains the payment (ApplePayPayment) attribute.\n * @param onPaymentMethodSelected - A promise that will complete the payment when resolved. Use this promise to process the payment.\n * @see {@link https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778013-onpaymentmethodselected}\n */\n onpaymentmethodselected(\n event: ApplePayJS.ApplePayPaymentMethodSelectedEvent,\n onPaymentMethodSelected: ApplePayServiceOptions['onPaymentMethodSelected']\n ) {\n return new Promise((resolve, reject) => onPaymentMethodSelected(resolve, reject, event))\n .then((paymentMethodUpdate: ApplePayJS.ApplePayPaymentMethodUpdate) => {\n this.session.completePaymentMethodSelection(paymentMethodUpdate);\n })\n .catch((paymentMethodUpdate: ApplePayJS.ApplePayPaymentMethodUpdate) => {\n this.session.completePaymentMethodSelection(paymentMethodUpdate);\n });\n }\n\n /**\n * An event handler that is called when a new payment method is selected.\n * The onpaymentmethodselected function must resolve before the 30 second timeout\n * @param event - The event parameter contains the shippingContact attribute.\n * @param onShippingContactSelected - A promise that will complete the selection of a shipping contact with an update.\n * @see {@link https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778009-onshippingcontactselected}\n */\n onshippingcontactselected(\n event: ApplePayJS.ApplePayShippingContactSelectedEvent,\n onShippingContactSelected: ApplePayConfiguration['onShippingContactSelected']\n ) {\n return new Promise((resolve, reject) => onShippingContactSelected(resolve, reject, event))\n .then((shippingContactUpdate: ApplePayJS.ApplePayShippingContactUpdate) => {\n this.session.completeShippingContactSelection(shippingContactUpdate);\n })\n .catch((shippingContactUpdate: ApplePayJS.ApplePayShippingContactUpdate) => {\n this.session.completeShippingContactSelection(shippingContactUpdate);\n });\n }\n\n /**\n * An event handler that is called when a new payment method is selected.\n * The onpaymentmethodselected function must resolve before the 30 second timeout\n * @param event - The event parameter contains the shippingMethod attribute.\n * @param onShippingMethodSelected - A promise that will complete the selection of a shipping method with an update.\n * @see {@link https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778009-onshippingcontactselected}\n */\n onshippingmethodselected(\n event: ApplePayJS.ApplePayShippingMethodSelectedEvent,\n onShippingMethodSelected: ApplePayConfiguration['onShippingMethodSelected']\n ) {\n return new Promise((resolve, reject) => onShippingMethodSelected(resolve, reject, event))\n .then((shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => {\n this.session.completeShippingMethodSelection(shippingMethodUpdate);\n })\n .catch((shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => {\n this.session.completeShippingMethodSelection(shippingMethodUpdate);\n });\n }\n\n /**\n * An event handler that is automatically called when the payment UI is dismissed.\n * This function can be called even after an onpaymentauthorized event has been dispatched.\n * @param event -\n * @param onCancel -\n * @see {@link https://developer.apple.com/documentation/apple_pay_on_the_web/applepaysession/1778029-oncancel}\n */\n oncancel(event: ApplePayJS.Event, onCancel: (event: ApplePayJS.Event) => void): void {\n onCancel(event);\n }\n}\n\nexport default ApplePayService;\n"],"names":["ApplePayService","begin","this","session","onvalidatemerchant","event","onValidateMerchant","Promise","resolve","reject","validationURL","then","response","completeMerchantValidation","catch","error","console","abort","options","onError","onpaymentauthorized","onPaymentAuthorized","result","completePayment","onpaymentmethodselected","onPaymentMethodSelected","paymentMethodUpdate","completePaymentMethodSelection","onshippingcontactselected","onShippingContactSelected","shippingContactUpdate","completeShippingContactSelection","onshippingmethodselected","onShippingMethodSelected","shippingMethodUpdate","completeShippingMethodSelection","oncancel","onCancel","constructor","paymentRequest","_define_property","ApplePaySession","version"],"mappings":"wHAiBA,MAAMA,EA2CFC,KAAAA,GACI,OAAOC,KAAKC,QAAQF,OACxB,CASAG,kBAAAA,CAAmBC,EAAiDC,GAChE,OAAO,IAAIC,QAAQ,CAACC,EAASC,KACpBH,EAAmBE,EAASC,EAAQJ,EAAMK,iBAE9CC,KAAKC,IACFV,KAAKC,QAAQU,2BAA2BD,KAE3CE,MAAMC,IACHC,QAAQD,MAAMA,GACdb,KAAKC,QAAQc,QACbf,KAAKgB,QAAQC,QAAQJ,IAEjC,CAUAK,mBAAAA,CACIf,EACAgB,GAEA,OAAO,IAAId,QAAQ,CAACC,EAASC,IAAWY,EAAoBb,EAASC,EAAQJ,IACxEM,KAAMW,IACHpB,KAAKC,QAAQoB,gBAAgBD,KAEhCR,MAAOQ,IACJpB,KAAKC,QAAQoB,gBAAgBD,IAEzC,CAUAE,uBAAAA,CACInB,EACAoB,GAEA,OAAO,IAAIlB,QAAQ,CAACC,EAASC,IAAWgB,EAAwBjB,EAASC,EAAQJ,IAC5EM,KAAMe,IACHxB,KAAKC,QAAQwB,+BAA+BD,KAE/CZ,MAAOY,IACJxB,KAAKC,QAAQwB,+BAA+BD,IAExD,CASAE,yBAAAA,CACIvB,EACAwB,GAEA,OAAO,IAAItB,QAAQ,CAACC,EAASC,IAAWoB,EAA0BrB,EAASC,EAAQJ,IAC9EM,KAAMmB,IACH5B,KAAKC,QAAQ4B,iCAAiCD,KAEjDhB,MAAOgB,IACJ5B,KAAKC,QAAQ4B,iCAAiCD,IAE1D,CASAE,wBAAAA,CACI3B,EACA4B,GAEA,OAAO,IAAI1B,QAAQ,CAACC,EAASC,IAAWwB,EAAyBzB,EAASC,EAAQJ,IAC7EM,KAAMuB,IACHhC,KAAKC,QAAQgC,gCAAgCD,KAEhDpB,MAAOoB,IACJhC,KAAKC,QAAQgC,gCAAgCD,IAEzD,CASAE,QAAAA,CAAS/B,EAAyBgC,GAC9BA,EAAShC,EACb,CA3JA,WAAAiC,CAAYC,EAAmDrB,GAH/DsB,EAAAtC,KAAQC,kBACRqC,EAAAtC,KAAiBgB,kBAGbhB,KAAKgB,QAAUA,EAEfhB,KAAKC,QAAU,IAAIsC,gBAAgBvB,EAAQwB,QAASH,GACpDrC,KAAKC,QAAQC,mBAAqBC,IACzBH,KAAKE,mBAAmBC,EAAOa,EAAQZ,qBAEhDJ,KAAKC,QAAQiB,oBAAsBf,IAC1BH,KAAKkB,oBAAoBf,EAAOa,EAAQG,sBAGjDnB,KAAKC,QAAQiC,SAAW/B,IACpBH,KAAKkC,SAAS/B,EAAOa,EAAQmB,WAGc,mBAApCnB,EAAQO,0BACfvB,KAAKC,QAAQqB,wBAA0BnB,IAC9BH,KAAKsB,wBAAwBnB,EAAOa,EAAQO,2BAIR,mBAAtCP,EAAQW,4BACf3B,KAAKC,QAAQyB,0BAA4BvB,IAChCH,KAAK0B,0BAA0BvB,EAAOa,EAAQW,6BAIX,mBAArCX,EAAQe,2BACf/B,KAAKC,QAAQ6B,yBAA2B3B,IAC/BH,KAAK8B,yBAAyB3B,EAAOa,EAAQe,2BAG9D"}
|
|
1
|
+
{"version":3,"file":"ApplePayService.js","sources":["../../../../../src/components/ApplePay/services/ApplePayService.ts"],"sourcesContent":["import { ApplePayConfiguration, ApplePayPaymentAuthorizationResult } from '../types';\n\nexport interface ApplePayServiceOptions {\n version: number;\n onError: (error?: unknown) => void;\n onCancel?: (event: ApplePayJS.Event) => void;\n onValidateMerchant: ApplePayConfiguration['onValidateMerchant'];\n onCouponCodeChanged?: ApplePayConfiguration['onCouponCodeChanged'];\n onPaymentMethodSelected?: ApplePayConfiguration['onPaymentMethodSelected'];\n onShippingMethodSelected?: ApplePayConfiguration['onShippingMethodSelected'];\n onShippingContactSelected?: ApplePayConfiguration['onShippingContactSelected'];\n onPaymentAuthorized: (\n resolve: (result: ApplePayPaymentAuthorizationResult) => void,\n reject: (result: ApplePayPaymentAuthorizationResult) => void,\n event: ApplePayJS.ApplePayPaymentAuthorizedEvent\n ) => void;\n}\n\nclass ApplePayService {\n private session: ApplePaySession;\n private readonly options: ApplePayServiceOptions;\n\n constructor(paymentRequest: ApplePayJS.ApplePayPaymentRequest, options: ApplePayServiceOptions) {\n this.options = options;\n\n this.session = new ApplePaySession(options.version, paymentRequest);\n this.session.onvalidatemerchant = event => {\n void this.onvalidatemerchant(event, options.onValidateMerchant);\n };\n this.session.onpaymentauthorized = event => {\n void this.onpaymentauthorized(event, options.onPaymentAuthorized);\n };\n\n this.session.oncancel = event => {\n this.oncancel(event, options.onCancel);\n };\n\n if (typeof options.onPaymentMethodSelected === 'function') {\n this.session.onpaymentmethodselected = event => {\n void this.onpaymentmethodselected(event, options.onPaymentMethodSelected);\n };\n }\n\n if (typeof options.onShippingContactSelected === 'function') {\n this.session.onshippingcontactselected = event => {\n void this.onshippingcontactselected(event, options.onShippingContactSelected);\n };\n }\n\n if (typeof options.onShippingMethodSelected === 'function') {\n this.session.onshippingmethodselected = event => {\n void this.onshippingmethodselected(event, options.onShippingMethodSelected);\n };\n }\n\n if (typeof options.onCouponCodeChanged === 'function') {\n this.session.oncouponcodechanged = event => {\n void this.oncouponcodechanged(event, options.onCouponCodeChanged);\n };\n }\n }\n\n /**\n * Begins the merchant validation process.\n * When this method is called, the payment sheet is presented and the merchant validation process is initiated.\n * @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/1778001-begin}\n */\n begin() {\n return this.session.begin();\n }\n\n /**\n * An event handler that is called when the payment sheet is displayed.\n * Use this attribute to request and return a merchant session.\n * @param event - An ApplePayValidateMerchantEvent object (contains validationURL)\n * @param onValidateMerchant - A promise implemented by the merchant that will resolve with the merchantSession\n * @see {@link https://developer.apple.com/documentation/applepayontheweb/apple_pay_js_api/providing_merchant_validation}\n */\n onvalidatemerchant(event: ApplePayJS.ApplePayValidateMerchantEvent, onValidateMerchant: ApplePayConfiguration['onValidateMerchant']) {\n return new Promise((resolve, reject) => {\n void onValidateMerchant(resolve, reject, event.validationURL);\n })\n .then(response => {\n this.session.completeMerchantValidation(response);\n })\n .catch(error => {\n console.error(error);\n this.session.abort();\n this.options.onError(error);\n });\n }\n\n /**\n * An event handler that is called when the user has authorized the Apple Pay payment with Touch ID, Face ID, or passcode.\n * The onpaymentauthorized function must complete the payment and respond by calling completePayment before the 30 second timeout.\n *\n * @param event - The event parameter contains the payment (ApplePayPayment) attribute.\n * @param onPaymentAuthorized - A promise that will complete the payment when resolved. Use this promise to process the payment.\n * @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/1778020-onpaymentauthorized}\n */\n onpaymentauthorized(\n event: ApplePayJS.ApplePayPaymentAuthorizedEvent,\n onPaymentAuthorized: ApplePayServiceOptions['onPaymentAuthorized']\n ): Promise<void> {\n return new Promise((resolve, reject) => onPaymentAuthorized(resolve, reject, event))\n .then((result: ApplePayPaymentAuthorizationResult) => {\n this.session.completePayment(result);\n })\n .catch((result: ApplePayPaymentAuthorizationResult) => {\n this.session.completePayment(result);\n });\n }\n\n /**\n * An event handler that is called when a new payment method is selected.\n * The onpaymentmethodselected function must resolve before the 30 second timeout\n *\n * @param event - The event parameter contains the payment (ApplePayPayment) attribute.\n * @param onPaymentMethodSelected - A promise that will complete the payment when resolved. Use this promise to process the payment.\n * @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/1778013-onpaymentmethodselected}\n */\n onpaymentmethodselected(\n event: ApplePayJS.ApplePayPaymentMethodSelectedEvent,\n onPaymentMethodSelected: ApplePayServiceOptions['onPaymentMethodSelected']\n ) {\n return new Promise((resolve, reject) => onPaymentMethodSelected(resolve, reject, event))\n .then((paymentMethodUpdate: ApplePayJS.ApplePayPaymentMethodUpdate) => {\n this.session.completePaymentMethodSelection(paymentMethodUpdate);\n })\n .catch((paymentMethodUpdate: ApplePayJS.ApplePayPaymentMethodUpdate) => {\n this.session.completePaymentMethodSelection(paymentMethodUpdate);\n });\n }\n\n /**\n * An event handler that is called when a new payment method is selected.\n * The onpaymentmethodselected function must resolve before the 30 second timeout\n * @param event - The event parameter contains the shippingContact attribute.\n * @param onShippingContactSelected - A promise that will complete the selection of a shipping contact with an update.\n * @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/1778009-onshippingcontactselected}\n */\n onshippingcontactselected(\n event: ApplePayJS.ApplePayShippingContactSelectedEvent,\n onShippingContactSelected: ApplePayConfiguration['onShippingContactSelected']\n ) {\n return new Promise((resolve, reject) => onShippingContactSelected(resolve, reject, event))\n .then((shippingContactUpdate: ApplePayJS.ApplePayShippingContactUpdate) => {\n this.session.completeShippingContactSelection(shippingContactUpdate);\n })\n .catch((shippingContactUpdate: ApplePayJS.ApplePayShippingContactUpdate) => {\n this.session.completeShippingContactSelection(shippingContactUpdate);\n });\n }\n\n /**\n * An event handler that is called when a new payment method is selected.\n * The onpaymentmethodselected function must resolve before the 30 second timeout\n * @param event - The event parameter contains the shippingMethod attribute.\n * @param onShippingMethodSelected - A promise that will complete the selection of a shipping method with an update.\n * @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/1778009-onshippingcontactselected}\n */\n onshippingmethodselected(\n event: ApplePayJS.ApplePayShippingMethodSelectedEvent,\n onShippingMethodSelected: ApplePayConfiguration['onShippingMethodSelected']\n ) {\n return new Promise((resolve, reject) => onShippingMethodSelected(resolve, reject, event))\n .then((shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => {\n this.session.completeShippingMethodSelection(shippingMethodUpdate);\n })\n .catch((shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => {\n this.session.completeShippingMethodSelection(shippingMethodUpdate);\n });\n }\n\n oncouponcodechanged(event: ApplePayJS.ApplePayCouponCodeChangedEvent, onCouponCodeChanged: ApplePayConfiguration['onCouponCodeChanged']) {\n return new Promise((resolve, reject) => onCouponCodeChanged(resolve, reject, event))\n .then((couponCodeUpdate: ApplePayJS.ApplePayCouponCodeUpdate) => {\n this.session.completeCouponCodeChange(couponCodeUpdate);\n })\n .catch((couponCodeUpdate: ApplePayJS.ApplePayCouponCodeUpdate) => {\n this.session.completeCouponCodeChange(couponCodeUpdate);\n });\n }\n\n /**\n * An event handler that is automatically called when the payment UI is dismissed.\n * This function can be called even after an onpaymentauthorized event has been dispatched.\n * @param event -\n * @param onCancel -\n * @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/1778029-oncancel}\n */\n oncancel(event: ApplePayJS.Event, onCancel: (event: ApplePayJS.Event) => void): void {\n onCancel(event);\n }\n}\n\nexport default ApplePayService;\n"],"names":["ApplePayService","begin","this","session","onvalidatemerchant","event","onValidateMerchant","Promise","resolve","reject","validationURL","then","response","completeMerchantValidation","catch","error","console","abort","options","onError","onpaymentauthorized","onPaymentAuthorized","result","completePayment","onpaymentmethodselected","onPaymentMethodSelected","paymentMethodUpdate","completePaymentMethodSelection","onshippingcontactselected","onShippingContactSelected","shippingContactUpdate","completeShippingContactSelection","onshippingmethodselected","onShippingMethodSelected","shippingMethodUpdate","completeShippingMethodSelection","oncouponcodechanged","onCouponCodeChanged","couponCodeUpdate","completeCouponCodeChange","oncancel","onCancel","constructor","paymentRequest","_define_property","ApplePaySession","version"],"mappings":"wHAkBA,MAAMA,EAiDFC,KAAAA,GACI,OAAOC,KAAKC,QAAQF,OACxB,CASAG,kBAAAA,CAAmBC,EAAiDC,GAChE,OAAO,IAAIC,QAAQ,CAACC,EAASC,KACpBH,EAAmBE,EAASC,EAAQJ,EAAMK,iBAE9CC,KAAKC,IACFV,K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B,GAH/D0B,EAAA1C,KAAQC,kBACRyC,EAAA1C,KAAiBgB,kBAGbhB,KAAKgB,QAAUA,EAEfhB,KAAKC,QAAU,IAAI0C,gBAAgB3B,EAAQ4B,QAASH,GACpDzC,KAAKC,QAAQC,mBAAqBC,IACzBH,KAAKE,mBAAmBC,EAAOa,EAAQZ,qBAEhDJ,KAAKC,QAAQiB,oBAAsBf,IAC1BH,KAAKkB,oBAAoBf,EAAOa,EAAQG,sBAGjDnB,KAAKC,QAAQqC,SAAWnC,IACpBH,KAAKsC,SAASnC,EAAOa,EAAQuB,WAGc,mBAApCvB,EAAQO,0BACfvB,KAAKC,QAAQqB,wBAA0BnB,IAC9BH,KAAKsB,wBAAwBnB,EAAOa,EAAQO,2BAIR,mBAAtCP,EAAQW,4BACf3B,KAAKC,QAAQyB,0BAA4BvB,IAChCH,KAAK0B,0BAA0BvB,EAAOa,EAAQW,6BAIX,mBAArCX,EAAQe,2BACf/B,KAAKC,QAAQ6B,yBAA2B3B,IAC/BH,KAAK8B,yBAAyB3B,EAAOa,EAAQe,4BAIf,mBAAhCf,EAAQmB,sBACfnC,KAAKC,QAAQiC,oBAAsB/B,IAC1BH,KAAKkC,oBAAoB/B,EAAOa,EAAQmB,sBAGzD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{getDecimalAmount as t}from"../../../utils/amount-util.js";const e=e=>{const{countryCode:i,companyName:
|
|
1
|
+
import{getDecimalAmount as t}from"../../../utils/amount-util.js";const e=e=>{const{countryCode:i,companyName:o,amount:n,...p}=e,r=(e=>String(t(e.value,e.currency)))(n);return i||console.warn("Apple Pay - Make sure to set the countryCode in the AdyenCheckout configuration or in the Checkout Session creation"),{countryCode:i,currencyCode:n.currency,total:{label:p.totalPriceLabel,amount:r,type:p.totalPriceStatus},lineItems:p.lineItems,shippingContactEditingMode:p.shippingContactEditingMode,shippingMethods:p.shippingMethods,shippingType:p.shippingType,recurringPaymentRequest:p.recurringPaymentRequest,merchantCapabilities:p.merchantCapabilities,supportedCountries:p.supportedCountries,supportedNetworks:p.supportedNetworks,requiredShippingContactFields:p.requiredShippingContactFields,requiredBillingContactFields:p.requiredBillingContactFields,billingContact:p.billingContact,shippingContact:p.shippingContact,applicationData:p.applicationData,couponCode:p.couponCode,supportsCouponCode:p.supportsCouponCode}};export{e as preparePaymentRequest};
|
|
2
2
|
//# sourceMappingURL=payment-request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment-request.js","sources":["../../../../../src/components/ApplePay/utils/payment-request.ts"],"sourcesContent":["import { getDecimalAmount } from '../../../utils/amount-util';\nimport { PaymentAmount } from '../../../types/global-types';\nimport { ApplePayConfiguration } from '../types';\n\nconst formatAmount = (amount: PaymentAmount) => String(getDecimalAmount(amount.value, amount.currency));\n\nexport const preparePaymentRequest = (\n paymentRequest: ApplePayConfiguration & {\n countryCode: string;\n companyName: string;\n }\n): ApplePayJS.ApplePayPaymentRequest => {\n const { countryCode, companyName, amount, ...props } = paymentRequest;\n const formattedAmount = formatAmount(amount);\n\n if (!countryCode) {\n console.warn('Apple Pay - Make sure to set the countryCode in the AdyenCheckout configuration or in the Checkout Session creation');\n }\n\n return {\n countryCode,\n currencyCode: amount.currency,\n\n total: {\n label: props.totalPriceLabel,\n amount: formattedAmount,\n type: props.totalPriceStatus\n },\n\n lineItems: props.lineItems,\n shippingContactEditingMode: props.shippingContactEditingMode,\n shippingMethods: props.shippingMethods,\n shippingType: props.shippingType,\n\n recurringPaymentRequest: props.recurringPaymentRequest,\n\n merchantCapabilities: props.merchantCapabilities,\n supportedCountries: props.supportedCountries,\n supportedNetworks: props.supportedNetworks,\n\n requiredShippingContactFields: props.requiredShippingContactFields,\n requiredBillingContactFields: props.requiredBillingContactFields,\n\n billingContact: props.billingContact,\n shippingContact: props.shippingContact,\n\n applicationData: props.applicationData\n };\n};\n\nexport default preparePaymentRequest;\n"],"names":["preparePaymentRequest","paymentRequest","countryCode","companyName","amount","props","formattedAmount","String","getDecimalAmount","value","currency","formatAmount","console","warn","currencyCode","total","label","totalPriceLabel","type","totalPriceStatus","lineItems","shippingContactEditingMode","shippingMethods","shippingType","recurringPaymentRequest","merchantCapabilities","supportedCountries","supportedNetworks","requiredShippingContactFields","requiredBillingContactFields","billingContact","shippingContact","applicationData"],"mappings":"iEAIA,MAEaA,EACTC,IAKA,MAAMC,YAAEA,EAAWC,YAAEA,EAAWC,OAAEA,KAAWC,GAAUJ,EACjDK,EATW,CAACF,GAA0BG,OAAOC,EAAiBJ,EAAOK,MAAOL,EAAOM,WASjEC,CAAaP,GAMrC,OAJKF,GACDU,QAAQC,KAAK,uHAGV,CACHX,cACAY,aAAcV,EAAOM,SAErBK,MAAO,CACHC,MAAOX,EAAMY,gBACbb,OAAQE,EACRY,KAAMb,EAAMc,kBAGhBC,UAAWf,EAAMe,UACjBC,2BAA4BhB,EAAMgB,2BAClCC,gBAAiBjB,EAAMiB,gBACvBC,aAAclB,EAAMkB,aAEpBC,wBAAyBnB,EAAMmB,wBAE/BC,qBAAsBpB,EAAMoB,qBAC5BC,mBAAoBrB,EAAMqB,mBAC1BC,kBAAmBtB,EAAMsB,kBAEzBC,8BAA+BvB,EAAMuB,8BACrCC,6BAA8BxB,EAAMwB,6BAEpCC,eAAgBzB,EAAMyB,eACtBC,gBAAiB1B,EAAM0B,gBAEvBC,gBAAiB3B,EAAM2B"}
|
|
1
|
+
{"version":3,"file":"payment-request.js","sources":["../../../../../src/components/ApplePay/utils/payment-request.ts"],"sourcesContent":["import { getDecimalAmount } from '../../../utils/amount-util';\nimport { PaymentAmount } from '../../../types/global-types';\nimport { ApplePayConfiguration } from '../types';\n\nconst formatAmount = (amount: PaymentAmount) => String(getDecimalAmount(amount.value, amount.currency));\n\nexport const preparePaymentRequest = (\n paymentRequest: ApplePayConfiguration & {\n countryCode: string;\n companyName: string;\n }\n): ApplePayJS.ApplePayPaymentRequest => {\n const { countryCode, companyName, amount, ...props } = paymentRequest;\n const formattedAmount = formatAmount(amount);\n\n if (!countryCode) {\n console.warn('Apple Pay - Make sure to set the countryCode in the AdyenCheckout configuration or in the Checkout Session creation');\n }\n\n return {\n countryCode,\n currencyCode: amount.currency,\n\n total: {\n label: props.totalPriceLabel,\n amount: formattedAmount,\n type: props.totalPriceStatus\n },\n\n lineItems: props.lineItems,\n shippingContactEditingMode: props.shippingContactEditingMode,\n shippingMethods: props.shippingMethods,\n shippingType: props.shippingType,\n\n recurringPaymentRequest: props.recurringPaymentRequest,\n\n merchantCapabilities: props.merchantCapabilities,\n supportedCountries: props.supportedCountries,\n supportedNetworks: props.supportedNetworks,\n\n requiredShippingContactFields: props.requiredShippingContactFields,\n requiredBillingContactFields: props.requiredBillingContactFields,\n\n billingContact: props.billingContact,\n shippingContact: props.shippingContact,\n\n applicationData: props.applicationData,\n\n couponCode: props.couponCode,\n supportsCouponCode: props.supportsCouponCode\n };\n};\n\nexport default preparePaymentRequest;\n"],"names":["preparePaymentRequest","paymentRequest","countryCode","companyName","amount","props","formattedAmount","String","getDecimalAmount","value","currency","formatAmount","console","warn","currencyCode","total","label","totalPriceLabel","type","totalPriceStatus","lineItems","shippingContactEditingMode","shippingMethods","shippingType","recurringPaymentRequest","merchantCapabilities","supportedCountries","supportedNetworks","requiredShippingContactFields","requiredBillingContactFields","billingContact","shippingContact","applicationData","couponCode","supportsCouponCode"],"mappings":"iEAIA,MAEaA,EACTC,IAKA,MAAMC,YAAEA,EAAWC,YAAEA,EAAWC,OAAEA,KAAWC,GAAUJ,EACjDK,EATW,CAACF,GAA0BG,OAAOC,EAAiBJ,EAAOK,MAAOL,EAAOM,WASjEC,CAAaP,GAMrC,OAJKF,GACDU,QAAQC,KAAK,uHAGV,CACHX,cACAY,aAAcV,EAAOM,SAErBK,MAAO,CACHC,MAAOX,EAAMY,gBACbb,OAAQE,EACRY,KAAMb,EAAMc,kBAGhBC,UAAWf,EAAMe,UACjBC,2BAA4BhB,EAAMgB,2BAClCC,gBAAiBjB,EAAMiB,gBACvBC,aAAclB,EAAMkB,aAEpBC,wBAAyBnB,EAAMmB,wBAE/BC,qBAAsBpB,EAAMoB,qBAC5BC,mBAAoBrB,EAAMqB,mBAC1BC,kBAAmBtB,EAAMsB,kBAEzBC,8BAA+BvB,EAAMuB,8BACrCC,6BAA8BxB,EAAMwB,6BAEpCC,eAAgBzB,EAAMyB,eACtBC,gBAAiB1B,EAAM0B,gBAEvBC,gBAAiB3B,EAAM2B,gBAEvBC,WAAY5B,EAAM4B,WAClBC,mBAAoB7B,EAAM6B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={test:"https://checkoutshopper-test.adyen.com/checkoutshopper/",live:"https://checkoutshopper-live.adyen.com/checkoutshopper/","live-us":"https://checkoutshopper-live-us.adyen.com/checkoutshopper/","live-au":"https://checkoutshopper-live-au.adyen.com/checkoutshopper/","live-apse":"https://checkoutshopper-live-apse.adyen.com/checkoutshopper/","live-in":"https://checkoutshopper-live-in.adyen.com/checkoutshopper/",fallback:"https://checkoutshopper-live.adyen.com/checkoutshopper/"},c={test:"https://checkoutshopper-test.cdn.adyen.com/checkoutshopper/",live:"https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/","live-us":"https://checkoutshopper-live-us.cdn.adyen.com/checkoutshopper/","live-au":"https://checkoutshopper-live-au.cdn.adyen.com/checkoutshopper/","live-apse":"https://checkoutshopper-live-apse.cdn.adyen.com/checkoutshopper/","live-in":"https://checkoutshopper-live-in.cdn.adyen.com/checkoutshopper/",fallback:"https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/"},t={test:"https://checkoutanalytics-test.adyen.com/checkoutanalytics/",live:"https://checkoutanalytics-live.adyen.com/checkoutanalytics/","live-us":"https://checkoutanalytics-live-us.adyen.com/checkoutanalytics/","live-au":"https://checkoutanalytics-live-au.adyen.com/checkoutanalytics/","live-apse":"https://checkoutanalytics-live-apse.adyen.com/checkoutanalytics/","live-in":"https://checkoutanalytics-live-in.adyen.com/checkoutanalytics/",fallback:"https://checkoutanalytics-live.adyen.com/checkoutanalytics/"};export{t as ANALYTICS_ENVIRONMENTS,e as API_ENVIRONMENTS,c as CDN_ENVIRONMENTS};
|
|
1
|
+
const e={test:"https://checkoutshopper-test.adyen.com/checkoutshopper/",live:"https://checkoutshopper-live.adyen.com/checkoutshopper/","live-us":"https://checkoutshopper-live-us.adyen.com/checkoutshopper/","live-au":"https://checkoutshopper-live-au.adyen.com/checkoutshopper/","live-apse":"https://checkoutshopper-live-apse.adyen.com/checkoutshopper/","live-in":"https://checkoutshopper-live-in.adyen.com/checkoutshopper/","live-nea":"https://checkoutshopper-live-nea.adyen.com/checkoutshopper/",fallback:"https://checkoutshopper-live.adyen.com/checkoutshopper/"},c={test:"https://checkoutshopper-test.cdn.adyen.com/checkoutshopper/",live:"https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/","live-us":"https://checkoutshopper-live-us.cdn.adyen.com/checkoutshopper/","live-au":"https://checkoutshopper-live-au.cdn.adyen.com/checkoutshopper/","live-apse":"https://checkoutshopper-live-apse.cdn.adyen.com/checkoutshopper/","live-in":"https://checkoutshopper-live-in.cdn.adyen.com/checkoutshopper/","live-nea":"https://checkoutshopper-live-nea.cdn.adyen.com/checkoutshopper/",fallback:"https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/"},t={test:"https://checkoutanalytics-test.adyen.com/checkoutanalytics/",live:"https://checkoutanalytics-live.adyen.com/checkoutanalytics/","live-us":"https://checkoutanalytics-live-us.adyen.com/checkoutanalytics/","live-au":"https://checkoutanalytics-live-au.adyen.com/checkoutanalytics/","live-apse":"https://checkoutanalytics-live-apse.adyen.com/checkoutanalytics/","live-in":"https://checkoutanalytics-live-in.adyen.com/checkoutanalytics/","live-nea":"https://checkoutanalytics-live-nea.adyen.com/checkoutanalytics/",fallback:"https://checkoutanalytics-live.adyen.com/checkoutanalytics/"};export{t as ANALYTICS_ENVIRONMENTS,e as API_ENVIRONMENTS,c as CDN_ENVIRONMENTS};
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../src/core/Environment/constants.ts"],"sourcesContent":["const API_ENVIRONMENTS = {\n test: 'https://checkoutshopper-test.adyen.com/checkoutshopper/',\n live: 'https://checkoutshopper-live.adyen.com/checkoutshopper/',\n 'live-us': 'https://checkoutshopper-live-us.adyen.com/checkoutshopper/',\n 'live-au': 'https://checkoutshopper-live-au.adyen.com/checkoutshopper/',\n 'live-apse': 'https://checkoutshopper-live-apse.adyen.com/checkoutshopper/',\n 'live-in': 'https://checkoutshopper-live-in.adyen.com/checkoutshopper/',\n fallback: 'https://checkoutshopper-live.adyen.com/checkoutshopper/'\n};\n\nconst CDN_ENVIRONMENTS = {\n test: 'https://checkoutshopper-test.cdn.adyen.com/checkoutshopper/',\n live: 'https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/',\n 'live-us': 'https://checkoutshopper-live-us.cdn.adyen.com/checkoutshopper/',\n 'live-au': 'https://checkoutshopper-live-au.cdn.adyen.com/checkoutshopper/',\n 'live-apse': 'https://checkoutshopper-live-apse.cdn.adyen.com/checkoutshopper/',\n 'live-in': 'https://checkoutshopper-live-in.cdn.adyen.com/checkoutshopper/',\n fallback: 'https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/'\n};\n\nconst ANALYTICS_ENVIRONMENTS = {\n test: 'https://checkoutanalytics-test.adyen.com/checkoutanalytics/',\n live: 'https://checkoutanalytics-live.adyen.com/checkoutanalytics/',\n 'live-us': 'https://checkoutanalytics-live-us.adyen.com/checkoutanalytics/',\n 'live-au': 'https://checkoutanalytics-live-au.adyen.com/checkoutanalytics/',\n 'live-apse': 'https://checkoutanalytics-live-apse.adyen.com/checkoutanalytics/',\n 'live-in': 'https://checkoutanalytics-live-in.adyen.com/checkoutanalytics/',\n fallback: 'https://checkoutanalytics-live.adyen.com/checkoutanalytics/'\n};\n\nexport { API_ENVIRONMENTS, CDN_ENVIRONMENTS, ANALYTICS_ENVIRONMENTS };\n"],"names":["API_ENVIRONMENTS","test","live","fallback","CDN_ENVIRONMENTS","ANALYTICS_ENVIRONMENTS"],"mappings":"AAAA,MAAMA,EAAmB,CACrBC,KAAM,0DACNC,KAAM,0DACN,UAAW,6DACX,UAAW,6DACX,YAAa,+DACb,UAAW,
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/core/Environment/constants.ts"],"sourcesContent":["const API_ENVIRONMENTS = {\n test: 'https://checkoutshopper-test.adyen.com/checkoutshopper/',\n live: 'https://checkoutshopper-live.adyen.com/checkoutshopper/',\n 'live-us': 'https://checkoutshopper-live-us.adyen.com/checkoutshopper/',\n 'live-au': 'https://checkoutshopper-live-au.adyen.com/checkoutshopper/',\n 'live-apse': 'https://checkoutshopper-live-apse.adyen.com/checkoutshopper/',\n 'live-in': 'https://checkoutshopper-live-in.adyen.com/checkoutshopper/',\n 'live-nea': 'https://checkoutshopper-live-nea.adyen.com/checkoutshopper/',\n fallback: 'https://checkoutshopper-live.adyen.com/checkoutshopper/'\n};\n\nconst CDN_ENVIRONMENTS = {\n test: 'https://checkoutshopper-test.cdn.adyen.com/checkoutshopper/',\n live: 'https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/',\n 'live-us': 'https://checkoutshopper-live-us.cdn.adyen.com/checkoutshopper/',\n 'live-au': 'https://checkoutshopper-live-au.cdn.adyen.com/checkoutshopper/',\n 'live-apse': 'https://checkoutshopper-live-apse.cdn.adyen.com/checkoutshopper/',\n 'live-in': 'https://checkoutshopper-live-in.cdn.adyen.com/checkoutshopper/',\n 'live-nea': 'https://checkoutshopper-live-nea.cdn.adyen.com/checkoutshopper/',\n fallback: 'https://checkoutshopper-live.cdn.adyen.com/checkoutshopper/'\n};\n\nconst ANALYTICS_ENVIRONMENTS = {\n test: 'https://checkoutanalytics-test.adyen.com/checkoutanalytics/',\n live: 'https://checkoutanalytics-live.adyen.com/checkoutanalytics/',\n 'live-us': 'https://checkoutanalytics-live-us.adyen.com/checkoutanalytics/',\n 'live-au': 'https://checkoutanalytics-live-au.adyen.com/checkoutanalytics/',\n 'live-apse': 'https://checkoutanalytics-live-apse.adyen.com/checkoutanalytics/',\n 'live-in': 'https://checkoutanalytics-live-in.adyen.com/checkoutanalytics/',\n 'live-nea': 'https://checkoutanalytics-live-nea.adyen.com/checkoutanalytics/',\n fallback: 'https://checkoutanalytics-live.adyen.com/checkoutanalytics/'\n};\n\nexport { API_ENVIRONMENTS, CDN_ENVIRONMENTS, ANALYTICS_ENVIRONMENTS };\n"],"names":["API_ENVIRONMENTS","test","live","fallback","CDN_ENVIRONMENTS","ANALYTICS_ENVIRONMENTS"],"mappings":"AAAA,MAAMA,EAAmB,CACrBC,KAAM,0DACNC,KAAM,0DACN,UAAW,6DACX,UAAW,6DACX,YAAa,+DACb,UAAW,6DACX,WAAY,8DACZC,SAAU,2DAGRC,EAAmB,CACrBH,KAAM,8DACNC,KAAM,8DACN,UAAW,iEACX,UAAW,iEACX,YAAa,mEACb,UAAW,iEACX,WAAY,kEACZC,SAAU,+DAGRE,EAAyB,CAC3BJ,KAAM,8DACNC,KAAM,8DACN,UAAW,iEACX,UAAW,iEACX,YAAa,mEACb,UAAW,iEACX,WAAY,kEACZC,SAAU"}
|
package/dist/es/core/config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e="https://checkoutshopper-live.adyen.com/checkoutshopper/",n="6.
|
|
1
|
+
const e="https://checkoutshopper-live.adyen.com/checkoutshopper/",n="6.33.0",o="esm",t=["amount","secondaryAmount","countryCode","environment","_environmentUrls","loadingContext","i18n","modules","order","session","clientKey","showPayButton","redirectFromTopWhenInIframe","onPaymentCompleted","onPaymentFailed","beforeRedirect","beforeSubmit","onSubmit","onActionHandled","onAdditionalDetails","onChange","onEnterKeyPressed","onError","onBalanceCheck","onOrderCancel","onOrderRequest","onOrderUpdated","onPaymentMethodsRequest"],r=6e4;export{r as DEFAULT_HTTP_TIMEOUT,e as FALLBACK_CONTEXT,t as GENERIC_OPTIONS,o as LIBRARY_BUNDLE_TYPE,n as LIBRARY_VERSION};
|
|
2
2
|
//# sourceMappingURL=config.js.map
|
package/dist/es/index.d.ts
CHANGED
|
@@ -849,12 +849,12 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
849
849
|
/**
|
|
850
850
|
* The Apple Pay version number your website supports.
|
|
851
851
|
* @default highest supported version by the shopper device
|
|
852
|
-
* @see {@link https://developer.apple.com/documentation/
|
|
852
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/apple-pay-on-the-web-version-history Apple Pay on the Web Version History}
|
|
853
853
|
*/
|
|
854
854
|
version?: number;
|
|
855
855
|
/**
|
|
856
856
|
* Part of the 'ApplePayLineItem' object, which sets the label of the payment request
|
|
857
|
-
* @see {@link https://developer.apple.com/documentation/
|
|
857
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaylineitem ApplePayLineItem docs}
|
|
858
858
|
*/
|
|
859
859
|
totalPriceLabel?: string;
|
|
860
860
|
/**
|
|
@@ -908,7 +908,7 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
908
908
|
supportedNetworks?: string[];
|
|
909
909
|
/**
|
|
910
910
|
* ApplePayRecurringPaymentRequest - Represents a request to set up a recurring payment, typically a subscription.
|
|
911
|
-
* {@link https://developer.apple.com/documentation/
|
|
911
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepayrecurringpaymentrequest}
|
|
912
912
|
*/
|
|
913
913
|
recurringPaymentRequest?: ApplePayJS.ApplePayRecurringPaymentRequest;
|
|
914
914
|
/**
|
|
@@ -973,7 +973,7 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
973
973
|
* Collect the order tracking details if available.
|
|
974
974
|
* This callback is invoked when a successfull payment is resolved
|
|
975
975
|
*
|
|
976
|
-
* {@link https://developer.apple.com/documentation/
|
|
976
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepaypaymentorderdetails}
|
|
977
977
|
* @param resolve - Must be called with the orderDetails fields
|
|
978
978
|
* @param reject - Must be called if something failed during the order creation. Calling 'reject' won't cancel the payment flow
|
|
979
979
|
*/
|
|
@@ -1014,6 +1014,25 @@ interface ApplePayConfiguration extends UIElementProps {
|
|
|
1014
1014
|
* @param event - The event parameter contains the shippingMethod attribute.
|
|
1015
1015
|
*/
|
|
1016
1016
|
onShippingMethodSelected?: (resolve: (shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => void, reject: (shippingMethodUpdate: ApplePayJS.ApplePayShippingMethodUpdate) => void, event: ApplePayJS.ApplePayShippingMethodSelectedEvent) => void;
|
|
1017
|
+
/**
|
|
1018
|
+
* The initial coupon code for the payment request.
|
|
1019
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaypaymentrequest/couponcode couponCode docs}
|
|
1020
|
+
*/
|
|
1021
|
+
couponCode?: ApplePayJS.ApplePayPaymentRequest['couponCode'];
|
|
1022
|
+
/**
|
|
1023
|
+
* A Boolean value that determines whether the payment sheet displays the coupon code field.
|
|
1024
|
+
* @see {@link https://developer.apple.com/documentation/applepayontheweb/applepaypaymentrequest/supportscouponcode supportsCouponCode docs}
|
|
1025
|
+
*/
|
|
1026
|
+
supportsCouponCode?: ApplePayJS.ApplePayPaymentRequest['supportsCouponCode'];
|
|
1027
|
+
/**
|
|
1028
|
+
* An event handler called by the system when the user enters or updates a coupon code.
|
|
1029
|
+
*
|
|
1030
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/oncouponcodechanged}
|
|
1031
|
+
* @param resolve - Completes the change of a coupon code with an update.
|
|
1032
|
+
* @param reject - Completes the change of a coupon code with no update.
|
|
1033
|
+
* @param event - The event parameter contains the couponCode attribute.
|
|
1034
|
+
*/
|
|
1035
|
+
onCouponCodeChanged?: (resolve: (update: ApplePayJS.ApplePayCouponCodeUpdate) => void, reject: (update: ApplePayJS.ApplePayCouponCodeUpdate) => void, event: ApplePayJS.ApplePayCouponCodeChangedEvent) => void;
|
|
1017
1036
|
buttonColor?: ApplePayButtonStyle;
|
|
1018
1037
|
buttonType?: ApplePayButtonType;
|
|
1019
1038
|
/**
|
|
@@ -3646,7 +3665,7 @@ declare class ApplePayElement extends UIElement<ApplePayConfiguration> {
|
|
|
3646
3665
|
* not mean there are no cards available, it means the status cannot be determined and as such defaulting
|
|
3647
3666
|
* and upstreaming should still be considered.
|
|
3648
3667
|
*
|
|
3649
|
-
* {@link https://developer.apple.com/documentation/
|
|
3668
|
+
* {@link https://developer.apple.com/documentation/applepayontheweb/applepaysession/4440085-applepaycapabilities}
|
|
3650
3669
|
* @param merchantIdentifier
|
|
3651
3670
|
*/
|
|
3652
3671
|
applePayCapabilities(merchantIdentifier?: string): Promise<ApplePayJS.PaymentCredentialStatusResponse>;
|
|
@@ -6139,7 +6158,7 @@ interface CoreConfiguration {
|
|
|
6139
6158
|
/**
|
|
6140
6159
|
* Use 'test'. When you're ready to accept live payments, change the value to one of our {@link https://docs.adyen.com/checkout/drop-in-web#testing-your-integration | live environments}.
|
|
6141
6160
|
*/
|
|
6142
|
-
environment?: 'test' | 'live' | 'live-us' | 'live-au' | 'live-apse' | 'live-in';
|
|
6161
|
+
environment?: 'test' | 'live' | 'live-us' | 'live-au' | 'live-apse' | 'live-in' | 'live-nea';
|
|
6143
6162
|
/**
|
|
6144
6163
|
* Show or hides a Pay Button for each payment method
|
|
6145
6164
|
* @default true
|
|
@@ -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 o from"./components/ApplePayButton.js";import
|
|
1
|
+
import{createElement as e}from"../../external/preact/dist/preact.js";import{UIElement as t}from"../internal/UIElement/UIElement.js";import o from"./components/ApplePayButton.js";import n from"./services/ApplePayService.js";import s from"../../utils/base64.js";import r from"./defaultProps.js";import{httpPost as i}from"../../core/Services/http.js";import{preparePaymentRequest as a}from"./utils/payment-request.js";import p from"../../core/Errors/AdyenCheckoutError.js";import{TxVariants as l}from"../tx-variants.js";import{sanitizeResponse as d,verifyPaymentDidNotFail as c}from"../internal/UIElement/utils.js";import{resolveSupportedVersion as h}from"./utils/resolve-supported-version.js";import{formatApplePayContactToAdyenAddressFormat as u}from"./utils/format-applepay-contact-to-adyen-format.js";import{mapBrands as y}from"./utils/map-adyen-brands-to-applepay-brands.js";import m from"./services/ApplePaySdkLoader.js";import{detectInIframe as P}from"../../utils/detectInIframe.js";import{AnalyticsInfoEvent as b,InfoEventType as f,UiTarget as A}from"../../core/Analytics/events/AnalyticsInfoEvent.js";function g(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function v(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{},n=Object.keys(o);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(o).filter(function(e){return Object.getOwnPropertyDescriptor(o,e).enumerable}))),n.forEach(function(t){g(e,t,o[t])})}return e}function w(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t.push.apply(t,o)}return t}(Object(t)).forEach(function(o){Object.defineProperty(e,o,Object.getOwnPropertyDescriptor(t,o))}),e}class S extends t{formatProps(e){var t,o,n,s,r;const i=(null===(n=e.brands)||void 0===n?void 0:n.length)?y(e.brands):e.supportedNetworks;return w(v({},e),{configuration:e.configuration,supportedNetworks:i,buttonLocale:null!==(t=e.buttonLocale)&&void 0!==t?t:null===(s=e.i18n)||void 0===s?void 0:s.locale,totalPriceLabel:e.totalPriceLabel||(null===(r=e.configuration)||void 0===r?void 0:r.merchantName),renderApplePayCodeAs:null!==(o=e.renderApplePayCodeAs)&&void 0!==o?o:P()?"window":"modal"})}formatData(){const{applePayToken:e,billingAddress:t,deliveryAddress:o}=this.state,{isExpress:n}=this.props;return v({paymentMethod:v({type:S.type,applePayToken:e},n&&{subtype:"express"})},t&&{billingAddress:t},o&&{deliveryAddress:o})}beforeRender(e){const t=new b(v({type:f.rendered,component:this.type,configData:w(v({},e),{showPayButton:this.props.showPayButton})},(null==e?void 0:e.isExpress)&&{isExpress:e.isExpress},(null==e?void 0:e.expressPage)&&{expressPage:e.expressPage}));this.analytics.sendAnalytics(t)}get isValid(){return!0}async applePayCapabilities(e){const t=e||this.props.configuration.merchantId;try{var o;return await this.sdkLoader.isSdkLoaded(),await(null===(o=ApplePaySession)||void 0===o?void 0:o.applePayCapabilities(t))}catch(e){throw new p("ERROR","Apple Pay: Error when requesting applePayCapabilities()",{cause:e})}}async isAvailable(){if("https:"!==window.location.protocol)return Promise.reject(new p("IMPLEMENTATION_ERROR","Trying to start an Apple Pay session from an insecure document"));try{var e;return await this.sdkLoader.isSdkLoaded(),(null===(e=ApplePaySession)||void 0===e?void 0:e.canMakePayments())?Promise.resolve():Promise.reject(new p("ERROR","Apple Pay is not available on this device"))}catch(e){return Promise.reject(new p("ERROR","Apple Pay SDK failed to load",{cause:e}))}}defineApplePayVersionNumber(){"https:"===window.location.protocol&&(this.applePayVersionNumber=this.props.version||h(14))}configureApplePayWebOptions(){if(window.ApplePayWebOptions){const{renderApplePayCodeAs:e,onApplePayCodeClose:t}=this.props;window.ApplePayWebOptions.set(v({renderApplePayCodeAs:e},t&&{onApplePayCodeClose:t}))}}startSession(){const{onValidateMerchant:e,onPaymentMethodSelected:t,onShippingMethodSelected:o,onShippingContactSelected:s,onCouponCodeChanged:r}=this.props,i=a(v({companyName:this.props.configuration.merchantName,countryCode:this.core.options.countryCode},this.props)),l=new n(i,{version:this.applePayVersionNumber,onError:e=>{this.handleError(new p("ERROR","ApplePay - Something went wrong on ApplePayService",{cause:e}))},onCancel:e=>{this.handleError(new p("CANCEL","ApplePay UI dismissed",{cause:e}))},onPaymentMethodSelected:t,onShippingMethodSelected:o,onShippingContactSelected:s,onCouponCodeChanged:r,onValidateMerchant:e||this.validateMerchant,onPaymentAuthorized:(e,t,o)=>{const n=u(o.payment.billingContact),s=u(o.payment.shippingContact,!0);this.setState(v({applePayToken:btoa(JSON.stringify(o.payment.token.paymentData)),authorizedEvent:o},n&&{billingAddress:n},s&&{deliveryAddress:s})),this.handleAuthorization().then(this.makePaymentsCall).then(d).then(c).then(this.collectOrderTrackingDetailsIfNeeded).then(({paymentResponse:t,orderDetails:o})=>(e(v({status:ApplePaySession.STATUS_SUCCESS},o&&{orderDetails:o})),t)).then(e=>{this.handleResponse(e)}).catch(e=>{var o;const n=null==e||null===(o=e.error)||void 0===o?void 0:o.applePayError;t({status:ApplePaySession.STATUS_FAILURE,errors:n?Array.isArray(n)?n:[n]:void 0});const s=w(v({},e),{error:{applePayError:n}});this.handleFailedResult(s)})}});return new Promise((e,t)=>this.props.onClick(e,t)).then(()=>{l.begin()}).catch(()=>({}))}async handleAuthorization(){return new Promise((e,t)=>{this.props.onAuthorized||e();const{authorizedEvent:o,billingAddress:n,deliveryAddress:s}=this.state;this.props.onAuthorized(v({authorizedEvent:o},n&&{billingAddress:n},s&&{deliveryAddress:s}),{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=>v({paymentResponse:e},t&&{orderDetails:t})).catch(()=>({paymentResponse:e}))}async validateMerchant(e,t){const{hostname:o}=window.location,{clientKey:n,configuration:r,loadingContext:a,initiative:p,domainName:l}=this.props,{merchantName:d,merchantId:c}=r,h={loadingContext:a,path:`v1/applePay/sessions?clientKey=${n}`},u={displayName:d,domainName:l||o,initiative:p,merchantIdentifier:c};try{const o=await i(h,u),n=s.decode(o.data);if(n.success){e(JSON.parse(n.data))}else t("Could not decode Apple Pay session")}catch(e){t("Could not get Apple Pay session")}}componentToRender(){return this.props.showPayButton?e(o,{buttonStyle:this.props.buttonColor,buttonType:this.props.buttonType,buttonLocale:this.props.buttonLocale,onClick:this.submit}):null}constructor(e,t){super(e,t),g(this,"sdkLoader",void 0),g(this,"applePayVersionNumber",void 0),g(this,"submit",()=>{if(this.props.isInstantPayment){const e=new b({component:this.type,type:f.selected,target:A.instantPaymentButton});this.submitAnalytics(e)}this.startSession()});const{isExpress:o,onShippingContactSelected:n,onShippingMethodSelected:s}=this.props;if(!1===o&&(n||s))throw new p("IMPLEMENTATION_ERROR",'ApplePay - You must set "isExpress" flag to "true" in order to use "onShippingContactSelected" and/or "onShippingMethodSelected" callbacks');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),this.defineApplePayVersionNumber=this.defineApplePayVersionNumber.bind(this),this.configureApplePayWebOptions=this.configureApplePayWebOptions.bind(this),this.sdkLoader=new m({analytics:this.analytics}),this.sdkLoader.load().then(this.defineApplePayVersionNumber).then(this.configureApplePayWebOptions).catch(e=>{this.handleError(e)})}}g(S,"type",l.applepay),g(S,"defaultProps",r);export{S as default};
|
|
2
2
|
//# sourceMappingURL=ApplePay.js.map
|