Skip to content

Commit

Permalink
Create a new internal campaing for members and their fees. (#527)
Browse files Browse the repository at this point in the history
* Create a new internal campaing for members only.
This way we can pay the annual fees using stripe and the subscriptions we support.

* Do not insert the campaign if there is no beneficiary.
We cannot execute this on an empty db. There are simply too many records to provide if the db is empty (person, city, country...)
  • Loading branch information
slavcho authored Aug 10, 2023
1 parent 1dcd8f5 commit 9d6e095
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
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
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;

0 comments on commit 9d6e095

Please sign in to comment.