Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
snowinszu committed Mar 6, 2024
1 parent 145ad7b commit 3764533
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 92 deletions.
28 changes: 14 additions & 14 deletions src/api/user/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ export function createOrder(userID, data) {
})
}

// 获取支付方式
export function fetchPayMethods() {
return request({
url: `charge/methods`,
method: 'get'
})
}

// 更新支付状态
export function updateCryptoTrade(data) {
return request({
Expand All @@ -52,20 +60,12 @@ export function fetchPayUrl(payMethod, orderID, device) {
})
}

// 检查支付宝支付状态
export function checkAlipayOrder(orderID) {
return request({
url: `charge/alipay/query?order_id=${orderID}`,
method: 'get'
})
}

// 检查paypal支付状态
export function checkPaypalOrder(orderID, paymentID, payerID) {
return request({
url: `charge/paypal/query?order_id=${orderID}&payment_id=${paymentID}&payer_id=${payerID}`,
method: 'get'
})
// 检查支付状态
export function checkOrderStatus(method, orderID) {
return request({
url: `charge/${method}/query?order_id=${orderID}`,
method: 'get'
})
}

// 用户签到
Expand Down
Binary file added src/assets/stripe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/utils/format.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import i18n from '@/lang'

//sha256 加密
export function setSha256(value) {
const sha256 = require("js-sha256").sha256
Expand Down Expand Up @@ -146,3 +148,18 @@ export const formatDuration = ms => {
.map(([key, val]) => `${val}${keyToText[key]}`)
.join(',');
}

export function formatterPayMethod(row) {
switch (row.payment) {
case 'alipay':
return i18n.t('order.alipay')
case 'paypal':
return 'Paypal'
case 'crypto':
return 'Coinbase'
case 'stripe':
return 'Stripe'
case 'balance':
return i18n.t('order.balance')
}
}
84 changes: 43 additions & 41 deletions src/views/dashboard/user/liveDataGlobal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import { getID } from '@/utils/auth'
import { fetchGlobalData, fetchDisData } from '@/api/user/liveData'
import { fetchUserGlobalData, fetchUserDisData } from '@/api/liveData'
import { checkAlipayOrder, checkPaypalOrder, updateCryptoTrade } from '@/api/user/package'
import { checkOrderStatus, updateCryptoTrade } from '@/api/user/package'
import { fetchGlobalDomains, fetchUserGlobalDomains } from '@/api/user/global'
import { formatTraffic, formatPieData } from '@/utils/format'
import NoBindTip from '@/components/NoBindTip'
Expand Down Expand Up @@ -252,6 +252,30 @@
_this.getData(uid, admin)
}, 20000)
},
showPaymentResult(data) {
this.checkResultLoading = false
if(data.is_payed) {
this.$messageBox.confirm(this.$t('package.paySuccess'), {
type: 'success',
confirmButtonText: this.$t('common.ok'),
showCancelButton: false
}).then(() => {
this.$router.replace('/')
})
} else if (data.processing) {
this.$messageBox.confirm(this.$t('package.payPending'), {
type: 'info',
confirmButtonText: this.$t('common.ok'),
showCancelButton: false
})
} else {
this.$messageBox.confirm(this.$t('package.payFail'), {
type: 'error',
confirmButtonText: this.$t('common.ok'),
showCancelButton: false
})
}
},
checkPayResult() {
const paramObj = this.$route.query
if(paramObj.cancel) {
Expand All @@ -273,54 +297,23 @@
this.checkResultLoading = true
switch (paramObj.payment) {
case 'alipay':
checkAlipayOrder(paramObj.out_trade_no)
.then(res => {
this.checkResultLoading = false
if(res.data.is_payed) {
this.$messageBox.confirm(this.$t('package.paySuccess'), {
type: 'success',
confirmButtonText: this.$t('common.ok'),
showCancelButton: false
}).then(() => {
this.$router.replace('/')
})
} else {
this.$messageBox.confirm(this.$t('package.payFail'), {
type: 'error',
confirmButtonText: this.$t('common.ok'),
showCancelButton: false
})
}
checkOrderStatus('alipay', paramObj.out_trade_no)
.then(({ data }) => {
this.showPaymentResult(data)
})
.catch(err => {
this.checkResultLoading = false
console.log(err)
})
break
case 'paypal':
// TODO 去掉paymentId PayerID
checkPaypalOrder(paramObj.orderId, paramObj.paymentId, paramObj.PayerID)
.then(res => {
if(res.data.is_payed) {
this.checkResultLoading = false
this.$messageBox.confirm(this.$t('package.paySuccess'), {
type: 'success',
confirmButtonText: this.$t('common.ok'),
showCancelButton: false
}).then(() => {
this.$router.replace('/')
})
} else {
this.$messageBox.confirm(this.$t('package.payFail'), {
type: 'error',
confirmButtonText: this.$t('common.ok'),
showCancelButton: false
})
}
checkOrderStatus('paypal', paramObj.orderId)
.then(({ data }) => {
this.showPaymentResult(data)
}).catch(err => {
this.checkResultLoading = false
console.log(err)
})
this.checkResultLoading = false
console.log(err)
})
break
case 'crypto':
updateCryptoTrade({
Expand All @@ -339,6 +332,15 @@
console.log(err)
})
break
case 'stripe':
checkOrderStatus('stripe', paramObj.orderId)
.then(({ data }) => {
this.showPaymentResult(data)
}).catch(err => {
this.checkResultLoading = false
console.log(err)
})
break
default:
this.checkResultLoading = false
break
Expand Down
20 changes: 8 additions & 12 deletions src/views/historyOrder/admin/OrderTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import { fetchTrades } from '@/api/finance'
import { mapGetters } from 'vuex'
import moment from 'moment'
import { formatterPayMethod } from '@/utils/format'
export default {
name: 'OrderTable',
Expand Down Expand Up @@ -100,6 +101,10 @@ export default {
{
label: 'Crypto',
value: 'crypto'
},
{
label: 'Stripe',
value: 'stripe'
}
]
}
Expand Down Expand Up @@ -127,6 +132,9 @@ export default {
},
]
},
formatterPayMethod(row) {
return formatterPayMethod(row)
},
formatterType(row) {
let type = ''
if (row.type.startsWith('flow_packet')){
Expand All @@ -146,18 +154,6 @@ export default {
this.currentPage = current
this.handleGetOrder()
},
formatterPayMethod(row) {
switch (row.payment) {
case 'alipay':
return this.$t('order.alipay')
case 'paypal':
return 'Paypal'
case 'crypto':
return 'Coinbase'
case 'balance':
return this.$t('order.balance')
}
},
formatData(data) {
if (!data) data = []
const showInvoiceDate = moment('2023-09-19')
Expand Down
12 changes: 2 additions & 10 deletions src/views/historyOrder/user/OrderTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { fetchOrder, closeOrder, fetchInvoicePdf } from '@/api/user/order'
import { getID } from '@/utils/auth'
import { mapGetters } from 'vuex'
import moment from 'moment'
import { formatterPayMethod } from '@/utils/format'
export default {
name: 'OrderTable',
Expand Down Expand Up @@ -166,16 +167,7 @@ export default {
this.handleGetOrder()
},
formatterPayMethod(row) {
switch (row.payment) {
case 'alipay':
return this.$t('order.alipay')
case 'paypal':
return 'Paypal'
case 'crypto':
return 'Coinbase'
case 'balance':
return this.$t('order.balance')
}
return formatterPayMethod(row)
},
formatData(data) {
if (!data) data = []
Expand Down
Loading

0 comments on commit 3764533

Please sign in to comment.