From 37bd1f43cd1c47c3da3c962afd89828d4d2505f8 Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 25 Aug 2020 10:05:49 -0400 Subject: [PATCH] feat: make a stripe element component --- src/_components/shared/StripeElement.vue | 118 +++++++++++++++++++++++ src/_components/shared/index.js | 1 + src/_pages/main/account/Payment.vue | 109 +-------------------- 3 files changed, 124 insertions(+), 104 deletions(-) create mode 100644 src/_components/shared/StripeElement.vue diff --git a/src/_components/shared/StripeElement.vue b/src/_components/shared/StripeElement.vue new file mode 100644 index 0000000..f76a564 --- /dev/null +++ b/src/_components/shared/StripeElement.vue @@ -0,0 +1,118 @@ + + + + + diff --git a/src/_components/shared/index.js b/src/_components/shared/index.js index 752518f..99f5f82 100644 --- a/src/_components/shared/index.js +++ b/src/_components/shared/index.js @@ -6,3 +6,4 @@ export { default as Button } from './Button'; export { default as Card } from './Card'; export { default as Checkbox } from './Checkbox'; export { default as Input } from './Input'; +export { default as StripeElement } from './StripeElement'; diff --git a/src/_pages/main/account/Payment.vue b/src/_pages/main/account/Payment.vue index 4b2d91f..1d267d2 100644 --- a/src/_pages/main/account/Payment.vue +++ b/src/_pages/main/account/Payment.vue @@ -34,14 +34,7 @@ -
- -
-
-
-
-
-
+

@@ -49,9 +42,6 @@

-

- {{ stripeError }} -

{ - this.toggleError(event); - this.cardNumberError = ''; - this.card.number = event.complete ? true : false; - if (this.card.number) { - this.brand = event.brand; - } - }); - - this.cardExpiry.addEventListener('change', (event) => { - this.toggleError(event); - this.cardExpiryError = ''; - this.card.expiry = event.complete ? true : false; - }); - - this.cardCvc.addEventListener('change', (event) => { - this.toggleError(event); - this.cardCvcError = ''; - this.card.cvc = event.complete ? true : false; - }); - }, - - toggleError(event) { - if (event.error) { - this.stripeError = event.error.message; - } else { - this.stripeError = ''; - } - }, - initDefaults() { this.getAllPlans(this.messages, this.errors); this.getAllPaymentMethods(this.messages, this.errors); @@ -408,7 +309,7 @@ export default { this.errors.clear(); - this.stripe.createToken(this.cardNumber).then((result) => { + this.$refs.stripeElement.verifyCard().then((result) => { if (result.error) { this.$snotify.error(result.error.message); } else { @@ -436,7 +337,7 @@ export default { watch: { paymentMethods() { - this.setUpStripe(); + this.$refs.stripeElement.setUpStripe(this.paymentMethods[0].driverConfig.publicApiKey); }, paymentStatus(ps) {