google.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. window.addEventListener('appMessage', function(e) {
  2. const {
  3. type,
  4. ...payData
  5. } = e.detail;
  6. if (type == 'pay') {
  7. init(payData)
  8. }
  9. });
  10. function init(payData) {
  11. try {
  12. Airwallex.init({
  13. env: 'prod',
  14. origin: window.location.origin,
  15. });
  16. console.log(JSON.stringify(payData), '???');
  17. const googlepay = Airwallex.createElement('googlePayButton', {
  18. ...payData
  19. });
  20. const domElement = googlepay.mount('googlepay');
  21. domElement.addEventListener('onError', (event) => {
  22. const {
  23. error
  24. } = event.detail;
  25. console.error('There was an error', JSON.stringify(error));
  26. });
  27. domElement.addEventListener('onSuccess', (event) => {
  28. console.log('----12321---',JSON.stringify(event));
  29. location.href = `callback?str=${escape(JSON.stringify({ label: 'success', text: event }))}`
  30. });
  31. } catch (error) {
  32. console.error('渲染失败', JSON.stringify(error));
  33. }
  34. }
  35. // // 给App发消息
  36. // setTimeout(() => {
  37. // location.href = `callback?str=${escape(JSON.stringify({ label: 'success', text: `向vue页面发送消息` }))}`
  38. // }, 1000);