123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- <template>
- <div class="pay-wrapper">
- <div class="pay-msg">
- <div class="row">Pay ${{finalAmountData.finalAmountValue || 0}}<span>(Available ${{finalAmountData.requestAmountValue / 100}})</span></div>
- <div class="msg">Paypal charges fee: 4.4% + $0.3</div>
- </div>
- <div class="pay-btn">
- <iframe
- class="iframe-pay"
- ref="iframe"
- :src="`${payConfig.paypalHtml}?paypalClientId=${payConfig.paypalClientId}`"></iframe>
- </div>
- </div>
- </template>
- <script setup>
- import { onMounted, ref, defineProps, defineEmits, watch } from "vue";
- let iframe = ref(null);
- const props = defineProps({
- finalAmountData: {
- type: Object,
- default: () => {
- return {
- currencyCode: "USD",
- feeAmountValue: 0,
- finalAmountValue: 0,
- requestAmountValue: 0
- }
- },
- },
- payConfig: {
- type: Object,
- default: () => {
- return {
- paypalClientId: '',
- paypalHtml: ''
- }
- }
- }
- });
- watch(
- () => props.finalAmountData.finalAmountValue,
- (newVal) => {
- iframe.value.contentWindow.postMessage({
- actionType: "setAmount", amount: newVal
- },
- "*"
- );
- },
- {
- deep: true
- }
- );
- const emits = defineEmits(["payPalFinsh"]);
- onMounted(() => {
- window.addEventListener("message", function (event) {
- if (event.data && event.data.actionType) {
- switch (event.data.actionType) {
- case "payCallBack":
- console.log(
- "payCallBack",
- event.data.orderData,
- event.data.transaction
- );
- emits("payPalFinsh", event.data);
- break;
- }
- }
- });
- });
- </script>
- <style lang="scss" scoped>
- .pay-wrapper {
- width: 100%;
- height: 68px;
- background-color: #fff;
- position: absolute;
- left: 0;
- bottom: 0;
- box-shadow: 0 -4px 8px -3px #00000026;
- border-bottom-right-radius: 16px;
- padding: 12px 30px;
- box-sizing: border-box;
- display: flex;
- align-items: center;
- justify-content: flex-end;
- .pay-msg {
- text-align: right;
- margin-right: 25px;
- .row {
- font-weight: 600;
- font-size: 16px;
- color: #389AFF;
- span {
- display: inline-block;
- color: #000000;
- margin-left: 6px;
- }
- }
- .msg {
- font-size: 13px;
- color: #898989;
- }
- }
- .pay-btn {
- width: 206px;
- height: 48px;
- iframe {
- border: medium none;
- width: 100%;
- height: 100%;
- }
- }
- }
- </style>
|