window.addEventListener('appMessage', function(e) {
	const {
		type,
		...payData
	} = e.detail;
	if (type == 'pay') {
		init(payData)
	}
});

function init(payData) {
	try {
		Airwallex.init({
			env: 'prod',
			origin: window.location.origin,
		});
		console.log(JSON.stringify(payData), '???');

		const googlepay = Airwallex.createElement('googlePayButton', {
			...payData
		});
		const domElement = googlepay.mount('googlepay');
		domElement.addEventListener('onError', (event) => {
			const {
				error
			} = event.detail;
			console.error('There was an error', JSON.stringify(error));
		});

		domElement.addEventListener('onSuccess', (event) => {
			console.log('----12321---',JSON.stringify(event));
			location.href = `callback?str=${escape(JSON.stringify({ label: 'success', text: event }))}`
		});
	} catch (error) {
		console.error('渲染失败', JSON.stringify(error));
	}
}

// // 给App发消息
// setTimeout(() => {
//   location.href = `callback?str=${escape(JSON.stringify({ label: 'success', text: `向vue页面发送消息` }))}`
// }, 1000);