paypal-button.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <template>
  2. <div class="pay-wrapper">
  3. <div class="pay-msg">
  4. <div class="row">
  5. <template v-if="currentCurrencyInfo.currencyCode == 'USD'">
  6. Pay ${{finalAmountData.finalAmountValue || 0}}
  7. <span>
  8. (Available ${{finalAmountData.requestAmountValue}})
  9. </span>
  10. </template>
  11. <template v-else>
  12. <span class="desc">
  13. Pay
  14. </span>
  15. {{payConfig.amount || 0}}
  16. <img :src="currentCurrencyInfo.iconPath" class="icon">
  17. <span>
  18. {{currentCurrencyInfo.tokenSymbol}}
  19. </span>
  20. </template>
  21. </div>
  22. <div class="msg">
  23. <template v-if="currentCurrencyInfo.currencyCode == 'USD'">
  24. {{payConfig.feeDesc}}
  25. </template>
  26. <template v-else>
  27. (Balance: {{currentCurrencyInfo.balance}})
  28. </template>
  29. </div>
  30. </div>
  31. <div class="pay-btn">
  32. <iframe
  33. v-show="currentCurrencyInfo.currencyCode == 'USD'"
  34. class="iframe-pay"
  35. ref="iframe"
  36. :src="`${payConfig.paypalHtml}?paypalClientId=${payConfig.paypalClientId}&amount=${props.finalAmountData.finalAmountValue}`"></iframe>
  37. <div class="token-pay"
  38. v-if="currentCurrencyInfo.currencyCode != 'USD'"
  39. @click="tokenPay">
  40. Pay Now
  41. </div>
  42. </div>
  43. </div>
  44. </template>
  45. <script setup>
  46. import { onMounted, ref, defineProps, defineEmits, watch } from "vue";
  47. import {payTaskLuckdropWithBalance} from "@/http/publishApi"
  48. const props = defineProps({
  49. finalAmountData: {
  50. type: Object,
  51. default: () => {
  52. return {
  53. currencyCode: "",
  54. feeAmountValue: 0,
  55. finalAmountValue: 0,
  56. requestAmountValue: 0
  57. }
  58. },
  59. },
  60. payConfig: {
  61. type: Object,
  62. default: () => {
  63. return {
  64. paypalClientId: '',
  65. paypalHtml: 'https://d1mcov78iir8kk.cloudfront.net/website/paypal_1.html'
  66. }
  67. }
  68. },
  69. currentCurrencyInfo: {
  70. type: Object,
  71. default: () => {
  72. }
  73. },
  74. postData: {
  75. type: Object,
  76. default: () => {
  77. }
  78. }
  79. });
  80. let iframe = ref(null);
  81. let payIng = false;
  82. watch(
  83. () => props.finalAmountData.finalAmountValue,
  84. (newVal) => {
  85. iframe.value.contentWindow.postMessage({
  86. actionType: "setAmount", amount: newVal
  87. },
  88. "*"
  89. );
  90. },
  91. {
  92. deep: true
  93. }
  94. );
  95. const emits = defineEmits(["payPalFinsh"]);
  96. const tokenPay = () => {
  97. if(payIng) {
  98. return;
  99. }
  100. payIng = true;
  101. payTaskLuckdropWithBalance({
  102. params: {
  103. currencyCode: props.currentCurrencyInfo.currencyCode,
  104. postId: props.postData.postId
  105. }
  106. }).then(res => {
  107. if(res.code == 0) {
  108. emits("payPalFinsh", {...res.data, payNetwork: 'bsc'});
  109. }
  110. payIng = false;
  111. }).catch(() => {
  112. payIng = false;
  113. })
  114. }
  115. onMounted(() => {
  116. window.addEventListener("message", function (event) {
  117. if (event.data && event.data.actionType) {
  118. switch (event.data.actionType) {
  119. case "payCallBack":
  120. console.log(
  121. "payCallBack",
  122. event.data.orderData,
  123. event.data.transaction
  124. );
  125. emits("payPalFinsh", {...event.data, payNetwork: 'paypal'});
  126. break;
  127. }
  128. }
  129. });
  130. });
  131. </script>
  132. <style lang="scss" scoped>
  133. .pay-wrapper {
  134. width: 100%;
  135. height: 80px;
  136. background-color: #fff;
  137. position: absolute;
  138. left: 0;
  139. bottom: 0;
  140. box-shadow: 0 -4px 8px -3px #00000026;
  141. border-bottom-right-radius: 16px;
  142. padding: 12px 30px;
  143. box-sizing: border-box;
  144. display: flex;
  145. align-items: center;
  146. justify-content: flex-end;
  147. .pay-msg {
  148. text-align: right;
  149. margin-right: 25px;
  150. .row {
  151. font-weight: 600;
  152. font-size: 16px;
  153. color: #389AFF;
  154. display: flex;
  155. align-items: center;
  156. margin-bottom: 6px;
  157. span {
  158. display: inline-block;
  159. color: #000000;
  160. margin-left: 6px;
  161. }
  162. .icon {
  163. width: 14px;
  164. margin-left:6px;
  165. }
  166. .desc {
  167. margin-right:6px
  168. }
  169. }
  170. .msg {
  171. font-size: 13px;
  172. color: #898989;
  173. }
  174. }
  175. .pay-btn {
  176. width: 206px;
  177. height: 48px;
  178. .token-pay {
  179. width: 100%;
  180. height: 100%;
  181. background: #389AFF;
  182. border-radius: 10000px;
  183. display: flex;
  184. align-items: center;
  185. justify-content: center;
  186. font-weight: 600;
  187. font-size: 18px;
  188. color: #fff;
  189. }
  190. iframe {
  191. border: medium none;
  192. width: 100%;
  193. height: 100%;
  194. }
  195. }
  196. }
  197. </style>