My SMM panel
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

126 satır
3.5 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. <form id="payment-form" action="">
  21. <label for="name">Name on Card</label>
  22. <input id="billing-name" type="name">
  23. <div id="card-element"></div>
  24. <div id="card-errors"></div>
  25. <div id=save-card>
  26. <input name="save-card" value="Save card" type="checkbox">
  27. <label for="">Save Card</label>
  28. </div>
  29. </form>
  30. <div id="payment-error"></div>
  31. </section>
  32. <section class="credits-confirm">
  33. <button @click="pay" :disabled="total == 0 || loading" class="brand-btn">Pay</button>
  34. </section>
  35. </template>
  36. <script>
  37. function total() {
  38. return this.packs.credits10*10.99 + this.packs.credits50*54.99
  39. + this.packs.credits100*109.99 + this.packs.credits1000*1010
  40. }
  41. //Gets the secret key specific to chosen payment amount and user
  42. function getSecret() {
  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. function mountPaymentForm() {
  63. this.card = this.stripe.elements().create('card')
  64. this.card.mount('#card-element')
  65. this.card.on('change', function(event) {
  66. let displayError = document.getElementById('card-errors');
  67. if (event.error) {
  68. displayError.textContent = event.error.message;
  69. } else {
  70. displayError.textContent = '';
  71. }
  72. });
  73. }
  74. //Gets key from the server then sends it with stripe
  75. function pay() {
  76. this.getSecret().then(secret => {
  77. if (!secret) {return}
  78. return this.stripe.confirmCardPayment(secret, {
  79. payment_method: {
  80. card: this.card,
  81. billing_details: {name:
  82. document.getElementById('billing-name').value}
  83. }
  84. })
  85. }).then(result => {
  86. if (result.error) {
  87. document.getElementById('payment-error').textContent =
  88. result.error.message
  89. } else if (result.paymentIntent.status === 'succeeded') {
  90. document.getElementById('payment-error').textContent =
  91. 'Purchase completed'
  92. } else {
  93. document.getElementById('payment-error').textContent =
  94. 'An unknown error occured'
  95. }
  96. })
  97. }
  98. export default {
  99. data() {
  100. return {packs: {credits10: 0, credits50: 0,
  101. credits100: 0, credits1000: 0}, loading: false, stripe:
  102. Stripe(process.env.VUE_APP_STRIPE_KEY), card:
  103. null}
  104. },
  105. computed: {total},
  106. methods: {getSecret, mountPaymentForm, pay},
  107. props: ['token'],
  108. mounted() {
  109. this.mountPaymentForm()
  110. }
  111. }
  112. </script>