Examples of code I've written in PHP, Javascript, SCSS, etc.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

189 linhas
6.1 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>Select a payment method</h4>
  20. <div class="sliding-menu">
  21. <a @click="method = 'payeer'" :class="{selected: method == 'payeer'}">Payeer</a>
  22. <a @click="method = 'pm'" :class="{selected: method == 'pm'}">Perfect Money</a>
  23. <div :class="{right: (method == 'pm')}" class="menu-slider"><div></div></div>
  24. </div>
  25. <div v-if="method == 'payeer'" class="payment-window">
  26. <img src="../../images/payeer.png" alt="">
  27. <p>Payeer allows you to pay securely by transfering your choice of cryptocurrency
  28. to a temporary address.
  29. </p>
  30. </div>
  31. <div v-if="method == 'pm'" class="payment-window">
  32. <img src="../../images/perfect_money.svg" alt="">
  33. <p>Pay by transfering USD from your Perfect Money wallet.</p>
  34. </div>
  35. <div id="agreement-check">
  36. <input v-model="agreed" type="checkbox"><label>I have read and agree to the <a
  37. href="/terms-and-policy">Terms and Policy</a> and will not pursue a dispute or chargeback.</label>
  38. <div id="payment-error"></div>
  39. </div>
  40. </section>
  41. <section class="credits-confirm">
  42. <button @click="pay" :disabled="!ready"
  43. class="brand-btn">Buy<loading v-if="loading"></loading></button>
  44. </section>
  45. </template>
  46. <script>
  47. import Loading from '../icons/loading.vue'
  48. function total() {
  49. return this.packs.credits10*10.99 + this.packs.credits50*54.99
  50. + this.packs.credits100*109.99 + this.packs.credits1000*1010
  51. }
  52. //Gets the secret key specific to chosen payment amount and user
  53. function getSecret() {
  54. document.getElementById('credits-errors').textContent = ''
  55. this.loading = true
  56. return fetch('/panel/secret', {
  57. method: 'POST',
  58. headers: {'Content-Type': 'application/json',
  59. 'Accept': 'application/json',
  60. 'X-XSRF-TOKEN': this.token},
  61. body: JSON.stringify({'packs': this.packs})
  62. }).then((response) => {
  63. if (response.ok) {
  64. return response.text()
  65. } else {
  66. document.getElementById('credits-errors').textContent =
  67. `${response.status}: ${response.statusText}`
  68. }
  69. }).then(secret => {
  70. this.loading = false
  71. return secret
  72. })
  73. }
  74. function pay() {
  75. if (this.method == 'payeer') {
  76. this.payPayeer()
  77. } else if (this.method == 'pm') {
  78. this.payPm()
  79. }
  80. }
  81. function makeInput(name, value) {
  82. let input = document.createElement('input')
  83. input.type = 'hidden'
  84. input.name = name
  85. input.value = value
  86. return input
  87. }
  88. function payPayeer() {
  89. fetch('/panel/payeer', {
  90. method: 'POST',
  91. headers: {'Content-Type': 'application/json',
  92. 'Accept': 'application/json',
  93. 'X-XSRF-TOKEN': this.token},
  94. body: JSON.stringify({'packs': this.packs})
  95. }).then(response => {return response.json()}).then(data => {
  96. let form = document.createElement('form')
  97. document.body.appendChild(form)
  98. form.method = 'POST'
  99. form.action = 'https://payeer.com/merchant/'
  100. form.appendChild(this.makeInput('m_shop', data.shop))
  101. form.appendChild(this.makeInput('m_orderid', data.transaction))
  102. form.appendChild(this.makeInput('m_amount', data.amount))
  103. form.appendChild(this.makeInput('m_curr', 'USD'))
  104. form.appendChild(this.makeInput('m_desc', data.description))
  105. form.appendChild(this.makeInput('m_sign', data.signature))
  106. form.appendChild(this.makeInput('m_params', data.params))
  107. form.appendChild(this.makeInput('m_cipher_method', 'AES-256-CBC'))
  108. form.submit()
  109. /* console.log(data.signature) */
  110. })
  111. }
  112. function payPm() {
  113. fetch('/panel/pm', {
  114. method: 'POST',
  115. headers: {'Content-Type': 'application/json',
  116. 'Accept': 'application/json',
  117. 'X-XSRF-TOKEN': this.token},
  118. body: JSON.stringify({'packs': this.packs})
  119. }).then(response => {return response.json()}).then(data => {
  120. let form = document.createElement('form')
  121. document.body.appendChild(form)
  122. form.method = 'POST'
  123. form.action = 'https://perfectmoney.is/api/step1.asp'
  124. form.appendChild(this.makeInput('PAYEE_ACCOUNT', data.account))
  125. form.appendChild(this.makeInput('PAYEE_NAME', 'Trendplays Network'))
  126. form.appendChild(this.makeInput('PAYMENT_AMOUNT', data.amount))
  127. form.appendChild(this.makeInput('PAYMENT_UNITS', 'USD'))
  128. form.appendChild(this.makeInput('PAYMENT_ID', data.transaction))
  129. form.appendChild(this.makeInput('STATUS_URL',
  130. 'https://trendplays.com/hooks/pm-transaction'))
  131. form.appendChild(this.makeInput('PAYMENT_URL',
  132. 'https://trendplays.com/panel/transaction-complete'))
  133. form.appendChild(this.makeInput('PAYMENT_URL_METHOD', 'POST'))
  134. form.appendChild(this.makeInput('NOPAYMENT_URL',
  135. 'https://trendplays.com/panel/transaction-failed'))
  136. form.appendChild(this.makeInput('NOPAYMENT_URL_METHOD', 'GET'))
  137. form.appendChild(this.makeInput('SUGGESTED_MEMO', data.description))
  138. form.appendChild(this.makeInput('SUGGESTED_MEMO_NOCHANGE', true))
  139. form.submit()
  140. })
  141. }
  142. function ready() {
  143. if (this.packs.credis10 < 0) {
  144. return false
  145. } else if (this.packs.credis50 < 0) {
  146. return false
  147. } else if (this.packs.credis100 < 0) {
  148. return false
  149. } else if (this.packs.credis1000 < 0) {
  150. return false
  151. }
  152. return this.total > 0 && !this.loading && this.agreed
  153. }
  154. export default {
  155. components:{Loading},
  156. data() {
  157. return {packs: {credits10: 0, credits50: 0,
  158. credits100: 0, credits1000: 0}, loading: false, method: 'payeer',
  159. agreed: false
  160. }
  161. },
  162. computed: {total, ready},
  163. methods: {getSecret, pay, payPm, payPayeer, makeInput},
  164. props: ['preferred', 'token'],
  165. emits: ['purchaseComplete'],
  166. }
  167. </script>