Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/glacials/splits-io. a speedrunning data store and analysis engine splits.io
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354import { loadScript } from '@paypal/paypal-js'
document.addEventListener("turbolinks:load", function () { if (!document.getElementById('paypal-button-container')) { return false }
loadScript({ 'client-id': process.env.PAYPAL_CLIENT_ID, 'vault': 'true', 'intent': 'subscription', 'disable-funding': 'credit' }).then(() => { const buttons = paypal.Buttons({ style: { shape: 'rect', color: 'gold', layout: 'horizontal', label: 'subscribe' }, createSubscription: function (_, actions) { return actions.subscription.create({ plan_id: process.env.PAYPAL_PLAN_ID, application_context: { shipping_preference: 'NO_SHIPPING' } }) }, onApprove: function (data) { fetch('/payments/paypal-create', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data) }) .then(response => { if (!response.ok) { throw new Error('Subscription failed') } return response.json() }) .then(data => { Turbolinks.visit(data.location) }) } })
buttons.render('#paypal-button-container').catch((err) => { console.warn( "Warning - Caught an error when attempting to render", err ) }) })})