Vue SDK
Payve Vue SDK 集成指南,为 Vue.js 应用提供简单优雅的加密货币支付组件
即将发布
Vue SDK 正在紧张开发中,将为 Vue.js 应用带来原生的加密货币支付集成体验。
预计特性
我们正在为 Vue 社区开发专门的 SDK,将包含以下特性:
Vue 3 原生支持
完全利用 Vue 3 的组合式 API 和响应式系统
组件库
PayveButton、PayveModal、PayveForm 等开箱即用的组件
组合式函数
usePayve、usePayment、useWallet 等自定义 Hooks
TypeScript
完整的 TypeScript 类型定义支持
预览 API 设计
虽然 SDK 尚未发布,但您可以预览我们计划的 API 设计:
组合式 API
<template>
<div class="payment-container">
<PayveButton
:amount="amount"
:currency="currency"
:loading="loading"
@success="handleSuccess"
@error="handleError"
>
立即支付
</PayveButton>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { PayveButton, usePayve } from '@payve/vue-sdk'
const amount = ref('99.99')
const currency = ref('USDT')
const { createPayment, loading } = usePayve({
apiKey: 'pk_live_your_api_key',
environment: 'production',
locale: 'zh'
})
const handleSuccess = (result) => {
console.log('支付成功:', result)
// 处理支付成功逻辑
}
const handleError = (error) => {
console.error('支付失败:', error)
// 处理支付失败逻辑
}
</script>选项式 API
<template>
<div class="checkout-page">
<PayveForm
v-model:amount="orderAmount"
v-model:currency="selectedCurrency"
:metadata="orderMetadata"
@payment-success="onPaymentSuccess"
@payment-error="onPaymentError"
/>
</div>
</template>
<script>
import { PayveForm } from '@payve/vue-sdk'
export default {
name: 'CheckoutPage',
components: {
PayveForm
},
data() {
return {
orderAmount: '100.00',
selectedCurrency: 'USDT',
orderMetadata: {
orderId: 'ORDER_123',
userId: 'user_456'
}
}
},
methods: {
onPaymentSuccess(result) {
this.$router.push('/success')
},
onPaymentError(error) {
this.$notify.error('支付失败: ' + error.message)
}
}
}
</script>当前替代方案
在 Vue SDK 正式发布之前,您可以使用以下方案:
方案 1:使用 JavaScript SDK
<template>
<div>
<button @click="handlePayment" :disabled="loading">
{{ loading ? '处理中...' : '立即支付' }}
</button>
<div ref="paymentContainer" v-show="showPayment"></div>
</div>
</template>
<script>
import Payve from '@payve/sdk'
export default {
data() {
return {
payve: null,
loading: false,
showPayment: false
}
},
async mounted() {
this.payve = new Payve({
apiKey: 'pk_live_your_api_key',
environment: 'production',
currency: 'USDT',
network: 'TRON',
locale: 'zh'
})
},
methods: {
async handlePayment() {
this.loading = true
try {
const payment = await this.payve.createPayment({
amount: '99.99',
description: '商品购买'
})
this.showPayment = true
this.payve.mount(this.$refs.paymentContainer, {
payment: payment,
onSuccess: this.handleSuccess,
onError: this.handleError
})
} catch (error) {
console.error('创建支付失败:', error)
} finally {
this.loading = false
}
},
handleSuccess(result) {
console.log('支付成功:', result)
this.$emit('payment-success', result)
},
handleError(error) {
console.error('支付失败:', error)
this.$emit('payment-error', error)
}
}
}
</script>方案 2:封装为 Vue 组件
创建一个简单的 Vue 组件封装:
<!-- PayvePayment.vue -->
<template>
<div class="payve-payment">
<button
@click="initPayment"
:disabled="loading"
class="pay-button"
>
<slot name="button-text">
{{ loading ? '处理中...' : '立即支付' }}
</slot>
</button>
<div
ref="paymentContainer"
v-show="paymentVisible"
class="payment-container"
></div>
</div>
</template>
<script>
import Payve from '@payve/sdk'
export default {
name: 'PayvePayment',
props: {
amount: {
type: [String, Number],
required: true
},
currency: {
type: String,
default: 'USDT'
},
network: {
type: String,
default: 'TRON'
},
description: String,
metadata: Object,
apiKey: {
type: String,
required: true
},
environment: {
type: String,
default: 'production'
}
},
emits: ['success', 'error', 'cancel', 'expire'],
data() {
return {
payve: null,
loading: false,
paymentVisible: false
}
},
mounted() {
this.initPayveSDK()
},
methods: {
initPayveSDK() {
this.payve = new Payve({
apiKey: this.apiKey,
environment: this.environment,
currency: this.currency,
network: this.network,
locale: 'zh'
})
},
async initPayment() {
this.loading = true
try {
const payment = await this.payve.createPayment({
amount: this.amount.toString(),
currency: this.currency,
network: this.network,
description: this.description,
metadata: this.metadata
})
this.paymentVisible = true
this.payve.mount(this.$refs.paymentContainer, {
payment: payment,
onSuccess: this.handleSuccess,
onError: this.handleError,
onCancel: this.handleCancel,
onExpire: this.handleExpire
})
} catch (error) {
this.handleError(error)
} finally {
this.loading = false
}
},
handleSuccess(result) {
this.$emit('success', result)
this.paymentVisible = false
},
handleError(error) {
this.$emit('error', error)
this.paymentVisible = false
},
handleCancel() {
this.$emit('cancel')
this.paymentVisible = false
},
handleExpire() {
this.$emit('expire')
this.paymentVisible = false
}
}
}
</script>
<style scoped>
.payve-payment {
/* 添加您的样式 */
}
.pay-button {
/* 按钮样式 */
}
.payment-container {
margin-top: 1rem;
/* 支付容器样式 */
}
</style>然后在您的应用中使用:
<template>
<div>
<h1>商品购买</h1>
<PayvePayment
:amount="99.99"
currency="USDT"
network="TRON"
description="高级会员订阅"
:metadata="{ userId: 'user_123' }"
:api-key="apiKey"
environment="production"
@success="handlePaymentSuccess"
@error="handlePaymentError"
>
<template #button-text>购买会员</template>
</PayvePayment>
</div>
</template>
<script>
import PayvePayment from './components/PayvePayment.vue'
export default {
components: {
PayvePayment
},
data() {
return {
apiKey: 'pk_live_your_api_key'
}
},
methods: {
handlePaymentSuccess(result) {
this.$router.push('/success')
},
handlePaymentError(error) {
this.$notify.error(`支付失败: ${error.message}`)
}
}
}
</script>发布时间表
开发路线图
获取更新通知
想要第一时间了解 Vue SDK 的发布进展?
订阅开发更新
我们会通过邮件通知您 Vue SDK 的重要进展,包括 Beta 版本发布和正式版本上线。
社区参与
我们欢迎 Vue 社区的参与和反馈:
- 🐙 GitHub:github.com/payve/vue-sdk
- 💬 Discord:加入我们的开发者社区
- 📧 邮件:sdk-feedback@payve.io
- 🐦 Twitter:@PayveHQ
常见问题
Q: 为什么选择开发独立的 Vue SDK?
A: Vue 有其独特的响应式系统和组合式 API,我们希望提供真正符合 Vue 开发习惯的集成体验,而不是简单的 JavaScript SDK 包装。
Q: Vue 2 是否会支持?
A: 我们优先支持 Vue 3,但会考虑为 Vue 2 提供兼容版本。具体计划将根据社区需求确定。
Q: 可以参与 Beta 测试吗?
A: 当然!请通过上面的邮箱订阅更新,我们会邀请感兴趣的开发者参与 Beta 测试。
Q: 当前使用 JavaScript SDK 是否影响后续迁移?
A: 不会。Vue SDK 发布时,我们会提供详细的迁移指南,确保从 JavaScript SDK 到 Vue SDK 的平滑过渡。
技术支持
如果您在使用当前的替代方案时遇到问题,或对 Vue SDK 有任何建议,请联系我们:
- 📖 文档:查看其他 SDK 文档了解通用概念
- 🛠️ 技术支持:support@payve.io
- 💡 功能建议:feature-request@payve.io
相关文档
在 Vue SDK 发布之前,您可以参考:
- JavaScript SDK - 了解核心 API 和概念
- React SDK - 参考组件设计思路
- 配置选项 - 了解 SDK 配置
- 支付 API - 了解后端集成
感谢您对 Payve Vue SDK 的关注,我们会尽快为 Vue 社区带来优秀的支付集成体验!
