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

Add paypal buttons back to donation and payment page #479

Merged
merged 1 commit into from
Sep 10, 2024
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
61 changes: 61 additions & 0 deletions metabrainz/templates/payments/donate.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ <h1 class="page-title">{{ _('Make a Donation') }}</h1>
<div id="buttons" class="form-group">
<div class="col-sm-offset-3 col-sm-6">
<button id="btn-stripe" type="button" class="btn">{{ _('Donate with Credit Card') }}</button>
<button id="btn-paypal" type="button" class="btn">
<img src="{{ url_for('static', filename='img/payments/paypal.svg') }}" />
</button>
</div>
</div>

Expand Down Expand Up @@ -150,9 +153,11 @@ <h3>{{ _('US Check') }}</h3>
// These must match form definitions.
US_Dollar: {
code: "USD",
paypal_id: '{{ config['PAYPAL_ACCOUNT_IDS']['USD'] }}'
},
Euro: {
code: "EUR",
paypal_id: '{{ config['PAYPAL_ACCOUNT_IDS']['USD'] }}'
}
};

Expand All @@ -162,6 +167,7 @@ <h3>{{ _('US Check') }}</h3>

var buttons = {
stripe: $('#btn-stripe'),
paypal: $('#btn-paypal')
};

function setButtonsState(enabled) {
Expand Down Expand Up @@ -265,6 +271,61 @@ <h3>{{ _('US Check') }}</h3>
form.submit();
});

// PayPal
buttons.paypal.on('click', function(e) {
setButtonsState(false);
{% if config.PAYMENT_PRODUCTION %}
form.attr("action", "https://www.paypal.com/cgi-bin/webscr");
{% else %}
form.attr("action", "https://www.sandbox.paypal.com/cgi-bin/webscr");
{% endif %}

{# Info about variables can be found at https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/ #}

$('<input>').attr({type: 'hidden', name: 'business', value: selectedCurrency.paypal_id}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'no_shipping', value: '2'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'return', value: '{{ url_for('payments.complete', is_donation=True, _external=True, _scheme=config.PREFERRED_URL_SCHEME) }}'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'cancel_return', value: '{{ url_for('payments.cancelled', is_donation=True, _external=True, _scheme=config.PREFERRED_URL_SCHEME) }}'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'notify_url', value: '{{ url_for('payments_paypal.ipn', _external=True, _scheme=config.PREFERRED_URL_SCHEME) }}'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'currency_code', value: selectedCurrency.code}).appendTo(form);

if ($('#recurring-flag').is(":checked")) { // Recurring donations
$('<input>').attr({type: 'hidden', name: 'cmd', value: '_xclick-subscriptions'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'item_name', value: 'Recurring donation to the MetaBrainz Foundation'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 't3', value: 'M'}).appendTo(form); {# units of duration ('M' is month) #}
$('<input>').attr({type: 'hidden', name: 'p3', value: '1'}).appendTo(form); {# subscription duration #}
$('<input>').attr({type: 'hidden', name: 'src', value: '1'}).appendTo(form); {# recurring payments #}
$('<input>').attr({type: 'hidden', name: 'sra', value: '1'}).appendTo(form); {# reattempt on failure #}

} else { // One-time donation
$('<input>').attr({type: 'hidden', name: 'cmd', value: '_xclick'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'item_name', value: 'Donation to the MetaBrainz Foundation'}).appendTo(form);
}

{# Reconfiguring inputs for PayPal #}
if ($('#recurring-flag').is(":checked")) { // Recurring donations
amount.attr('name', 'a3');
} else { // One-time donation
amount.attr('name', 'amount');
}

editor.attr('name', 'custom');

$('<input>').attr({type: 'hidden', name: 'on3', value: 'is_donation'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'os3', value: 'yes'}).appendTo(form);

$('<input>').attr({type: 'hidden', name: 'on0', value: 'contact'}).appendTo(form);
$("#can-contact-flag").attr('name', 'os0');
$("#can-contact-flag").attr('value', 'yes'); {# Boolean values are compared to 'yes' in IPN processor. #}

$('<input>').attr({type: 'hidden', name: 'on1', value: 'anonymous'}).appendTo(form);
$("#anonymous-flag").attr('name', 'os1');
$("#anonymous-flag").attr('value', 'yes'); {# Boolean values are compared to 'yes' in IPN processor. #}

form.submit();
return false;
});

});
</script>
{% endblock %}
55 changes: 55 additions & 0 deletions metabrainz/templates/payments/payment.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<button id="btn-stripe" type="button" class="btn">
{{ _('Pay with Credit Card') }}
</button>
<button id="btn-paypal" type="button" class="btn">
<img src="{{ url_for('static', filename='img/payments/paypal.svg') }}" />
</button>
</div>
</div>

Expand Down Expand Up @@ -89,12 +92,14 @@

var form = $("#payment-form");


//////////////////
// PAYMENT BUTTONS
//////////////////

var buttons = {
stripe: $('#btn-stripe'),
paypal: $('#btn-paypal')
};

function setButtonsState(enabled) {
Expand Down Expand Up @@ -142,6 +147,56 @@
e.preventDefault();
});

// PayPal
buttons.paypal.on('click', function(e) {
setButtonsState(false);
{% if config.PAYMENT_PRODUCTION %}
form.attr("action", "https://www.paypal.com/cgi-bin/webscr");
{% else %}
form.attr("action", "https://www.sandbox.paypal.com/cgi-bin/webscr");
{% endif %}

{# Info about variables can be found at https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/ #}

$('<input>').attr({type: 'hidden', name: 'business', value: '{{ config['PAYPAL_ACCOUNT_IDS'][currency|upper] }}'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'no_shipping', value: '2'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'return', value: '{{ url_for('payments.complete', donation=True, _external=True, _scheme=config.PREFERRED_URL_SCHEME) }}'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'cancel_return', value: '{{ url_for('payments.cancelled', donation=True, _external=True, _scheme=config.PREFERRED_URL_SCHEME) }}'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'notify_url', value: '{{ url_for('payments_paypal.ipn', _external=True, _scheme=config.PREFERRED_URL_SCHEME) }}'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'currency_code', value: '{{ currency|upper }}'}).appendTo(form);

if ($('#recurring-flag').is(":checked")) { // Recurring payments
$('<input>').attr({type: 'hidden', name: 'cmd', value: '_xclick-subscriptions'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'item_name', value: 'Recurring payment to the MetaBrainz Foundation'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 't3', value: 'M'}).appendTo(form); {# units of duration ('M' is month) #}
$('<input>').attr({type: 'hidden', name: 'p3', value: '1'}).appendTo(form); {# subscription duration #}
$('<input>').attr({type: 'hidden', name: 'src', value: '1'}).appendTo(form); {# recurring payments #}
$('<input>').attr({type: 'hidden', name: 'sra', value: '1'}).appendTo(form); {# reattempt on failure #}

} else { // One-time payment
$('<input>').attr({type: 'hidden', name: 'cmd', value: '_xclick'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'item_name', value: 'Payment to the MetaBrainz Foundation'}).appendTo(form);
}

{# Reconfiguring inputs for PayPal #}
if ($('#recurring-flag').is(":checked")) { // Recurring payments
amount.attr('name', 'a3');
} else { // One-time payment
amount.attr('name', 'amount');
}

{# `on0` and `on1` are used for donation metadata #}

$('<input>').attr({type: 'hidden', name: 'on2', value: 'is_donation'}).appendTo(form);
$('<input>').attr({type: 'hidden', name: 'os2', value: 'no'}).appendTo(form);

$('<input>').attr({type: 'hidden', name: 'on3', value: 'invoice_number'}).appendTo(form);
$("#input-invoice-number").attr('name', 'os3');

form.submit();
return false;
});

});
</script>
{% endblock %}
Loading