Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #384 from beabee-communityrm/feat/payment-paypal
Browse files Browse the repository at this point in the history
feat(payment-paypal)!: Add paypal payment method
  • Loading branch information
JumpLink authored Apr 4, 2024
2 parents 22e50de + ba9c93b commit bdcc9e4
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 172 deletions.
90 changes: 83 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# beabee
# 🐝 beabee

This repository hosts beabee's API and legacy app. [Go here](https://beabee.io/en/home/) to find out more about beabee.

Expand All @@ -12,10 +12,7 @@ and repurposed by [The Bristol Cable](https://thebristolcable.org).
![Deploy](https://github.com/beabee-communityrm/beabee/workflows/Deploy/badge.svg)
![Known Vulnerabilities](https://snyk.io/test/github/beabee-communityrm/beabee/badge.svg?targetFile=package.json)

Browser testing with<br/>
<a href="https://www.browserstack.com/"><img src="https://user-images.githubusercontent.com/2084823/46341120-52388b00-c62f-11e8-8f41-270915ccc03b.png" width="150" /></a>

## Install
## 💻 Install

> ⚠️⚠️⚠️ **WARNING** ⚠️⚠️⚠️
>
Expand Down Expand Up @@ -67,7 +64,7 @@ Need some test data? Download it here: coming soon
docker compose run --rm -T app node built/tools/database/import.js < <import file>
```

## Development
## `</>` Development

Development is containerized, in general you should be able to use the following to get started

Expand Down Expand Up @@ -111,7 +108,7 @@ docker compose run app npm run typeorm migration:run

> Note: If you get an `EACCES: permission denied` error, you may need to run the above commands with `docker compose run -u root`.
### Documentation
### 📰 Documentation

Documentation is currently very limited, email [[email protected]](mailto:[email protected]) if you have any questions.

Expand Down Expand Up @@ -164,3 +161,82 @@ The codebase is broadly split into a few different parts
```
./src/migrations
```

#### 🤲 Common Package

The backend and frontend share some code through the [beabee-common](https://github.com/beabee-communityrm/beabee-common) NPM package.

#### 📡 Webhooks

Webhooks are handled by the `webhook_app` service. This is a separate service from the API to allow for scaling independently.

**`/webhook/ping`** - Used to check if the webhook service is running and available, e.g. http://localhost:3001/webhook/ping

**`/webhook/stripe`** - Stripe webhooks are handled by the `stripe` service, see [Payment Providers](#payment-providers) for more information.

**`/webhook/gocardless`** - GoCardless webhooks are handled by the `gocardless` service, see [Payment Providers](#payment-providers) for more information.

**`/webhook/mailchimp`** - Mailchimp webhooks are handled by the `mailchimp` service, see [MailChimp](#mailchimp) for more information.

### 📧 E-mail

#### Prepare for local development

By default we are using [MailDev](https://github.com/maildev/maildev) for local development. For this to work it must be configured the first time, run the following command:

```bash
docker compose exec app node built/tools/configure
```

If the Docker Compose Stack is started, you can reach MailDev via http://localhost:3025/ by default. If you now receive an e-mail during your tests, you will find it there.

#### 📮 MailChimp

MailChimp is used for sending newsletters and other marketing emails.

To be able to send emails you need to create a MailChimp account and create a new API key in the [MailChimp dashboard](https://mailchimp.com/).

The API key can be found in the MailChimp dashboard under the API keys section.

### 💰 Payment Providers

We are using stripe for membership payments.

#### Prepare for local development

Make sure you have defined the environment variables in the .env file:

```bash
BEABEE_STRIPE_PUBLICKEY=<public key>
BEABEE_STRIPE_SECRETKEY=<secret key>
```

And also that you have configured the payment methods using

```bash
docker compose exec app node built/tools/configure
```

You can get the public key and secret key in the [Stripe dashboard](https://dashboard.stripe.com).

To be able to receive webhooks from stripe you need to forward them to your local environment and create a webhook secret using the [Stripe CLI](https://docs.stripe.com/stripe-cli):

```bash
stripe login
stripe listen --forward-to localhost:3001/webhook/stripe
```

Now the stripe CLI prints out the webhook secret, copy it and add it to the .env file while you keep the forwarding process running:

```bash
BEABEE_STRIPE_WEBHOOKSECRET=<webhook secret>
```

> ⚠️ To be able to create a payment in the frontend you need to be able to receive confirmation emails, so make sure you have setup [E-Mail](#email).
> ⚠️ Since the environment variable has changed you also need to [rebuild the containers](#rebuilding-containers).
## 🤝 Advertising

Browser testing with<br/>
<a href="https://www.browserstack.com/"><img src="https://user-images.githubusercontent.com/2084823/46341120-52388b00-c62f-11e8-8f41-270915ccc03b.png" width="150" /></a>
99 changes: 14 additions & 85 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test": "jest --setupFiles dotenv/config"
},
"dependencies": {
"@beabee/beabee-common": "^0.20.2",
"@beabee/beabee-common": "^0.20.3",
"@captchafox/node": "^1.2.0",
"@inquirer/prompts": "^3.3.0",
"@sendgrid/mail": "^8.1.0",
Expand Down Expand Up @@ -83,7 +83,7 @@
"reflect-metadata": "^0.1.13",
"routing-controllers": "^0.10.4",
"slugify": "^1.6.6",
"stripe": "^9.16.0",
"stripe": "^14.21.0",
"tar-stream": "^3.1.6",
"typeorm": "^0.3.17",
"uuid": "^9.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/api/dto/ContactDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
MembershipStatus,
NewsletterStatus,
RoleType,
RoleTypes
RoleTypes,
PaymentSource
} from "@beabee/beabee-common";
import { Type } from "class-transformer";
import {
Expand Down Expand Up @@ -38,7 +39,6 @@ import IsPassword from "@api/validators/IsPassword";
import { GetContactWith } from "@enums/get-contact-with";

import { ContributionInfo } from "@type/contribution-info";
import { PaymentSource } from "@type/payment-source";

const contactSortFields = [
"firstname",
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import Stripe from "stripe";
import config from "@config";

export default new Stripe(config.stripe.secretKey, {
apiVersion: "2020-08-27",
apiVersion: "2023-10-16",
typescript: true
});
3 changes: 1 addition & 2 deletions src/core/providers/payment/GCProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PaymentMethod } from "@beabee/beabee-common";
import { PaymentMethod, PaymentSource } from "@beabee/beabee-common";
import { Subscription } from "gocardless-nodejs";
import moment from "moment";

Expand All @@ -25,7 +25,6 @@ import NoPaymentMethod from "@api/errors/NoPaymentMethod";
import config from "@config";

import { ContributionInfo } from "@type/contribution-info";
import { PaymentSource } from "@type/payment-source";

const log = mainLogger.child({ app: "gc-payment-provider" });

Expand Down
3 changes: 1 addition & 2 deletions src/core/providers/payment/StripeProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContributionType } from "@beabee/beabee-common";
import { ContributionType, PaymentSource } from "@beabee/beabee-common";
import { add } from "date-fns";
import Stripe from "stripe";

Expand All @@ -24,7 +24,6 @@ import NoPaymentMethod from "@api/errors/NoPaymentMethod";
import config from "@config";

import { ContributionInfo } from "@type/contribution-info";
import { PaymentSource } from "@type/payment-source";

const log = mainLogger.child({ app: "stripe-payment-provider" });

Expand Down
16 changes: 10 additions & 6 deletions src/core/services/GiftService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ export default class GiftService {
payment_method_types: ["card"],
line_items: [
{
name: `Gift membership - ${giftForm.months} month${
giftForm.months != 1 ? "s" : ""
}`,
amount: giftForm.months * GiftService.giftMonthlyAmount * 100,
currency: config.currencyCode.toLowerCase(),
quantity: 1
quantity: 1,
price_data: {
unit_amount: giftForm.months * GiftService.giftMonthlyAmount * 100,
currency: config.currencyCode.toLowerCase(),
product_data: {
name: `Gift membership - ${giftForm.months} month${
giftForm.months != 1 ? "s" : ""
}`
}
}
}
]
});
Expand Down
1 change: 1 addition & 0 deletions src/core/services/PaymentFlowService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const paymentProviders = {
[PaymentMethod.StripeCard]: StripeProvider,
[PaymentMethod.StripeSEPA]: StripeProvider,
[PaymentMethod.StripeBACS]: StripeProvider,
[PaymentMethod.StripePayPal]: StripeProvider,
[PaymentMethod.GoCardlessDirectDebit]: GCProvider
};

Expand Down
Loading

0 comments on commit bdcc9e4

Please sign in to comment.