From e0c6a794af8088f7300e128c5c24c5d784e95508 Mon Sep 17 00:00:00 2001 From: Joerg Lehmann Date: Mon, 5 Apr 2021 13:28:20 +0200 Subject: [PATCH] checkout is integrated --- snippets/checkout.html | 19 ---------- static/js/checkout.js | 81 ------------------------------------------ static/js/tracker.js | 2 +- 3 files changed, 1 insertion(+), 101 deletions(-) delete mode 100644 snippets/checkout.html delete mode 100644 static/js/checkout.js diff --git a/snippets/checkout.html b/snippets/checkout.html deleted file mode 100644 index 1abc018..0000000 --- a/snippets/checkout.html +++ /dev/null @@ -1,19 +0,0 @@ -{{define "header_additions"}} - -{{end}} -{{define "body_content"}} -

Checkout

- - - -
- -
- - - - - - - -{{end}} diff --git a/static/js/checkout.js b/static/js/checkout.js deleted file mode 100644 index 2e3607f..0000000 --- a/static/js/checkout.js +++ /dev/null @@ -1,81 +0,0 @@ -// Set your publishable key: remember to change this to your live publishable key in production -// See your keys here: https://dashboard.stripe.com/account/apikeys -var stripe = Stripe('pk_test_51Icq29K2XyHQRTs2DeltUIWrbFb5evfJVGaQzMv4r50g8Q7HAUkSFr7BBGv0aP1damXIhM6fZ4Yf9Wz0qW6TpTVi00dWcW7J1O'); -var elements = stripe.elements(); - -// Set up Stripe.js and Elements to use in checkout form -var style = { - base: { - color: "#32325d", - } -}; - -var card = elements.create("card", { style: style }); -card.mount("#card-element"); - - -card.addEventListener('change', ({error}) => { - const displayError = document.getElementById('card-errors'); - if (error) { - displayError.textContent = error.message; - } else { - displayError.textContent = ''; - } -}); - - -var submitButton = document.getElementById('submit'); - -function GetClientSecret() { - var result = ""; - $.ajax({ - async: false, - url: "getstripepaymentintent", - type: "get", //send it through get method - dataType: "json", - data: { - charge_data: $("#charge_data").html() - }, - success: function(response) { - console.log('pay success'); - console.log(response.stripesessionid); - console.log('rc: '+response.rc); - if (response.rc == 0) { - result = response.stripeclientsecret; - } - }, - error: function(xhr) { - console.log('getstripepaymentintent error'); - //Do Something to handle error - } - }); - - return result; -} - -submitButton.addEventListener('click', function(ev) { - var clientSecret = GetClientSecret(); - stripe.confirmCardPayment(clientSecret, { - payment_method: { - card: card, - billing_details: { - name: 'Jenny Rosen' - } - } - }).then(function(result) { - if (result.error) { - // Show error to your customer (e.g., insufficient funds) - console.log(result.error.message); - } else { - // The payment has been processed! - if (result.paymentIntent.status === 'succeeded') { - // Show a success message to your customer - // There's a risk of the customer closing the window before callback - // execution. Set up a webhook or plugin to listen for the - // payment_intent.succeeded event that handles any business critical - // post-payment actions. - alert("Payment succeeded!!!"); - } - } - }); -}); diff --git a/static/js/tracker.js b/static/js/tracker.js index 2ec2a0e..0ae39ad 100644 --- a/static/js/tracker.js +++ b/static/js/tracker.js @@ -157,7 +157,7 @@ function loadStripeLibrary() { function SetupStripe() { // Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/account/apikeys - stripe = Stripe('pk_test_51Icq29K2XyHQRTs2DeltUIWrbFb5evfJVGaQzMv4r50g8Q7HAUkSFr7BBGv0aP1damXIhM6fZ4Yf9Wz0qW6TpTVi00dWcW7J1O'); + stripe = Stripe('pk_live_51Icq29K2XyHQRTs2oNQMPT75m7J96ajcKDADEE8FCSA3WWD98je6IZgN0E7Q2t5Vccdu1ar5kQZUIjbPhRluTkS500rgdMr0dF'); elements = stripe.elements({ locale: "de" }); // Set up Stripe.js and Elements to use in checkout form