Browse Source

feat(api,webapp): add recurring donations

Peter Thomassen 4 years ago
parent
commit
beef375f73

+ 10 - 0
api/desecapi/models.py

@@ -471,6 +471,11 @@ class Donation(ExportModelOperationsMixin('Donation'), models.Model):
     def _mref_default():
         return "ONDON" + str(time.time())
 
+    class Interval(models.IntegerChoices):
+        ONCE = 0
+        MONTHLY = 1
+        QUARTERLY = 3
+
     created = models.DateTimeField(default=_created_default.__func__)
     name = models.CharField(max_length=255)
     iban = models.CharField(max_length=34)
@@ -479,11 +484,16 @@ class Donation(ExportModelOperationsMixin('Donation'), models.Model):
     message = models.CharField(max_length=255, blank=True)
     due = models.DateTimeField(default=_due_default.__func__)
     mref = models.CharField(max_length=32, default=_mref_default.__func__)
+    interval = models.IntegerField(choices=Interval.choices, default=Interval.ONCE)
     email = models.EmailField(max_length=255, blank=True)
 
     class Meta:
         managed = False
 
+    @property
+    def interval_label(self):
+        return dict(self.Interval.choices)[self.interval]
+
 
 # RR set types: the good, the bad, and the ugly
 # known, but unsupported types

+ 1 - 1
api/desecapi/serializers.py

@@ -589,7 +589,7 @@ class DonationSerializer(serializers.ModelSerializer):
 
     class Meta:
         model = models.Donation
-        fields = ('name', 'iban', 'bic', 'amount', 'message', 'email', 'mref')
+        fields = ('name', 'iban', 'bic', 'amount', 'message', 'email', 'mref', 'interval')
         read_only_fields = ('mref',)
 
 

+ 2 - 0
api/desecapi/templates/emails/donation/desec-content.txt

@@ -2,6 +2,8 @@ Woha,
 
 {{ donation.name }} <{{ donation.email }}> hat {{ donation.amount }}€ gespendet.
 
+Häufigkeit: alle {{ donation.interval }} Monate
+
 Nachricht:
 {{ donation.message | default:"(keine)" }}
 

+ 1 - 1
api/desecapi/templates/emails/donation/desec-subject.txt

@@ -1 +1 @@
-Spende: {{ donation.amount }}€
+Spende: {{ donation.amount }}  ({{ donation.interval_label }})

+ 14 - 0
webapp/src/components/DonateDirectDebitForm.vue

@@ -32,6 +32,16 @@
         </div>
       </v-alert>
 
+      <v-radio-group
+          v-model="interval"
+          mandatory
+          row
+      >
+        <v-radio label="Just once" :value="0"></v-radio>
+        <v-radio label="Monthly" :value="1"></v-radio>
+        <v-radio label="Quarterly" :value="3"></v-radio>
+      </v-radio-group>
+
       <v-text-field
               v-model="name"
               label="Full Name of the Account Holder"
@@ -146,6 +156,9 @@
       email_rules: [v => v === '' || !!email_pattern.test(v || '') || 'This is not an email address.'],
       email_errors: [],
 
+      /* donation interval (every N months) */
+      interval: 1,
+
       /* sent by server */
       mref: '',
     }),
@@ -167,6 +180,7 @@
             bic: "",
             message: this.message,
             email: this.email,
+            interval: this.interval,
           });
           this.mref = response.data.mref;
           this.done = true;

+ 2 - 4
webapp/src/views/Donate.vue

@@ -76,8 +76,7 @@
                   <p>
                     Are you based in Europe? You almost certainly can perform a donation via direct debit or bank
                     transfer above (you just need your IBAN). With these payment methods, the fees subtracted from your
-                    donation will be much less, and we will receive more of your money! If you want to support us
-                    regularly, you can also set up a recurring direct debit donation through Liberapay.
+                    donation will be much less, and we will receive more of your money!
                   </p>
                 </v-expansion-panel-content>
               </v-expansion-panel>
@@ -101,8 +100,7 @@
                   <p>
                     Are you based in Europe? You almost certainly can perform a donation via direct debit or bank
                     transfer above (you just need your IBAN). With these payment methods, the fees subtracted from your
-                    donation will be much less, and we will receive more of your money! If you want to support us
-                    regularly, you can also set up a recurring direct debit donation through Liberapay.
+                    donation will be much less, and we will receive more of your money!
                   </p>
                 </v-expansion-panel-content>
               </v-expansion-panel>