paypal-button.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <template>
  2. <div class="pay-wrapper">
  3. <div class="pay-msg">
  4. <div class="row">Pay ${{finalAmountData.finalAmountValue || 0}}<span>(Available ${{finalAmountData.requestAmountValue / 100}})</span></div>
  5. <div class="msg">Paypal charges fee: 4.4% + $0.3</div>
  6. </div>
  7. <div class="pay-btn">
  8. <iframe
  9. class="iframe-pay"
  10. ref="iframe"
  11. :src="`${payConfig.paypalHtml}?paypalClientId=${payConfig.paypalClientId}&a=${props.finalAmountData.finalAmountValue}`"></iframe>
  12. </div>
  13. </div>
  14. </template>
  15. <script setup>
  16. import { onMounted, ref, defineProps, defineEmits, watch } from "vue";
  17. let iframe = ref(null);
  18. const props = defineProps({
  19. finalAmountData: {
  20. type: Object,
  21. default: () => {
  22. return {
  23. currencyCode: "USD",
  24. feeAmountValue: 0,
  25. finalAmountValue: 0,
  26. requestAmountValue: 0
  27. }
  28. },
  29. },
  30. payConfig: {
  31. type: Object,
  32. default: () => {
  33. return {
  34. paypalClientId: '',
  35. paypalHtml: 'https://d1mcov78iir8kk.cloudfront.net/website/paypal_1.html'
  36. }
  37. }
  38. }
  39. });
  40. watch(
  41. () => props.finalAmountData.finalAmountValue,
  42. (newVal) => {
  43. iframe.value.contentWindow.postMessage({
  44. actionType: "setAmount", amount: newVal
  45. },
  46. "*"
  47. );
  48. },
  49. {
  50. deep: true
  51. }
  52. );
  53. const emits = defineEmits(["payPalFinsh"]);
  54. onMounted(() => {
  55. window.addEventListener("message", function (event) {
  56. if (event.data && event.data.actionType) {
  57. switch (event.data.actionType) {
  58. case "payCallBack":
  59. console.log(
  60. "payCallBack",
  61. event.data.orderData,
  62. event.data.transaction
  63. );
  64. emits("payPalFinsh", event.data);
  65. break;
  66. }
  67. }
  68. });
  69. });
  70. </script>
  71. <style lang="scss" scoped>
  72. .pay-wrapper {
  73. width: 100%;
  74. height: 68px;
  75. background-color: #fff;
  76. position: absolute;
  77. left: 0;
  78. bottom: 0;
  79. box-shadow: 0 -4px 8px -3px #00000026;
  80. border-bottom-right-radius: 16px;
  81. padding: 12px 30px;
  82. box-sizing: border-box;
  83. display: flex;
  84. align-items: center;
  85. justify-content: flex-end;
  86. .pay-msg {
  87. text-align: right;
  88. margin-right: 25px;
  89. .row {
  90. font-weight: 600;
  91. font-size: 16px;
  92. color: #389AFF;
  93. span {
  94. display: inline-block;
  95. color: #000000;
  96. margin-left: 6px;
  97. }
  98. }
  99. .msg {
  100. font-size: 13px;
  101. color: #898989;
  102. }
  103. }
  104. .pay-btn {
  105. width: 206px;
  106. height: 48px;
  107. iframe {
  108. border: medium none;
  109. width: 100%;
  110. height: 100%;
  111. }
  112. }
  113. }
  114. </style>