Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/components/CheckoutContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,8 @@ import qs from 'qs'
import { payWithSSP, payWithZelcore } from '@/utils/walletService'
import { useTheme } from 'vuetify'
import { useI18n } from 'vue-i18n'
import PaymentService from '@/services/PaymentService'
import { getDetectedBackendURL } from '@/utils/backend'

// Props
const props = defineProps({
Expand Down Expand Up @@ -1120,11 +1122,26 @@ const initializeFluxPayment = async (walletType = 'zelcore') => {
// Use Zelcore wallet
console.log('Opening Zelcore wallet for payment')
try {
// Generate payment request ID for callback
let callbackUrl = null
try {
const paymentResponse = await PaymentService.paymentRequest()
if (paymentResponse.data.status === 'success') {
const paymentId = paymentResponse.data.data.paymentId
const backendURL = localStorage.getItem('backendURL') || getDetectedBackendURL()
callbackUrl = `${backendURL}/payment/verifypayment?paymentid=${paymentId}`
console.log('Generated payment callback:', callbackUrl)
}
} catch (err) {
console.warn('Failed to generate payment callback, proceeding without:', err)
}

await payWithZelcore({
address: fluxPayment.value.paymentAddr,
amount: amount,
message: message,
coin: 'flux',
callback: callbackUrl,
})

// Set payment processing state and start monitoring
Expand Down Expand Up @@ -1271,11 +1288,26 @@ const initializeFluxPayment = async (walletType = 'zelcore') => {
// Use Zelcore wallet
console.log('Opening Zelcore wallet for payment')
try {
// Generate payment request ID for callback
let callbackUrl = null
try {
const paymentResponse = await PaymentService.paymentRequest()
if (paymentResponse.data.status === 'success') {
const paymentId = paymentResponse.data.data.paymentId
const backendURL = localStorage.getItem('backendURL') || getDetectedBackendURL()
callbackUrl = `${backendURL}/payment/verifypayment?paymentid=${paymentId}`
console.log('Generated payment callback:', callbackUrl)
}
} catch (err) {
console.warn('Failed to generate payment callback, proceeding without:', err)
}

await payWithZelcore({
address: paymentPayload.payment_addr,
amount: amount,
message: message,
coin: 'flux',
callback: callbackUrl,
})

// Set payment processing state and start monitoring
Expand Down
13 changes: 8 additions & 5 deletions src/services/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@ export default function Api() {
error => Promise.reject(error),
)

// Response interceptor: Capture node IP from loginphrase response
// Response interceptor: Capture node IP from loginphrase and paymentrequest responses
instance.interceptors.response.use(
response => {
// Check if this is a loginphrase response AND we're using round-robin backend
if (response.config.url && response.config.url.includes('/id/loginphrase') && isRoundRobinBackend(baseURL)) {
// Check if this is a loginphrase or paymentrequest response AND we're using round-robin backend
const isLoginPhrase = response.config.url && response.config.url.includes('/id/loginphrase')
const isPaymentRequest = response.config.url && response.config.url.includes('/payment/paymentrequest')

if ((isLoginPhrase || isPaymentRequest) && isRoundRobinBackend(baseURL)) {
const nodeIP = extractNodeIPFromResponse(response)
if (nodeIP) {
const dnsFormat = ipToDNSFormat(nodeIP)
Expand All @@ -115,10 +118,10 @@ export default function Api() {
console.warn('[ApiClient] Could not convert node IP to DNS format:', nodeIP)
}
} else {
console.warn('[ApiClient] Could not extract node IP from loginphrase response')
console.warn('[ApiClient] Could not extract node IP from response')
}
}

return response
},
error => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/IDService.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default {
loginPhrase,
}


return Api().post('/id/checkprivilege', qs.stringify(data))
},
}
21 changes: 21 additions & 0 deletions src/services/PaymentService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Api from '@/services/ApiClient'
import qs from 'qs'

export default {
/**
* Generate a payment request ID
* @returns {Promise} Payment request response with paymentId
*/
paymentRequest() {
return Api().get('/payment/paymentrequest')
},

/**
* Verify payment (used by backend callback)
* @param {object} paymentData - Payment data from callback
* @returns {Promise} Verification response
*/
verifyPayment(paymentData) {
return Api().post('/payment/verifypayment', qs.stringify(paymentData))
},
}
11 changes: 9 additions & 2 deletions src/utils/walletService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1049,11 +1049,18 @@ export async function signWithZelcore(message, zelid, callbackUrl = null, icon =
* @param {number} params.amount - Amount to pay
* @param {string} params.message - Payment message/memo
* @param {string} [params.coin='zelcash'] - Coin type
* @param {string} [params.callback] - Optional callback URL for payment confirmation
* @returns {Promise<void>} Opens Zelcore payment protocol
*/
export async function payWithZelcore({ address, amount, message, coin = 'zelcash' }) {
export async function payWithZelcore({ address, amount, message, coin = 'zelcash', callback }) {
try {
const protocol = `zel:?action=pay&coin=${coin}&address=${address}&amount=${amount}&message=${message}`
let protocol = `zel:?action=pay&coin=${coin}&address=${address}&amount=${amount}&message=${message}`

// Add callback parameter if provided
if (callback) {
protocol += `&callback=${encodeURIComponent(callback)}`
console.log('[Zelcore Payment] Callback URL added:', callback)
}

// Try using window.zelcore.protocol if available (extension)
if (window.zelcore && typeof window.zelcore.protocol === 'function') {
Expand Down