| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- import paystack from 'vue-paystack'
- // 保留复消 V1 的 SN/metadata 协议,补上脚本与 SDK 错误的恢复路径。
- export default {
- name: 'OrderPaystack',
- extends: paystack,
- beforeDestroy() {
- clearTimeout(this.loadTimer)
- },
- methods: {
- loadScript(callback) {
- if (window.PaystackPop?.setup) {
- callback()
- return
- }
- const script = document.createElement('script')
- const finish = error => {
- clearTimeout(this.loadTimer)
- this.loadError = error
- callback()
- }
- script.src = 'https://js.paystack.co/v1/inline.js'
- script.onload = () => finish(null)
- script.onerror = () => finish(new Error('Unable to load Paystack. Please try again.'))
- this.loadTimer = setTimeout(script.onerror, 15000)
- document.head.appendChild(script)
- },
- payWithPaystack() {
- return this.scriptLoaded
- .then(() => {
- if (this._isDestroyed) return
- if (this.loadError) throw this.loadError
- if (!this.paystackkey) {
- throw new Error('Paystack is unavailable. Please contact customer service.')
- }
- const callback = this.callback
- const close = this.close
- window.PaystackPop.setup({
- key: this.paystackkey,
- email: this.email,
- amount: this.amount,
- currency: 'NGN',
- ref: this.reference,
- metadata: this.metadata,
- channels: this.channels,
- callback,
- onClose: close
- }).openIframe()
- })
- .catch(error => {
- if (!this._isDestroyed) this.$emit('error', error)
- })
- }
- }
- }
|