|
|
@@ -19,9 +19,8 @@ |
|
|
|
<div id="credits-errors"></div> |
|
|
|
</section> |
|
|
|
|
|
|
|
|
|
|
|
<section id="payment-section"> |
|
|
|
<h4>Payment Method</h4> |
|
|
|
<h4>Select a payment method</h4> |
|
|
|
|
|
|
|
<div class="sliding-menu"> |
|
|
|
<a @click="selectSaved = true" :class="{selected: selectSaved}">Saved Card</a> |
|
|
@@ -29,15 +28,19 @@ |
|
|
|
<div :class="{right: !selectSaved}" class="menu-slider"><div></div></div> |
|
|
|
</div> |
|
|
|
|
|
|
|
<saved-cards v-model:picked-card="picked" :cards="cards" |
|
|
|
:token="token" v-if="selectSaved"></saved-cards> |
|
|
|
|
|
|
|
<payment-card @set-card="(c) => {card = c}" @card-valid="(val) => {cardValid = val}" |
|
|
|
@update-billing-name="billingName = $event.target.value" :stripe="stripe" |
|
|
|
v-if="!selectSaved"></payment-card> |
|
|
|
v-if="!selectSaved"> |
|
|
|
</payment-card> |
|
|
|
|
|
|
|
<div id="payment-error"></div> |
|
|
|
</section> |
|
|
|
|
|
|
|
<section class="credits-confirm"> |
|
|
|
<button @click="pay" :disabled="total == 0 || loading || !cardValid || !billingName" |
|
|
|
<button @click="pay" :disabled="!ready" |
|
|
|
class="brand-btn">Buy<loading v-if="loading"></loading></button> |
|
|
|
</section> |
|
|
|
</template> |
|
|
@@ -45,6 +48,7 @@ |
|
|
|
<script> |
|
|
|
import Loading from '../icons/loading.vue' |
|
|
|
import PaymentCard from './payment-card.vue' |
|
|
|
import SavedCards from './saved-cards.vue' |
|
|
|
|
|
|
|
function total() { |
|
|
|
return this.packs.credits10*10.99 + this.packs.credits50*54.99 |
|
|
@@ -75,20 +79,27 @@ function getSecret() { |
|
|
|
} |
|
|
|
|
|
|
|
//Gets key from the server then sends it with stripe |
|
|
|
//Maybe it should asl attach the user's receipt email |
|
|
|
function pay() { |
|
|
|
console.log() |
|
|
|
console.log('paying') |
|
|
|
this.getSecret().then(secret => { |
|
|
|
if (!secret) {return} |
|
|
|
this.loading = true |
|
|
|
return this.stripe.confirmCardPayment(secret, { |
|
|
|
payment_method: { |
|
|
|
card: this.card, |
|
|
|
billing_details: {name: |
|
|
|
document.getElementById('billing-name').value}, |
|
|
|
}, |
|
|
|
setup_future_usage: document.querySelector( |
|
|
|
"#save-card input").value == 'on' ? 'off_session' : null |
|
|
|
}) |
|
|
|
if (!this.selectSaved) { |
|
|
|
return this.stripe.confirmCardPayment(secret, { |
|
|
|
payment_method: { |
|
|
|
card: this.card, |
|
|
|
billing_details: {name: |
|
|
|
document.getElementById('billing-name').value}, |
|
|
|
}, |
|
|
|
setup_future_usage: document.querySelector( |
|
|
|
"#save-card input").value == 'on' ? 'off_session' : null |
|
|
|
}) |
|
|
|
} else { |
|
|
|
return this.stripe.confirmCardPayment(secret, { |
|
|
|
payment_method: this.picked |
|
|
|
}) |
|
|
|
} |
|
|
|
}).then(result => { |
|
|
|
if (result.error) { |
|
|
|
document.getElementById('payment-error').textContent = |
|
|
@@ -104,19 +115,39 @@ function pay() { |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
function getCards() { |
|
|
|
fetch('/panel/cards', { |
|
|
|
method: 'GET', |
|
|
|
headers: {'Content-Type': 'application/json', |
|
|
|
'Accept': 'application/json', |
|
|
|
'X-XSRF-TOKEN': this.token} |
|
|
|
}).then((response) => {response.json().then(data => { |
|
|
|
this.cards = data.data |
|
|
|
if (this.cards) { |
|
|
|
this.picked = this.cards[0].id |
|
|
|
} |
|
|
|
})}) |
|
|
|
} |
|
|
|
function ready() { |
|
|
|
return this.total != 0 && !this.loading && ((this.cardValid && |
|
|
|
this.billingName) || this.picked) |
|
|
|
} |
|
|
|
|
|
|
|
export default { |
|
|
|
components:{Loading, PaymentCard}, |
|
|
|
components:{Loading, PaymentCard, SavedCards}, |
|
|
|
data() { |
|
|
|
return {packs: {credits10: 0, credits50: 0, |
|
|
|
credits100: 0, credits1000: 0}, loading: false, stripe: |
|
|
|
Stripe(process.env.VUE_APP_STRIPE_KEY), card: |
|
|
|
null, billingName: null, selectSaved: true, cardValid: false} |
|
|
|
window.Stripe(process.env.VUE_APP_STRIPE_KEY), card: |
|
|
|
null, billingName: null, selectSaved: true, cardValid: false, cards: |
|
|
|
null, picked: null |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: {total}, |
|
|
|
methods: {getSecret, pay}, |
|
|
|
computed: {total, ready}, |
|
|
|
methods: {getSecret, pay, getCards}, |
|
|
|
props: ['token'], |
|
|
|
mounted() { |
|
|
|
/* this.mountPaymentForm() */ |
|
|
|
created() { |
|
|
|
this.getCards() |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |