Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new internal campaing for members and their fees. #527

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/api/src/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,4 +791,12 @@ export class CampaignService {

return articles
}

async isMembershipCampaign(campaignTypeId: string): Promise<boolean> {
const campaignType = await this.prisma.campaignType.findUnique({
where: { id: campaignTypeId },
})

return campaignType?.name.toLowerCase() === 'membership'
}
}
7 changes: 6 additions & 1 deletion apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,18 @@ export class DonationsService {
campaign: Campaign,
): Promise<Stripe.Checkout.SessionCreateParams.LineItem[]> {
if (sessionDto.mode == 'subscription') {
// the membership campaign is internal only
// we need to make the subscriptions once a year
const isMembership = await this.campaignService.isMembershipCampaign(campaign.campaignTypeId)
const interval = isMembership ? 'year' : 'month'

//use an inline price for subscriptions
const stripeItem = {
price_data: {
currency: campaign.currency,
unit_amount: sessionDto.amount,
recurring: {
interval: 'month' as Stripe.Price.Recurring.Interval,
interval: interval as Stripe.Price.Recurring.Interval,
interval_count: 1,
},
product_data: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add a new campaign type for membership campaigns

INSERT INTO api.campaign_types (name, slug, description, parent_id, category)
VALUES ('Membership', 'membership', 'Membership Campaigns', null, 'others');

55 changes: 55 additions & 0 deletions migrations/20230802163505_insert_membership_campaign/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
--insert an internal campaign for members only and their membership fee
--insert an internal campaign for members only and their membership fee
DO $$
DECLARE
v_coordinator_id UUID;
v_beneficiary_id UUID;
v_campaign_type_id UUID;

BEGIN

select id INTO v_coordinator_id from coordinators limit 1;
select id INTO v_beneficiary_id from beneficiaries where coordinator_id = v_coordinator_id limit 1;
select id INTO v_campaign_type_id from campaign_types where name = 'Membership';

IF v_beneficiary_id IS NULL THEN
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inserting a campaign on an empty DB is too much of a hustle.
Too many objects need to be created from scratch (coordinator, person, city, country...)

RETURN;
END IF;

insert into campaigns (
state,
slug,
title,
coordinator_id,
beneficiary_id,
campaign_type_id,
essence,
description,
target_amount,
start_date,
end_date,
created_at,
updated_at,
currency,
allow_donation_on_complete,
payment_reference)
values ('approved',
'podkrepi-membership',
'Podkrepi.bg membership',
v_coordinator_id,
v_beneficiary_id,
v_campaign_type_id,
'Internal campaign for members only',
'Internal campaign for members only. Here you can pay your membership fee. Subscribe it as an annual donation in this campaign.',
10000000,
NOW(),
'2123-08-01',
NOW(),
NOW(),
'BGN',
true,
'46M3-3ARQ-R326'
);
END;
$$ LANGUAGE plpgsql;

Loading