Skip to content

Commit

Permalink
switch back to Sources API for SEPA Direct Debit
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Jun 6, 2024
1 parent 2fe2d53 commit 9eba56b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 28 deletions.
80 changes: 53 additions & 27 deletions js/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,59 @@ Liberapay.stripe_form_init = function($form) {
if (local_address.length === 1) {
local_address.push(null);
}
var pmData = {
billing_details: {
address: {
city: $postal_address_city.val(),
country: $postal_address_country.val(),
line1: local_address[0],
line2: local_address[1],
postal_code: $postal_address_code.val(),
state: $postal_address_region.val(),
},
email: $form.find('input[name="owner.email"]').val(),
name: $form.find('input[name="owner.name"]').val(),
}
};
stripe.createPaymentMethod(pmType, element, pmData).then(Liberapay.wrap(function(result) {
if (result.error) {
$errorElement.text(result.error.message);
} else {
submitting = true;
$form.find('input[name="route"]').remove();
$form.find('input[name="stripe_pm_id"]').remove();
var $hidden_input = $('<input type="hidden" name="stripe_pm_id">');
$hidden_input.val(result.paymentMethod.id);
$form.append($hidden_input);
$form.submit();
}
}));
if (element_type == 'iban') {
var tokenData = {
currency: 'EUR',
account_holder_name: $form.find('input[name="owner.name"]').val(),
address_country: $postal_address_country.val(),
address_state: $postal_address_region.val(),
address_city: $postal_address_city.val(),
address_zip: $postal_address_code.val(),
address_line1: local_address[0],
address_line2: local_address[1],
};
stripe.createToken(element, tokenData).then(Liberapay.wrap(function(result) {
if (result.error) {
$errorElement.text(result.error.message);
} else {
submitting = true;
$form.find('input[name="route"]').remove();
$form.find('input[name="token"]').remove();
var $hidden_input = $('<input type="hidden" name="token">');
$hidden_input.val(result.token.id);
$form.append($hidden_input);
$form.submit();
}
}));
} else {
var pmData = {
billing_details: {
address: {
city: $postal_address_city.val(),
country: $postal_address_country.val(),
line1: local_address[0],
line2: local_address[1],
postal_code: $postal_address_code.val(),
state: $postal_address_region.val(),
},
email: $form.find('input[name="owner.email"]').val(),
name: $form.find('input[name="owner.name"]').val(),
}
};
stripe.createPaymentMethod(pmType, element, pmData).then(Liberapay.wrap(function(result) {
if (result.error) {
$errorElement.text(result.error.message);
} else {
submitting = true;
$form.find('input[name="route"]').remove();
$form.find('input[name="stripe_pm_id"]').remove();
var $hidden_input = $('<input type="hidden" name="stripe_pm_id">');
$hidden_input.val(result.paymentMethod.id);
$form.append($hidden_input);
$form.submit();
}
}));
}
}));
$form.attr('action', '');
};
Expand Down
4 changes: 3 additions & 1 deletion www/%username/giving/pay/stripe/%payin_id.spt
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,20 @@ if tippees:
raise response.redirect(payer.path(
'giving/pay?redirect_reason=unaccepted_currency'
))
route_address_pattern = 'src_%' if payment_type == 'sdd' and len(tips) == 1 else '%'
routes = website.db.all("""
SELECT r
FROM exchange_routes r
WHERE r.participant = %s
AND r.status = 'chargeable'
AND r.network::text LIKE %s
AND (r.one_off IS FALSE OR r.ctime > (current_timestamp - interval '6 hours'))
AND r.address LIKE %s
ORDER BY r.is_default_for = %s DESC NULLS LAST
, r.is_default DESC NULLS LAST
, r.network = 'stripe-sdd' DESC
, r.id DESC
""", (payer.id, 'stripe-' + (payment_type or '%'), payment.currency))
""", (payer.id, 'stripe-' + (payment_type or '%'), route_address_pattern, payment.currency))
if routes:
route = None
while routes:
Expand Down

0 comments on commit 9eba56b

Please sign in to comment.