From 5aebba9b2a63a58c1c478758293828ee6de28668 Mon Sep 17 00:00:00 2001 From: Alexander Thiel Date: Mon, 11 Jan 2021 19:03:22 +0100 Subject: [PATCH 01/12] chore: adds stripe ENVs --- .env.local | 1 - .gitignore | 1 + readme.md | 12 ++++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) delete mode 100644 .env.local diff --git a/.env.local b/.env.local deleted file mode 100644 index 61b4d79..0000000 --- a/.env.local +++ /dev/null @@ -1 +0,0 @@ -# GA_MEASUREMENT_ID=UA-169820463-3 diff --git a/.gitignore b/.gitignore index 1f1d315..fb730e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .next node_modules +.env \ No newline at end of file diff --git a/readme.md b/readme.md index f087cbd..b04b995 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,15 @@ # TBD To Be Documented. + +# Local development + +1. Install dependencies +```sh +yarn +``` +2. Create `/.env` file based on `/.env.template` +3. Run +```sh +yarn develop +``` \ No newline at end of file From 1cb19ff2225c46c2d2c1cc54d27452cc340b0a08 Mon Sep 17 00:00:00 2001 From: Alexander Thiel Date: Mon, 11 Jan 2021 19:04:44 +0100 Subject: [PATCH 02/12] feat: forwards to Stripe checkout upon donation --- components/Payment/Payment.js | 73 +++++++++++++++-------------------- data/de.json | 5 +-- hooks/index.js | 1 + hooks/usePayment.js | 37 ++++++++++++++++++ package.json | 4 +- pages/_document.js | 12 +++++- pages/api/payment.js | 40 +++++++++++++++++++ pages/success.js | 8 ++++ yarn.lock | 23 +++++++++++ 9 files changed, 156 insertions(+), 47 deletions(-) create mode 100644 hooks/usePayment.js create mode 100644 pages/api/payment.js create mode 100644 pages/success.js diff --git a/components/Payment/Payment.js b/components/Payment/Payment.js index eee08d2..3f3bcf5 100644 --- a/components/Payment/Payment.js +++ b/components/Payment/Payment.js @@ -1,6 +1,6 @@ import { useState } from 'react'; -import { useTrip, useTranslation } from '../../hooks'; +import { usePayment, useTrip, useTranslation } from '../../hooks'; import { Select } from '../Select'; @@ -12,57 +12,48 @@ import { button, } from './Payment.module.css'; -function usePayment() { - const { t, formatNumber } = useTranslation(); - const { - trip: { cost }, - } = useTrip(); - const [recipient, setRecipient] = useState('trees'); - const getUrl = () => { - const amount = formatNumber(cost, 2); - const language = t('lang'); - switch (recipient) { - case 'trees': - return `https://donorbox.org/trees-for-lure?amount=${amount}&language=${language}`; - case 'greenpeace': - return `https://www.greenpeace.de/spenden?betrag=${amount}`; - default: - throw new Error('unknown recipient'); - } - }; - return { - options: { - trees: t('donateTrees'), - greenpeace: t('donateToGreenpeace'), - }, - value: recipient, - onChange: setRecipient, - href: getUrl(), - }; -} +// function usePayment() { +// const { t, formatNumber } = useTranslation(); +// const { +// trip: { cost }, +// } = useTrip(); +// const [recipient, setRecipient] = useState('trees'); +// const getUrl = () => { +// const amount = formatNumber(cost, 2); +// const language = t('lang'); +// switch (recipient) { +// case 'trees': +// return `https://donorbox.org/trees-for-lure?amount=${amount}&language=${language}`; +// case 'greenpeace': +// return `https://www.greenpeace.de/spenden?betrag=${amount}`; +// default: +// throw new Error('unknown recipient'); +// } +// }; +// return { +// options: { +// trees: t('donateTrees'), +// greenpeace: t('donateToGreenpeace'), +// }, +// value: recipient, +// onChange: setRecipient, +// href: getUrl(), +// }; +// } export default function Payment() { const { t, formatNumber } = useTranslation(); const { trip: { cost }, } = useTrip(); - const { options, value, onChange, href } = usePayment(); + const { process } = usePayment(); return (

{t('paymentHeadline')}

{formatNumber(cost, 2)} €

-