mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-23 21:04:36 -05:00
* feat: unify post payment actions * feat: handle stripe card error and add donation after auth * feat: add donation saga stripe test * feat: add more coverage to stripe tests * feat: add initial stripe card saga test * feat: finalize initial stripe card saga test * feat: add patreon test saga * feat: test clean up * feat: do not show processing for Patreon * feat: normalize donation settings * feat: turn payment provider/contex to enum * feat: remove donation-settings.js * fix: git ignore generated config * fix: ignore the generate config from everything * fix: remove types.js * fix: update linting to include types.js Co-authored-by: Mrugesh Mohapatra <1884376+raisedadead@users.noreply.github.com>
51 lines
1.4 KiB
TypeScript
51 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
import {
|
|
donationUrls,
|
|
patreonDefaultPledgeAmount,
|
|
PaymentProvider
|
|
} from '../../../../config/donation-settings';
|
|
import envData from '../../../../config/env.json';
|
|
import PatreonLogo from '../../assets/images/components/patreon-logo';
|
|
import { PostPayment } from './types';
|
|
|
|
const { patreonClientId }: { patreonClientId: string | null } = envData as {
|
|
patreonClientId: string | null;
|
|
};
|
|
|
|
interface PatreonButtonProps {
|
|
postPayment: (arg0: PostPayment) => void;
|
|
}
|
|
|
|
const PatreonButton = ({
|
|
postPayment
|
|
}: PatreonButtonProps): JSX.Element | null => {
|
|
if (
|
|
!patreonClientId ||
|
|
!patreonDefaultPledgeAmount ||
|
|
!donationUrls.successUrl
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
const clientId = `&client_id=${patreonClientId}`;
|
|
const pledgeLevel = `$&min_cents=${patreonDefaultPledgeAmount}`;
|
|
const v2Params = '&scope=identity%20identity[email]';
|
|
const redirectUri = `&redirect_uri=${donationUrls.successUrl}`;
|
|
const href = `https://www.patreon.com/oauth2/become-patron?response_type=code${pledgeLevel}${clientId}${redirectUri}${v2Params}`;
|
|
|
|
return (
|
|
<a
|
|
className='patreon-button link-button'
|
|
data-patreon-widget-type='become-patron-button'
|
|
href={href}
|
|
onClick={() => postPayment({ paymentProvider: PaymentProvider.Patreon })}
|
|
rel='noreferrer'
|
|
target='_blank'
|
|
>
|
|
<PatreonLogo />
|
|
</a>
|
|
);
|
|
};
|
|
|
|
export default PatreonButton;
|