예제 #1
0
def revoked(request):
    if 'error-title' in request.session or 'error-message' in request.session:
        error_title = request.session.pop('error-title', '')
        error_message = request.session.pop('error-message', '')
        return render(
            request, 'donations/revoked.html', {
                'isValid': False,
                'error_message': error_message,
                'error_title': error_title
            })
    if 'return-donation-id' in request.session:
        donation = Donation.objects.get(
            pk=request.session['return-donation-id'])
        paymentMethod = displayGateway(donation)
        donation.payment_status = STATUS_REVOKED
        # No need to update recurring_status as no subscription object has been created yet
        donation.save()
        # logs user in
        if donation.user:
            login(request,
                  donation.user,
                  backend='django.contrib.auth.backends.ModelBackend')
        return render(
            request, 'donations/revoked.html', {
                'isValid': True,
                'isFirstTime': donation.is_user_first_donation,
                'paymentMethod': paymentMethod,
                'donation': donation
            })
    return render(
        request, 'donations/revoked.html', {
            'isValid': False,
            'error_message': _('No Payment Data is received.'),
            'error_title': _("Unknown Error")
        })
예제 #2
0
def get_recurring_cancelled_donor_text(subscription):
    return _("""DONATION CANCELLED\n
\n
Dear %(name)s,\n
Thanks very much for your recent support.\n
Your recurring donation to HKFP has been suspended at your request - no further payments will be processed.\n
Sign into our support page(%(siteurl)s) (click "forgot password?" if you have trouble logging in) if you wish to support us again in the future. Please email [email protected] if you have any further enquiries.\n
From all of us, thank you for backing our team and helping us keep independent media alive in Hong Kong!\n
Details of your recurring donation:\n
\n
Donor: %(name)s\n
Recurring donation identifier: %(profile_id)s\n
Payment method: %(gateway)s\n
Recurring donation amount: %(amount)s\n
Recurring Status: %(recurring_status)s\n
\n
Thank you,\n
%(sitename)s""") % {
        'name': subscription.user.fullname,
        'siteurl': get_site_url(),
        'url': reverse_with_site_url('donations:my-recurring-donations'),
        'profile_id': subscription.profile_id,
        'gateway': displayGateway(subscription),
        'amount': displayRecurringAmountWithCurrency(subscription),
        'recurring_status': subscription.recurring_status,
        'sitename': get_site_name()
    }
예제 #3
0
def get_recurring_resumed_donor_text(subscription):
    return _("""DONATION RESUMED\n
\n
Dear %(name)s,\n
A big "thank you" for resuming your %(amount)s contribution - it is very much appreciated and it will go a long way in supporting our operations. Recurring donations, in particular, are vital to our sustainability.
As an HKFP Patron, your contribution will be well-spent, allowing us to invest more in original reporting and safeguard press freedom. Please check out HKFP's latest Annual Report(https://hongkongfp.com/hong-kong-free-press-annual-report-2020/) - it includes our yearly, audited Transparency Report(https://hongkongfp.com/hong-kong-free-press-transparency-report-2019/), so you can see how carefully we spend our income.\n
Sign into our support page (click "forgot password?" if you have trouble logging in) to adjust or suspend your donation(%(url)s). Please email [email protected] if you have any further enquiries.\n
From all of us, thank you for helping us keep independent media alive in Hong Kong!\n
Details of your recurring donation:\n
\n
Donor: %(name)s\n
Recurring donation identifier: %(profile_id)s\n
Payment method: %(gateway)s\n
Recurring donation amount: %(amount)s\n
Recurring Status: %(recurring_status)s\n
\n
Thank you,\n
%(sitename)s""") % {
        'name': subscription.user.fullname,
        'url': reverse_with_site_url('donations:my-recurring-donations'),
        'profile_id': subscription.profile_id,
        'gateway': displayGateway(subscription),
        'amount': displayRecurringAmountWithCurrency(subscription),
        'recurring_status': subscription.recurring_status,
        'sitename': get_site_name()
    }
예제 #4
0
def get_donation_status_change_text(donation):
    donation_url = reverse_with_site_url(
        'donations:my-renewals', kwargs={
            'id': donation.subscription.id
        }) if donation.is_recurring else reverse_with_site_url(
            'donations:my-onetime-donations')
    if donation.user:
        url_text = str(
            _('Sign into our support page (click "forgot password?" if you have trouble logging in) to view your updated donation(%(url)s).'
              ) % {'url': donation_url}) + "\n"
    else:
        url_text = ''
    return _("""ONE-OFF DONATION STATUS UPDATED\n
\n
Dear %(name)s,\n
%(url_text)s
Details of your donation:\n
\n
Transaction ID: %(transaction_id)s\n
Donation frequency: %(frequency)s\n
Payment method: %(gateway)s\n
Donation amount: %(amount)s\n
Payment status: %(status)s\n
\n
Thank you,\n
%(sitename)s""") % {
        'name': donation.donor_name(),
        'url_text': url_text,
        'transaction_id': donation.transaction_id,
        'frequency': donation.donation_frequency,
        'gateway': displayGateway(donation),
        'amount': displayDonationAmountWithCurrency(donation),
        'status': donation.payment_status,
        'sitename': get_site_name()
    }
예제 #5
0
def thank_you(request):
    reminders_html = None
    extra_text = None
    is_tmp_transaction_id = False
    if 'error-title' in request.session or 'error-message' in request.session:
        error_title = request.session.pop('error-title', '')
        error_message = request.session.pop('error-message', '')
        return render(
            request, 'donations/thankyou.html', {
                'isValid': False,
                'error_message': error_message,
                'error_title': error_title
            })
    if 'return-donation-id' in request.session:
        donation = Donation.objects.get(
            pk=request.session['return-donation-id'])
        paymentMethod = displayGateway(donation)
        # logs user in
        if donation.user:
            login(request,
                  donation.user,
                  backend='django.contrib.auth.backends.ModelBackend')
        # display extra html if donation is offline
        if donation.gateway.is_offline():
            offlineSettings = getOfflineSettings()
            # manually casting offline_thankyou_text from LazyI18nString to str to avoid the "richtext expects a string" error in the template
            reminders_html = str(offlineSettings.offline_thankyou_text)
        # display extra text for certain scenarios
        if donation.gateway.is_paypal(
        ) and donation.payment_status == STATUS_PROCESSING:
            extra_text = _('Your donation should be complete in 1-2 minutes. ')
            is_tmp_transaction_id = True
        if donation.gateway.is_offline(
        ) and donation.payment_status == STATUS_PROCESSING:
            extra_text = _(
                'Please complete your donation by following either one of the payment methods stated below. '
            )
        return render(
            request, 'donations/thankyou.html', {
                'reminders_html': reminders_html,
                'is_tmp_transaction_id': is_tmp_transaction_id,
                'isValid': True,
                'paymentMethod': paymentMethod,
                'extra_text': extra_text,
                'isFirstTime': donation.is_user_first_donation,
                'donation': donation
            })
    return render(
        request, 'donations/thankyou.html', {
            'reminders_html': reminders_html,
            'is_tmp_transaction_id': is_tmp_transaction_id,
            'isValid': False,
            'extra_text': extra_text,
            'error_message': _('No Payment Data is received.'),
            'error_title': _("Unknown Error")
        })
예제 #6
0
def get_donation_receipt_text(donation):
    donation_url = reverse_with_site_url(
        'donations:my-recurring-donations'
    ) if donation.is_recurring else reverse_with_site_url(
        'donations:my-onetime-donations')
    if donation.user:
        url_text = str(
            _('Sign into our support page (click "forgot password?" if you have trouble logging in) to view your donation(%(url)s). Please email [email protected] if you have any further enquiries.'
              ) % {'url': donation_url})
    else:
        url_text = ''
    return _("""NEW ONE-OFF DONATION\n
\n
Dear %(name)s,\n
A big "thank you" for your kind %(amount)s donation - it is very much appreciated and it will go a long way in supporting our operations.\n
Your contribution will be well-spent, allowing us to invest more in original reporting and safeguard press freedom. Please check out HKFP's latest Annual Report(https://hongkongfp.com/hong-kong-free-press-annual-report-2020/) - it includes our yearly, audited Transparency Report(https://hongkongfp.com/hong-kong-free-press-transparency-report-2019/), so you can see how carefully we spend our income.\n
%(url_text)s\n
From all of us, thank you for helping us keep independent media alive in Hong Kong!\n
Details of your donation:\n
\n
Transaction ID: %(transaction_id)s\n
Donation frequency: %(frequency)s\n
Payment method: %(gateway)s\n
Donation amount: %(amount)s\n
Payment status: %(status)s\n
%(recurring_status)s
\n
Thank you,\n
%(sitename)s""") % {
        'name':
        donation.donor_name(),
        'url_text':
        url_text,
        'transaction_id':
        donation.transaction_id,
        'frequency':
        donation.donation_frequency,
        'gateway':
        displayGateway(donation),
        'amount':
        displayDonationAmountWithCurrency(donation),
        'status':
        donation.payment_status,
        'recurring_status':
        'Recurring Status: ' + donation.subscription.recurring_status +
        "\n" if donation.is_recurring and donation.subscription else '',
        'sitename':
        get_site_name()
    }
예제 #7
0
def get_donation_revoked_donor_text(donation):
    donation_url = reverse_with_site_url(
        'donations:my-recurring-donations'
    ) if donation.is_recurring else reverse_with_site_url(
        'donations:my-onetime-donations')
    if donation.user:
        url_text = str(
            _('Go to %(url)s to view your donation on the website.') %
            {'url': donation_url})
    else:
        url_text = ''
    return _("""DONATION REVOKED\n
\n
Dear %(name)s,\n
Your donation is unfortunately revoked by the payment gateway. %(url_text)s\n
Here are the details of your donation:\n
\n
Transaction ID: %(transaction_id)s\n
Donation frequency: %(frequency)s\n
Payment method: %(gateway)s\n
Donation amount: %(amount)s\n
Payment status: %(status)s\n
%(recurring_status)s
\n
Thank you,\n
%(sitename)s""") % {
        'name':
        donation.donor_name(),
        'url_text':
        url_text,
        'transaction_id':
        donation.transaction_id,
        'frequency':
        donation.donation_frequency,
        'gateway':
        displayGateway(donation),
        'amount':
        displayDonationAmountWithCurrency(donation),
        'status':
        donation.payment_status,
        'recurring_status':
        'Recurring Status: ' + donation.subscription.recurring_status +
        "\n" if donation.is_recurring and donation.subscription else '',
        'sitename':
        get_site_name()
    }
예제 #8
0
def get_subscription_status_change_text(subscription):
    return _("""RECURRING DONATION STATUS UPDATED\n
\n
Dear %(name)s,\n
Sign into our support page (click "forgot password?" if you have trouble logging in) to view your updated recurring donation(%(url)s).\n
Details of your recurring donation:\n
\n
Profile ID: %(profile_id)s\n
Payment method: %(gateway)s\n
Recurring Amount: %(amount)s\n
Status: %(status)s\n
\n
Thank you,\n
%(sitename)s""") % {
        'name': subscription.user.fullname,
        'url': reverse_with_site_url('donations:my-recurring-donations'),
        'profile_id': subscription.profile_id,
        'gateway': displayGateway(subscription),
        'amount': displayRecurringAmountWithCurrency(subscription),
        'status': subscription.recurring_status,
        'sitename': get_site_name()
    }
예제 #9
0
def confirm_donation(request):
    try:
        siteSettings = get_site_settings_from_default_site()
        tmpd = TempDonation.objects.get(
            pk=request.session.get('temp_donation_id', None))
        paymentMethod = displayGateway(tmpd)
        isGatewayHostedBool = isGatewayHosted(tmpd.gateway)
        if request.method == 'POST':
            # determine path based on submit-choice
            if request.POST.get('submit-choice', '') == 'change-submit':
                # goes back to step 1 which is donation details
                return redirect('donations:donate')
            elif request.POST.get('submit-choice', '') == 'confirm-submit':
                # proceed with the rest of the payment procedures
                # create processing donation
                transaction_id = gen_transaction_id(gateway=tmpd.gateway)
                donation = Donation(
                    is_test=tmpd.is_test,
                    transaction_id=transaction_id,
                    user=request.user
                    if request.user.is_authenticated else None,
                    form=tmpd.form,
                    gateway=tmpd.gateway,
                    is_recurring=tmpd.is_recurring,
                    donation_amount=tmpd.donation_amount,
                    currency=tmpd.currency,
                    guest_email=tmpd.guest_email
                    if not request.user.is_authenticated else '',
                    payment_status=STATUS_PROCESSING,
                    metas=temp_donation_meta_to_donation_meta(
                        tmpd.temp_metas.all()),
                    donation_date=datetime.now(timezone.utc),
                )
                # create a processing subscription if is_recurring
                if tmpd.is_recurring:
                    # create new Subscription object, with a temporary profile_id created by uuidv4
                    # user should have been authenticated according to flow logic
                    subscription = Subscription(
                        is_test=tmpd.is_test,
                        profile_id=uuid4_str(),
                        user=request.user
                        if request.user.is_authenticated else None,
                        gateway=tmpd.gateway,
                        recurring_amount=tmpd.donation_amount,
                        currency=tmpd.currency,
                        recurring_status=STATUS_PROCESSING,
                        subscribe_date=datetime.now(timezone.utc))
                    subscription.save()
                    # link subscription to the donation
                    donation.subscription = subscription

                donation.save()
                request.session.pop('temp_donation_id')
                # delete temp donation instead of saving it as processed
                tmpd.delete()
                # tmpd.status = STATUS_PROCESSED
                # tmpd.save()

                if 'first_time_registration' in request.session:
                    dpmeta = DonationPaymentMeta(
                        donation=donation,
                        field_key='is_user_first_donation',
                        field_value=request.session['first_time_registration'])
                    dpmeta.save()
                    request.session.pop('first_time_registration')

                # redirect to payment_gateway
                gatewayManager = InitPaymentGateway(request, donation=donation)
                return gatewayManager.redirect_to_gateway_url()
            else:
                raise Exception(
                    _('No valid submit-choice is being submitted.'))
    except TempDonation.DoesNotExist as e:
        messages.add_message(
            request, messages.ERROR,
            str(
                _('Session data has expired. Please enter the donation details again.'
                  )))
        return redirect('donations:donate')
    except Exception as e:
        # Should rarely happen, but in case some bugs or order id repeats itself
        _exception(str(e))
    return render(
        request, 'donations/confirm_donation.html', {
            'tmpd': tmpd,
            'paymentMethod': paymentMethod,
            'isGatewayHosted': isGatewayHostedBool
        })
예제 #10
0
def display_gateway(instance):
    return displayGateway(instance)