My SMM panel
 
 
 
 
 
 

119 строки
3.6 KiB

  1. <template>
  2. <section class="select-credits">
  3. <div class="credits-pane"><h2>10 Credits</h2>
  4. <h3>$10.99</h3><div><span>Qty</span><input min="0" max="1000" v-model="packs.credits10" type="number"></div>
  5. </div>
  6. <div class="credits-pane"><div><h2>50 Credits</h2><span>+5 Free Credits</span></div>
  7. <h3>$54.99 </h3><div><span>Qty</span><input min="0" max="1000" v-model="packs.credits50" type="number"></div>
  8. </div>
  9. <div class="credits-pane"><div><h2>100 Credits</h2><span>+10 Free Credits</span></div>
  10. <h3>$109.99</h3> <div><span>Qty</span><input min="0" max="1000" v-model="packs.credits100" type="number"></div>
  11. </div>
  12. <div class="credits-pane"><div><h2>1000 Credits</h2><span>+150 Free Credits</span></div>
  13. <h3>$1010.00</h3> <div><span>Qty</span><input min="0" max="1000" v-model="packs.credits1000" type="number"></div>
  14. </div>
  15. <h3>Total: ${{total.toLocaleString('en')}}</h3>
  16. <div id="credits-errors"></div>
  17. </section>
  18. <section id="payment-section">
  19. <h4>Payment Method</h4>
  20. <div class="sliding-menu">
  21. <a @click="selectSaved = true" :class="{selected: selectSaved}">Saved Card</a>
  22. <a @click="selectSaved = false" :class="{selected: !selectSaved}">New Card</a>
  23. <div :class="{right: !selectSaved}" class="menu-slider"><div></div></div>
  24. </div>
  25. <payment-card :stripe="stripe" v-if="!selectSaved"></payment-card>
  26. <div id="payment-error"></div>
  27. </section>
  28. <section class="credits-confirm">
  29. <button @click="pay" :disabled="total == 0 || loading || !cardValid || !billingName"
  30. class="brand-btn">Buy<loading v-if="loading"></loading></button>
  31. </section>
  32. </template>
  33. <script>
  34. import Loading from '../icons/loading.vue'
  35. import PaymentCard from './payment-card.vue'
  36. function total() {
  37. return this.packs.credits10*10.99 + this.packs.credits50*54.99
  38. + this.packs.credits100*109.99 + this.packs.credits1000*1010
  39. }
  40. //Gets the secret key specific to chosen payment amount and user
  41. function getSecret() {
  42. document.getElementById('credits-errors').textContent = ''
  43. this.loading = true
  44. return fetch('/panel/secret', {
  45. method: 'POST',
  46. headers: {'Content-Type': 'application/json',
  47. 'Accept': 'application/json',
  48. 'X-XSRF-TOKEN': this.token},
  49. body: JSON.stringify({'packs': this.packs})
  50. }).then((response) => {
  51. if (response.ok) {
  52. return response.text()
  53. } else {
  54. document.getElementById('credits-errors').textContent =
  55. `${response.status}: ${response.statusText}`
  56. }
  57. }).then(secret => {
  58. this.loading = false
  59. return secret
  60. })
  61. }
  62. //Gets key from the server then sends it with stripe
  63. function pay() {
  64. this.getSecret().then(secret => {
  65. if (!secret) {return}
  66. this.loading = true
  67. return this.stripe.confirmCardPayment(secret, {
  68. payment_method: {
  69. card: this.card,
  70. billing_details: {name:
  71. document.getElementById('billing-name').value},
  72. setup_future_usage: document.querySelector('#save-card input') == 'on' ? 'off_session' : null
  73. }
  74. })
  75. }).then(result => {
  76. if (result.error) {
  77. document.getElementById('payment-error').textContent =
  78. result.error.message
  79. } else if (result.paymentIntent.status === 'succeeded') {
  80. document.getElementById('payment-error').textContent =
  81. 'Purchase completed'
  82. } else {
  83. document.getElementById('payment-error').textContent =
  84. 'An unknown error occured'
  85. }
  86. this.loading = false
  87. })
  88. }
  89. export default {
  90. components:{Loading, PaymentCard},
  91. data() {
  92. return {packs: {credits10: 0, credits50: 0,
  93. credits100: 0, credits1000: 0}, loading: false, stripe:
  94. Stripe(process.env.VUE_APP_STRIPE_KEY), card:
  95. null, cardValid: false, billingName: null, selectSaved: true}
  96. },
  97. computed: {total},
  98. methods: {getSecret, pay},
  99. props: ['token'],
  100. mounted() {
  101. /* this.mountPaymentForm() */
  102. }
  103. }
  104. </script>