mirror of
https://github.com/pretix/pretix.git
synced 2026-09-12 16:04:42 +00:00
* ESlint: Ignore vendored and pre-vue code * Format pre-vue code with eslint where possible --------- Co-authored-by: Kara Engelhardt <engelhardt@pretix.eu>
73 lines
2.4 KiB
JavaScript
73 lines
2.4 KiB
JavaScript
/* global google, gettext */
|
|
'use strict'
|
|
|
|
let walletdetection = {
|
|
applepay: async function () {
|
|
// This is a weak check for Apple Pay - in order to do a proper check, we would need to also call
|
|
// canMakePaymentsWithActiveCard(merchantIdentifier)
|
|
|
|
return !!(window.ApplePaySession && window.ApplePaySession.canMakePayments())
|
|
},
|
|
googlepay: async function () {
|
|
// Checking for Google Pay is a little bit more involved, since it requires including the Google Pay JS SDK, and
|
|
// providing a lot of information.
|
|
// So for the time being, we only check if Google Pay is available in TEST-mode, which should hopefully give us a
|
|
// good enough idea if Google Pay could be present on this device; even though there are still a lot of other
|
|
// factors that could inhibit Google Pay from actually being offered to the customer.
|
|
|
|
return $.ajax({
|
|
url: 'https://pay.google.com/gp/p/js/pay.js',
|
|
dataType: 'script',
|
|
}).then(function () {
|
|
const paymentsClient = new google.payments.api.PaymentsClient({ environment: 'TEST' })
|
|
return paymentsClient.isReadyToPay({
|
|
apiVersion: 2,
|
|
apiVersionMinor: 0,
|
|
allowedPaymentMethods: [{
|
|
type: 'CARD',
|
|
parameters: {
|
|
allowedAuthMethods: ['PAN_ONLY', 'CRYPTOGRAM_3DS'],
|
|
allowedCardNetworks: ['AMEX', 'DISCOVER', 'INTERAC', 'JCB', 'MASTERCARD', 'VISA']
|
|
}
|
|
}],
|
|
})
|
|
}).then(function (response) {
|
|
return !!response.result
|
|
})
|
|
},
|
|
name_map: {
|
|
applepay: gettext('Apple Pay'),
|
|
googlepay: gettext('Google Pay'),
|
|
}
|
|
}
|
|
|
|
$(function () {
|
|
const wallets = $('[data-wallets]')
|
|
.map(function (_index, pm) {
|
|
return pm.getAttribute('data-wallets').split('|')
|
|
})
|
|
.get()
|
|
.flat()
|
|
.filter(function (item, pos, self) {
|
|
// filter out empty or duplicate values
|
|
return item && self.indexOf(item) == pos
|
|
})
|
|
|
|
wallets.forEach(function (wallet) {
|
|
const labels = $('[data-wallets*=' + wallet + '] + .accordion-label-text')
|
|
.append('<span class="wallet wallet-loading" data-wallet="' + wallet + '"> <span aria-hidden="true" class="fa fa-cog fa-spin"></span></span>')
|
|
walletdetection[wallet]()
|
|
.then(function (result) {
|
|
const spans = labels.find('.wallet-loading[data-wallet=' + wallet + ']')
|
|
if (result) {
|
|
spans.removeClass('wallet-loading').hide().text(', ' + walletdetection.name_map[wallet]).fadeIn(300)
|
|
} else {
|
|
spans.remove()
|
|
}
|
|
})
|
|
.catch(function () {
|
|
labels.find('.wallet-loading[data-wallet=' + wallet + ']').remove()
|
|
})
|
|
})
|
|
})
|