You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

149 lines
3.5 KiB

2 years ago
  1. <template>
  2. <div>
  3. <div id="ECPayPayment"></div><br />
  4. <form action="" id="PayProcess" method="post">
  5. <div style="text-align: center;">
  6. <input id="PaymentType" name="PaymentType" type="hidden" value="" />
  7. </div>
  8. </form>
  9. </div>
  10. </template>
  11. <script>
  12. export default {
  13. head() {
  14. return {
  15. script: this.script
  16. }
  17. },
  18. props: {
  19. method: {
  20. type: String,
  21. },
  22. orderNo: {
  23. type: String
  24. }
  25. },
  26. data() {
  27. return {
  28. script: [
  29. {
  30. src:
  31. "https://code.jquery.com/jquery-3.5.1.min.js",
  32. body: true,
  33. type: "text/javascript",
  34. async: true,
  35. onload: this.jqueryOnload()
  36. },
  37. ],
  38. devECPayUrl: 'https://dev-lambda.showeasy.com',
  39. token: '',
  40. payToken: '',
  41. once: false,
  42. }
  43. },
  44. created() {
  45. this.getToken();
  46. },
  47. mounted() {
  48. // this.$nextTick(function () {
  49. // this.init();
  50. // })
  51. },
  52. methods: {
  53. getToken() {
  54. this.$axios
  55. .post(
  56. `${this.devECPayUrl}/payment/ecpay/token`, {
  57. payment_flow: "ecpay",
  58. product_order_no: this.orderNo,
  59. pay_price: 1200,
  60. prod_desc: "dev test",
  61. payer_email: "ss22333@gmail.com"
  62. }
  63. )
  64. .then((response) => {
  65. this.token = response.data.token;
  66. })
  67. .catch((error) => console.log(error));
  68. },
  69. init() {
  70. var vm = this;
  71. var Environment = 'STAGE'; //請設定要連線的環境: 測試 STAGE ,正式PROD
  72. var envi = vm.GetEnvi(Environment);
  73. var _token = vm.token; //請設定你取到的廠商驗證碼
  74. //初始化SDK畫面
  75. if (!vm.once) {
  76. ECPay.initialize(envi, 1, function (errMsg) {
  77. // if (_token === '') {
  78. // _token = prompt('請填入Token: ');
  79. // }
  80. try {
  81. ECPay.createPayment(_token, ECPay.Language.zhTW, function (errMsg) {
  82. console.log('Callback Message: ' + errMsg);
  83. if (errMsg != null)
  84. vm.ErrHandle(errMsg);
  85. });
  86. } catch (err) {
  87. vm.ErrHandle(err);
  88. }
  89. });
  90. vm.once = true;
  91. }
  92. },
  93. GetEnvi(env) {
  94. var result = 'STAGE';
  95. switch (env) {
  96. case 'STAGE':
  97. result = 'Stage';
  98. break;
  99. case 'PROD':
  100. result = 'Prod';
  101. break;
  102. }
  103. return result;
  104. },
  105. ErrHandle(strErr) {
  106. if (strErr != null) {
  107. $('#ECPayPayment').append('<div style="text-align: center;"><label style="color: red;">' + strErr + '</label></div>');
  108. console.log(strErr);
  109. } else {
  110. $('#ECPayPayment').append('<div style="text-align: center;"><label style="color: red;">Token取得失敗</label></div>');
  111. console.log('Wrong');
  112. }
  113. //$('#btnPay').hide();
  114. },
  115. jqueryOnload() {
  116. this.$nextTick(() => {
  117. setTimeout(() => {
  118. this.script.push({
  119. src:
  120. "https://cdn.jsdelivr.net/npm/node-forge@0.7.0/dist/forge.min.js",
  121. body: true,
  122. async: true,
  123. type: "text/javascript",
  124. }, {
  125. src:
  126. "https://ecpg.ecpay.com.tw/Scripts/sdk-1.0.0.js?t=20210121100116",
  127. body: true,
  128. async: true,
  129. type: "text/javascript",
  130. })
  131. }, 1000)
  132. })
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss" scoped>
  138. :deep(.ecpay-pay-list-wrap) {
  139. background-color: transparent;
  140. }
  141. :deep(.ecpay-pay-list-wrap .ecpay-pay-list) {
  142. padding: 0;
  143. margin: 0 auto 0 0;
  144. }
  145. </style>