Hpp.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <div>
  3. <h2>申泽智能</h2>
  4. <button @click="redirectHpp()">Redirect to HPP</button>
  5. </div>
  6. </template>
  7. <script>
  8. import { redirectToCheckout, loadAirwallex } from 'airwallex-payment-elements';
  9. import { useRoute } from "vue-router";
  10. export default {
  11. name: 'Hpp',
  12. setup() {
  13. const mode = 'payment';
  14. const route = useRoute();
  15. // const router = useRouter();
  16. console.log(route.query.intent_id)
  17. const redirectHppForCheckout = () => {
  18. redirectToCheckout({
  19. env: 'demo',
  20. mode,
  21. currency: route.query.currency,
  22. intent_id: route.query.intent_id,
  23. client_secret: route.query.client_secret,
  24. //主题
  25. theme: {
  26. fonts: [
  27. {
  28. src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',
  29. family: 'AxLLCircular',
  30. weight: 400,
  31. },
  32. ],
  33. },
  34. // successUrl: 'https://www.baidu.com', // 支付成功跳转页面
  35. // failUrl: 'https://www.baidu.com', // 支付失败跳转页面
  36. logoUrl: '', //支付页面展示商户LOGO
  37. });
  38. };
  39. const redirectHppForRecurring = () => {
  40. redirectToCheckout({
  41. env: 'demo',
  42. // mode,
  43. // currency,
  44. // client_secret,
  45. recurringOptions: {
  46. card: {
  47. next_triggered_by: 'customer',
  48. merchant_trigger_reason: 'scheduled',
  49. // currency,
  50. },
  51. },
  52. theme: {
  53. fonts: [
  54. {
  55. src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',
  56. family: 'AxLLCircular',
  57. weight: 400,
  58. },
  59. ],
  60. },
  61. // successUrl: 'https://www.google.com',
  62. // failUrl: 'https://www.google.com',
  63. });
  64. };
  65. loadAirwallex({
  66. env: 'demo', // Can choose other production environments, 'staging | 'demo' | 'prod'
  67. });
  68. const redirectHpp = async () => {
  69. try {
  70. await loadAirwallex({
  71. env: 'demo',
  72. });
  73. if (mode === 'payment') {
  74. redirectHppForCheckout();
  75. } else if (mode === 'recurring') {
  76. redirectHppForRecurring();
  77. }
  78. } catch (error) {
  79. window.alert('There was an error with HPP redirection', error);
  80. }
  81. };
  82. return {
  83. redirectHpp,
  84. redirectHppForCheckout,
  85. redirectHppForRecurring
  86. };
  87. }
  88. };
  89. /* const intent_id = this.$route.query.intent_id;
  90. const client_secret = 'replace-with-your-client-secret';
  91. const currency = 'replace-with-your-currency';
  92. const mode = 'payment';
  93. // console.log(this.intent_id);
  94. const redirectHppForCheckout = () => {
  95. redirectToCheckout({
  96. env: 'demo',
  97. mode,
  98. currency,
  99. intent_id,
  100. client_secret,
  101. //主题
  102. theme: {
  103. fonts: [
  104. {
  105. src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',
  106. family: 'AxLLCircular',
  107. weight: 400,
  108. },
  109. ],
  110. },
  111. successUrl: 'https://www.baidu.com', // 支付成功跳转页面
  112. failUrl: 'https://www.baidu.com', // 支付失败跳转页面
  113. logoUrl: '', //支付页面展示商户LOGO
  114. });
  115. };
  116. const redirectHppForRecurring = () => {
  117. redirectToCheckout({
  118. env: 'demo',
  119. mode,
  120. currency,
  121. client_secret,
  122. recurringOptions: {
  123. card: {
  124. next_triggered_by: 'customer',
  125. merchant_trigger_reason: 'scheduled',
  126. currency,
  127. },
  128. },
  129. theme: {
  130. fonts: [
  131. {
  132. src: 'https://checkout.airwallex.com/fonts/CircularXXWeb/CircularXXWeb-Regular.woff2',
  133. family: 'AxLLCircular',
  134. weight: 400,
  135. },
  136. ],
  137. },
  138. successUrl: 'https://www.google.com',
  139. failUrl: 'https://www.google.com',
  140. });
  141. };
  142. loadAirwallex({
  143. env: 'demo', // Can choose other production environments, 'staging | 'demo' | 'prod'
  144. });
  145. const redirectHpp = async () => {
  146. try {
  147. await loadAirwallex({
  148. env: 'demo',
  149. });
  150. if (mode === 'payment') {
  151. redirectHppForCheckout();
  152. } else if (mode === 'recurring') {
  153. redirectHppForRecurring();
  154. }
  155. } catch (error) {
  156. window.alert('There was an error with HPP redirection', error);
  157. }
  158. };
  159. export default {
  160. name: 'Hpp',
  161. data() {
  162. return {
  163. redirectHpp,
  164. msg: this.$route.query.intent_id,
  165. intent_id: this.$route.query.intent_id,
  166. client_secret: this.$route.query.client_secret,
  167. currency: this.$route.query.currency
  168. };
  169. },
  170. }; */
  171. </script>