Wondering if you have a card payment with vue.js 3 example, or shed any light on the following issue?
I am trying to make a card payment page with vue.js 3. I can’t find any vue.js example, therefore, just tried following the instructions from https://developer.squareup.com/docs/web-payments/take-card-payment.
The card initialized and container rendered successfully, however, card.tokenize() does not work.
Here is the page:
<template>
<div class="page-checkout">
<div>
<form id="payment-form" v-on:submit.prevent="submitOrderForm">
<div id="card-container"></div>
<button type="submit" class="button is-info is-fullwidth">Pay with Card</button>
</form>
</div>
</div>
</template>
<script>
export default {
name: "CheckoutTest",
data() {
return {
card: null,
errors: []
}
},
mounted() {
this.initializeCard()
},
methods: {
async initializeCard() {
const app_id = "replace with sandbox_application_id"
const location_id = "replace with sandbox_location_id"
const payments = Square.payments(app_id, location_id)
await payments.card()
.then((card) => {
card.attach("#card-container")
this.card = card
})
},
async submitOrderForm() {
const tokenResult = await this.card.tokenize()
console.log(tokenResult.token)
}
}
}
</script>
The public index.html page added following script line:
Chrome Console Error Message:
Uncaught (in promise) TokenizationError: Tokenization has failed
An unknown error has occurred
at Qr (square.js:1)
at square.js:1
at Generator.next ()
at ul (square.js:1)
at a (square.js:1)
at square.js:1
at G ((index):909)
at new b ((index):913)
at square.js:1
at Proxy.tokenize (square.js:1)
at Proxy.submitOrderForm (CheckoutTest.vue?a871:37)
at eval (CheckoutTest.vue?a871:4)
at eval (runtime-dom.esm-bundler.js?2725:1450)
at callWithErrorHandling (runtime-core.esm-bundler.js?d2dd:6701)
at callWithAsyncErrorHandling (runtime-core.esm-bundler.js?d2dd:6710)
at HTMLFormElement.invoker (runtime-dom.esm-bundler.js?2725:350)